From b943309dd2225a5af2663484b61330a18a8fbfb0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 23 Feb 2024 10:17:55 +0100 Subject: [PATCH 1/4] Add localization for pronons support --- .../mastodon/helper/PronounsHelper.java | 31 +++++++++++++++++++ .../ui/drawer/AccountsSearchAdapter.java | 3 +- .../mastodon/ui/drawer/ComposeAdapter.java | 3 +- .../mastodon/ui/drawer/StatusAdapter.java | 3 +- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java new file mode 100644 index 00000000..f3bcdbbc --- /dev/null +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java @@ -0,0 +1,31 @@ +package app.fedilab.android.mastodon.helper; +/* Copyright 2024 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ +import java.util.ArrayList; +import java.util.List; + +public class PronounsHelper { + + public static List pronouns = new ArrayList<>() { + { + add("pronouns"); + add("pronoms"); + add("pronombres"); + add("לשון פנייה"); + add("כינויי גוף"); + add("Pronomen"); + } + }; +} diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java index 974b2325..a5a72862 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java @@ -33,6 +33,7 @@ import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Field; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; +import app.fedilab.android.mastodon.helper.PronounsHelper; public class AccountsSearchAdapter extends ArrayAdapter implements Filterable { @@ -120,7 +121,7 @@ public class AccountsSearchAdapter extends ArrayAdapter implements Filt holder.binding.accountDn.setVisibility(View.VISIBLE); account.pronouns = null; for (Field field : account.fields) { - if (field.name.trim().equalsIgnoreCase("pronouns")) { + if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { account.pronouns = Helper.parseHtml(field.value); break; } 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 1578e4de..09bab05a 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 @@ -128,6 +128,7 @@ import app.fedilab.android.mastodon.helper.ComposeHelper; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.LongClickLinkMovementMethod; import app.fedilab.android.mastodon.helper.MastodonHelper; +import app.fedilab.android.mastodon.helper.PronounsHelper; import app.fedilab.android.mastodon.helper.ThemeHelper; import app.fedilab.android.mastodon.imageeditor.EditImageActivity; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; @@ -1428,7 +1429,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { for (Field field : accountFromUser.fields) { - if (field.name.toLowerCase().startsWith("pronoun")) { + if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { statusList.get(position).pronouns = Helper.parseHtml(field.value); break; } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index 479c8746..188378f0 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -169,6 +169,7 @@ import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.LongClickLinkMovementMethod; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.MediaHelper; +import app.fedilab.android.mastodon.helper.PronounsHelper; import app.fedilab.android.mastodon.helper.SpannableHelper; import app.fedilab.android.mastodon.helper.ThemeHelper; import app.fedilab.android.mastodon.helper.TimelineHelper; @@ -483,7 +484,7 @@ public class StatusAdapter extends RecyclerView.Adapter String loadMediaType = sharedpreferences.getString(context.getString(R.string.SET_LOAD_MEDIA_TYPE), "ALWAYS"); if (statusToDeal.pronouns == null && statusToDeal.account.fields != null && statusToDeal.account.fields.size() > 0) { for (Field field : statusToDeal.account.fields) { - if (field.name.toLowerCase().startsWith("pronoun")) { + if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { statusToDeal.pronouns = Helper.parseHtml(field.value); break; } From 26d51caaf8488128c3a3a63be42a5a2e03c6f6f9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 23 Feb 2024 10:29:36 +0100 Subject: [PATCH 2/4] Allow to disable pronouns support - Default enabled --- .../ui/drawer/AccountsSearchAdapter.java | 15 ++++++++++---- .../mastodon/ui/drawer/ComposeAdapter.java | 13 +++++++----- .../mastodon/ui/drawer/StatusAdapter.java | 20 +++++++++++-------- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_timelines.xml | 7 +++++++ 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java index a5a72862..40449cdf 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchAdapter.java @@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.drawer; * see . */ import android.content.Context; +import android.content.SharedPreferences; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -23,11 +24,13 @@ import android.widget.Filter; import android.widget.Filterable; import androidx.annotation.NonNull; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; +import app.fedilab.android.R; import app.fedilab.android.databinding.DrawerAccountSearchBinding; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Field; @@ -120,10 +123,14 @@ public class AccountsSearchAdapter extends ArrayAdapter implements Filt holder.binding.accountDn.setText(account.display_name); holder.binding.accountDn.setVisibility(View.VISIBLE); account.pronouns = null; - for (Field field : account.fields) { - if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { - account.pronouns = Helper.parseHtml(field.value); - break; + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean pronounsSupport = sharedpreferences.getBoolean(getContext().getString(R.string.SET_PRONOUNS_SUPPORT), true); + if(pronounsSupport) { + for (Field field : account.fields) { + if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { + account.pronouns = Helper.parseHtml(field.value); + break; + } } } if (account.pronouns != null) { 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 09bab05a..220db680 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 @@ -1427,11 +1427,14 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { - for (Field field : accountFromUser.fields) { - if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { - statusList.get(position).pronouns = Helper.parseHtml(field.value); - break; + boolean pronounsSupport = sharedpreferences.getBoolean(context.getString(R.string.SET_PRONOUNS_SUPPORT), true); + if(pronounsSupport) { + if (accountFromUser.fields != null && accountFromUser.fields.size() > 0) { + for (Field field : accountFromUser.fields) { + if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { + statusList.get(position).pronouns = Helper.parseHtml(field.value); + break; + } } } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index 188378f0..596d25fa 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -482,17 +482,21 @@ public class StatusAdapter extends RecyclerView.Adapter } String loadMediaType = sharedpreferences.getString(context.getString(R.string.SET_LOAD_MEDIA_TYPE), "ALWAYS"); - if (statusToDeal.pronouns == null && statusToDeal.account.fields != null && statusToDeal.account.fields.size() > 0) { - for (Field field : statusToDeal.account.fields) { - if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { - statusToDeal.pronouns = Helper.parseHtml(field.value); - break; + boolean pronounsSupport = sharedpreferences.getBoolean(context.getString(R.string.SET_PRONOUNS_SUPPORT), true); + if(pronounsSupport) { + if (statusToDeal.pronouns == null && statusToDeal.account.fields != null && statusToDeal.account.fields.size() > 0) { + for (Field field : statusToDeal.account.fields) { + if (PronounsHelper.pronouns.contains(field.name.toLowerCase().trim())) { + statusToDeal.pronouns = Helper.parseHtml(field.value); + break; + } + } + if (statusToDeal.pronouns == null) { + statusToDeal.pronouns = "none"; } - } - if (statusToDeal.pronouns == null) { - statusToDeal.pronouns = "none"; } } + if (statusToDeal.pronouns != null && !statusToDeal.pronouns.equalsIgnoreCase("none")) { holder.binding.pronouns.setVisibility(View.VISIBLE); holder.binding.pronouns.setText(statusToDeal.pronouns); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7a0c32a8..22177660 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -639,6 +639,7 @@ Other Eg.: Sensitive Content Pronouns + Pronouns support Add status Remove status @@ -1197,6 +1198,7 @@ SET_MARKDOWN_SUPPORT SET_TRUNCATE_LINKS SET_UNDERLINE_CLICKABLE + SET_PRONOUNS_SUPPORT SET_TRUNCATE_LINKS_MAX SET_HIDE_SINGLE_MEDIA_WITH_CARD diff --git a/app/src/main/res/xml/pref_timelines.xml b/app/src/main/res/xml/pref_timelines.xml index 90ad7ca0..4f47cb44 100644 --- a/app/src/main/res/xml/pref_timelines.xml +++ b/app/src/main/res/xml/pref_timelines.xml @@ -79,6 +79,13 @@ app:singleLineTitle="false" app:title="@string/underline_links" /> + + Date: Fri, 23 Feb 2024 10:31:54 +0100 Subject: [PATCH 3/4] update list for pronouns --- .../fedilab/android/mastodon/helper/PronounsHelper.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java index f3bcdbbc..f0ca7188 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java @@ -25,7 +25,12 @@ public class PronounsHelper { add("pronombres"); add("לשון פנייה"); add("כינויי גוף"); - add("Pronomen"); + add("pronomen"); + add("pronomina"); + add("称谓"); + add("pronomes"); + add("pronomoj"); + add("zaimki"); } }; } From f87c63acec8699b283736116743533e8bd323a42 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 23 Feb 2024 15:57:12 +0100 Subject: [PATCH 4/4] Add more pronouns --- .../fedilab/android/mastodon/helper/PronounsHelper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java index f0ca7188..dd30eddb 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/PronounsHelper.java @@ -20,8 +20,10 @@ public class PronounsHelper { public static List pronouns = new ArrayList<>() { { + add("pronoun"); add("pronouns"); add("pronoms"); + add("pronom"); add("pronombres"); add("לשון פנייה"); add("כינויי גוף"); @@ -29,8 +31,14 @@ public class PronounsHelper { add("pronomina"); add("称谓"); add("pronomes"); + add("pronome"); + add("pronomi"); add("pronomoj"); add("zaimki"); + add("voornaamwoorden"); + add("riochdairean"); + add("כינויי גוף"); + add("personlig pronomen"); } }; }