From b7d233b94d4c97ba23494145e246f10f57e32d8e Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Thu, 11 Mar 2021 11:34:14 -0500 Subject: [PATCH 1/3] fix #467? --- .../fragments/settings/MorePreferencesFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java index fce752e1..2b39f02b 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java @@ -45,10 +45,9 @@ import static awais.instagrabber.utils.Utils.settingsHelper; public class MorePreferencesFragment extends BasePreferencesFragment { private static final String TAG = "MorePreferencesFragment"; - private final AccountRepository accountRepository; + private AccountRepository accountRepository; public MorePreferencesFragment() { - accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(getContext())); } @Override @@ -58,6 +57,7 @@ public class MorePreferencesFragment extends BasePreferencesFragment { // screen.addPreference(new MoreHeaderPreference(getContext())); final Context context = getContext(); if (context == null) return; + accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context)); final PreferenceCategory accountCategory = new PreferenceCategory(context); accountCategory.setTitle(R.string.account); accountCategory.setIconSpaceReserved(false); From d551969da3764f4f0d2b6a3564099bf6d6fb3069 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Thu, 11 Mar 2021 14:30:33 -0500 Subject: [PATCH 2/3] close #660 --- .../fragments/main/ProfileFragment.java | 88 ++++++++++++++++--- .../repositories/FriendshipRepository.java | 5 ++ .../webservices/FriendshipService.java | 32 +++++++ .../webservices/StoriesService.java | 1 + app/src/main/res/menu/profile_menu.xml | 14 +++ app/src/main/res/values/strings.xml | 4 + 6 files changed, 130 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index a90bac90..4cb6cc64 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -122,9 +122,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe private boolean hasStories = false; private HighlightsAdapter highlightsAdapter; private HighlightsViewModel highlightsViewModel; - private MenuItem blockMenuItem; - private MenuItem restrictMenuItem; - private MenuItem chainingMenuItem; + private MenuItem blockMenuItem, restrictMenuItem, chainingMenuItem; + private MenuItem muteStoriesMenuItem, mutePostsMenuItem; private boolean highlightsFetching; private boolean postsSetupDone = false; private Set selectedFeedModels; @@ -381,6 +380,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe restrictMenuItem.setVisible(false); } } + muteStoriesMenuItem = menu.findItem(R.id.mute_stories); + if (muteStoriesMenuItem != null) { + if (profileModel != null) { + muteStoriesMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie))); + muteStoriesMenuItem.setTitle(profileModel.getFriendshipStatus().isMutingReel() ? R.string.mute_stories : R.string.unmute_stories); + } else { + muteStoriesMenuItem.setVisible(false); + } + } + mutePostsMenuItem = menu.findItem(R.id.mute_posts); + if (mutePostsMenuItem != null) { + if (profileModel != null) { + mutePostsMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie))); + mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.mute_posts : R.string.unmute_posts); + } + else { + mutePostsMenuItem.setVisible(false); + } + } chainingMenuItem = menu.findItem(R.id.chaining); if (chainingMenuItem != null) { if (profileModel != null) { @@ -459,6 +477,48 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe NavHostFragment.findNavController(this).navigate(navDirections); return true; } + if (item.getItemId() == R.id.mute_stories) { + if (!isLoggedIn) return false; + final String action = profileModel.getFriendshipStatus().isMutingReel() ? "Unmute stories" : "Mute stories"; + friendshipService.changeMute( + profileModel.getFriendshipStatus().isMutingReel(), + profileModel.getPk(), + true, + new ServiceCallback() { + @Override + public void onSuccess(final FriendshipChangeResponse result) { + Log.d(TAG, action + " success: " + result); + fetchProfileDetails(); + } + + @Override + public void onFailure(final Throwable t) { + Log.e(TAG, "Error while performing " + action, t); + } + }); + return true; + } + if (item.getItemId() == R.id.mute_posts) { + if (!isLoggedIn) return false; + final String action = profileModel.getFriendshipStatus().isMuting() ? "Unmute stories" : "Mute stories"; + friendshipService.changeMute( + profileModel.getFriendshipStatus().isMuting(), + profileModel.getPk(), + false, + new ServiceCallback() { + @Override + public void onSuccess(final FriendshipChangeResponse result) { + Log.d(TAG, action + " success: " + result); + fetchProfileDetails(); + } + + @Override + public void onFailure(final Throwable t) { + Log.e(TAG, "Error while performing " + action, t); + } + }); + return true; + } return super.onOptionsItemSelected(item); } @@ -896,21 +956,21 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } if (restrictMenuItem != null) { restrictMenuItem.setVisible(true); - if (profileModel.getFriendshipStatus().isRestricted()) { - restrictMenuItem.setTitle(R.string.unrestrict); - } else { - restrictMenuItem.setTitle(R.string.restrict); - } + restrictMenuItem.setTitle(profileModel.getFriendshipStatus().isRestricted() ? R.string.unrestrict : R.string.restrict); } if (blockMenuItem != null) { blockMenuItem.setVisible(true); - if (profileModel.getFriendshipStatus().isBlocking()) { - blockMenuItem.setTitle(R.string.unblock); - } else { - blockMenuItem.setTitle(R.string.block); - } + blockMenuItem.setTitle(profileModel.getFriendshipStatus().isBlocking() ? R.string.unblock : R.string.block); } - if (chainingMenuItem != null && !Objects.equals(profileId, myId)) { + if (muteStoriesMenuItem != null) { + muteStoriesMenuItem.setVisible(true); + muteStoriesMenuItem.setTitle(profileModel.getFriendshipStatus().isMutingReel() ? R.string.unmute_stories : R.string.mute_stories); + } + if (mutePostsMenuItem != null) { + mutePostsMenuItem.setVisible(true); + mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.unmute_posts : R.string.mute_posts); + } + if (chainingMenuItem != null) { chainingMenuItem.setVisible(true); } return; diff --git a/app/src/main/java/awais/instagrabber/repositories/FriendshipRepository.java b/app/src/main/java/awais/instagrabber/repositories/FriendshipRepository.java index 123a7a4d..b3da4772 100644 --- a/app/src/main/java/awais/instagrabber/repositories/FriendshipRepository.java +++ b/app/src/main/java/awais/instagrabber/repositories/FriendshipRepository.java @@ -29,4 +29,9 @@ public interface FriendshipRepository { Call getList(@Path("userId") long userId, @Path("type") String type, // following or followers @QueryMap(encoded = true) Map queryParams); + + @FormUrlEncoded + @POST("/api/v1/friendships/{action}/") + Call changeMute(@Path("action") String action, + @FieldMap Map form); } diff --git a/app/src/main/java/awais/instagrabber/webservices/FriendshipService.java b/app/src/main/java/awais/instagrabber/webservices/FriendshipService.java index ec69ff54..7c5da8cf 100644 --- a/app/src/main/java/awais/instagrabber/webservices/FriendshipService.java +++ b/app/src/main/java/awais/instagrabber/webservices/FriendshipService.java @@ -158,6 +158,38 @@ public class FriendshipService extends BaseService { }); } + public void changeMute(final boolean unmute, + final long targetUserId, + final boolean story, // true for story, false for posts + final ServiceCallback callback) { + final Map form = new HashMap<>(4); + form.put("_csrftoken", csrfToken); + form.put("_uid", String.valueOf(userId)); + form.put("_uuid", deviceUuid); + form.put(story ? "target_reel_author_id" : "target_posts_author_id", String.valueOf(targetUserId)); + final Call request = repository.changeMute(unmute ? + "unmute_posts_or_story_from_follow" : + "mute_posts_or_story_from_follow", + form); + request.enqueue(new Callback() { + @Override + public void onResponse(@NonNull final Call call, + @NonNull final Response response) { + if (callback != null) { + callback.onSuccess(response.body()); + } + } + + @Override + public void onFailure(@NonNull final Call call, + @NonNull final Throwable t) { + if (callback != null) { + callback.onFailure(t); + } + } + }); + } + public void getList(final boolean follower, final long targetUserId, final String maxId, diff --git a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java index 96e6866f..adfd27c6 100644 --- a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java +++ b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java @@ -137,6 +137,7 @@ public class StoriesService extends BaseService { final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray"); for (int i = 0; i < feedStoriesReel.length(); ++i) { final JSONObject node = feedStoriesReel.getJSONObject(i); + if (node.optBoolean("hide_from_feed_unit")) continue; final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner"); try { final User user = new User(userJson.getLong("pk"), diff --git a/app/src/main/res/menu/profile_menu.xml b/app/src/main/res/menu/profile_menu.xml index cb30d82c..d8950667 100644 --- a/app/src/main/res/menu/profile_menu.xml +++ b/app/src/main/res/menu/profile_menu.xml @@ -26,4 +26,18 @@ android:title="@string/action_ayml" android:visible="false" app:showAsAction="never" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ae6ec58..7e814f5e 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -123,6 +123,10 @@ Unblock Restrict Unrestrict + Mute stories + Mute posts + Unmute stories + Unmute posts Copy bio Translate bio Mutual From 9c7015ff9b94557f5599713e9b53377980f50453 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Thu, 11 Mar 2021 14:47:54 -0500 Subject: [PATCH 3/3] reorganize fav string again hopefully this is the final fix for #489 --- .../instagrabber/fragments/HashTagFragment.java | 2 +- .../instagrabber/fragments/LocationFragment.java | 2 +- .../fragments/main/ProfileFragment.java | 8 ++++---- app/src/main/res/values/strings.xml | 16 +++++++++------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java index 550d43e1..96d99644 100644 --- a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java @@ -540,7 +540,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe public void onSuccess(final Void result) { hashtagDetailsBinding.favChip.setText(R.string.favorite_short); hashtagDetailsBinding.favChip.setChipIconResource(R.drawable.ic_star_check_24); - showSnackbar(getString(R.string.added_to_favs_short)); + showSnackbar(getString(R.string.added_to_favs)); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java index 4c1c9618..ee2852c8 100644 --- a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java @@ -528,7 +528,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR public void onSuccess(final Void result) { locationDetailsBinding.favChip.setText(R.string.favorite_short); locationDetailsBinding.favChip.setChipIconResource(R.drawable.ic_star_check_24); - showSnackbar(getString(R.string.added_to_favs_short)); + showSnackbar(getString(R.string.added_to_favs)); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 4cb6cc64..7b0a1c35 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -677,7 +677,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe @Override public void onSuccess(final Favorite result) { profileDetailsBinding.favChip.setChipIconResource(R.drawable.ic_star_check_24); - profileDetailsBinding.favChip.setText(R.string.added_to_favs_short); + profileDetailsBinding.favChip.setText(R.string.favorite_short); favoriteRepository.insertOrUpdateFavorite(new Favorite( result.getId(), profileModel.getUsername(), @@ -729,9 +729,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe ), new RepositoryCallback() { @Override public void onSuccess(final Void result) { - profileDetailsBinding.favChip.setText(R.string.added_to_favs_short); + profileDetailsBinding.favChip.setText(R.string.favorite_short); profileDetailsBinding.favChip.setChipIconResource(R.drawable.ic_star_check_24); - showSnackbar(getString(R.string.added_to_favs_short)); + showSnackbar(getString(R.string.added_to_favs)); } @Override @@ -749,7 +749,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final String postCount = String.valueOf(profileModel.getMediaCount()); - SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline, + SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count, profileModel.getMediaCount() > 2000000000L ? 2000000000 : (int) profileModel.getMediaCount(), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7e814f5e..ab473cd0 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,10 +48,14 @@ Use Instadp for high definition profile pictures Import/Export Language - + %s\nPost %s\nPosts + + %s Post + %s Posts + %s\nFollower %s\nFollowers @@ -117,8 +121,7 @@ Unbookmark Follow Unfollow - Favorite - Unfavorite + Favorite Block Unblock Restrict @@ -314,14 +317,13 @@ Barista Bibliogram Material Dark - Added to Favorites - Favorited - Favorite + Added to Favorites! + Add to Favorites Accounts Hashtags Locations Unknown - Removed from Favourites + Removed from Favourites! Backup & Restore Backup Barinsta app settings, account login data, and/or favorites to a plain text or encrypted backup file for later restoration. If you\'re backing up account login data, treat the file as confidential and keep it somewhere safe!