From 9ba48ebe2ecf9e758ac758c6d77a3ebfbd408605 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 11 Jan 2021 12:52:45 -0500 Subject: [PATCH] more small fixes, closes #498 --- .../fragments/PostViewV2Fragment.java | 18 ++++++++++-------- .../repositories/responses/Media.java | 7 +++++++ .../instagrabber/utils/DirectItemFactory.java | 2 ++ .../instagrabber/utils/ResponseBodyUtils.java | 1 + .../instagrabber/webservices/NewsService.java | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index 60a3b8f6..9bf4c264 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -465,16 +465,16 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im binding.date.setVisibility(View.VISIBLE); binding.date.setText(date); })); - if (viewModel.getMedia().isCommentLikesEnabled()) { - viewModel.getLikeCount().observe(getViewLifecycleOwner(), count -> { - final long safeCount = getSafeCount(count); - final String likesString = getResources().getQuantityString(R.plurals.likes_count, (int) safeCount, safeCount); - binding.likesCount.setText(likesString); - }); + viewModel.getLikeCount().observe(getViewLifecycleOwner(), count -> { + final long safeCount = getSafeCount(count); + final String likesString = getResources().getQuantityString(R.plurals.likes_count, (int) safeCount, safeCount); + binding.likesCount.setText(likesString); + }); + if (!viewModel.getMedia().isCommentsDisabled()) { viewModel.getCommentCount().observe(getViewLifecycleOwner(), count -> { final long safeCount = getSafeCount(count); final String likesString = getResources().getQuantityString(R.plurals.comments_count, (int) safeCount, safeCount); - binding.likesCount.setText(likesString); + binding.commentsCount.setText(likesString); }); } viewModel.getViewCount().observe(getViewLifecycleOwner(), count -> { @@ -538,7 +538,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im } private void setupComment() { - if (!viewModel.hasPk() || !viewModel.getMedia().isCommentLikesEnabled()) { + if (!viewModel.hasPk() || viewModel.getMedia().isCommentsDisabled()) { binding.comment.setVisibility(View.GONE); binding.commentsCount.setVisibility(View.GONE); return; @@ -577,12 +577,14 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im } private void setupLike() { + /* final boolean likableMedia = viewModel.hasPk() && viewModel.getMedia().isCommentLikesEnabled(); if (!likableMedia) { binding.like.setVisibility(View.GONE); binding.likesCount.setVisibility(View.GONE); return; } + */ if (!viewModel.isLoggedIn()) { binding.like.setVisibility(View.GONE); return; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/Media.java b/app/src/main/java/awais/instagrabber/repositories/responses/Media.java index 6667fd1e..f864a434 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/Media.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/Media.java @@ -19,6 +19,7 @@ public class Media implements Serializable { private final MediaItemType mediaType; private final boolean canViewerReshare; private final boolean commentLikesEnabled; + private final boolean commentsDisabled; private final long nextMaxId; private final long commentCount; private final ImageVersions2 imageVersions2; @@ -56,6 +57,7 @@ public class Media implements Serializable { final int originalHeight, final MediaItemType mediaType, final boolean commentLikesEnabled, + final boolean commentsDisabled, final long nextMaxId, final long commentCount, final long likeCount, @@ -87,6 +89,7 @@ public class Media implements Serializable { this.originalHeight = originalHeight; this.mediaType = mediaType; this.commentLikesEnabled = commentLikesEnabled; + this.commentsDisabled = commentsDisabled; this.nextMaxId = nextMaxId; this.commentCount = commentCount; this.likeCount = likeCount; @@ -182,6 +185,10 @@ public class Media implements Serializable { return commentLikesEnabled; } + public boolean isCommentsDisabled() { + return commentsDisabled; + } + public long getNextMaxId() { return nextMaxId; } diff --git a/app/src/main/java/awais/instagrabber/utils/DirectItemFactory.java b/app/src/main/java/awais/instagrabber/utils/DirectItemFactory.java index 44f28942..31efa897 100644 --- a/app/src/main/java/awais/instagrabber/utils/DirectItemFactory.java +++ b/app/src/main/java/awais/instagrabber/utils/DirectItemFactory.java @@ -81,6 +81,7 @@ public class DirectItemFactory { height, isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE, false, + false, -1, -1, -1, @@ -156,6 +157,7 @@ public class DirectItemFactory { 0, MediaItemType.MEDIA_TYPE_VOICE, false, + false, -1, 0, 0, diff --git a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java index 63f6fd63..b78b3d01 100644 --- a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java @@ -857,6 +857,7 @@ public final class ResponseBodyUtils { height, mediaItemType, false, + feedItem.optBoolean("comments_disabled"), -1, commentsCount, likesCount, diff --git a/app/src/main/java/awais/instagrabber/webservices/NewsService.java b/app/src/main/java/awais/instagrabber/webservices/NewsService.java index 945b1f17..407cfd4a 100644 --- a/app/src/main/java/awais/instagrabber/webservices/NewsService.java +++ b/app/src/main/java/awais/instagrabber/webservices/NewsService.java @@ -181,7 +181,7 @@ public class NewsService extends BaseService { data.getLong("profile_id"), data.getString("profile_name"), data.getString("profile_image"), - !data.isNull("media") ? data.getJSONArray("media").getJSONObject(0).getLong("id") : 0, + !data.isNull("media") ? Long.valueOf(data.getJSONArray("media").getJSONObject(0).getString("id").split("_")[0]) : 0, !data.isNull("media") ? data.getJSONArray("media").getJSONObject(0).getString("image") : null, notificationType); }