adapter: replace simple viewholders by SingleViewHolder(extended from RecyclerView.ViewHolder but allowed to instantiate)
This commit is contained in:
parent
d273c9dec4
commit
18c19be90c
|
@ -1,39 +0,0 @@
|
|||
package com.keylesspalace.tusky.adapter;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.emoji.widget.EmojiAppCompatButton;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.google.android.flexbox.FlexboxLayoutManager;
|
||||
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.entity.Status;
|
||||
import com.keylesspalace.tusky.entity.EmojiReaction;
|
||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
||||
import com.keylesspalace.tusky.util.CardViewMode;
|
||||
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;
|
||||
|
||||
public class EmojiReactionViewHolder extends RecyclerView.ViewHolder {
|
||||
public EmojiAppCompatButton emojiReaction;
|
||||
EmojiReactionViewHolder(View view) {
|
||||
super(view);
|
||||
emojiReaction = view.findViewById(R.id.status_emoji_reaction);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
|||
import java.util.Date;
|
||||
|
||||
|
||||
public class EmojiReactionsAdapter extends RecyclerView.Adapter<EmojiReactionViewHolder> {
|
||||
public class EmojiReactionsAdapter extends RecyclerView.Adapter<SingleViewHolder> {
|
||||
private final List<EmojiReaction> reactions;
|
||||
private final StatusActionListener listener;
|
||||
private final String statusId;
|
||||
|
@ -42,21 +42,23 @@ public class EmojiReactionsAdapter extends RecyclerView.Adapter<EmojiReactionVie
|
|||
}
|
||||
|
||||
@Override
|
||||
public EmojiReactionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public SingleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item_emoji_reaction, parent, false);
|
||||
return new EmojiReactionViewHolder(view);
|
||||
return new SingleViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(EmojiReactionViewHolder holder, int position) {
|
||||
public void onBindViewHolder(SingleViewHolder holder, int position) {
|
||||
EmojiReaction reaction = reactions.get(position);
|
||||
String str = reaction.getName() + " " + reaction.getCount();
|
||||
|
||||
// no custom emoji yet!
|
||||
holder.emojiReaction.setText(str);
|
||||
holder.emojiReaction.setActivated(reaction.getMe());
|
||||
holder.emojiReaction.setOnClickListener(v -> {
|
||||
EmojiAppCompatButton btn = (EmojiAppCompatButton)holder.itemView;
|
||||
|
||||
btn.setText(str);
|
||||
btn.setActivated(reaction.getMe());
|
||||
btn.setOnClickListener(v -> {
|
||||
listener.onEmojiReactMenu(v, reaction, statusId);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.keylesspalace.tusky.adapter;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
// empty class to be able to instantiate ViewHolder which is abstract for dumbass reason
|
||||
public class SingleViewHolder extends RecyclerView.ViewHolder {
|
||||
public SingleViewHolder(View view) {
|
||||
super(view);
|
||||
}
|
||||
}
|
|
@ -1,24 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.emoji.widget.EmojiAppCompatButton
|
||||
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.EmojiAppCompatButton
|
||||
android:id="@+id/status_emoji_reaction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="2dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:minWidth="0dp"
|
||||
android:lines="1"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="?attr/status_text_medium"
|
||||
app:backgroundTint="@color/emoji_reaction_button"
|
||||
tools:text="A 0" />
|
||||
|
||||
</FrameLayout>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="2dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:minWidth="0dp"
|
||||
android:lines="1"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="?attr/status_text_medium"
|
||||
app:backgroundTint="@color/emoji_reaction_button"
|
||||
tools:text="A 0" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue