Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
924098a5
Commit
924098a5
authored
Jan 04, 2019
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename BodyFragmentNew to BodyFragment
parent
71db08b4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
269 additions
and
504 deletions
+269
-504
app/src/main/java/app/insti/Utils.java
app/src/main/java/app/insti/Utils.java
+2
-4
app/src/main/java/app/insti/fragment/BodyFragment.java
app/src/main/java/app/insti/fragment/BodyFragment.java
+265
-76
app/src/main/java/app/insti/fragment/BodyFragmentNew.java
app/src/main/java/app/insti/fragment/BodyFragmentNew.java
+0
-421
app/src/main/res/layout/fragment_body.xml
app/src/main/res/layout/fragment_body.xml
+1
-2
app/src/main/res/layout/fragment_body_fragment_new.xml
app/src/main/res/layout/fragment_body_fragment_new.xml
+1
-1
No files found.
app/src/main/java/app/insti/Utils.java
View file @
924098a5
...
@@ -20,7 +20,6 @@ import com.google.gson.Gson;
...
@@ -20,7 +20,6 @@ import com.google.gson.Gson;
import
com.squareup.picasso.Callback
;
import
com.squareup.picasso.Callback
;
import
com.squareup.picasso.Picasso
;
import
com.squareup.picasso.Picasso
;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -31,7 +30,6 @@ import app.insti.api.model.Event;
...
@@ -31,7 +30,6 @@ import app.insti.api.model.Event;
import
app.insti.api.model.Notification
;
import
app.insti.api.model.Notification
;
import
app.insti.api.model.User
;
import
app.insti.api.model.User
;
import
app.insti.fragment.BodyFragment
;
import
app.insti.fragment.BodyFragment
;
import
app.insti.fragment.BodyFragmentNew
;
import
app.insti.fragment.EventFragment
;
import
app.insti.fragment.EventFragment
;
import
app.insti.fragment.TransitionTargetChild
;
import
app.insti.fragment.TransitionTargetChild
;
import
app.insti.fragment.TransitionTargetFragment
;
import
app.insti.fragment.TransitionTargetFragment
;
...
@@ -141,11 +139,11 @@ public final class Utils {
...
@@ -141,11 +139,11 @@ public final class Utils {
.
commit
();
.
commit
();
}
}
public
static
BodyFragment
New
getBodyFragment
(
Body
body
,
boolean
sharedElements
)
{
public
static
BodyFragment
getBodyFragment
(
Body
body
,
boolean
sharedElements
)
{
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
body
));
bundle
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
body
));
bundle
.
putBoolean
(
Constants
.
NO_SHARED_ELEM
,
!
sharedElements
);
bundle
.
putBoolean
(
Constants
.
NO_SHARED_ELEM
,
!
sharedElements
);
BodyFragment
New
bodyFragment
=
new
BodyFragmentNew
();
BodyFragment
bodyFragment
=
new
BodyFragment
();
bodyFragment
.
setArguments
(
bundle
);
bodyFragment
.
setArguments
(
bundle
);
return
bodyFragment
;
return
bodyFragment
;
}
}
...
...
app/src/main/java/app/insti/fragment/BodyFragment.java
View file @
924098a5
...
@@ -5,15 +5,13 @@ import android.animation.Animator;
...
@@ -5,15 +5,13 @@ import android.animation.Animator;
import
android.animation.AnimatorListenerAdapter
;
import
android.animation.AnimatorListenerAdapter
;
import
android.animation.AnimatorSet
;
import
android.animation.AnimatorSet
;
import
android.animation.ObjectAnimator
;
import
android.animation.ObjectAnimator
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.graphics.Color
;
import
android.graphics.Point
;
import
android.graphics.Point
;
import
android.graphics.Rect
;
import
android.graphics.Rect
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.widget.NestedScrollView
;
import
android.support.v4.widget.SwipeRefreshLayout
;
import
android.support.v4.widget.SwipeRefreshLayout
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.RecyclerView
;
...
@@ -22,11 +20,7 @@ import android.view.LayoutInflater;
...
@@ -22,11 +20,7 @@ import android.view.LayoutInflater;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.view.animation.DecelerateInterpolator
;
import
android.view.animation.DecelerateInterpolator
;
import
android.widget.Button
;
import
android.widget.ImageButton
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.squareup.picasso.Picasso
;
import
com.squareup.picasso.Picasso
;
...
@@ -36,21 +30,19 @@ import java.util.List;
...
@@ -36,21 +30,19 @@ import java.util.List;
import
app.insti.Constants
;
import
app.insti.Constants
;
import
app.insti.R
;
import
app.insti.R
;
import
app.insti.ShareURLMaker
;
import
app.insti.Utils
;
import
app.insti.Utils
;
import
app.insti.activity.MainActivity
;
import
app.insti.activity.MainActivity
;
import
app.insti.adapter.BodyAdapter
;
import
app.insti.adapter.GenericAdapter
;
import
app.insti.adapter.FeedAdapter
;
import
app.insti.adapter.UserAdapter
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.model.Body
;
import
app.insti.api.model.Body
;
import
app.insti.api.model.Event
;
import
app.insti.api.model.Role
;
import
app.insti.api.model.Role
;
import
app.insti.api.model.User
;
import
app.insti.api.model.User
;
import
app.insti.interfaces.CardInterface
;
import
app.insti.utils.BodyHeadCard
;
import
app.insti.utils.TitleCard
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Response
;
import
ru.noties.markwon.Markwon
;
/**
/**
* A simple {@link Fragment} subclass.
* A simple {@link Fragment} subclass.
...
@@ -58,10 +50,32 @@ import ru.noties.markwon.Markwon;
...
@@ -58,10 +50,32 @@ import ru.noties.markwon.Markwon;
* create an instance of this fragment.
* create an instance of this fragment.
*/
*/
public
class
BodyFragment
extends
BackHandledFragment
implements
TransitionTargetFragment
{
public
class
BodyFragment
extends
BackHandledFragment
implements
TransitionTargetFragment
{
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
String
TAG
=
"BodyFragment"
;
String
TAG
=
"BodyFragment"
;
// TODO: Rename and change types of parameters
private
Body
min_body
;
private
Body
min_body
;
private
SwipeRefreshLayout
bodySwipeRefreshLayout
;
// Hold a reference to the current animator,
// so that it can be canceled mid-way.
private
Animator
mCurrentAnimator
;
// The system "short" animation time duration, in milliseconds. This
// duration is ideal for subtle animations or animations that occur
// very frequently.
private
int
mShortAnimationDuration
;
private
boolean
zoomMode
;
private
ImageView
expandedImageView
;
private
Rect
startBounds
;
private
float
startScaleFinal
;
private
ImageView
bodyPicture
;
private
Body
body
;
private
Body
body
;
private
boolean
bodyDisplayed
=
false
;
private
boolean
bodyDisplayed
=
false
;
private
boolean
transitionEnded
=
false
;
public
BodyFragment
()
{
public
BodyFragment
()
{
// Required empty public constructor
// Required empty public constructor
...
@@ -85,6 +99,18 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
...
@@ -85,6 +99,18 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
@Override
@Override
public
boolean
onBackPressed
()
{
public
boolean
onBackPressed
()
{
if
(
zoomMode
)
{
zoomOut
(
expandedImageView
,
startBounds
,
startScaleFinal
,
bodyPicture
);
zoomMode
=
false
;
/* Show fab if the user has access */
if
(((
MainActivity
)
getActivity
()).
editBodyAccess
(
body
))
{
final
FloatingActionButton
fab
=
getView
().
findViewById
(
R
.
id
.
edit_fab
);
fab
.
show
();
}
return
true
;
}
return
false
;
return
false
;
}
}
...
@@ -99,6 +125,9 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
...
@@ -99,6 +125,9 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
@Override
@Override
public
void
transitionEnd
()
{
public
void
transitionEnd
()
{
if
(
getActivity
()
==
null
||
getView
()
==
null
)
return
;
if
(
getActivity
()
==
null
||
getView
()
==
null
)
return
;
bodyPicture
=
(
ImageView
)
getView
().
findViewById
(
R
.
id
.
body_picture
);
Utils
.
loadImageWithPlaceholder
(
bodyPicture
,
body
.
getBodyImageURL
());
transitionEnded
=
true
;
}
}
@Override
@Override
...
@@ -107,10 +136,25 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
...
@@ -107,10 +136,25 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
/* Initialize */
/* Initialize */
bodyDisplayed
=
false
;
bodyDisplayed
=
false
;
body
=
min_body
;
int
index
=
Utils
.
bodyCache
.
indexOf
(
min_body
);
if
(
index
<
0
)
{
body
=
min_body
;
updateBody
();
}
else
{
body
=
Utils
.
bodyCache
.
get
(
index
);
}
displayBody
();
displayBody
();
updateBody
();
bodySwipeRefreshLayout
=
getActivity
().
findViewById
(
R
.
id
.
body_swipe_refresh_layout
);
bodySwipeRefreshLayout
.
setOnRefreshListener
(
new
SwipeRefreshLayout
.
OnRefreshListener
()
{
@Override
public
void
onRefresh
()
{
bodyDisplayed
=
false
;
updateBody
();
}
});
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
toolbar
);
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
toolbar
);
toolbar
.
setTitle
(
min_body
.
getBodyName
());
toolbar
.
setTitle
(
min_body
.
getBodyName
());
...
@@ -128,17 +172,19 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
...
@@ -128,17 +172,19 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
public
void
onResponse
(
Call
<
Body
>
call
,
Response
<
Body
>
response
)
{
public
void
onResponse
(
Call
<
Body
>
call
,
Response
<
Body
>
response
)
{
if
(
response
.
isSuccessful
())
{
if
(
response
.
isSuccessful
())
{
Body
bodyResponse
=
response
.
body
();
Body
bodyResponse
=
response
.
body
();
Utils
.
bodyCache
.
updateCache
(
response
.
body
());
if
(!
bodyDisplayed
)
{
if
(!
bodyDisplayed
)
{
body
=
bodyResponse
;
body
=
bodyResponse
;
displayBody
();
displayBody
();
}
}
bodySwipeRefreshLayout
.
setRefreshing
(
false
);
}
}
}
}
@Override
@Override
public
void
onFailure
(
Call
<
Body
>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
Body
>
call
,
Throwable
t
)
{
// Network Error
bodySwipeRefreshLayout
.
setRefreshing
(
false
);
}
}
});
});
}
}
...
@@ -146,87 +192,230 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
...
@@ -146,87 +192,230 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
private
void
displayBody
()
{
private
void
displayBody
()
{
/* Skip if we're already destroyed */
/* Skip if we're already destroyed */
if
(
getActivity
()
==
null
||
getView
()
==
null
)
return
;
if
(
getActivity
()
==
null
||
getView
()
==
null
)
return
;
if
(!
body
.
equals
(
min_body
))
bodyDisplayed
=
true
;
if
(!
(
body
==
min_body
))
bodyDisplayed
=
true
;
TextView
bodyName
=
(
TextView
)
getView
().
findViewById
(
R
.
id
.
body_name
);
bodyPicture
=
(
ImageView
)
getActivity
().
findViewById
(
R
.
id
.
body_picture
);
TextView
bodySubtitle
=
getView
().
findViewById
(
R
.
id
.
body_subtitle
);
TextView
bodyDescription
=
(
TextView
)
getView
().
findViewById
(
R
.
id
.
body_description
);
ImageButton
webBodyButton
=
getActivity
().
findViewById
(
R
.
id
.
web_body_button
);
ImageButton
shareBodyButton
=
getActivity
().
findViewById
(
R
.
id
.
share_body_button
);
final
Button
followButton
=
getActivity
().
findViewById
(
R
.
id
.
follow_button
);
/* Set body information */
/* Load only low res image if transition is not completed */
bodyName
.
setText
(
body
.
getBodyName
());
if
(
transitionEnded
)
{
bodySubtitle
.
setText
(
body
.
getBodyShortDescription
());
Utils
.
loadImageWithPlaceholder
(
bodyPicture
,
body
.
getBodyImageURL
());
}
else
{
Picasso
.
get
().
load
(
Utils
.
resizeImageUrl
(
body
.
getBodyImageURL
())).
into
(
bodyPicture
);
}
/*
Return if it's a
min body */
/*
Skip for
min body */
if
(
body
.
getBodyDescription
()
==
null
)
{
if
(
body
==
min_body
)
{
return
;
return
;
}
}
Markwon
.
setMarkdown
(
bodyDescription
,
body
.
getBodyDescription
());
bodyPicture
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
/* Check if user is already following
* Initialize follow button */
followButton
.
setBackgroundColor
(
getResources
().
getColor
(
body
.
getBodyUserFollows
()
?
R
.
color
.
colorAccent
:
R
.
color
.
colorWhite
));
followButton
.
setText
(
EventFragment
.
getCountBadgeSpannable
(
"FOLLOW"
,
body
.
getBodyFollowersCount
()));
followButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
view
)
{
public
void
onClick
(
View
v
)
{
RetrofitInterface
retrofitInterface
=
Utils
.
getRetrofitInterface
();
zoomImageFromThumb
(
bodyPicture
);
retrofitInterface
.
updateBodyFollowing
(
Utils
.
getSessionIDHeader
(),
body
.
getBodyID
(),
body
.
getBodyUserFollows
()
?
0
:
1
).
enqueue
(
new
Callback
<
Void
>()
{
final
FloatingActionButton
fab
=
getView
().
findViewById
(
R
.
id
.
edit_fab
);
@Override
fab
.
hide
();
public
void
onResponse
(
Call
<
Void
>
call
,
Response
<
Void
>
response
)
{
if
(
response
.
isSuccessful
())
{
body
.
setBodyUserFollows
(!
body
.
getBodyUserFollows
());
body
.
setBodyFollowersCount
(
body
.
getBodyUserFollows
()?
body
.
getBodyFollowersCount
()+
1
:
body
.
getBodyFollowersCount
()-
1
);
followButton
.
setBackgroundColor
(
getResources
().
getColor
(
body
.
getBodyUserFollows
()
?
R
.
color
.
colorAccent
:
R
.
color
.
colorWhite
));
followButton
.
setText
(
EventFragment
.
getCountBadgeSpannable
(
"FOLLOW"
,
body
.
getBodyFollowersCount
()));
}
}
@Override
public
void
onFailure
(
Call
<
Void
>
call
,
Throwable
t
)
{
Toast
.
makeText
(
getContext
(),
"Network Error"
,
Toast
.
LENGTH_LONG
).
show
();
}
});
}
}
});
});
mShortAnimationDuration
=
getResources
().
getInteger
(
android
.
R
.
integer
.
config_shortAnimTime
);
final
List
<
Role
>
roles
=
body
.
getBodyRoles
();
final
List
<
User
>
users
=
new
ArrayList
<>();
for
(
Role
role
:
roles
)
{
if
(
role
.
getRoleUsersDetail
()
!=
null
)
{
for
(
User
user
:
role
.
getRoleUsersDetail
())
{
user
.
setCurrentRole
(
role
.
getRoleName
());
users
.
add
(
user
);
}
}
}
/* Initialize web button */
final
List
<
CardInterface
>
cards
=
new
ArrayList
<>();
if
(
body
.
getBodyWebsiteURL
()
!=
null
&&
!
body
.
getBodyWebsiteURL
().
isEmpty
())
{
cards
.
add
(
new
BodyHeadCard
(
body
));
webBodyButton
.
setVisibility
(
View
.
VISIBLE
);
addWithTitleCard
(
cards
,
body
.
getBodyEvents
(),
"Events"
);
webBodyButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
addWithTitleCard
(
cards
,
users
,
"People"
);
String
bodywebURL
=
body
.
getBodyWebsiteURL
();
addWithTitleCard
(
cards
,
body
.
getBodyChildren
(),
"Organizations"
);
addWithTitleCard
(
cards
,
body
.
getBodyParents
(),
"Part of"
);
final
RecyclerView
recyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
body_recycler_view
);
GenericAdapter
genericAdapter
=
new
GenericAdapter
(
cards
,
this
);
recyclerView
.
setAdapter
(
genericAdapter
);
recyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
getActivity
().
findViewById
(
R
.
id
.
loadingPanel
).
setVisibility
(
View
.
GONE
);
/* Show update button if role */
if
(((
MainActivity
)
getActivity
()).
editBodyAccess
(
body
))
{
final
FloatingActionButton
fab
=
getView
().
findViewById
(
R
.
id
.
edit_fab
);
fab
.
show
();
recyclerView
.
addOnScrollListener
(
new
RecyclerView
.
OnScrollListener
()
{
@Override
public
void
onScrolled
(
@NonNull
RecyclerView
recyclerView
,
int
dx
,
int
dy
)
{
super
.
onScrolled
(
recyclerView
,
dx
,
dy
);
if
(
dy
>
0
)
fab
.
hide
();
else
fab
.
show
();
}
});
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
view
)
{
public
void
onClick
(
View
v
)
{
Intent
browserIntent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
bodywebURL
));
AddEventFragment
addEventFragment
=
new
AddEventFragment
();
startActivity
(
browserIntent
);
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"bodyId"
,
body
.
getBodyID
());
addEventFragment
.
setArguments
(
bundle
);
((
MainActivity
)
getActivity
()).
updateFragment
(
addEventFragment
);
}
}
});
});
}
}
}
/* Initialize share button */
private
<
R
extends
CardInterface
>
void
addWithTitleCard
(
List
<
CardInterface
>
cards
,
List
<
R
>
cardsToAdd
,
String
title
)
{
shareBodyButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
if
(
cardsToAdd
.
size
()
==
0
)
return
;
String
shareUrl
=
ShareURLMaker
.
getBodyURL
(
body
);
cards
.
add
(
new
TitleCard
(
title
));
cards
.
addAll
(
cardsToAdd
);
@Override
public
void
onClick
(
View
view
)
{
Intent
i
=
new
Intent
(
Intent
.
ACTION_SEND
);
i
.
setType
(
"text/plain"
);
i
.
putExtra
(
Intent
.
EXTRA_SUBJECT
,
"Sharing URL"
);
i
.
putExtra
(
Intent
.
EXTRA_TEXT
,
shareUrl
);
startActivity
(
Intent
.
createChooser
(
i
,
"Share URL"
));
}
});
}
}
@Override
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
Bundle
savedInstanceState
)
{
// Inflate the layout for this fragment
// Inflate the layout for this fragment
return
inflater
.
inflate
(
R
.
layout
.
fragment_body
,
container
,
false
);
return
inflater
.
inflate
(
R
.
layout
.
fragment_body_fragment_new
,
container
,
false
);
}
private
void
zoomImageFromThumb
(
final
ImageView
thumbView
)
{
// If there's an animation in progress, cancel it
// immediately and proceed with this one.
if
(
mCurrentAnimator
!=
null
)
{
mCurrentAnimator
.
cancel
();
}
// Load the high-resolution "zoomed-in" image.
expandedImageView
=
(
ImageView
)
getView
().
findViewById
(
R
.
id
.
expanded_image_body
);
expandedImageView
.
setImageDrawable
(
thumbView
.
getDrawable
());
// Calculate the starting and ending bounds for the zoomed-in image.
// This step involves lots of math. Yay, math.
startBounds
=
new
Rect
();
final
Rect
finalBounds
=
new
Rect
();
final
Point
globalOffset
=
new
Point
();
// The start bounds are the global visible rectangle of the thumbnail,
// and the final bounds are the global visible rectangle of the container
// view. Also set the container view's offset as the origin for the
// bounds, since that's the origin for the positioning animation
// properties (X, Y).
thumbView
.
getGlobalVisibleRect
(
startBounds
);
getActivity
().
findViewById
(
R
.
id
.
container_body
)
.
getGlobalVisibleRect
(
finalBounds
,
globalOffset
);
startBounds
.
offset
(-
globalOffset
.
x
,
-
globalOffset
.
y
);
finalBounds
.
offset
(-
globalOffset
.
x
,
-
globalOffset
.
y
);
// Adjust the start bounds to be the same aspect ratio as the final
// bounds using the "center crop" technique. This prevents undesirable
// stretching during the animation. Also calculate the start scaling
// factor (the end scaling factor is always 1.0).
float
startScale
;
if
((
float
)
finalBounds
.
width
()
/
finalBounds
.
height
()
>
(
float
)
startBounds
.
width
()
/
startBounds
.
height
())
{
// Extend start bounds horizontally
startScale
=
(
float
)
startBounds
.
height
()
/
finalBounds
.
height
();
float
startWidth
=
startScale
*
finalBounds
.
width
();
float
deltaWidth
=
(
startWidth
-
startBounds
.
width
())
/
2
;
startBounds
.
left
-=
deltaWidth
;
startBounds
.
right
+=
deltaWidth
;
}
else
{
// Extend start bounds vertically
startScale
=
(
float
)
startBounds
.
width
()
/
finalBounds
.
width
();
float
startHeight
=
startScale
*
finalBounds
.
height
();
float
deltaHeight
=
(
startHeight
-
startBounds
.
height
())
/
2
;
startBounds
.
top
-=
deltaHeight
;
startBounds
.
bottom
+=
deltaHeight
;
}
// Hide the thumbnail and show the zoomed-in view. When the animation
// begins, it will position the zoomed-in view in the place of the
// thumbnail.
thumbView
.
setAlpha
(
0
f
);
expandedImageView
.
setVisibility
(
View
.
VISIBLE
);
// Set the pivot point for SCALE_X and SCALE_Y transformations
// to the top-left corner of the zoomed-in view (the default
// is the center of the view).
expandedImageView
.
setPivotX
(
0
f
);
expandedImageView
.
setPivotY
(
0
f
);
// Construct and run the parallel animation of the four translation and
// scale properties (X, Y, SCALE_X, and SCALE_Y).
AnimatorSet
set
=
new
AnimatorSet
();
set
.
play
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
X
,
startBounds
.
left
,
finalBounds
.
left
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
Y
,
startBounds
.
top
,
finalBounds
.
top
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_X
,
startScale
,
1
f
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_Y
,
startScale
,
1
f
));
set
.
setDuration
(
mShortAnimationDuration
);
set
.
setInterpolator
(
new
DecelerateInterpolator
());
set
.
addListener
(
new
AnimatorListenerAdapter
()
{
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
mCurrentAnimator
=
null
;
expandedImageView
.
setBackgroundColor
(
Color
.
parseColor
(
"#9E9E9E"
));
}
@Override
public
void
onAnimationCancel
(
Animator
animation
)
{
mCurrentAnimator
=
null
;
}
});
set
.
start
();
mCurrentAnimator
=
set
;
startScaleFinal
=
startScale
;
zoomMode
=
true
;
}
private
void
zoomOut
(
final
ImageView
expandedImageView
,
Rect
startBounds
,
float
startScaleFinal
,
final
View
thumbView
)
{
expandedImageView
.
setBackgroundColor
(
0x00000000
);
if
(
mCurrentAnimator
!=
null
)
{
mCurrentAnimator
.
cancel
();
}
// Animate the four positioning/sizing properties in parallel,
// back to their original values.
AnimatorSet
set
=
new
AnimatorSet
();
set
.
play
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
X
,
startBounds
.
left
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
Y
,
startBounds
.
top
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_X
,
startScaleFinal
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_Y
,
startScaleFinal
));
set
.
setDuration
(
mShortAnimationDuration
);
set
.
setInterpolator
(
new
DecelerateInterpolator
());
set
.
addListener
(
new
AnimatorListenerAdapter
()
{
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
thumbView
.
setAlpha
(
1
f
);
expandedImageView
.
setVisibility
(
View
.
GONE
);
mCurrentAnimator
=
null
;
}
@Override
public
void
onAnimationCancel
(
Animator
animation
)
{
thumbView
.
setAlpha
(
1
f
);
expandedImageView
.
setVisibility
(
View
.
GONE
);
mCurrentAnimator
=
null
;
}
});
set
.
start
();
mCurrentAnimator
=
set
;
}
}
}
}
app/src/main/java/app/insti/fragment/BodyFragmentNew.java
deleted
100644 → 0
View file @
71db08b4
package
app.insti.fragment
;
import
android.animation.Animator
;
import
android.animation.AnimatorListenerAdapter
;
import
android.animation.AnimatorSet
;
import
android.animation.ObjectAnimator
;
import
android.graphics.Color
;
import
android.graphics.Point
;
import
android.graphics.Rect
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.widget.SwipeRefreshLayout
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.Toolbar
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.animation.DecelerateInterpolator
;
import
android.widget.ImageView
;
import
com.google.gson.Gson
;
import
com.squareup.picasso.Picasso
;
import
java.util.ArrayList
;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.R
;
import
app.insti.Utils
;
import
app.insti.activity.MainActivity
;
import
app.insti.adapter.GenericAdapter
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.model.Body
;
import
app.insti.api.model.Role
;
import
app.insti.api.model.User
;
import
app.insti.interfaces.CardInterface
;
import
app.insti.utils.BodyHeadCard
;
import
app.insti.utils.TitleCard
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
/**
* A simple {@link Fragment} subclass.
* Use the {@link BodyFragmentNew#newInstance} factory method to
* create an instance of this fragment.
*/
public
class
BodyFragmentNew
extends
BackHandledFragment
implements
TransitionTargetFragment
{
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
String
TAG
=
"BodyFragmentNew"
;
// TODO: Rename and change types of parameters
private
Body
min_body
;
private
SwipeRefreshLayout
bodySwipeRefreshLayout
;
// Hold a reference to the current animator,
// so that it can be canceled mid-way.
private
Animator
mCurrentAnimator
;
// The system "short" animation time duration, in milliseconds. This
// duration is ideal for subtle animations or animations that occur
// very frequently.
private
int
mShortAnimationDuration
;
private
boolean
zoomMode
;
private
ImageView
expandedImageView
;
private
Rect
startBounds
;
private
float
startScaleFinal
;
private
ImageView
bodyPicture
;
private
Body
body
;
private
boolean
bodyDisplayed
=
false
;
private
boolean
transitionEnded
=
false
;
public
BodyFragmentNew
()
{
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param arg_body Body for details
* @return A new instance of fragment BodyFragmentNew.
*/
// TODO: Rename and change types and number of parameters
public
static
BodyFragmentNew
newInstance
(
Body
arg_body
)
{
BodyFragmentNew
fragment
=
new
BodyFragmentNew
();
Bundle
args
=
new
Bundle
();
args
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
arg_body
));
fragment
.
setArguments
(
args
);
return
fragment
;
}
@Override
public
boolean
onBackPressed
()
{
if
(
zoomMode
)
{
zoomOut
(
expandedImageView
,
startBounds
,
startScaleFinal
,
bodyPicture
);
zoomMode
=
false
;
/* Show fab if the user has access */
if
(((
MainActivity
)
getActivity
()).
editBodyAccess
(
body
))
{
final
FloatingActionButton
fab
=
getView
().
findViewById
(
R
.
id
.
edit_fab
);
fab
.
show
();
}
return
true
;
}
return
false
;
}
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
if
(
getArguments
()
!=
null
)
{
min_body
=
new
Gson
().
fromJson
(
getArguments
().
getString
(
Constants
.
BODY_JSON
),
Body
.
class
);
}
}
@Override
public
void
transitionEnd
()
{
if
(
getActivity
()
==
null
||
getView
()
==
null
)
return
;
bodyPicture
=
(
ImageView
)
getView
().
findViewById
(
R
.
id
.
body_picture
);
Utils
.
loadImageWithPlaceholder
(
bodyPicture
,
body
.
getBodyImageURL
());
transitionEnded
=
true
;
}
@Override
public
void
onStart
()
{
super
.
onStart
();
/* Initialize */
bodyDisplayed
=
false
;
int
index
=
Utils
.
bodyCache
.
indexOf
(
min_body
);
if
(
index
<
0
)
{
body
=
min_body
;
updateBody
();
}
else
{
body
=
Utils
.
bodyCache
.
get
(
index
);
}
displayBody
();
bodySwipeRefreshLayout
=
getActivity
().
findViewById
(
R
.
id
.
body_swipe_refresh_layout
);
bodySwipeRefreshLayout
.
setOnRefreshListener
(
new
SwipeRefreshLayout
.
OnRefreshListener
()
{
@Override
public
void
onRefresh
()
{
bodyDisplayed
=
false
;
updateBody
();
}
});
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
toolbar
);
toolbar
.
setTitle
(
min_body
.
getBodyName
());
Bundle
bundle
=
getArguments
();
if
(
bundle
!=
null
&&
bundle
.
getBoolean
(
Constants
.
NO_SHARED_ELEM
,
true
))
{
this
.
transitionEnd
();
}
}
private
void
updateBody
()
{
RetrofitInterface
retrofitInterface
=
Utils
.
getRetrofitInterface
();
retrofitInterface
.
getBody
(
Utils
.
getSessionIDHeader
(),
min_body
.
getBodyID
()).
enqueue
(
new
Callback
<
Body
>()
{
@Override
public
void
onResponse
(
Call
<
Body
>
call
,
Response
<
Body
>
response
)
{
if
(
response
.
isSuccessful
())
{
Body
bodyResponse
=
response
.
body
();
Utils
.
bodyCache
.
updateCache
(
response
.
body
());
if
(!
bodyDisplayed
)
{
body
=
bodyResponse
;
displayBody
();
}
bodySwipeRefreshLayout
.
setRefreshing
(
false
);
}
}
@Override
public
void
onFailure
(
Call
<
Body
>
call
,
Throwable
t
)
{
bodySwipeRefreshLayout
.
setRefreshing
(
false
);
}
});
}
private
void
displayBody
()
{
/* Skip if we're already destroyed */
if
(
getActivity
()
==
null
||
getView
()
==
null
)
return
;
if
(!(
body
==
min_body
))
bodyDisplayed
=
true
;
bodyPicture
=
(
ImageView
)
getActivity
().
findViewById
(
R
.
id
.
body_picture
);
/* Load only low res image if transition is not completed */
if
(
transitionEnded
)
{
Utils
.
loadImageWithPlaceholder
(
bodyPicture
,
body
.
getBodyImageURL
());
}
else
{
Picasso
.
get
().
load
(
Utils
.
resizeImageUrl
(
body
.
getBodyImageURL
())).
into
(
bodyPicture
);
}
/* Skip for min body */
if
(
body
==
min_body
)
{
return
;
}
bodyPicture
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
zoomImageFromThumb
(
bodyPicture
);
final
FloatingActionButton
fab
=
getView
().
findViewById
(
R
.
id
.
edit_fab
);
fab
.
hide
();
}
});
mShortAnimationDuration
=
getResources
().
getInteger
(
android
.
R
.
integer
.
config_shortAnimTime
);
final
List
<
Role
>
roles
=
body
.
getBodyRoles
();
final
List
<
User
>
users
=
new
ArrayList
<>();
for
(
Role
role
:
roles
)
{
if
(
role
.
getRoleUsersDetail
()
!=
null
)
{
for
(
User
user
:
role
.
getRoleUsersDetail
())
{
user
.
setCurrentRole
(
role
.
getRoleName
());
users
.
add
(
user
);
}
}
}
final
List
<
CardInterface
>
cards
=
new
ArrayList
<>();
cards
.
add
(
new
BodyHeadCard
(
body
));
addWithTitleCard
(
cards
,
body
.
getBodyEvents
(),
"Events"
);
addWithTitleCard
(
cards
,
users
,
"People"
);
addWithTitleCard
(
cards
,
body
.
getBodyChildren
(),
"Organizations"
);
addWithTitleCard
(
cards
,
body
.
getBodyParents
(),
"Part of"
);
final
RecyclerView
recyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
body_recycler_view
);
GenericAdapter
genericAdapter
=
new
GenericAdapter
(
cards
,
this
);
recyclerView
.
setAdapter
(
genericAdapter
);
recyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
getActivity
().
findViewById
(
R
.
id
.
loadingPanel
).
setVisibility
(
View
.
GONE
);
/* Show update button if role */
if
(((
MainActivity
)
getActivity
()).
editBodyAccess
(
body
))
{
final
FloatingActionButton
fab
=
getView
().
findViewById
(
R
.
id
.
edit_fab
);
fab
.
show
();
recyclerView
.
addOnScrollListener
(
new
RecyclerView
.
OnScrollListener
()
{
@Override
public
void
onScrolled
(
@NonNull
RecyclerView
recyclerView
,
int
dx
,
int
dy
)
{
super
.
onScrolled
(
recyclerView
,
dx
,
dy
);
if
(
dy
>
0
)
fab
.
hide
();
else
fab
.
show
();
}
});
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
AddEventFragment
addEventFragment
=
new
AddEventFragment
();
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"bodyId"
,
body
.
getBodyID
());
addEventFragment
.
setArguments
(
bundle
);
((
MainActivity
)
getActivity
()).
updateFragment
(
addEventFragment
);
}
});
}
}
private
<
R
extends
CardInterface
>
void
addWithTitleCard
(
List
<
CardInterface
>
cards
,
List
<
R
>
cardsToAdd
,
String
title
)
{
if
(
cardsToAdd
.
size
()
==
0
)
return
;
cards
.
add
(
new
TitleCard
(
title
));
cards
.
addAll
(
cardsToAdd
);
}
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
// Inflate the layout for this fragment
return
inflater
.
inflate
(
R
.
layout
.
fragment_body_fragment_new
,
container
,
false
);
}
private
void
zoomImageFromThumb
(
final
ImageView
thumbView
)
{
// If there's an animation in progress, cancel it
// immediately and proceed with this one.
if
(
mCurrentAnimator
!=
null
)
{
mCurrentAnimator
.
cancel
();
}
// Load the high-resolution "zoomed-in" image.
expandedImageView
=
(
ImageView
)
getView
().
findViewById
(
R
.
id
.
expanded_image_body
);
expandedImageView
.
setImageDrawable
(
thumbView
.
getDrawable
());
// Calculate the starting and ending bounds for the zoomed-in image.
// This step involves lots of math. Yay, math.
startBounds
=
new
Rect
();
final
Rect
finalBounds
=
new
Rect
();
final
Point
globalOffset
=
new
Point
();
// The start bounds are the global visible rectangle of the thumbnail,
// and the final bounds are the global visible rectangle of the container
// view. Also set the container view's offset as the origin for the
// bounds, since that's the origin for the positioning animation
// properties (X, Y).
thumbView
.
getGlobalVisibleRect
(
startBounds
);
getActivity
().
findViewById
(
R
.
id
.
container_body
)
.
getGlobalVisibleRect
(
finalBounds
,
globalOffset
);
startBounds
.
offset
(-
globalOffset
.
x
,
-
globalOffset
.
y
);
finalBounds
.
offset
(-
globalOffset
.
x
,
-
globalOffset
.
y
);
// Adjust the start bounds to be the same aspect ratio as the final
// bounds using the "center crop" technique. This prevents undesirable
// stretching during the animation. Also calculate the start scaling
// factor (the end scaling factor is always 1.0).
float
startScale
;
if
((
float
)
finalBounds
.
width
()
/
finalBounds
.
height
()
>
(
float
)
startBounds
.
width
()
/
startBounds
.
height
())
{
// Extend start bounds horizontally
startScale
=
(
float
)
startBounds
.
height
()
/
finalBounds
.
height
();
float
startWidth
=
startScale
*
finalBounds
.
width
();
float
deltaWidth
=
(
startWidth
-
startBounds
.
width
())
/
2
;
startBounds
.
left
-=
deltaWidth
;
startBounds
.
right
+=
deltaWidth
;
}
else
{
// Extend start bounds vertically
startScale
=
(
float
)
startBounds
.
width
()
/
finalBounds
.
width
();
float
startHeight
=
startScale
*
finalBounds
.
height
();
float
deltaHeight
=
(
startHeight
-
startBounds
.
height
())
/
2
;
startBounds
.
top
-=
deltaHeight
;
startBounds
.
bottom
+=
deltaHeight
;
}
// Hide the thumbnail and show the zoomed-in view. When the animation
// begins, it will position the zoomed-in view in the place of the
// thumbnail.
thumbView
.
setAlpha
(
0
f
);
expandedImageView
.
setVisibility
(
View
.
VISIBLE
);
// Set the pivot point for SCALE_X and SCALE_Y transformations
// to the top-left corner of the zoomed-in view (the default
// is the center of the view).
expandedImageView
.
setPivotX
(
0
f
);
expandedImageView
.
setPivotY
(
0
f
);
// Construct and run the parallel animation of the four translation and
// scale properties (X, Y, SCALE_X, and SCALE_Y).
AnimatorSet
set
=
new
AnimatorSet
();
set
.
play
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
X
,
startBounds
.
left
,
finalBounds
.
left
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
Y
,
startBounds
.
top
,
finalBounds
.
top
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_X
,
startScale
,
1
f
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_Y
,
startScale
,
1
f
));
set
.
setDuration
(
mShortAnimationDuration
);
set
.
setInterpolator
(
new
DecelerateInterpolator
());
set
.
addListener
(
new
AnimatorListenerAdapter
()
{
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
mCurrentAnimator
=
null
;
expandedImageView
.
setBackgroundColor
(
Color
.
parseColor
(
"#9E9E9E"
));
}
@Override
public
void
onAnimationCancel
(
Animator
animation
)
{
mCurrentAnimator
=
null
;
}
});
set
.
start
();
mCurrentAnimator
=
set
;
startScaleFinal
=
startScale
;
zoomMode
=
true
;
}
private
void
zoomOut
(
final
ImageView
expandedImageView
,
Rect
startBounds
,
float
startScaleFinal
,
final
View
thumbView
)
{
expandedImageView
.
setBackgroundColor
(
0x00000000
);
if
(
mCurrentAnimator
!=
null
)
{
mCurrentAnimator
.
cancel
();
}
// Animate the four positioning/sizing properties in parallel,
// back to their original values.
AnimatorSet
set
=
new
AnimatorSet
();
set
.
play
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
X
,
startBounds
.
left
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
Y
,
startBounds
.
top
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_X
,
startScaleFinal
))
.
with
(
ObjectAnimator
.
ofFloat
(
expandedImageView
,
View
.
SCALE_Y
,
startScaleFinal
));
set
.
setDuration
(
mShortAnimationDuration
);
set
.
setInterpolator
(
new
DecelerateInterpolator
());
set
.
addListener
(
new
AnimatorListenerAdapter
()
{
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
thumbView
.
setAlpha
(
1
f
);
expandedImageView
.
setVisibility
(
View
.
GONE
);
mCurrentAnimator
=
null
;
}
@Override
public
void
onAnimationCancel
(
Animator
animation
)
{
thumbView
.
setAlpha
(
1
f
);
expandedImageView
.
setVisibility
(
View
.
GONE
);
mCurrentAnimator
=
null
;
}
});
set
.
start
();
mCurrentAnimator
=
set
;
}
}
app/src/main/res/layout/fragment_body.xml
View file @
924098a5
...
@@ -5,8 +5,7 @@
...
@@ -5,8 +5,7 @@
android:id=
"@+id/container_body"
android:id=
"@+id/container_body"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:orientation=
"vertical"
>
tools:context=
".fragment.BodyFragment"
>
<android.support.v7.widget.CardView
<android.support.v7.widget.CardView
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/fragment_body_fragment_new.xml
View file @
924098a5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:orientation=
"vertical"
tools:context=
".fragment.BodyFragment
New
"
tools:context=
".fragment.BodyFragment"
android:background=
"?attr/themeColor"
>
android:background=
"?attr/themeColor"
>
<android.support.design.widget.CoordinatorLayout
<android.support.design.widget.CoordinatorLayout
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment