Commit 553d3f1e authored by atharvkotwal's avatar atharvkotwal

Number of followers increase/decrease on clicking follow in body

parent ec32a6de
...@@ -232,7 +232,7 @@ public class BodyFragment extends BackHandledFragment { ...@@ -232,7 +232,7 @@ public class BodyFragment extends BackHandledFragment {
* Initialize follow button */ * Initialize follow button */
followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite)); followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite));
followButton.setText(EventFragment.getCountBadgeSpannable("FOLLOW", body.getBodyFollowersCount())); followButton.setText(EventFragment.getCountBadgeSpannable("FOLLOW", body.getBodyFollowersCount()));
final boolean initial = body.getBodyUserFollows();
followButton.setOnClickListener(new View.OnClickListener() { followButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
...@@ -241,11 +241,14 @@ public class BodyFragment extends BackHandledFragment { ...@@ -241,11 +241,14 @@ public class BodyFragment extends BackHandledFragment {
@Override @Override
public void onResponse(Call<Void> call, Response<Void> response) { public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
body.setBodyUserFollows(!body.getBodyUserFollows()); body.setBodyUserFollows(!body.getBodyUserFollows());
new updateDbBody().execute(body);
followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite)); followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite));
if (body.getBodyUserFollows()) followButton.setText( body.getBodyFollowersCount() + 1 ); followButton.setText( EventFragment.getCountBadgeSpannable("FOLLOW", body.getBodyFollowersCount()) );
else {followButton.setText( body.getBodyFollowersCount() + 1 );} if (! initial ) { if (body.getBodyUserFollows()) {
followButton.setText(EventFragment.getCountBadgeSpannable("FOLLOW", body.getBodyFollowersCount()+1)); }}
else { if (!body.getBodyUserFollows()) {
followButton.setText(EventFragment.getCountBadgeSpannable("FOLLOW", body.getBodyFollowersCount()-1)); }}
} }
} }
......
...@@ -48,6 +48,8 @@ public class NewsFragment extends BaseFragment { ...@@ -48,6 +48,8 @@ public class NewsFragment extends BaseFragment {
private AppDatabase appDatabase; private AppDatabase appDatabase;
private boolean freshNewsDisplayed = false; private boolean freshNewsDisplayed = false;
private String searchQuery; private String searchQuery;
LinearLayoutManager mLayoutManager;
public static int index = -1, top = -1;
public NewsFragment() { public NewsFragment() {
// Required empty public constructor // Required empty public constructor
...@@ -125,6 +127,7 @@ public class NewsFragment extends BaseFragment { ...@@ -125,6 +127,7 @@ public class NewsFragment extends BaseFragment {
public void run(Activity pActivity) { public void run(Activity pActivity) {
try { try {
newsRecyclerView = getActivity().findViewById(R.id.news_recycler_view); newsRecyclerView = getActivity().findViewById(R.id.news_recycler_view);
newsRecyclerView.setAdapter(newsAdapter); newsRecyclerView.setAdapter(newsAdapter);
newsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); newsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
newsRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { newsRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment