diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index fd0f2420f0..6f14482dc4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -87,6 +87,11 @@ public static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); } + private static SharedPreferences getPreReplyPrefs(){ + return MastodonApp.context.getSharedPreferences("pre_reply_sheets", Context.MODE_PRIVATE); + } + + public static T fromJson(String json, Type type, T orElse){ if(json==null) return orElse; try{ @@ -239,12 +244,41 @@ public static void save(){ .apply(); } + public static boolean isOptedOutOfPreReplySheet(PreReplySheetType type, Account account, String accountID){ + if(getPreReplyPrefs().getBoolean("opt_out_"+type, false)) + return true; + if(account==null) + return false; + String accountKey=account.acct; + if(!accountKey.contains("@")) + accountKey+="@"+AccountSessionManager.get(accountID).domain; + return getPreReplyPrefs().getBoolean("opt_out_"+type+"_"+accountKey.toLowerCase(), false); + } + + public static void optOutOfPreReplySheet(PreReplySheetType type, Account account, String accountID){ + String key; + if(account==null){ + key="opt_out_"+type; + }else{ + String accountKey=account.acct; + if(!accountKey.contains("@")) + accountKey+="@"+AccountSessionManager.get(accountID).domain; + key="opt_out_"+type+"_"+accountKey.toLowerCase(); + } + getPreReplyPrefs().edit().putBoolean(key, true).apply(); + } + public enum ThemePreference{ AUTO, LIGHT, DARK } + public enum PreReplySheetType{ + OLD_POST, + NON_MUTUAL + } + public enum AutoRevealMode { NEVER, THREADS, @@ -309,5 +343,4 @@ private static void migrateToUpstreamVersion61(){ } //endregion - } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java index d5cb4c13ac..e17136d9e4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountLocalPreferences.java @@ -174,9 +174,4 @@ public enum ShowEmojiReactions{ ONLY_OPENED, ALWAYS } - -// public enum PreReplySheetType{ -// OLD_POST, -// NON_MUTUAL -// } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 9cfb5c5183..ea6c5f99eb 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -28,6 +28,7 @@ import org.joinmastodon.android.api.requests.polls.SubmitPollVote; import org.joinmastodon.android.api.requests.statuses.AkkomaTranslateStatus; import org.joinmastodon.android.api.requests.statuses.TranslateStatus; +import org.joinmastodon.android.api.session.AccountLocalPreferences; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.api.session.AccountSessionManager; @@ -1079,27 +1080,23 @@ public void rebuildAllDisplayItems(){ } public void maybeShowPreReplySheet(Status status, Runnable proceed){ - // TODO: figure this stuff out -// Relationship rel=getRelationship(status.account.id); -// if(!GlobalUserPreferences.isOptedOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.NON_MUTUAL, status.account, accountID) && -// !status.account.id.equals(AccountSessionManager.get(accountID).self.id) && rel!=null && !rel.followedBy && status.account.followingCount>=1){ -// new NonMutualPreReplySheet(getActivity(), notAgain->{ -// GlobalUserPreferences.optOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.NON_MUTUAL, notAgain ? null : status.account, accountID); -// proceed.run(); -// }, status.account, accountID).show(); -// }else if(!GlobalUserPreferences.isOptedOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.OLD_POST, null, null) && -// status.createdAt.isBefore(Instant.now().minus(90, ChronoUnit.DAYS))){ -// new OldPostPreReplySheet(getActivity(), notAgain->{ -// if(notAgain) -// GlobalUserPreferences.optOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.OLD_POST, null, null); -// proceed.run(); -// }, status).show(); -// }else{ -// proceed.run(); -// } - - - proceed.run(); + Relationship rel=getRelationship(status.account.id); + if(!GlobalUserPreferences.isOptedOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.NON_MUTUAL, status.account, accountID) && + !status.account.id.equals(AccountSessionManager.get(accountID).self.id) && rel!=null && !rel.followedBy && status.account.followingCount>=1){ + new NonMutualPreReplySheet(getActivity(), notAgain->{ + GlobalUserPreferences.optOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.NON_MUTUAL, notAgain ? null : status.account, accountID); + proceed.run(); + }, status.account, accountID).show(); + }else if(!GlobalUserPreferences.isOptedOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.OLD_POST, null, null) && + status.createdAt.isBefore(Instant.now().minus(90, ChronoUnit.DAYS))){ + new OldPostPreReplySheet(getActivity(), notAgain->{ + if(notAgain) + GlobalUserPreferences.optOutOfPreReplySheet(GlobalUserPreferences.PreReplySheetType.OLD_POST, null, null); + proceed.run(); + }, status).show(); + }else{ + proceed.run(); + } } protected void onModifyItemViewHolder(BindableViewHolder holder){}