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
a3ea3c2a
Commit
a3ea3c2a
authored
Oct 01, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor updateFragment into Utils
parent
c09b5ecd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
72 deletions
+61
-72
app/src/main/java/app/insti/Utils.java
app/src/main/java/app/insti/Utils.java
+45
-0
app/src/main/java/app/insti/adapter/BodyAdapter.java
app/src/main/java/app/insti/adapter/BodyAdapter.java
+3
-16
app/src/main/java/app/insti/adapter/FeedAdapter.java
app/src/main/java/app/insti/adapter/FeedAdapter.java
+1
-10
app/src/main/java/app/insti/adapter/UserAdapter.java
app/src/main/java/app/insti/adapter/UserAdapter.java
+2
-10
app/src/main/java/app/insti/fragment/NotificationsFragment.java
...c/main/java/app/insti/fragment/NotificationsFragment.java
+8
-30
app/src/main/java/app/insti/fragment/UserFragment.java
app/src/main/java/app/insti/fragment/UserFragment.java
+2
-6
No files found.
app/src/main/java/app/insti/Utils.java
View file @
a3ea3c2a
package
app.insti
;
import
android.os.Bundle
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentActivity
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentTransaction
;
import
android.widget.ImageView
;
import
com.google.gson.Gson
;
import
com.squareup.picasso.Callback
;
import
com.squareup.picasso.Picasso
;
import
app.insti.api.model.Body
;
import
app.insti.api.model.Event
;
import
app.insti.api.model.User
;
import
app.insti.fragment.BodyFragment
;
import
app.insti.fragment.EventFragment
;
import
app.insti.fragment.UserFragment
;
public
final
class
Utils
{
public
static
UpdatableList
<
Event
>
eventCache
=
new
UpdatableList
<>();
...
...
@@ -34,4 +45,38 @@ public final class Utils {
if
(
url
==
null
)
{
return
url
;
}
return
url
.
replace
(
"api.insti.app/static/"
,
"img.insti.app/static/"
+
dim
.
toString
()
+
"/"
);
}
/** Update the open fragment */
public
static
final
void
updateFragment
(
Fragment
fragment
,
FragmentActivity
fragmentActivity
)
{
FragmentTransaction
ft
=
fragmentActivity
.
getSupportFragmentManager
().
beginTransaction
();
ft
.
setCustomAnimations
(
R
.
anim
.
slide_in_left
,
R
.
anim
.
slide_out_left
,
R
.
anim
.
slide_in_right
,
R
.
anim
.
slide_out_right
);
ft
.
replace
(
R
.
id
.
framelayout_for_fragment
,
fragment
,
fragment
.
getTag
());
ft
.
addToBackStack
(
fragment
.
getTag
());
ft
.
commit
();
}
public
static
void
openBodyFragment
(
Body
body
,
FragmentActivity
fragmentActivity
)
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
body
));
BodyFragment
bodyFragment
=
new
BodyFragment
();
bodyFragment
.
setArguments
(
bundle
);
updateFragment
(
bodyFragment
,
fragmentActivity
);
}
public
static
void
openEventFragment
(
Event
event
,
FragmentActivity
fragmentActivity
)
{
String
eventJson
=
new
Gson
().
toJson
(
event
);
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
EVENT_JSON
,
eventJson
);
EventFragment
eventFragment
=
new
EventFragment
();
eventFragment
.
setArguments
(
bundle
);
updateFragment
(
eventFragment
,
fragmentActivity
);
}
public
static
void
openUserFragment
(
User
user
,
FragmentActivity
fragmentActivity
)
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
USER_ID
,
user
.
getUserID
());
UserFragment
userFragment
=
new
UserFragment
();
userFragment
.
setArguments
(
bundle
);
updateFragment
(
userFragment
,
fragmentActivity
);
}
}
app/src/main/java/app/insti/adapter/BodyAdapter.java
View file @
a3ea3c2a
...
...
@@ -2,6 +2,7 @@ package app.insti.adapter;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v7.widget.RecyclerView
;
...
...
@@ -19,6 +20,7 @@ import java.util.List;
import
app.insti.Constants
;
import
app.insti.Utils
;
import
app.insti.R
;
import
app.insti.activity.MainActivity
;
import
app.insti.api.model.Body
;
import
app.insti.fragment.BodyFragment
;
...
...
@@ -44,28 +46,13 @@ public class BodyAdapter extends RecyclerView.Adapter<BodyAdapter.ViewHolder> {
v
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
openBody
(
bodyList
.
get
(
postViewHolder
.
getAdapterPosition
()
));
Utils
.
openBodyFragment
(
bodyList
.
get
(
postViewHolder
.
getAdapterPosition
()),
fragment
.
getActivity
(
));
}
});
return
postViewHolder
;
}
/**
* Open body fragment for a body
*/
private
void
openBody
(
Body
body
)
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
body
));
BodyFragment
bodyFragment
=
new
BodyFragment
();
bodyFragment
.
setArguments
(
bundle
);
FragmentTransaction
ft
=
fragment
.
getActivity
().
getSupportFragmentManager
().
beginTransaction
();
ft
.
setCustomAnimations
(
R
.
anim
.
slide_in_left
,
R
.
anim
.
slide_out_left
,
R
.
anim
.
slide_in_right
,
R
.
anim
.
slide_out_right
);
ft
.
replace
(
R
.
id
.
framelayout_for_fragment
,
bodyFragment
,
bodyFragment
.
getTag
());
ft
.
addToBackStack
(
bodyFragment
.
getTag
());
ft
.
commit
();
}
@Override
public
void
onBindViewHolder
(
ViewHolder
holder
,
int
position
)
{
...
...
app/src/main/java/app/insti/adapter/FeedAdapter.java
View file @
a3ea3c2a
...
...
@@ -105,16 +105,7 @@ public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
postView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
String
eventJson
=
new
Gson
().
toJson
(
events
.
get
(
postViewHolder
.
getAdapterPosition
()));
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
EVENT_JSON
,
eventJson
);
EventFragment
eventFragment
=
new
EventFragment
();
eventFragment
.
setArguments
(
bundle
);
FragmentManager
manager
=
mFragment
.
getActivity
().
getSupportFragmentManager
();
FragmentTransaction
transaction
=
manager
.
beginTransaction
();
transaction
.
setCustomAnimations
(
R
.
anim
.
slide_in_left
,
R
.
anim
.
slide_out_left
,
R
.
anim
.
slide_in_right
,
R
.
anim
.
slide_out_right
);
transaction
.
replace
(
R
.
id
.
framelayout_for_fragment
,
eventFragment
,
eventFragment
.
getTag
());
transaction
.
addToBackStack
(
eventFragment
.
getTag
()).
commit
();
Utils
.
openEventFragment
(
events
.
get
(
postViewHolder
.
getAdapterPosition
()),
mFragment
.
getActivity
());
}
});
...
...
app/src/main/java/app/insti/adapter/UserAdapter.java
View file @
a3ea3c2a
...
...
@@ -17,6 +17,7 @@ import java.util.List;
import
app.insti.Constants
;
import
app.insti.R
;
import
app.insti.Utils
;
import
app.insti.api.model.User
;
import
app.insti.fragment.UserFragment
;
...
...
@@ -41,16 +42,7 @@ public class UserAdapter extends RecyclerView.Adapter<UserAdapter.ViewHolder> {
v
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
User
user
=
userList
.
get
(
postViewHolder
.
getAdapterPosition
());
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
USER_ID
,
user
.
getUserID
());
UserFragment
userFragment
=
new
UserFragment
();
userFragment
.
setArguments
(
bundle
);
FragmentTransaction
ft
=
fragment
.
getActivity
().
getSupportFragmentManager
().
beginTransaction
();
ft
.
setCustomAnimations
(
R
.
anim
.
slide_in_left
,
R
.
anim
.
slide_out_left
,
R
.
anim
.
slide_in_right
,
R
.
anim
.
slide_out_right
);
ft
.
replace
(
R
.
id
.
framelayout_for_fragment
,
userFragment
,
userFragment
.
getTag
());
ft
.
addToBackStack
(
userFragment
.
getTag
());
ft
.
commit
();
Utils
.
openUserFragment
(
userList
.
get
(
postViewHolder
.
getAdapterPosition
()),
fragment
.
getActivity
());
}
});
...
...
app/src/main/java/app/insti/fragment/NotificationsFragment.java
View file @
a3ea3c2a
...
...
@@ -17,6 +17,8 @@ import com.google.gson.Gson;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.Utils
;
import
app.insti.api.model.Event
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.R
;
import
app.insti.activity.MainActivity
;
...
...
@@ -91,47 +93,23 @@ public class NotificationsFragment extends BaseFragment {
String
sessId
=
((
MainActivity
)
getActivity
()).
getSessionIDHeader
();
retrofitInterface
.
markNotificationRead
(
sessId
,
notification
.
getNotificationId
().
toString
()).
enqueue
(
new
EmptyCallback
<
Void
>());
FragmentManager
manager
=
getActivity
().
getSupportFragmentManager
();
FragmentTransaction
transaction
=
manager
.
beginTransaction
();
String
tag
=
""
;
Bundle
bundle
=
getArguments
();
if
(
bundle
==
null
)
{
bundle
=
new
Bundle
();
}
bundle
.
putString
(
Constants
.
SESSION_ID
,
((
MainActivity
)
getActivity
()).
getSessionIDHeader
());
/* Open event */
if
(
notification
.
getNotificationActorType
().
contains
(
"event"
))
{
String
eventJson
=
new
Gson
().
toJson
(
notification
.
getNotificationActor
());
bundle
.
putString
(
Constants
.
EVENT_JSON
,
eventJson
);
EventFragment
eventFragment
=
new
EventFragment
();
eventFragment
.
setArguments
(
bundle
);
tag
=
eventFragment
.
getTag
();
transaction
.
replace
(
R
.
id
.
framelayout_for_fragment
,
eventFragment
,
tag
);
Gson
gson
=
new
Gson
();
Event
event
=
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
Event
.
class
)
;
Utils
.
openEventFragment
(
event
,
getActivity
());
}
else
if
(
notification
.
getNotificationActorType
().
contains
(
"newsentry"
))
{
NewsFragment
newsFragment
=
new
NewsFragment
();
tag
=
newsFragment
.
getTag
();
transaction
.
replace
(
R
.
id
.
framelayout_for_fragment
,
newsFragment
,
tag
);
newsFragment
.
setArguments
(
bundle
);
Utils
.
updateFragment
(
newsFragment
,
getActivity
());
}
else
if
(
notification
.
getNotificationActorType
().
contains
(
"blogentry"
))
{
Gson
gson
=
new
Gson
();
PlacementBlogPost
post
=
gson
.
fromJson
(
gson
.
toJson
(
notification
.
getNotificationActor
()),
PlacementBlogPost
.
class
);
if
(
post
.
getLink
().
contains
(
"training"
))
{
TrainingBlogFragment
trainingBlogFragment
=
new
TrainingBlogFragment
();
trainingBlogFragment
.
setArguments
(
bundle
);
tag
=
trainingBlogFragment
.
getTag
();
transaction
.
replace
(
R
.
id
.
framelayout_for_fragment
,
trainingBlogFragment
,
tag
);
Utils
.
updateFragment
(
new
TrainingBlogFragment
(),
getActivity
());
}
else
{
PlacementBlogFragment
placementBlogFragment
=
new
PlacementBlogFragment
();
placementBlogFragment
.
setArguments
(
bundle
);
tag
=
placementBlogFragment
.
getTag
();
transaction
.
replace
(
R
.
id
.
framelayout_for_fragment
,
placementBlogFragment
,
tag
);
Utils
.
updateFragment
(
new
PlacementBlogFragment
(),
getActivity
());
}
}
transaction
.
setCustomAnimations
(
R
.
anim
.
slide_in_left
,
R
.
anim
.
slide_out_left
,
R
.
anim
.
slide_in_right
,
R
.
anim
.
slide_out_right
);
transaction
.
addToBackStack
(
tag
).
commit
();
}
});
notificationsRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
notifications_recycler_view
);
...
...
app/src/main/java/app/insti/fragment/UserFragment.java
View file @
a3ea3c2a
...
...
@@ -31,6 +31,7 @@ import com.squareup.picasso.Picasso;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.Utils
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.R
;
import
app.insti.ShareURLMaker
;
...
...
@@ -147,12 +148,7 @@ public class UserFragment extends BackHandledFragment {
public
void
onItemClick
(
View
v
,
int
position
)
{
Role
role
=
roleList
.
get
(
position
);
Body
roleBody
=
role
.
getRoleBodyDetails
();
BodyFragment
bodyFragment
=
BodyFragment
.
newInstance
(
roleBody
);
FragmentTransaction
ft
=
getActivity
().
getSupportFragmentManager
().
beginTransaction
();
ft
.
setCustomAnimations
(
R
.
anim
.
slide_in_left
,
R
.
anim
.
slide_out_left
,
R
.
anim
.
slide_in_right
,
R
.
anim
.
slide_out_right
);
ft
.
replace
(
R
.
id
.
framelayout_for_fragment
,
bodyFragment
,
bodyFragment
.
getTag
());
ft
.
addToBackStack
(
bodyFragment
.
getTag
());
ft
.
commit
();
Utils
.
openBodyFragment
(
roleBody
,
getActivity
());
}
});
...
...
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