From 7ab24d900b493d4ae9f68fb9ed5498a591cbc619 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 23 Jan 2024 18:48:42 +0100 Subject: [PATCH] Indicator with pronouns --- .../mastodon/client/entities/api/Status.java | 2 ++ .../mastodon/ui/drawer/ComposeAdapter.java | 23 +++++++++++++-- .../mastodon/ui/drawer/StatusAdapter.java | 20 +++++++++++-- .../layouts/mastodon/layout/drawer_status.xml | 14 ++++++++- .../mastodon/layout/drawer_status_compose.xml | 29 +++++++++++++++++-- app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 82 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java index cb3437ea..c6ef8d87 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java @@ -143,6 +143,8 @@ public class Status implements Serializable, Cloneable { public transient MathJaxView mathJaxView; public String lemmy_post_id; + public transient String pronouns = null; + @Override public boolean equals(@Nullable Object obj) { boolean same = false; 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 69520727..05e1c913 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 @@ -113,6 +113,7 @@ import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Emoji; import app.fedilab.android.mastodon.client.entities.api.EmojiInstance; +import app.fedilab.android.mastodon.client.entities.api.Field; import app.fedilab.android.mastodon.client.entities.api.Mention; import app.fedilab.android.mastodon.client.entities.api.Poll; import app.fedilab.android.mastodon.client.entities.api.Status; @@ -1358,6 +1359,7 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { holder.binding.simpleMedia.removeAllViews(); List attachmentList = statusList.get(position).media_attachments; @@ -1421,13 +1423,30 @@ public class ComposeAdapter extends RecyclerView.Adapter 0 && getItemViewType(position -1 ) == TYPE_NORMAL) { + Status statusFromUser = statusList.get(position-1); + Account accountFromUser = statusFromUser.account; + statusFromUser.pronouns = null; + if(accountFromUser.fields != null && accountFromUser.fields.size() > 0) { + for(Field field: accountFromUser.fields) { + if(field.name.toLowerCase().startsWith("pronoun")) { + statusList.get(position).pronouns = field.value; + break; + } + } + } + } ComposeViewHolder holder = (ComposeViewHolder) viewHolder; boolean extraFeatures = sharedpreferences.getBoolean(context.getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, false); boolean mathsComposer = sharedpreferences.getBoolean(context.getString(R.string.SET_MATHS_COMPOSER), true); boolean forwardTag = sharedpreferences.getBoolean(context.getString(R.string.SET_FORWARD_TAGS_IN_REPLY), false); - + if(statusDraft.pronouns != null) { + holder.binding.genders.setVisibility(View.VISIBLE); + holder.binding.pronouns.setText(statusDraft.pronouns); + } else { + holder.binding.genders.setVisibility(View.GONE); + } if (mathsComposer) { holder.binding.buttonMathsComposer.setVisibility(View.VISIBLE); holder.binding.buttonMathsComposer.setOnClickListener(v -> { 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 e088e0af..a659d4ae 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 @@ -58,7 +58,6 @@ import android.os.Looper; import android.text.Html; import android.text.SpannableString; import android.text.TextUtils; -import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -148,6 +147,7 @@ import app.fedilab.android.mastodon.activities.StatusInfoActivity; import app.fedilab.android.mastodon.activities.TimelineActivity; import app.fedilab.android.mastodon.activities.admin.AdminAccountActivity; import app.fedilab.android.mastodon.client.entities.api.Attachment; +import app.fedilab.android.mastodon.client.entities.api.Field; import app.fedilab.android.mastodon.client.entities.api.Poll; import app.fedilab.android.mastodon.client.entities.api.Reaction; import app.fedilab.android.mastodon.client.entities.api.Status; @@ -482,7 +482,23 @@ 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")) { + statusToDeal.pronouns = field.value; + break; + } + } + 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); + } else { + holder.binding.pronouns.setVisibility(View.INVISIBLE); + } if (statusToDeal.quote != null && (statusToDeal.spoiler_text == null || statusToDeal.spoiler_text.trim().isEmpty() || statusToDeal.isExpended)) { holder.binding.quotedMessage.cardviewContainer.setCardElevation((int) Helper.convertDpToPixel(5, context)); holder.binding.quotedMessage.dividerCard.setVisibility(View.GONE); diff --git a/app/src/main/res/layouts/mastodon/layout/drawer_status.xml b/app/src/main/res/layouts/mastodon/layout/drawer_status.xml index d331c73d..4cae9d71 100644 --- a/app/src/main/res/layouts/mastodon/layout/drawer_status.xml +++ b/app/src/main/res/layouts/mastodon/layout/drawer_status.xml @@ -163,13 +163,25 @@ + + + tools:text="He/Him" /> - - + + + + Followers only Other Eg.: Sensitive Content + Pronouns + Add status Remove status Posting messageā€¦