From aa35bb2bcdca82772204ba7b9277c0a8bdfa8ea0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 8 Jun 2022 15:27:11 +0200 Subject: [PATCH] Fix issue #150 - Pleroma uses a different object for max chars & poll options --- .../android/client/entities/api/Instance.java | 7 ++++++- .../android/ui/drawer/ComposeAdapter.java | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Instance.java b/app/src/main/java/app/fedilab/android/client/entities/api/Instance.java index 5bde38a32..53b362105 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Instance.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Instance.java @@ -55,7 +55,10 @@ public class Instance implements Serializable { public Account contact_account; @SerializedName("configuration") public Configuration configuration; - + @SerializedName("poll_limits") + public PollsConf poll_limits; + @SerializedName("max_toot_chars") + public String max_toot_chars; public List getMimeTypeAudio() { List mimeTypes = new ArrayList<>(); @@ -175,4 +178,6 @@ public class Instance implements Serializable { public String text; public transient boolean isChecked = false; } + + } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index 5dab3aec7..34390d987 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -667,13 +667,14 @@ public class ComposeAdapter extends RecyclerView.Adapter instanceInfo.configuration.statusesConf.max_characters + 1) { - int from = instanceInfo.configuration.statusesConf.max_characters - holder.binding.contentSpoiler.getText().length(); + int max_car = instanceInfo.max_toot_chars != null ? Integer.parseInt(instanceInfo.max_toot_chars) : instanceInfo.configuration.statusesConf.max_characters; + if (currentLength > max_car + 1) { + int from = max_car - holder.binding.contentSpoiler.getText().length(); int to = (currentLength - holder.binding.contentSpoiler.getText().length()); if (to <= s.length()) { holder.binding.content.setText(s.delete(from, to)); } - } else if (currentLength > instanceInfo.configuration.statusesConf.max_characters) { + } else if (currentLength > max_car) { if (cPosition + 1 <= s.length()) { holder.binding.content.setText(s.delete(cPosition, cPosition + 1)); } @@ -1178,7 +1179,8 @@ public class ComposeAdapter extends RecyclerView.Adapter instanceInfo.configuration.statusesConf.max_characters + 1) { - holder.binding.contentSpoiler.setText(s.delete(instanceInfo.configuration.statusesConf.max_characters - holder.binding.content.getText().length(), (currentLength - holder.binding.content.getText().length()))); + if (currentLength > max_car + 1) { + holder.binding.contentSpoiler.setText(s.delete(max_car - holder.binding.content.getText().length(), (currentLength - holder.binding.content.getText().length()))); buttonVisibility(holder); - } else if (currentLength > instanceInfo.configuration.statusesConf.max_characters) { + } else if (currentLength > max_car) { buttonVisibility(holder); holder.binding.contentSpoiler.setText(s.delete(cPosition, cPosition + 1)); } @@ -1267,6 +1269,9 @@ public class ComposeAdapter extends RecyclerView.Adapter