From a7a6a5cc2cdb6e8dec3db40101abb968683f98fb Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Sun, 9 Jul 2023 18:23:18 +0200 Subject: [PATCH] added poll option emoji support, restructured adapter holder, code cleanup --- .../api/mastodon/impl/MastodonField.java | 50 +++++++++++++++++++ .../api/mastodon/impl/MastodonPoll.java | 34 +++++++++---- .../api/mastodon/impl/MastodonUser.java | 15 ++++++ .../backend/api/twitter/v1/impl/UserV1.java | 6 +++ .../backend/api/twitter/v2/impl/PollV2.java | 7 +++ .../backend/api/twitter/v2/impl/UserV2.java | 6 +++ .../twidda/backend/helper/MediaStatus.java | 2 +- .../backend/helper/update/ProfileUpdate.java | 3 ++ .../twidda/database/impl/DatabasePoll.java | 7 +++ .../twidda/database/impl/DatabaseUser.java | 6 +++ .../org/nuclearfog/twidda/model/Poll.java | 4 ++ .../org/nuclearfog/twidda/model/User.java | 32 ++++++++++++ .../twidda/ui/activities/ImageViewer.java | 3 +- .../twidda/ui/adapter/MessageAdapter.java | 8 +-- .../ui/adapter/NotificationAdapter.java | 10 ++-- .../twidda/ui/adapter/OptionsAdapter.java | 6 ++- .../twidda/ui/adapter/StatusAdapter.java | 8 +-- .../twidda/ui/adapter/UserAdapter.java | 9 +--- .../twidda/ui/adapter/UserlistAdapter.java | 8 +-- .../ui/adapter/holder/MessageHolder.java | 8 +-- .../ui/adapter/holder/Optionholder.java | 44 +++++++++++++--- .../ui/adapter/holder/StatusHolder.java | 8 +-- .../twidda/ui/adapter/holder/UserHolder.java | 14 +++--- .../ui/adapter/holder/UserlistHolder.java | 6 +-- .../twidda/ui/fragments/MessageFragment.java | 2 +- .../ui/fragments/NotificationFragment.java | 2 +- .../twidda/ui/fragments/StatusFragment.java | 2 +- .../twidda/ui/fragments/UserFragment.java | 2 +- .../twidda/ui/fragments/UserListFragment.java | 2 +- .../main/res/layout/dialog_description.xml | 2 +- app/src/main/res/layout/dialog_license.xml | 2 +- app/src/main/res/menu/image.xml | 2 +- app/src/main/res/menu/video.xml | 4 +- app/src/main/res/values/dimens.xml | 1 + 34 files changed, 246 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonField.java diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonField.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonField.java new file mode 100644 index 00000000..61997804 --- /dev/null +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonField.java @@ -0,0 +1,50 @@ +package org.nuclearfog.twidda.backend.api.mastodon.impl; + +import org.json.JSONException; +import org.json.JSONObject; +import org.nuclearfog.twidda.backend.utils.StringUtils; +import org.nuclearfog.twidda.model.User.Field; + +/** + * User fields implementation of Mastodon + * + * @author nuclearfog + */ +public class MastodonField implements Field { + + private static final long serialVersionUID = 2278113885084330065L; + + private String key; + private String value; + private long timestamp = 0L; + + /** + * @param json fields json + */ + public MastodonField(JSONObject json) throws JSONException { + key = json.getString("name"); + value = json.getString("value"); + String timeStr = json.getString("verified_at"); + if (!timeStr.equals("null")) { + timestamp = StringUtils.getTime(timeStr, StringUtils.TIME_MASTODON); + } + } + + + @Override + public String getKey() { + return key; + } + + + @Override + public String getValue() { + return value; + } + + + @Override + public long getTimestamp() { + return timestamp; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonPoll.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonPoll.java index 09f6d3ea..f86bfa3e 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonPoll.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonPoll.java @@ -7,6 +7,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.nuclearfog.twidda.backend.utils.StringUtils; +import org.nuclearfog.twidda.model.Emoji; import org.nuclearfog.twidda.model.Poll; /** @@ -25,15 +26,17 @@ public class MastodonPoll implements Poll { private boolean multipleChoice; private int voteCount; private MastodonOption[] options; + private Emoji[] emojis = {}; /** * @param json Mastodon poll jswon format */ public MastodonPoll(JSONObject json) throws JSONException { - String idStr = json.getString("id"); + JSONArray optionArray = json.getJSONArray("options"); + JSONArray voteArray = json.optJSONArray("own_votes"); + JSONArray emojiArray = json.optJSONArray("emojis"); String exTimeStr = json.getString("expires_at"); - JSONArray optionsJson = json.getJSONArray("options"); - JSONArray votesJson = json.optJSONArray("own_votes"); + String idStr = json.getString("id"); exTime = StringUtils.getTime(exTimeStr, StringUtils.TIME_MASTODON); expired = json.getBoolean("expired"); voted = json.optBoolean("voted", false); @@ -41,20 +44,25 @@ public class MastodonPoll implements Poll { if (!json.isNull("voters_count")) { voteCount = json.getInt("voters_count"); } - - options = new MastodonOption[optionsJson.length()]; - for (int i = 0; i < optionsJson.length(); i++) { - JSONObject option = optionsJson.getJSONObject(i); + options = new MastodonOption[optionArray.length()]; + for (int i = 0; i < optionArray.length(); i++) { + JSONObject option = optionArray.getJSONObject(i); options[i] = new MastodonOption(option); } - if (votesJson != null) { - for (int i = 0; i < votesJson.length(); i++) { - int index = votesJson.getInt(i); + if (voteArray != null) { + for (int i = 0; i < voteArray.length(); i++) { + int index = voteArray.getInt(i); if (index >= 0 && index < options.length) { options[index].setSelected(); } } } + if (emojiArray != null && emojiArray.length() > 0) { + emojis = new Emoji[emojiArray.length()]; + for (int i = 0; i < emojis.length; i++) { + emojis[i] = new MastodonEmoji(emojiArray.getJSONObject(i)); + } + } try { id = Long.parseLong(idStr); } catch (NumberFormatException e) { @@ -105,6 +113,12 @@ public class MastodonPoll implements Poll { } + @Override + public Emoji[] getEmojis() { + return emojis; + } + + @Override public boolean equals(Object o) { return o instanceof Poll && ((Poll) o).getId() == getId(); diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonUser.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonUser.java index daba1991..09b6b3d4 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonUser.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/mastodon/impl/MastodonUser.java @@ -37,6 +37,7 @@ public class MastodonUser implements User { private boolean locked; private boolean isCurrentUser; private Emoji[] emojis = {}; + private Field[] fields = {}; /** * constructor used to create an user instance of the current user @@ -56,6 +57,7 @@ public class MastodonUser implements User { */ public MastodonUser(JSONObject json, long currentUserId) throws JSONException { JSONArray emojiArray = json.optJSONArray("emojis"); + JSONArray fieldsArray = json.optJSONArray("fields"); String idStr = json.getString("id"); String description = json.optString("note", ""); String profileUrl = json.optString("avatar_static", ""); @@ -85,6 +87,13 @@ public class MastodonUser implements User { emojis[i] = new MastodonEmoji(emojiJson); } } + if (fieldsArray != null && fieldsArray.length() > 0) { + fields = new Field[fieldsArray.length()]; + for (int i = 0; i < fields.length; i++) { + JSONObject fieldJson = fieldsArray.getJSONObject(i); + fields[i] = new MastodonField(fieldJson); + } + } try { id = Long.parseLong(idStr); isCurrentUser = currentUserId == id; @@ -220,6 +229,12 @@ public class MastodonUser implements User { } + @Override + public Field[] getFields() { + return fields; + } + + @Override public boolean equals(@Nullable Object obj) { if (!(obj instanceof User)) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v1/impl/UserV1.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v1/impl/UserV1.java index 202cda11..9bb4dc86 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v1/impl/UserV1.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v1/impl/UserV1.java @@ -236,6 +236,12 @@ public class UserV1 implements User { } + @Override + public Field[] getFields() { + return new Field[0]; + } + + @Override public boolean equals(@Nullable Object obj) { if (!(obj instanceof User)) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/PollV2.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/PollV2.java index 70481b0f..c34d0ee3 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/PollV2.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/PollV2.java @@ -7,6 +7,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.nuclearfog.twidda.backend.utils.StringUtils; +import org.nuclearfog.twidda.model.Emoji; import org.nuclearfog.twidda.model.Poll; /** @@ -98,6 +99,12 @@ public class PollV2 implements Poll { } + @Override + public Emoji[] getEmojis() { + return new Emoji[0]; + } + + @Override public boolean equals(Object o) { return o instanceof Poll && ((Poll) o).getId() == getId(); diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/UserV2.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/UserV2.java index 2274605b..784738d5 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/UserV2.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/twitter/v2/impl/UserV2.java @@ -220,6 +220,12 @@ public class UserV2 implements User { } + @Override + public Field[] getFields() { + return new Field[0]; + } + + @Override public boolean equals(@Nullable Object obj) { if (!(obj instanceof User)) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/helper/MediaStatus.java b/app/src/main/java/org/nuclearfog/twidda/backend/helper/MediaStatus.java index ba21d477..407d500f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/helper/MediaStatus.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/helper/MediaStatus.java @@ -77,7 +77,7 @@ public class MediaStatus implements Serializable, Closeable { /** * create MediaStatus from an offline source * - * @param uri path to the local file + * @param uri path to the local file * @throws FileNotFoundException if the file is invalid */ public MediaStatus(Context context, Uri uri) throws FileNotFoundException { diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/ProfileUpdate.java b/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/ProfileUpdate.java index 302443b3..0c68b07e 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/ProfileUpdate.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/ProfileUpdate.java @@ -4,6 +4,7 @@ import android.content.ContentResolver; import androidx.annotation.NonNull; import androidx.annotation.Nullable; + import org.nuclearfog.twidda.backend.helper.MediaStatus; import java.io.Closeable; @@ -52,12 +53,14 @@ public class ProfileUpdate implements Closeable { } /** + * */ public void setProfileImage(MediaStatus profileImage) { this.profileImage = profileImage; } /** + * */ public void setBannerImage(MediaStatus bannerImage) { this.bannerImage = bannerImage; diff --git a/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabasePoll.java b/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabasePoll.java index e80fa8e6..b43096f4 100644 --- a/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabasePoll.java +++ b/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabasePoll.java @@ -6,6 +6,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import org.nuclearfog.twidda.database.DatabaseAdapter.PollTable; +import org.nuclearfog.twidda.model.Emoji; import org.nuclearfog.twidda.model.Poll; import java.util.regex.Pattern; @@ -86,6 +87,12 @@ public class DatabasePoll implements Poll, PollTable { } + @Override + public Emoji[] getEmojis() { + return new Emoji[0]; + } + + @Override public boolean equals(Object o) { return o instanceof Poll && ((Poll) o).getId() == getId(); diff --git a/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabaseUser.java b/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabaseUser.java index 3ba613ae..7d834984 100644 --- a/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabaseUser.java +++ b/app/src/main/java/org/nuclearfog/twidda/database/impl/DatabaseUser.java @@ -211,6 +211,12 @@ public class DatabaseUser implements User, UserTable, UserRegisterTable { } + @Override + public Field[] getFields() { + return new Field[0];// todo implement this + } + + @Override public boolean equals(@Nullable Object obj) { if (!(obj instanceof User)) diff --git a/app/src/main/java/org/nuclearfog/twidda/model/Poll.java b/app/src/main/java/org/nuclearfog/twidda/model/Poll.java index 3dfb9aa6..60bcb79f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/model/Poll.java +++ b/app/src/main/java/org/nuclearfog/twidda/model/Poll.java @@ -44,6 +44,10 @@ public interface Poll extends Serializable { */ Option[] getOptions(); + /** + * @return emojis used in option titles + */ + Emoji[] getEmojis(); /** * represents a vote option diff --git a/app/src/main/java/org/nuclearfog/twidda/model/User.java b/app/src/main/java/org/nuclearfog/twidda/model/User.java index dafa7f32..28c20b6f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/model/User.java +++ b/app/src/main/java/org/nuclearfog/twidda/model/User.java @@ -114,9 +114,41 @@ public interface User extends Serializable, Comparable { */ Emoji[] getEmojis(); + /** + * @return fields set by user + */ + Field[] getFields(); + @Override default int compareTo(User o) { return Long.compare(o.getId(), getId()); } + + /** + * represents an user field. + */ + interface Field extends Serializable { + + /** + * get the key of a given field’s key-value pair. + * + * @return key string + */ + String getKey(); + + /** + * get the value associated with the name key. + * + * @return value string + */ + String getValue(); + + /** + * get the timestamp of the verification if any + * + * @return ISO 8601 Datetime or '0' if not defined + */ + long getTimestamp(); + } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/ImageViewer.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/ImageViewer.java index e81f8ead..35f8d36b 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/ImageViewer.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/ImageViewer.java @@ -213,8 +213,7 @@ public class ImageViewer extends MediaActivity implements AsyncCallback implements OnItemClickLi public static final int CLEAR_LIST = -1; private OnMessageClickListener itemClickListener; - private TextEmojiLoader emojiLoader; private Messages messages = new Messages(); private int loadingIndex = NO_LOADING; @@ -52,8 +49,7 @@ public class MessageAdapter extends Adapter implements OnItemClickLi /** * @param itemClickListener click listener */ - public MessageAdapter(Context context, OnMessageClickListener itemClickListener) { - emojiLoader = new TextEmojiLoader(context); + public MessageAdapter(OnMessageClickListener itemClickListener) { this.itemClickListener = itemClickListener; } @@ -76,7 +72,7 @@ public class MessageAdapter extends Adapter implements OnItemClickLi @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == TYPE_MESSAGE) { - return new MessageHolder(parent, emojiLoader, this); + return new MessageHolder(parent, this); } else { return new PlaceHolder(parent, this, false); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/NotificationAdapter.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/NotificationAdapter.java index e8beb528..42ea3800 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/NotificationAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/NotificationAdapter.java @@ -1,13 +1,11 @@ package org.nuclearfog.twidda.ui.adapter; -import android.content.Context; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView.Adapter; import androidx.recyclerview.widget.RecyclerView.ViewHolder; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader; import org.nuclearfog.twidda.model.Notification; import org.nuclearfog.twidda.model.User; import org.nuclearfog.twidda.model.lists.Notifications; @@ -46,7 +44,6 @@ public class NotificationAdapter extends Adapter implements OnHolder private static final int TYPE_USER = 2; private OnNotificationClickListener listener; - private TextEmojiLoader emojiLoader; private Notifications notifications = new Notifications(); private int loadingIndex = NO_LOADING; @@ -54,8 +51,7 @@ public class NotificationAdapter extends Adapter implements OnHolder /** * */ - public NotificationAdapter(Context context, OnNotificationClickListener listener) { - emojiLoader = new TextEmojiLoader(context); + public NotificationAdapter(OnNotificationClickListener listener) { this.listener = listener; } @@ -64,9 +60,9 @@ public class NotificationAdapter extends Adapter implements OnHolder @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == TYPE_STATUS) { - return new StatusHolder(parent, emojiLoader, this); + return new StatusHolder(parent, this); } else if (viewType == TYPE_USER) { - return new UserHolder(parent, emojiLoader, this, false); + return new UserHolder(parent, this, false); } else { return new PlaceHolder(parent, this, false); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/OptionsAdapter.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/OptionsAdapter.java index 7db19f11..ec1cb80f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/OptionsAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/OptionsAdapter.java @@ -5,6 +5,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView.Adapter; +import org.nuclearfog.twidda.model.Emoji; import org.nuclearfog.twidda.model.Poll; import org.nuclearfog.twidda.ui.adapter.holder.OnHolderClickListener; import org.nuclearfog.twidda.ui.adapter.holder.Optionholder; @@ -22,6 +23,7 @@ public class OptionsAdapter extends Adapter implements OnHolderCli private int totalVotes, limitVotes; private Poll.Option[] options = {}; + private Emoji[] emojis = {}; private Set selection = new TreeSet<>(); @@ -34,7 +36,7 @@ public class OptionsAdapter extends Adapter implements OnHolderCli @Override public void onBindViewHolder(@NonNull Optionholder holder, int position) { - holder.setContent(options[position], selection.contains(position), totalVotes); + holder.setContent(options[position], emojis, selection.contains(position), totalVotes); } @@ -70,6 +72,7 @@ public class OptionsAdapter extends Adapter implements OnHolderCli */ public void addItems(Poll poll) { options = poll.getOptions(); + emojis = poll.getEmojis(); for (int i = 0; i < options.length; i++) { Poll.Option option = options[i]; if (option.isSelected()) { @@ -84,7 +87,6 @@ public class OptionsAdapter extends Adapter implements OnHolderCli limitVotes = 1; } totalVotes = poll.voteCount(); - notifyDataSetChanged(); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/StatusAdapter.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/StatusAdapter.java index a37b148b..de6d7ca3 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/StatusAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/StatusAdapter.java @@ -1,13 +1,11 @@ package org.nuclearfog.twidda.ui.adapter; -import android.content.Context; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView.Adapter; import androidx.recyclerview.widget.RecyclerView.ViewHolder; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader; import org.nuclearfog.twidda.model.Status; import org.nuclearfog.twidda.model.lists.Statuses; import org.nuclearfog.twidda.ui.adapter.holder.OnHolderClickListener; @@ -48,7 +46,6 @@ public class StatusAdapter extends Adapter implements OnHolderClickL */ public static final int CLEAR_LIST = -1; - private TextEmojiLoader emojiLoader; private StatusSelectListener listener; private Statuses items; @@ -57,8 +54,7 @@ public class StatusAdapter extends Adapter implements OnHolderClickL /** * @param itemClickListener listener for item click */ - public StatusAdapter(Context context, StatusSelectListener itemClickListener) { - emojiLoader = new TextEmojiLoader(context); + public StatusAdapter(StatusSelectListener itemClickListener) { loadingIndex = NO_LOADING; items = new Statuses(); this.listener = itemClickListener; @@ -83,7 +79,7 @@ public class StatusAdapter extends Adapter implements OnHolderClickL @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_STATUS) { - return new StatusHolder(parent, emojiLoader, this); + return new StatusHolder(parent, this); } else { return new PlaceHolder(parent, this, false); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserAdapter.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserAdapter.java index 3ffd4347..58de4c97 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserAdapter.java @@ -1,13 +1,11 @@ package org.nuclearfog.twidda.ui.adapter; -import android.content.Context; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView.Adapter; import androidx.recyclerview.widget.RecyclerView.ViewHolder; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader; import org.nuclearfog.twidda.model.User; import org.nuclearfog.twidda.model.lists.Users; import org.nuclearfog.twidda.ui.adapter.holder.OnHolderClickListener; @@ -42,8 +40,6 @@ public class UserAdapter extends Adapter implements OnHolderClickLis */ public static final int CLEAR_LIST = -1; - private TextEmojiLoader emojiLoader; - private UserClickListener listener; private boolean enableDelete; @@ -53,8 +49,7 @@ public class UserAdapter extends Adapter implements OnHolderClickLis /** * @param listener item click listener */ - public UserAdapter(Context context, UserClickListener listener) { - emojiLoader = new TextEmojiLoader(context); + public UserAdapter(UserClickListener listener) { this.listener = listener; } @@ -77,7 +72,7 @@ public class UserAdapter extends Adapter implements OnHolderClickLis @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == ITEM_USER) { - return new UserHolder(parent, emojiLoader, this, enableDelete); + return new UserHolder(parent, this, enableDelete); } else { return new PlaceHolder(parent, this, false); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserlistAdapter.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserlistAdapter.java index 6d90c233..58a0b9b9 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserlistAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/UserlistAdapter.java @@ -1,13 +1,11 @@ package org.nuclearfog.twidda.ui.adapter; -import android.content.Context; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView.Adapter; import androidx.recyclerview.widget.RecyclerView.ViewHolder; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader; import org.nuclearfog.twidda.model.User; import org.nuclearfog.twidda.model.UserList; import org.nuclearfog.twidda.model.lists.UserLists; @@ -48,7 +46,6 @@ public class UserlistAdapter extends Adapter implements OnHolderClic */ private ListClickListener listener; - private TextEmojiLoader emojiLoader; private UserLists userlists = new UserLists(); private int loadingIndex = NO_LOADING; @@ -56,9 +53,8 @@ public class UserlistAdapter extends Adapter implements OnHolderClic /** * @param listener item click listener */ - public UserlistAdapter(Context context, ListClickListener listener) { + public UserlistAdapter(ListClickListener listener) { this.listener = listener; - emojiLoader = new TextEmojiLoader(context); } @@ -80,7 +76,7 @@ public class UserlistAdapter extends Adapter implements OnHolderClic @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == ITEM_LIST) { - return new UserlistHolder(parent, emojiLoader, this); + return new UserlistHolder(parent, this); } else { return new PlaceHolder(parent, this, false); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/MessageHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/MessageHolder.java index 38c6870d..2f108163 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/MessageHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/MessageHolder.java @@ -69,13 +69,15 @@ public class MessageHolder extends ViewHolder implements OnClickListener, OnTagC private long tagId; - - public MessageHolder(ViewGroup parent, TextEmojiLoader emojiLoader, OnItemClickListener listener) { + /** + * + */ + public MessageHolder(ViewGroup parent, OnItemClickListener listener) { super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message, parent, false)); settings = GlobalSettings.get(parent.getContext()); picasso = PicassoBuilder.get(parent.getContext()); + emojiLoader = new TextEmojiLoader(parent.getContext()); this.listener = listener; - this.emojiLoader = emojiLoader; CardView background = (CardView) itemView; ViewGroup container = itemView.findViewById(R.id.item_message_container); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/Optionholder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/Optionholder.java index 632407a2..842e297f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/Optionholder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/Optionholder.java @@ -1,5 +1,7 @@ package org.nuclearfog.twidda.ui.adapter.holder; +import android.text.Spannable; +import android.text.SpannableString; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -8,13 +10,20 @@ import android.widget.ImageView; import android.widget.SeekBar; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.ViewHolder; import org.nuclearfog.twidda.R; +import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback; +import org.nuclearfog.twidda.backend.async.TextEmojiLoader; +import org.nuclearfog.twidda.backend.async.TextEmojiLoader.EmojiParam; +import org.nuclearfog.twidda.backend.async.TextEmojiLoader.EmojiResult; import org.nuclearfog.twidda.backend.utils.AppStyles; +import org.nuclearfog.twidda.backend.utils.EmojiUtils; import org.nuclearfog.twidda.backend.utils.StringUtils; import org.nuclearfog.twidda.config.GlobalSettings; +import org.nuclearfog.twidda.model.Emoji; import org.nuclearfog.twidda.model.Poll.Option; /** @@ -22,21 +31,25 @@ import org.nuclearfog.twidda.model.Poll.Option; * * @author nuclearfog */ -public class Optionholder extends ViewHolder implements OnClickListener { +public class Optionholder extends ViewHolder implements OnClickListener, AsyncCallback { private SeekBar voteProgress; private TextView optionName, optionVotes; private ImageView checkIcon; private OnHolderClickListener listener; + private TextEmojiLoader emojiLoader; private GlobalSettings settings; + private long tagId; + /** * */ public Optionholder(ViewGroup parent, OnHolderClickListener listener) { super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_option, parent, false)); settings = GlobalSettings.get(parent.getContext()); + emojiLoader = new TextEmojiLoader(parent.getContext()); this.listener = listener; optionName = itemView.findViewById(R.id.item_option_name); @@ -66,6 +79,15 @@ public class Optionholder extends ViewHolder implements OnClickListener { } } + + @Override + public void onResult(@NonNull EmojiResult result) { + if (result.images != null && result.id == tagId) { + Spannable spannable = EmojiUtils.addEmojis(optionName.getContext(), result.spannable, result.images); + optionName.setText(spannable); + } + } + /** * set viewholder content * @@ -73,16 +95,24 @@ public class Optionholder extends ViewHolder implements OnClickListener { * @param selected true if option is selected * @param totalCount total vote count */ - public void setContent(Option option, boolean selected, int totalCount) { + public void setContent(Option option, Emoji[] emojis, boolean selected, int totalCount) { + voteProgress.setMax(Math.max(totalCount, 1)); + AppStyles.setDrawableColor(checkIcon, settings.getIconColor()); + voteProgress.setProgress(option.getVotes()); + optionVotes.setText(StringUtils.NUMBER_FORMAT.format(option.getVotes())); + if (emojis.length > 0 && settings.imagesEnabled()) { + tagId = option.getTitle().hashCode(); + SpannableString optionSpan = new SpannableString(option.getTitle()); + EmojiParam param = new EmojiParam(tagId, emojis, optionSpan, optionName.getResources().getDimensionPixelSize(R.dimen.item_option_emoji_size)); + optionName.setText(EmojiUtils.removeTags(optionSpan)); + emojiLoader.execute(param, this); + } else { + optionName.setText(option.getTitle()); + } if (option.isSelected() | selected) { checkIcon.setImageResource(R.drawable.check); } else { checkIcon.setImageResource(R.drawable.circle); } - voteProgress.setMax(Math.max(totalCount, 1)); - AppStyles.setDrawableColor(checkIcon, settings.getIconColor()); - optionName.setText(option.getTitle()); - voteProgress.setProgress(option.getVotes()); - optionVotes.setText(StringUtils.NUMBER_FORMAT.format(option.getVotes())); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/StatusHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/StatusHolder.java index 37c2cd91..d7709b18 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/StatusHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/StatusHolder.java @@ -72,13 +72,15 @@ public class StatusHolder extends ViewHolder implements OnClickListener, OnMedia private long tagId = 0L; - - public StatusHolder(ViewGroup parent, TextEmojiLoader emojiLoader, OnHolderClickListener listener) { + /** + * + */ + public StatusHolder(ViewGroup parent, OnHolderClickListener listener) { super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_status, parent, false)); settings = GlobalSettings.get(parent.getContext()); picasso = PicassoBuilder.get(parent.getContext()); + emojiLoader = new TextEmojiLoader(parent.getContext()); this.listener = listener; - this.emojiLoader = emojiLoader; CardView cardLayout = (CardView) itemView; ViewGroup container = itemView.findViewById(R.id.item_status_container); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserHolder.java index 9c8d44e3..1e417559 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserHolder.java @@ -63,13 +63,15 @@ public class UserHolder extends ViewHolder implements OnClickListener, AsyncCall private long tagId = 0L; - - public UserHolder(ViewGroup parent, TextEmojiLoader emojiLoader, OnHolderClickListener listener, boolean enableDelete) { + /** + * @param enableRemoveButton true to enable remove button + */ + public UserHolder(ViewGroup parent, OnHolderClickListener listener, boolean enableRemoveButton) { super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user, parent, false)); - this.settings = GlobalSettings.get(parent.getContext()); - this.picasso = PicassoBuilder.get(parent.getContext()); + settings = GlobalSettings.get(parent.getContext()); + picasso = PicassoBuilder.get(parent.getContext()); + emojiLoader = new TextEmojiLoader(parent.getContext()); this.listener = listener; - this.emojiLoader = emojiLoader; CardView background = (CardView) itemView; ViewGroup container = itemView.findViewById(R.id.item_user_container); @@ -87,7 +89,7 @@ public class UserHolder extends ViewHolder implements OnClickListener, AsyncCall AppStyles.setTheme(container, Color.TRANSPARENT); background.setCardBackgroundColor(settings.getCardColor()); - if (enableDelete) { + if (enableRemoveButton) { delete.setVisibility(View.VISIBLE); } else { delete.setVisibility(View.GONE); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserlistHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserlistHolder.java index bb55216d..306e01ea 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserlistHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/UserlistHolder.java @@ -62,13 +62,13 @@ public class UserlistHolder extends ViewHolder implements OnClickListener { private long tagId; /** - * @param parent Parent view from adapter + * */ - public UserlistHolder(ViewGroup parent, TextEmojiLoader emojiLoader, OnHolderClickListener listener) { + public UserlistHolder(ViewGroup parent, OnHolderClickListener listener) { super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, parent, false)); settings = GlobalSettings.get(parent.getContext()); picasso = PicassoBuilder.get(parent.getContext()); - this.emojiLoader = emojiLoader; + emojiLoader = new TextEmojiLoader(parent.getContext()); this.listener = listener; CardView background = (CardView) itemView; diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/MessageFragment.java b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/MessageFragment.java index 4362eb41..845f34cc 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/MessageFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/MessageFragment.java @@ -53,7 +53,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); confirmDialog = new ConfirmDialog(requireActivity(), this); - adapter = new MessageAdapter(requireContext(), this); + adapter = new MessageAdapter(this); messageLoader = new MessageLoader(requireContext()); setAdapter(adapter); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/NotificationFragment.java b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/NotificationFragment.java index 40554fc7..5e642bda 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/NotificationFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/NotificationFragment.java @@ -64,7 +64,7 @@ public class NotificationFragment extends ListFragment implements OnNotification confirmDialog = new ConfirmDialog(requireActivity(), this); notificationLoader = new NotificationLoader(requireContext()); notificationAction = new NotificationAction(requireContext()); - adapter = new NotificationAdapter(requireContext(), this); + adapter = new NotificationAdapter(this); setAdapter(adapter); if (savedInstanceState != null) { diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/StatusFragment.java b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/StatusFragment.java index a58305b8..4c13175f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/StatusFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/StatusFragment.java @@ -127,7 +127,7 @@ public class StatusFragment extends ListFragment implements StatusSelectListener public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); statusLoader = new StatusLoader(requireContext()); - adapter = new StatusAdapter(requireContext(), this); + adapter = new StatusAdapter(this); setAdapter(adapter); Bundle param = getArguments(); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserFragment.java b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserFragment.java index af2c7072..9c19b6d0 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserFragment.java @@ -168,7 +168,7 @@ public class UserFragment extends ListFragment implements UserClickListener, OnC userLoader = new UsersLoader(requireContext()); userlistManager = new UserlistManager(requireContext()); confirmDialog = new ConfirmDialog(requireActivity(), this); - adapter = new UserAdapter(requireContext(), this); + adapter = new UserAdapter(this); setAdapter(adapter); Bundle param = getArguments(); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserListFragment.java b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserListFragment.java index adcf11ae..d3038c57 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserListFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/fragments/UserListFragment.java @@ -79,7 +79,7 @@ public class UserListFragment extends ListFragment implements ListClickListener, public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); userlistLoader = new UserlistLoader(requireContext()); - adapter = new UserlistAdapter(requireContext(), this); + adapter = new UserlistAdapter(this); setAdapter(adapter); Bundle param = getArguments(); diff --git a/app/src/main/res/layout/dialog_description.xml b/app/src/main/res/layout/dialog_description.xml index 47fbaa2f..2018d458 100644 --- a/app/src/main/res/layout/dialog_description.xml +++ b/app/src/main/res/layout/dialog_description.xml @@ -11,7 +11,7 @@ android:text="@string/dialog_description_title" android:lines="1" android:textSize="@dimen/dialog_description_textsize_title" - android:layout_margin="@dimen/dialog_description_layout_margin"/> + android:layout_margin="@dimen/dialog_description_layout_margin" /> + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/app/src/main/res/menu/image.xml b/app/src/main/res/menu/image.xml index 5eb9f645..9101bd13 100644 --- a/app/src/main/res/menu/image.xml +++ b/app/src/main/res/menu/image.xml @@ -9,5 +9,5 @@ + android:visible="false" /> \ No newline at end of file diff --git a/app/src/main/res/menu/video.xml b/app/src/main/res/menu/video.xml index 53ef68aa..7607207b 100644 --- a/app/src/main/res/menu/video.xml +++ b/app/src/main/res/menu/video.xml @@ -4,10 +4,10 @@ + android:visible="true" /> + android:visible="false" /> \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index c1142c1a..3bb5339f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -289,6 +289,7 @@ 13sp 5dp 10dp + 13sp 3dp