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
e171e27a
Commit
e171e27a
authored
Oct 01, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor body adapter itemonclick into BodyAdapter.java
parent
b3883b89
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
76 deletions
+32
-76
app/src/main/java/app/insti/adapter/BodyAdapter.java
app/src/main/java/app/insti/adapter/BodyAdapter.java
+24
-5
app/src/main/java/app/insti/fragment/BodyFragment.java
app/src/main/java/app/insti/fragment/BodyFragment.java
+3
-28
app/src/main/java/app/insti/fragment/BodyRecyclerViewFragment.java
...ain/java/app/insti/fragment/BodyRecyclerViewFragment.java
+1
-17
app/src/main/java/app/insti/fragment/EventFragment.java
app/src/main/java/app/insti/fragment/EventFragment.java
+1
-14
app/src/main/java/app/insti/fragment/ExploreFragment.java
app/src/main/java/app/insti/fragment/ExploreFragment.java
+3
-12
No files found.
app/src/main/java/app/insti/adapter/BodyAdapter.java
View file @
e171e27a
package
app.insti.adapter
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.LayoutInflater
;
import
android.view.View
;
...
...
@@ -8,25 +11,26 @@ import android.view.ViewGroup;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.google.gson.Gson
;
import
com.squareup.picasso.Picasso
;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.R
;
import
app.insti.api.model.Body
;
import
app.insti.fragment.BodyFragment
;
public
class
BodyAdapter
extends
RecyclerView
.
Adapter
<
BodyAdapter
.
ViewHolder
>
{
private
List
<
Body
>
bodyList
;
private
ItemClickListener
itemClickListener
;
private
Context
context
;
private
Fragment
fragment
;
public
BodyAdapter
(
List
<
Body
>
bodyList
,
ItemClickListener
itemClickListener
)
{
public
BodyAdapter
(
List
<
Body
>
bodyList
,
Fragment
mFragment
)
{
this
.
bodyList
=
bodyList
;
this
.
itemClickListener
=
itemClickListener
;
fragment
=
mFragment
;
}
@Override
...
...
@@ -39,13 +43,28 @@ public class BodyAdapter extends RecyclerView.Adapter<BodyAdapter.ViewHolder> {
v
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
itemClickListener
.
onItemClick
(
view
,
postViewHolder
.
getAdapterPosition
(
));
openBody
(
bodyList
.
get
(
postViewHolder
.
getAdapterPosition
()
));
}
});
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/fragment/BodyFragment.java
View file @
e171e27a
...
...
@@ -36,7 +36,6 @@ import java.util.ArrayList;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.R
;
import
app.insti.ShareURLMaker
;
import
app.insti.activity.MainActivity
;
...
...
@@ -48,6 +47,7 @@ import app.insti.api.model.Body;
import
app.insti.api.model.Event
;
import
app.insti.api.model.Role
;
import
app.insti.api.model.User
;
import
app.insti.interfaces.ItemClickListener
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
...
...
@@ -314,23 +314,13 @@ public class BodyFragment extends BackHandledFragment {
/* Initialize Parent bodies */
RecyclerView
parentsRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
parentorg_card_recycler_view
);
BodyAdapter
parentAdapter
=
new
BodyAdapter
(
body
.
getBodyParents
(),
new
ItemClickListener
()
{
@Override
public
void
onItemClick
(
View
v
,
int
position
)
{
openBody
(
body
.
getBodyParents
().
get
(
position
));
}
});
BodyAdapter
parentAdapter
=
new
BodyAdapter
(
body
.
getBodyParents
(),
this
);
parentsRecyclerView
.
setAdapter
(
parentAdapter
);
parentsRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
/* Initialize child bodies */
RecyclerView
childrenRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
org_card_recycler_view
);
BodyAdapter
childrenAdapter
=
new
BodyAdapter
(
body
.
getBodyChildren
(),
new
ItemClickListener
()
{
@Override
public
void
onItemClick
(
View
v
,
int
position
)
{
openBody
(
body
.
getBodyChildren
().
get
(
position
));
}
});
BodyAdapter
childrenAdapter
=
new
BodyAdapter
(
body
.
getBodyChildren
(),
this
);
childrenRecyclerView
.
setAdapter
(
childrenAdapter
);
childrenRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
...
...
@@ -362,21 +352,6 @@ public class BodyFragment extends BackHandledFragment {
}
}
/**
* 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
=
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
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
...
...
app/src/main/java/app/insti/fragment/BodyRecyclerViewFragment.java
View file @
e171e27a
...
...
@@ -3,7 +3,6 @@ package app.insti.fragment;
import
android.os.Bundle
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.LayoutInflater
;
...
...
@@ -16,7 +15,6 @@ import com.google.gson.reflect.TypeToken;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.R
;
import
app.insti.adapter.BodyAdapter
;
import
app.insti.api.model.Body
;
...
...
@@ -65,21 +63,7 @@ public class BodyRecyclerViewFragment extends Fragment {
super
.
onStart
();
recyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
body_recycler_view
);
bodyAdapter
=
new
BodyAdapter
(
bodyList
,
new
ItemClickListener
()
{
@Override
public
void
onItemClick
(
View
v
,
int
position
)
{
Body
body
=
bodyList
.
get
(
position
);
BodyFragment
bodyFragment
=
new
BodyFragment
();
Bundle
arguments
=
getArguments
();
arguments
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
body
));
bodyFragment
.
setArguments
(
getArguments
());
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
();
}
});
bodyAdapter
=
new
BodyAdapter
(
bodyList
,
this
);
recyclerView
.
setAdapter
(
bodyAdapter
);
recyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
...
...
app/src/main/java/app/insti/fragment/EventFragment.java
View file @
e171e27a
...
...
@@ -13,7 +13,6 @@ import android.net.Uri;
import
android.os.Bundle
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v4.widget.NestedScrollView
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
...
...
@@ -42,7 +41,6 @@ import java.util.Date;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.R
;
import
app.insti.ShareURLMaker
;
import
app.insti.activity.MainActivity
;
...
...
@@ -171,18 +169,7 @@ public class EventFragment extends BackHandledFragment {
final
List
<
Body
>
bodyList
=
event
.
getEventBodies
();
bodyRecyclerView
=
(
RecyclerView
)
getActivity
().
findViewById
(
R
.
id
.
body_card_recycler_view
);
BodyAdapter
bodyAdapter
=
new
BodyAdapter
(
bodyList
,
new
ItemClickListener
()
{
@Override
public
void
onItemClick
(
View
v
,
int
position
)
{
Body
body
=
bodyList
.
get
(
position
);
BodyFragment
bodyFragment
=
BodyFragment
.
newInstance
(
body
);
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
();
}
});
BodyAdapter
bodyAdapter
=
new
BodyAdapter
(
bodyList
,
this
);
bodyRecyclerView
.
setAdapter
(
bodyAdapter
);
bodyRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
...
...
app/src/main/java/app/insti/fragment/ExploreFragment.java
View file @
e171e27a
...
...
@@ -14,23 +14,21 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.widget.EditText
;
import
com.google.gson.Gson
;
import
java.util.ArrayList
;
import
java.util.List
;
import
app.insti.Constants
;
import
app.insti.interfaces.ItemClickListener
;
import
app.insti.R
;
import
app.insti.activity.MainActivity
;
import
app.insti.adapter.BodyAdapter
;
import
app.insti.adapter.FeedAdapter
;
import
app.insti.adapter.UserAdapter
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.response.ExploreResponse
;
import
app.insti.api.model.Body
;
import
app.insti.api.model.Event
;
import
app.insti.api.model.User
;
import
app.insti.api.response.ExploreResponse
;
import
app.insti.interfaces.ItemClickListener
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
...
...
@@ -178,14 +176,7 @@ public class ExploreFragment extends Fragment {
if
(
getActivity
()
==
null
||
getView
()
==
null
)
return
;
// Bodies
RecyclerView
bodiesRecyclerView
=
getView
().
findViewById
(
R
.
id
.
explore_body_recycler_view
);
bodyAdapter
=
new
BodyAdapter
(
bodies
,
new
ItemClickListener
()
{
@Override
public
void
onItemClick
(
View
v
,
int
position
)
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
Constants
.
BODY_JSON
,
new
Gson
().
toJson
(
bodies
.
get
(
position
)));
updateFragment
(
new
BodyFragment
(),
bundle
);
}
});
bodyAdapter
=
new
BodyAdapter
(
bodies
,
this
);
bodiesRecyclerView
.
setAdapter
(
bodyAdapter
);
bodiesRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
()));
...
...
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