Commit 510ba7ba authored by Thomas's avatar Thomas
Browse files

Fix issue #418 - Define favorite languages in settings to reduce the list when composing

parent cdaba2f3
Loading
Loading
Loading
Loading
+26 −10
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
@@ -384,13 +385,26 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
            }
        } else if (item.getItemId() == R.id.action_language) {
            final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ComposeActivity.this);
            List<Languages.Language> languages = Languages.get(ComposeActivity.this);
            Set<String> storedLanguages = sharedpreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null);

            String[] codesArr = new String[0];
            String[] languagesArr = new String[0];

            String currentCode = sharedpreferences.getString(getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, null);
            int selection = 0;

            if (storedLanguages != null && storedLanguages.size() > 0) {
                int i = 0;
                codesArr = new String[storedLanguages.size()];
                languagesArr = new String[storedLanguages.size()];
                for (String language : storedLanguages) {
                    codesArr[i] = language;
                    languagesArr[i] = language;
                    if (currentCode != null && currentCode.equalsIgnoreCase(language)) {
                        selection = i;
                    }
                    i++;
                }
            } else {
                List<Languages.Language> languages = Languages.get(ComposeActivity.this);
                if (languages != null) {
                    codesArr = new String[languages.size()];
                    languagesArr = new String[languages.size()];
@@ -404,6 +418,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
                        i++;
                    }
                }
            }

            SharedPreferences.Editor editor = sharedpreferences.edit();
            AlertDialog.Builder builder = new AlertDialog.Builder(ComposeActivity.this, Helper.dialogStyle());
            builder.setTitle(getString(R.string.message_language));
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.preference.EditTextPreference;
import androidx.preference.MultiSelectListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreferenceCompat;
@@ -45,6 +46,11 @@ public class FragmentComposeSettings extends PreferenceFragmentCompat implements
            String val = sharedPreferences.getString(getString(R.string.SET_WATERMARK_TEXT) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, sharedPreferences.getString(getString(R.string.SET_WATERMARK_TEXT), null));
            SET_WATERMARK_TEXT.setText(val);
        }
        MultiSelectListPreference SET_SELECTED_LANGUAGE = findPreference(getString(R.string.SET_SELECTED_LANGUAGE));
        if (SET_SELECTED_LANGUAGE != null) {
            SET_SELECTED_LANGUAGE.getContext().setTheme(Helper.dialogStyle());
        }

    }

    @Override
+15 −0
Original line number Diff line number Diff line
@@ -61,6 +61,21 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
    private boolean isViewInitialized;
    private Conversations initialConversations;

    //Allow to recreate data when detaching/attaching fragment
    public void recreate() {
        initialConversations = null;
        if (conversationList != null && conversationList.size() > 0) {
            int count = conversationList.size();
            conversationList.clear();
            conversationList = new ArrayList<>();
            if (conversationAdapter != null) {
                conversationAdapter.notifyItemRangeRemoved(0, count);
                max_id = null;
                flagLoading = false;
                route(null, false);
            }
        }
    }

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
+18 −0
Original line number Diff line number Diff line
@@ -113,6 +113,22 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
    private NotificationTypeEnum notificationType;
    private boolean aggregateNotification;

    //Allow to recreate data when detaching/attaching fragment
    public void recreate() {
        initialNotifications = null;
        if (notificationList != null && notificationList.size() > 0) {
            int count = notificationList.size();
            notificationList.clear();
            notificationList = new ArrayList<>();
            if (notificationAdapter != null) {
                notificationAdapter.notifyItemRangeRemoved(0, count);
                max_id = null;
                flagLoading = false;
                route(null, false);
            }
        }
    }

    /**
     * Return the position of the status in the ArrayList
     *
@@ -324,6 +340,8 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
            isViewInitialized = true;
            if (initialNotifications != null) {
                initializeNotificationView(initialNotifications);
            } else {
                recreate();
            }
        }
    }
+3 −2
Original line number Diff line number Diff line
@@ -170,9 +170,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
    //Allow to recreate data when detaching/attaching fragment
    public void recreate() {
        initialStatuses = null;
        int count = 0;
        if (timelineStatuses != null && timelineStatuses.size() > 0) {
            count = timelineStatuses.size();
            int count = timelineStatuses.size();
            timelineStatuses.clear();
            timelineStatuses = new ArrayList<>();
            if (statusAdapter != null) {
@@ -200,6 +199,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
            isViewInitialized = true;
            if (initialStatuses != null) {
                initializeStatusesCommonView(initialStatuses);
            } else {
                recreate();
            }
        }
        if (timelineStatuses != null && timelineStatuses.size() > 0) {
Loading