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

main
Alibek Omarov 5 years ago
parent ae1cfc1d56
commit e1eaea9d5a
  1. 1
      app/build.gradle
  2. 63
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java
  3. 20
      app/src/main/res/layout/item_emoji_reaction.xml
  4. 16
      app/src/main/res/layout/item_status_detailed.xml

@ -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"

@ -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);
}
@ -121,6 +129,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,
final StatusActionListener listener,
@ -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);

@ -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>

@ -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"

Loading…
Cancel
Save