diff --git a/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java b/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java index cce11d6..bf466a0 100644 --- a/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java +++ b/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java @@ -11,14 +11,6 @@ import android.widget.TextView; import android.widget.Toast; -import appteam.nith.hillffair.R; -import appteam.nith.hillffair.application.MyApplication; -import appteam.nith.hillffair.application.SharedPref; -import appteam.nith.hillffair.models.Dislike; -import appteam.nith.hillffair.models.Likecount; -import appteam.nith.hillffair.models.NewsfeedModel2; -import appteam.nith.hillffair.utilities.APIINTERFACE; -import appteam.nith.hillffair.utilities.Utils; import com.bumptech.glide.Glide; import com.like.LikeButton; import com.like.OnLikeListener; @@ -29,13 +21,17 @@ import java.util.Date; import java.util.Locale; +import appteam.nith.hillffair.R; +import appteam.nith.hillffair.application.MyApplication; +import appteam.nith.hillffair.application.SharedPref; +import appteam.nith.hillffair.models.Likecount; +import appteam.nith.hillffair.models.NewsfeedModel2; +import appteam.nith.hillffair.utilities.APIINTERFACE; +import appteam.nith.hillffair.utilities.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -import static appteam.nith.hillffair.R.id.lyk_status; -import static appteam.nith.hillffair.R.id.no_of_likes; - /** * Created by parvesh_dhull on 28/9/16. @@ -136,8 +132,10 @@ public void onResponse(Call call, Response response) { Likecount likes = response.body(); if (likes != null && response.isSuccess()) { if (likes.isSuccess()) { + card.setStatus(true); Log.d("id",card.get_id()); Toast.makeText(mContext, "Post Liked", Toast.LENGTH_SHORT).show(); + card.setLikes(likes.getLikes()); h.no_of_likes.setText("" + likes.getLikes()); } else { Toast.makeText(mContext, "Internal Error", Toast.LENGTH_SHORT).show(); @@ -156,20 +154,20 @@ public void onFailure(Call call, Throwable t) { @Override public void unLiked(LikeButton likeButton) { - APIINTERFACE mApiService = Utils.getRetrofitService(); - Call mservice = mApiService.dislike(card.get_id(),new SharedPref(MyApplication.getAppContext()).getUserId()); + Call mservice = mApiService.likecount(card.get_id(),new SharedPref(MyApplication.getAppContext()).getUserId()); - mservice.enqueue(new Callback() { + mservice.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { - Dislike likes1 = response.body(); - if (likes1 != null && response.isSuccess()) { - if (likes1.isSuccess()) { - + public void onResponse(Call call, Response response) { + Likecount likes = response.body(); + if (likes != null && response.isSuccess()) { + if (likes.isSuccess()) { + card.setStatus(false); Log.d("id",card.get_id()); Toast.makeText(mContext, "Post Disliked", Toast.LENGTH_SHORT).show(); - h.no_of_likes.setText("" + likes1.getDisLikes()); + card.setLikes(likes.getLikes()); + h.no_of_likes.setText("" + likes.getLikes()); } else { Toast.makeText(mContext, "Internal Error", Toast.LENGTH_SHORT).show(); @@ -178,7 +176,7 @@ public void onResponse(Call call, Response response) { } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { Toast.makeText(mContext, "Check Your Internet Connectivity and Permissions", Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/appteam/nith/hillffair/fragments/ProfileTab2.java b/app/src/main/java/appteam/nith/hillffair/fragments/ProfileTab2.java index bd3a22d..659081d 100644 --- a/app/src/main/java/appteam/nith/hillffair/fragments/ProfileTab2.java +++ b/app/src/main/java/appteam/nith/hillffair/fragments/ProfileTab2.java @@ -12,14 +12,13 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.Toast; +import com.google.gson.annotations.SerializedName; import appteam.nith.hillffair.R; import appteam.nith.hillffair.application.SharedPref; import appteam.nith.hillffair.models.ProfileDataModel; import appteam.nith.hillffair.utilities.APIINTERFACE; import appteam.nith.hillffair.utilities.Utils; -import com.google.gson.annotations.SerializedName; - import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -270,6 +269,7 @@ public void onResponse(Call call, Response r else { progress.setVisibility(View.GONE); Toast.makeText(getActivity(), "Please check your network connection and internet permission", Toast.LENGTH_LONG).show(); + } } } diff --git a/app/src/main/java/appteam/nith/hillffair/models/NewsfeedModel2.java b/app/src/main/java/appteam/nith/hillffair/models/NewsfeedModel2.java index 3eefdde..cb3e794 100644 --- a/app/src/main/java/appteam/nith/hillffair/models/NewsfeedModel2.java +++ b/app/src/main/java/appteam/nith/hillffair/models/NewsfeedModel2.java @@ -150,4 +150,8 @@ public boolean isStatus() { public void setStatus(boolean status) { this.status = status; } + + public void setLikes(int likes) { + this.likes = likes; + } }