From d044d1d36fa1db148e0a14af57ca02499babe86a Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 21 Apr 2025 10:27:56 +0200 Subject: [PATCH] Disable by default the mention to the booster when replying. Can be enabled in Settings > Compose (per account) --- .../mastodon/activities/ComposeActivity.java | 9 ++- .../mastodon/ui/drawer/ComposeAdapter.java | 68 +++++++++---------- .../settings/FragmentComposeSettings.java | 14 +++- app/src/main/res/values/strings.xml | 4 +- app/src/main/res/xml/pref_compose.xml | 9 +++ 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java index d0e53c86..bfd204e7 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java @@ -502,6 +502,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana private void initializeAfterBundle(Bundle b) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + new Thread(() -> { if (b != null) { statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY); @@ -514,6 +515,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana if (account == null) { account = Helper.getCurrentAccount(ComposeActivity.this); } + boolean setMentionBooster = sharedpreferences.getBoolean(getString(R.string.SET_MENTION_BOOSTER) + account.user_id + account.instance, false); + editMessageId = b.getString(Helper.ARG_EDIT_STATUS_ID, null); instance = b.getString(Helper.ARG_INSTANCE, null); token = b.getString(Helper.ARG_TOKEN, null); @@ -523,7 +526,11 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana } else if (visibility == null && Helper.getCurrentAccount(ComposeActivity.this) != null && Helper.getCurrentAccount(ComposeActivity.this).mastodon_account != null && Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.source != null) { visibility = Helper.getCurrentAccount(ComposeActivity.this).mastodon_account.source.privacy; } - mentionBooster = (Account) b.getSerializable(Helper.ARG_MENTION_BOOSTER); + if(setMentionBooster) { + mentionBooster = (Account) b.getSerializable(Helper.ARG_MENTION_BOOSTER); + } else { + mentionBooster = null; + } accountMention = (Account) b.getSerializable(Helper.ARG_ACCOUNT_MENTION); //Shared elements sharedAttachments = (ArrayList) b.getSerializable(Helper.ARG_MEDIA_ATTACHMENTS); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java index 92d04578..53b01946 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java @@ -315,7 +315,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (statusDraft.mentions != null && (statusDraft.text == null || statusDraft.text.isEmpty()) && !statusDraft.mentions.isEmpty()) { //Retrieves mentioned accounts + OP and adds them at the beginin of the toot final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); Mention inReplyToUser; @@ -426,25 +426,25 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (instanceInfo != null && instanceInfo.getMimeTypeImage() != null && !instanceInfo.getMimeTypeImage().isEmpty()) { mimetypes = instanceInfo.getMimeTypeImage().toArray(new String[0]); } else { mimetypes = new String[]{"image/*"}; } } else if (type == ComposeActivity.mediaType.VIDEO) { - if (instanceInfo != null && instanceInfo.getMimeTypeVideo() != null && instanceInfo.getMimeTypeVideo().size() > 0) { + if (instanceInfo != null && instanceInfo.getMimeTypeVideo() != null && !instanceInfo.getMimeTypeVideo().isEmpty()) { mimetypes = instanceInfo.getMimeTypeVideo().toArray(new String[0]); } else { mimetypes = new String[]{"video/*"}; } } else if (type == ComposeActivity.mediaType.AUDIO) { - if (instanceInfo != null && instanceInfo.getMimeTypeAudio() != null && instanceInfo.getMimeTypeAudio().size() > 0) { + if (instanceInfo != null && instanceInfo.getMimeTypeAudio() != null && !instanceInfo.getMimeTypeAudio().isEmpty()) { mimetypes = instanceInfo.getMimeTypeAudio().toArray(new String[0]); } else { mimetypes = new String[]{"audio/*"}; } } else if (type == ComposeActivity.mediaType.ALL) { - if (instanceInfo != null && instanceInfo.getMimeTypeOther() != null && instanceInfo.getMimeTypeOther().size() > 0) { + if (instanceInfo != null && instanceInfo.getMimeTypeOther() != null && !instanceInfo.getMimeTypeOther().isEmpty()) { mimetypes = instanceInfo.getMimeTypeOther().toArray(new String[0]); } else { mimetypes = new String[]{"*/*"}; @@ -509,9 +509,9 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (!mentions.isEmpty()) { for (String mention : mentions) { newContent[0] += mention + " "; } @@ -734,7 +734,7 @@ public class ComposeAdapter extends RecyclerView.Adapter quotes = gson.fromJson(json, new TypeToken>() { }.getType()); - if (quotes != null && quotes.size() > 0) { + if (quotes != null && !quotes.isEmpty()) { final int random = new Random().nextInt(quotes.size()); Quotes.Quote quote = quotes.get(random); newContent[0] += quote.content + "\n- " + quote.author; @@ -762,7 +762,7 @@ public class ComposeAdapter extends RecyclerView.Adapter= oldContent.length()) deltaSearch = oldContent.substring(currentCursorPosition - searchLength); } - if (!search.equals("")) + if (!search.isEmpty()) deltaSearch = deltaSearch.replace("@" + search, ""); String newContent = oldContent.substring(0, currentCursorPosition - searchLength); newContent += deltaSearch; @@ -886,10 +886,10 @@ public class ComposeAdapter extends RecyclerView.Adapter { - if (results == null || results.hashtags == null || results.hashtags.size() == 0) { + if (results == null || results.hashtags == null || results.hashtags.isEmpty()) { return; } - if (camelTags != null && camelTags.size() > 0) { + if (camelTags != null && !camelTags.isEmpty()) { for (String camelTag : camelTags) { Tag tag = new Tag(); tag.name = camelTag; @@ -931,7 +931,7 @@ public class ComposeAdapter extends RecyclerView.Adapter { List emojisToDisplay = new ArrayList<>(); try { - if (emojisList == null || emojisList.size() == 0) { + if (emojisList == null || emojisList.isEmpty()) { emojisList = new EmojiInstance(context).getEmojiList(BaseMainActivity.currentInstance); } if (emojis == null) { @@ -997,7 +997,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (title != null && !title.trim().isEmpty()) { contentBuilder.append(title); - } else if (subject != null && subject.trim().length() > 0) { + } else if (subject != null && !subject.trim().isEmpty()) { contentBuilder.append(subject); } @@ -1059,12 +1059,12 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (description != null && !description.trim().isEmpty()) { if (url != null && !description.contains(url)) { contentBuilder.append(url).append("\n\n"); } contentBuilder.append("> ").append(description); - } else if (content != null && content.trim().length() > 0) { + } else if (content != null && !content.trim().isEmpty()) { if (!content.contains(url)) { contentBuilder.append(url).append("\n\n"); } @@ -1311,7 +1311,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (status != null && status.media_attachments != null && !status.media_attachments.isEmpty()) { int mediaPosition = 0; for (Attachment attachment : status.media_attachments) { if (attachment.description == null || attachment.description.trim().isEmpty()) { @@ -1355,7 +1355,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (status.media_attachments != null && !status.media_attachments.isEmpty()) { holder.binding.simpleMedia.removeAllViews(); List attachmentList = statusList.get(position).media_attachments; for (Attachment attachment : attachmentList) { @@ -1449,7 +1449,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (accountFromUser.fields != null && !accountFromUser.fields.isEmpty()) { for (Field field : accountFromUser.fields) { if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { statusList.get(position).pronouns = Helper.parseHtml(field.value); @@ -1572,16 +1572,16 @@ public class ComposeAdapter extends RecyclerView.Adapter { if (instanceInfo.configuration.media_attachments.supported_mime_types != null) { - if (instanceInfo.getMimeTypeAudio().size() == 0) { + if (instanceInfo.getMimeTypeAudio().isEmpty()) { holder.binding.buttonAttachAudio.setEnabled(false); } - if (instanceInfo.getMimeTypeImage().size() == 0) { + if (instanceInfo.getMimeTypeImage().isEmpty()) { holder.binding.buttonAttachImage.setEnabled(false); } - if (instanceInfo.getMimeTypeVideo().size() == 0) { + if (instanceInfo.getMimeTypeVideo().isEmpty()) { holder.binding.buttonAttachVideo.setEnabled(false); } - if (instanceInfo.getMimeTypeOther().size() == 0) { + if (instanceInfo.getMimeTypeOther().isEmpty()) { holder.binding.buttonAttachManual.setEnabled(false); } } @@ -1689,7 +1689,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (statusDraft.spoilerChecked || statusDraft.spoiler_text != null && !statusDraft.spoiler_text.trim().isEmpty()) { holder.binding.contentSpoiler.setVisibility(View.VISIBLE); } else { holder.binding.contentSpoiler.setVisibility(View.GONE); @@ -1709,7 +1709,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (emojis != null && !emojis.isEmpty()) { holder.binding.buttonEmoji.setVisibility(View.VISIBLE); } else { holder.binding.buttonEmoji.setVisibility(View.GONE); @@ -1785,7 +1785,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (!camelCaseTags.isEmpty()) { statusDraft.text += "\n\n"; int lenght = 0; for (String tag : camelCaseTags) { @@ -1819,7 +1819,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (!camelCaseTags.isEmpty()) { statusList.get(position).tagAdded = true; int lenght = 0; for (String tag : camelCaseTags) { @@ -1902,7 +1902,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + if (storedLanguages != null && !storedLanguages.isEmpty()) { int i = 0; codesArr = new String[storedLanguages.size()]; languagesArr = new String[storedLanguages.size()]; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentComposeSettings.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentComposeSettings.java index 2b27992e..232d731c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentComposeSettings.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentComposeSettings.java @@ -23,6 +23,7 @@ import androidx.preference.ListPreference; import androidx.preference.MultiSelectListPreference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; +import androidx.preference.SwitchPreferenceCompat; import java.util.List; import java.util.Objects; @@ -59,6 +60,12 @@ public class FragmentComposeSettings extends PreferenceFragmentCompat implements SET_WATERMARK_TEXT.setText(val); } + SwitchPreferenceCompat SET_MENTION_BOOSTER = findPreference(getString(R.string.SET_MENTION_BOOSTER)); + if (SET_MENTION_BOOSTER != null) { + boolean val = sharedPreferences.getBoolean(getString(R.string.SET_MENTION_BOOSTER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, sharedPreferences.getBoolean(getString(R.string.SET_MENTION_BOOSTER), false)); + SET_MENTION_BOOSTER.setChecked(val); + } + MultiSelectListPreference SET_SELECTED_LANGUAGE = findPreference(getString(R.string.SET_SELECTED_LANGUAGE)); if (SET_SELECTED_LANGUAGE != null) { @@ -66,7 +73,7 @@ public class FragmentComposeSettings extends PreferenceFragmentCompat implements Set storedLanguages = sharedPreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null); String[] selectedValue = new String[0]; - if (storedLanguages != null && storedLanguages.size() > 0) { + if (storedLanguages != null && !storedLanguages.isEmpty()) { if (storedLanguages.size() == 1 && storedLanguages.toArray()[0] == null) { sharedPreferences.edit().remove(getString(R.string.SET_SELECTED_LANGUAGE)).commit(); } else { @@ -102,6 +109,11 @@ public class FragmentComposeSettings extends PreferenceFragmentCompat implements editor.putString(getString(R.string.SET_WATERMARK_TEXT) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, sharedPreferences.getString(getString(R.string.SET_WATERMARK_TEXT), null)); editor.apply(); } + if (Objects.requireNonNull(key).equalsIgnoreCase(getString(R.string.SET_MENTION_BOOSTER))) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean(getString(R.string.SET_MENTION_BOOSTER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, sharedPreferences.getBoolean(getString(R.string.SET_MENTION_BOOSTER), false)); + editor.apply(); + } } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 302fc920..2766016d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1148,7 +1148,7 @@ SET_DISABLE_ANIMATED_EMOJI SET_CAPITALIZE SET_MENTIONS_AT_TOP - + SET_MENTION_BOOSTER SET_THREAD_MESSAGE SET_THEME_BASE SET_DYNAMICCOLOR @@ -2060,6 +2060,8 @@ Mentions at the top When replying mentions will all be added to the beginning of the message + Mention the booster + When replying to a boost, the person who boosted will be mentioned in the reply Number of media Number of replies diff --git a/app/src/main/res/xml/pref_compose.xml b/app/src/main/res/xml/pref_compose.xml index 8d5711e3..6facecb4 100644 --- a/app/src/main/res/xml/pref_compose.xml +++ b/app/src/main/res/xml/pref_compose.xml @@ -32,6 +32,15 @@ app:singleLineTitle="false" app:summary="@string/set_mention_at_top_indication" app:title="@string/set_mention_at_top" /> + + +