From 33dc848a93e9c3ac58cf7c61277361d1754400cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schu=CC=88ller?= Date: Fri, 4 Jan 2019 23:32:07 +0100 Subject: [PATCH] - Like / dislike, basic functionality --- .../fragment/VideoMetaDataFragment.java | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java index 6184bcd..95507a6 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java @@ -72,9 +72,10 @@ public class VideoMetaDataFragment extends Fragment { if (Session.getInstance().isLoggedIn()) { + // TODO: move this out helper/service RequestBody body = RequestBody.create( - okhttp3.MediaType.parse("application/json; charset=utf-8"), - "{rating: \"none\"}" + okhttp3.MediaType.parse("application/json"), + "{\"rating\":\"like\"}" ); String apiBaseURL = APIUrlHelper.getUrlWithVersion(context); @@ -89,6 +90,7 @@ public class VideoMetaDataFragment extends Fragment { Log.v(TAG, response.toString() ); + // if 20x update likes } @Override @@ -110,7 +112,43 @@ public class VideoMetaDataFragment extends Fragment { TextView thumbsDownButton = activity.findViewById(R.id.video_thumbs_down); thumbsDownButton.setText(R.string.video_thumbs_down_icon); new Iconics.IconicsBuilder().ctx(context).on(thumbsDownButton).build(); - thumbsDownButton.setOnClickListener(v -> Toast.makeText(context, "Not Implemented", Toast.LENGTH_SHORT).show()); + thumbsDownButton.setOnClickListener(v -> { + + if (Session.getInstance().isLoggedIn()) { + + // TODO: move this out helper/service + RequestBody body = RequestBody.create( + okhttp3.MediaType.parse("application/json"), + "{\"rating\":\"dislike\"}" + ); + + String apiBaseURL = APIUrlHelper.getUrlWithVersion(context); + GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(GetVideoDataService.class); + + Call call = service.rateVideo(video.getId(), body); + + call.enqueue(new Callback() { + + @Override + public void onResponse(Call call, Response response) { + + // if 20x update likes + + Log.v(TAG, response.toString() ); + + } + + @Override + public void onFailure(Call call, Throwable t) { + Toast.makeText(context, "Rating Failed", Toast.LENGTH_SHORT).show(); + } + }); + } else { + Toast.makeText(context, "You must login to use this service", Toast.LENGTH_SHORT).show(); + + } + + }); TextView thumbsDownButtonTotal = activity.findViewById(R.id.video_thumbs_down_total); thumbsDownButtonTotal.setText(video.getDislikes().toString());