Very dirty, very quick, read-only implementation of emoji reactions

This commit is contained in:
Alibek Omarov 2020-02-07 01:21:10 +03:00
parent 7c286c61cd
commit b09aa35b8e
4 changed files with 97 additions and 3 deletions

View File

@ -128,6 +128,7 @@ dependencies {
kapt "androidx.room:room-compiler:$roomVersion"
implementation "com.google.android.material:material:1.1.0-rc01"
implementation 'com.google.android:flexbox:2.0.1'
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"

View File

@ -6,15 +6,19 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.emoji.widget.EmojiButton;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
@ -22,12 +26,14 @@ import com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Card;
import com.keylesspalace.tusky.entity.Status;
import com.keylesspalace.tusky.entity.EmojiReaction;
import com.keylesspalace.tusky.interfaces.StatusActionListener;
import com.keylesspalace.tusky.util.LinkHelper;
import com.keylesspalace.tusky.util.StatusDisplayOptions;
import com.keylesspalace.tusky.viewdata.StatusViewData;
import java.text.DateFormat;
import java.util.List;
import java.util.Date;
class StatusDetailedViewHolder extends StatusBaseViewHolder {
@ -40,6 +46,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
private TextView cardDescription;
private TextView cardUrl;
private View infoDivider;
private RecyclerView emojiReactionsView;
StatusDetailedViewHolder(View view) {
super(view);
@ -52,6 +59,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
cardDescription = view.findViewById(R.id.card_description);
cardUrl = view.findViewById(R.id.card_link);
infoDivider = view.findViewById(R.id.status_info_divider);
emojiReactionsView = view.findViewById(R.id.status_emoji_reactions);
cardView.setClipToOutline(true);
}
@ -120,6 +128,59 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
}
}
}
private class EmojiReactionViewHolder extends RecyclerView.ViewHolder {
public EmojiButton emojiReaction;
EmojiReactionViewHolder(View view) {
super(view);
emojiReaction = view.findViewById(R.id.status_emoji_reaction);
}
}
private class EmojiReactionsAdapter extends RecyclerView.Adapter<EmojiReactionViewHolder> {
private List<EmojiReaction> reactions;
EmojiReactionsAdapter(List<EmojiReaction> reactions) {
this.reactions = reactions;
}
@Override
public EmojiReactionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_emoji_reaction, parent, false);
return new EmojiReactionViewHolder(view);
}
@Override
public void onBindViewHolder(EmojiReactionViewHolder holder, int position) {
EmojiReaction reaction = reactions.get(position);
String str = reaction.getEmoji() + " " + reaction.getCount();
// no custom emoji yet!
holder.emojiReaction.setText(str);
}
// total number of rows
@Override
public int getItemCount() {
return reactions.size();
}
}
private void setEmojiReactions(@Nullable List<EmojiReaction> reactions) {
if(reactions != null) {
emojiReactionsView.setVisibility(View.VISIBLE);
FlexboxLayoutManager lm = new FlexboxLayoutManager(emojiReactionsView.getContext());
// lm.setFlexDirection(FlexDirection.COLUMN);
// StaggeredGridLayoutManager.HORIZONTAL);
// lm.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
emojiReactionsView.setLayoutManager(lm);
emojiReactionsView.setAdapter(new EmojiReactionsAdapter(reactions));
//emojiReactionsView.setLayoutManager StaggeredGridLayoutManager
}
}
@Override
protected void setupWithStatus(final StatusViewData.Concrete status,
@ -131,7 +192,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
setReblogAndFavCount(status.getReblogsCount(), status.getFavouritesCount(), listener);
setApplication(status.getApplication());
setEmojiReactions(status.getEmojiReactions());
View.OnLongClickListener longClickListener = view -> {
TextView textView = (TextView) view;
ClipboardManager clipboard = (ClipboardManager) view.getContext().getSystemService(Context.CLIPBOARD_SERVICE);

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- not a best way but I'm lazy to do proper button -->
<androidx.emoji.widget.EmojiButton
android:id="@+id/status_emoji_reaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorPrimary"
android:textSize="?attr/status_text_small"
tools:text="A 0" />
</FrameLayout>

View File

@ -264,17 +264,29 @@
app:layout_constraintTop_toBottomOf="@id/status_poll_description"
tools:text="21 Dec 2018 18:45" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/status_emoji_reactions"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:nestedScrollingEnabled="false"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_timestamp_info" />
<View
android:id="@+id/status_info_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/status_timestamp_info"
android:layout_below="@id/status_emoji_reactions"
android:layout_marginTop="6dp"
android:background="?android:attr/listDivider"
android:importantForAccessibility="no"
android:paddingStart="16dp"
android:paddingEnd="16dp"
app:layout_constraintTop_toBottomOf="@id/status_timestamp_info" />
app:layout_constraintTop_toBottomOf="@id/status_emoji_reactions" />
<TextView
android:id="@+id/status_reblogs"