Commit d044d1d3 authored by Thomas's avatar Thomas
Browse files

Disable by default the mention to the booster when replying. Can be enabled in...

Disable by default the mention to the booster when replying. Can be enabled in Settings > Compose (per account)
parent bbd9c909
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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;
                }
                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<Attachment>) b.getSerializable(Helper.ARG_MEDIA_ATTACHMENTS);
+34 −34
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
     */
    private void manageMentions(Context context, Status statusDraft, ComposeViewHolder holder) {

        if (statusDraft.mentions != null && (statusDraft.text == null || statusDraft.text.length() == 0) && statusDraft.mentions.size() > 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<RecyclerView.ViewHolder
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        String[] mimetypes = new String[0];
        if (type == ComposeActivity.mediaType.PHOTO) {
            if (instanceInfo != null && instanceInfo.getMimeTypeImage() != null && instanceInfo.getMimeTypeImage().size() > 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<RecyclerView.ViewHolder
     */
    private boolean canBeRemoved(Status draft) {
        return draft.poll == null
                && (draft.media_attachments == null || draft.media_attachments.size() == 0)
                && (draft.text == null || draft.text.trim().length() == 0)
                && (draft.spoiler_text == null || draft.spoiler_text.trim().length() == 0);
                && (draft.media_attachments == null || draft.media_attachments.isEmpty())
                && (draft.text == null || draft.text.trim().isEmpty())
                && (draft.spoiler_text == null || draft.spoiler_text.trim().isEmpty());
    }

    /**
@@ -717,7 +717,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder

                                InputStream is;
                                newContent[0] = "";
                                if (mentions.size() > 0) {
                                if (!mentions.isEmpty()) {
                                    for (String mention : mentions) {
                                        newContent[0] += mention + " ";
                                    }
@@ -734,7 +734,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
                                    Gson gson = new Gson();
                                    List<Quotes.Quote> quotes = gson.fromJson(json, new TypeToken<List<Quotes.Quote>>() {
                                    }.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<RecyclerView.ViewHolder

                if (holder.binding.content.getSelectionStart() != 0)
                    currentCursorPosition[0] = holder.binding.content.getSelectionStart();
                if (contentString.length() == 0)
                if (contentString.isEmpty())
                    currentCursorPosition[0] = 0;
                //Only check last 15 characters before cursor position to avoid lags
                //Less than 15 characters are written before the cursor position
@@ -858,7 +858,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
                                        if (currentCursorPosition >= 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<RecyclerView.ViewHolder
                                "hashtags", false, true, false, 0,
                                null, null, 10).observe((LifecycleOwner) context,
                                results -> {
                                    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<RecyclerView.ViewHolder
                                                deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
                                        }

                                        if (!search.equals(""))
                                        if (!search.isEmpty())
                                            deltaSearch = deltaSearch.replace("#" + search, "");
                                        String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
                                        newContent += deltaSearch;
@@ -954,7 +954,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
                    new Thread(() -> {
                        List<Emoji> 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<RecyclerView.ViewHolder
                                                deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
                                        }

                                        if (!search.equals(""))
                                        if (!search.isEmpty())
                                            deltaSearch = deltaSearch.replace(":" + search, "");
                                        String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
                                        newContent += deltaSearch;
@@ -1049,9 +1049,9 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder

        StringBuilder contentBuilder = new StringBuilder();

        if (title != null && title.trim().length() > 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<RecyclerView.ViewHolder
            contentBuilder.append("\n\n");
        }

        if (description != null && description.trim().length() > 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<RecyclerView.ViewHolder
        }
        for (Status status : statusList) {
            if (getItemViewType(position) == TYPE_COMPOSE) {
                if (status != null && status.media_attachments != null && status.media_attachments.size() > 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<RecyclerView.ViewHolder
                    holder.binding.buttonAttachManual.setEnabled(false);
                    holder.binding.buttonPoll.setEnabled(true);
                }
                holder.binding.buttonPoll.setEnabled(statusDraft.media_attachments == null || statusDraft.media_attachments.size() == 0);
                holder.binding.buttonPoll.setEnabled(statusDraft.media_attachments == null || statusDraft.media_attachments.isEmpty());
            }
        }
    }
@@ -1380,7 +1380,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
            Status status = statusList.get(position);
            StatusSimpleViewHolder holder = (StatusSimpleViewHolder) viewHolder;

            if (status.media_attachments != null && status.media_attachments.size() > 0) {
            if (status.media_attachments != null && !status.media_attachments.isEmpty()) {
                holder.binding.simpleMedia.removeAllViews();
                List<Attachment> attachmentList = statusList.get(position).media_attachments;
                for (Attachment attachment : attachmentList) {
@@ -1449,7 +1449,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
                statusFromUser.pronouns = null;
                boolean pronounsSupport = sharedpreferences.getBoolean(context.getString(R.string.SET_PRONOUNS_SUPPORT), true);
                if(pronounsSupport) {
                    if (accountFromUser.fields != null && accountFromUser.fields.size() > 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<RecyclerView.ViewHolder
            holder.binding.buttonAttach.setOnClickListener(v -> {

                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<RecyclerView.ViewHolder
                unlisted_changed = true;
            });

            if (statusDraft.spoilerChecked || statusDraft.spoiler_text != null && statusDraft.spoiler_text.trim().length() > 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<RecyclerView.ViewHolder
            //Last compose drawer
            buttonVisibility(holder);

            if (emojis != null && emojis.size() > 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<RecyclerView.ViewHolder
                        camelCaseTags.add(tag);
                    }
                }
                if (camelCaseTags.size() > 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<RecyclerView.ViewHolder
                        camelCaseTags.add(tag);
                    }
                }
                if (camelCaseTags.size() > 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<RecyclerView.ViewHolder
                String[] languagesArr = new String[0];

                int selection = 0;
                if (storedLanguages != null && storedLanguages.size() > 0) {
                if (storedLanguages != null && !storedLanguages.isEmpty()) {
                    int i = 0;
                    codesArr = new String[storedLanguages.size()];
                    languagesArr = new String[storedLanguages.size()];
+13 −1
Original line number Diff line number Diff line
@@ -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<String> 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
+3 −1
Original line number Diff line number Diff line
@@ -1148,7 +1148,7 @@
    <string name="SET_DISABLE_ANIMATED_EMOJI" translatable="false">SET_DISABLE_ANIMATED_EMOJI</string>
    <string name="SET_CAPITALIZE" translatable="false">SET_CAPITALIZE</string>
    <string name="SET_MENTIONS_AT_TOP" translatable="false">SET_MENTIONS_AT_TOP</string>

    <string name="SET_MENTION_BOOSTER" translatable="false">SET_MENTION_BOOSTER</string>
    <string name="SET_THREAD_MESSAGE" translatable="false">SET_THREAD_MESSAGE</string>
    <string name="SET_THEME_BASE" translatable="false">SET_THEME_BASE</string>
    <string name="SET_DYNAMICCOLOR" translatable="false">SET_DYNAMICCOLOR</string>
@@ -2060,6 +2060,8 @@
    <string name="set_mention_at_top">Mentions at the top</string>
    <string name="set_mention_at_top_indication">When replying mentions will all be added to the beginning of the message</string>

    <string name="set_mention_booster">Mention the booster</string>
    <string name="set_mention_booster_indication">When replying to a boost, the person who boosted will be mentioned in the reply</string>

    <string name="number_of_media">Number of media</string>
    <string name="number_of_replies">Number of replies</string>
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,15 @@
        app:singleLineTitle="false"
        app:summary="@string/set_mention_at_top_indication"
        app:title="@string/set_mention_at_top" />

    <SwitchPreferenceCompat
        app:defaultValue="false"
        app:iconSpaceReserved="false"
        app:key="@string/SET_MENTION_BOOSTER"
        app:singleLineTitle="false"
        app:summary="@string/set_mention_booster_indication"
        app:title="@string/set_mention_booster" />

    <!--
    <SwitchPreferenceCompat
        app:defaultValue="false"