From 510ba7ba479c7a475ee2ce6791b57cd871417070 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 14 Nov 2022 18:47:14 +0100 Subject: [PATCH] Fix issue #418 - Define favorite languages in settings to reduce the list when composing --- .../android/activities/ComposeActivity.java | 36 +- .../settings/FragmentComposeSettings.java | 6 + .../FragmentMastodonConversation.java | 15 + .../FragmentMastodonNotification.java | 18 + .../timeline/FragmentMastodonTimeline.java | 5 +- app/src/main/res/values/strings.xml | 374 ++++++++++++++++++ app/src/main/res/xml/pref_compose.xml | 9 + 7 files changed, 451 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index 8df0e9c5d..ef6562d62 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -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,26 +385,41 @@ 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 = Languages.get(ComposeActivity.this); + Set 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 (languages != null) { - codesArr = new String[languages.size()]; - languagesArr = new String[languages.size()]; + if (storedLanguages != null && storedLanguages.size() > 0) { int i = 0; - for (Languages.Language language : languages) { - codesArr[i] = language.code; - languagesArr[i] = language.language; - if (currentCode != null && currentCode.equalsIgnoreCase(language.code)) { + 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 = Languages.get(ComposeActivity.this); + if (languages != null) { + codesArr = new String[languages.size()]; + languagesArr = new String[languages.size()]; + int i = 0; + for (Languages.Language language : languages) { + codesArr[i] = language.code; + languagesArr[i] = language.language; + if (currentCode != null && currentCode.equalsIgnoreCase(language.code)) { + selection = i; + } + i++; + } + } } + SharedPreferences.Editor editor = sharedpreferences.edit(); AlertDialog.Builder builder = new AlertDialog.Builder(ComposeActivity.this, Helper.dialogStyle()); builder.setTitle(getString(R.string.message_language)); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentComposeSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentComposeSettings.java index 699ed0cd6..f40623d1d 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentComposeSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentComposeSettings.java @@ -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 diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java index 4eede2b01..98c3a1872 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java @@ -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) { diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java index 3b64b88ee..880e9c63d 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java @@ -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(); } } } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 07045c62a..d2fa13226 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -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) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8ee9bc36b..e630c7863 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -865,6 +865,376 @@ + + aa + ab + ae + af + ak + am + an + ar + as + av + ay + az + ba + be + bg + bh + bi + bm + bn + bo + br + bs + ca + ce + ch + co + cr + cs + cu + cv + cy + da + de + dv + dz + ee + el + en + eo + es + et + eu + fa + ff + fi + fj + fo + fr + fy + ga + gd + gl + gu + gv + ha + he + hi + ho + hr + ht + hu + hy + hz + ia + id + ie + ig + ii + ik + io + is + it + iu + ja + jv + ka + kg + ki + kj + kk + kl + km + kn + ko + kr + ks + ku + kv + kw + ky + la + lb + lg + li + ln + lo + lt + lu + lv + mg + mh + mi + mk + ml + mn + mr + ms + mt + my + na + nb + nd + ne + ng + nl + nn + no + nr + nv + ny + oc + oj + om + or + os + pa + pi + pl + ps + pt + qu + rm + rn + ro + ru + rw + sa + sc + sd + se + sg + si + sk + sl + sn + so + sq + sr + ss + st + su + sv + sw + ta + te + tg + th + ti + tk + tl + tn + to + tr + ts + tt + tw + ty + ug + uk + ur + uz + ve + vi + vo + wa + wo + xh + yi + yo + za + zh + zu + + + + Afaraf + аҧсуа бызшәа + avesta + Afrikaans + Akan + አማርኛ + aragonés + اللغة العربية + অসমীয়া + авар мацӀ + aymar aru + azərbaycan dili + башҡорт теле + беларуская мова + български език + भोजपुरी + Bislama + bamanankan + বাংলা + བོད་ཡིག + brezhoneg + bosanski jezik + Català + нохчийн мотт + Chamoru + corsu + ᓀᐦᐃᔭᐍᐏᐣ + čeština + ѩзыкъ словѣньскъ + чӑваш чӗлхи + Cymraeg + dansk + Deutsch + Dhivehi + རྫོང་ཁ + Eʋegbe + Ελληνικά + English + Esperanto + Español + eesti + euskara + فارسی + Fulfulde + suomi + Vakaviti + føroyskt + Français + Frysk + Gaeilge + Gàidhlig + galego + ગુજરાતી + Gaelg + هَوُسَ + עברית + हिन्दी + Hiri Motu + Hrvatski + Kreyòl ayisyen + magyar + Հայերեն + Otjiherero + Interlingua + Bahasa Indonesia + Interlingue + Asụsụ Igbo + ꆈꌠ꒿ Nuosuhxop + Iñupiaq + Ido + Íslenska + Italiano + ᐃᓄᒃᑎᑐᑦ + 日本語 + basa Jawa + ქართული + Kikongo + Gĩkũyũ + Kuanyama + қазақ тілі + kalaallisut + ខេមរភាសា + ಕನ್ನಡ + 한국어 + Kanuri + कश्मीरी + Kurmancî + коми кыв + Kernewek + Кыргызча + latine + Lëtzebuergesch + Luganda + Limburgs + Lingála + ພາສາ + lietuvių kalba + Tshiluba + latviešu valoda + fiteny malagasy + Kajin M̧ajeļ + te reo Māori + македонски јазик + മലയാളം + Монгол хэл + मराठी + Bahasa Melayu + Malti + ဗမာစာ + Ekakairũ Naoero + Norsk bokmål + isiNdebele + नेपाली + Owambo + Nederlands + Norsk Nynorsk + Norsk + isiNdebele + Diné bizaad + chiCheŵa + occitan + ᐊᓂᔑᓈᐯᒧᐎᓐ + Afaan Oromoo + ଓଡ଼ିଆ + ирон æвзаг + ਪੰਜਾਬੀ + पाऴि + Polski + پښتو + Português + Runa Simi + rumantsch grischun + Ikirundi + Română + Русский + Ikinyarwanda + संस्कृतम् + sardu + सिन्धी + Davvisámegiella + yângâ tî sängö + සිංහල + slovenčina + slovenščina + chiShona + Soomaaliga + Shqip + српски језик + SiSwati + Sesotho + Basa Sunda + Svenska + Kiswahili + தமிழ் + తెలుగు + тоҷикӣ + ไทย + ትግርኛ + Türkmen + Wikang Tagalog + Setswana + faka Tonga + Türkçe + Xitsonga + татар теле + Twi + Reo Tahiti + ئۇيغۇرچە‎ + Українська + اردو + Ўзбек + Tshivenḓa + Tiếng Việt + Volapük + walon + Wollof + isiXhosa + ייִדיש + Yorùbá + Saɯ cueŋƅ + 中文 + isiZulu + + default en @@ -997,6 +1367,8 @@ SET_VIDEO_CACHE SET_WATERMARK SET_UNLISTED_REPLIES + SET_SELECTED_LANGUAGE + SET_WATERMARK_TEXT SET_PROXY_PASSWORD @@ -1600,4 +1972,6 @@ Restart the app? Restart You should restart the application to apply changes. + Languages in picker + Allow to reduce the list of languages in the picker when composing a message. diff --git a/app/src/main/res/xml/pref_compose.xml b/app/src/main/res/xml/pref_compose.xml index 1d0a29447..4f263dd5f 100644 --- a/app/src/main/res/xml/pref_compose.xml +++ b/app/src/main/res/xml/pref_compose.xml @@ -38,6 +38,15 @@ app:summary="@string/set_unlisted_replies_indication" app:title="@string/set_unlisted_replies" /> + +