adapter: replace simple viewholders by SingleViewHolder(extended from RecyclerView.ViewHolder but allowed to instantiate)

main
Alibek Omarov 5 years ago
parent 78cf552a32
commit 8d89f83bae
  1. 39
      app/src/main/java/com/keylesspalace/tusky/adapter/EmojiReactionViewHolder.java
  2. 16
      app/src/main/java/com/keylesspalace/tusky/adapter/EmojiReactionsAdapter.java
  3. 11
      app/src/main/java/com/keylesspalace/tusky/adapter/SingleViewHolder.java
  4. 31
      app/src/main/res/layout/item_emoji_reaction.xml

@ -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; 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 List<EmojiReaction> reactions;
private final StatusActionListener listener; private final StatusActionListener listener;
private final String statusId; private final String statusId;
@ -42,21 +42,23 @@ public class EmojiReactionsAdapter extends RecyclerView.Adapter<EmojiReactionVie
} }
@Override @Override
public EmojiReactionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public SingleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_emoji_reaction, parent, false); .inflate(R.layout.item_emoji_reaction, parent, false);
return new EmojiReactionViewHolder(view); return new SingleViewHolder(view);
} }
@Override @Override
public void onBindViewHolder(EmojiReactionViewHolder holder, int position) { public void onBindViewHolder(SingleViewHolder holder, int position) {
EmojiReaction reaction = reactions.get(position); EmojiReaction reaction = reactions.get(position);
String str = reaction.getName() + " " + reaction.getCount(); String str = reaction.getName() + " " + reaction.getCount();
// no custom emoji yet! // no custom emoji yet!
holder.emojiReaction.setText(str); EmojiAppCompatButton btn = (EmojiAppCompatButton)holder.itemView;
holder.emojiReaction.setActivated(reaction.getMe());
holder.emojiReaction.setOnClickListener(v -> { btn.setText(str);
btn.setActivated(reaction.getMe());
btn.setOnClickListener(v -> {
listener.onEmojiReactMenu(v, reaction, statusId); 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"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:layout_marginRight="2dp"
<!-- not a best way but I'm lazy to do proper button --> android:layout_marginBottom="1dp"
<androidx.emoji.widget.EmojiAppCompatButton android:minWidth="0dp"
android:id="@+id/status_emoji_reaction" android:lines="1"
android:layout_width="wrap_content" android:textAlignment="viewStart"
android:layout_height="wrap_content" android:textColor="?android:attr/textColorPrimary"
android:layout_marginRight="2dp" android:textSize="?attr/status_text_medium"
android:layout_marginBottom="1dp" app:backgroundTint="@color/emoji_reaction_button"
android:minWidth="0dp" tools:text="A 0" />
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>

Loading…
Cancel
Save