comment #411 - Reactions in drawer
This commit is contained in:
parent
37704b72a0
commit
9240c16e93
|
@ -1,5 +1,5 @@
|
||||||
package app.fedilab.android.drawers;
|
package app.fedilab.android.drawers;
|
||||||
/* Copyright 2018 Thomas Schneider
|
/* Copyright 2020 Thomas Schneider
|
||||||
*
|
*
|
||||||
* This file is a part of Fedilab
|
* This file is a part of Fedilab
|
||||||
*
|
*
|
||||||
|
@ -16,77 +16,43 @@ package app.fedilab.android.drawers;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
import app.fedilab.android.client.Entities.Reaction;
|
||||||
import app.fedilab.android.sqlite.TagsCacheDAO;
|
|
||||||
import es.dmoral.toasty.Toasty;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 01/12/2018.
|
* Created by Thomas on 10/03/2020.
|
||||||
* Adapter for tags when editing
|
* Adapter for reactions on messages
|
||||||
*/
|
*/
|
||||||
public class TagsEditAdapter extends RecyclerView.Adapter {
|
public class ReactionAdapter extends RecyclerView.Adapter {
|
||||||
|
|
||||||
private Context context;
|
private List<Reaction> reactions;
|
||||||
private List<String> tags;
|
|
||||||
private TagsEditAdapter tagsEditAdapter;
|
|
||||||
|
|
||||||
public TagsEditAdapter(List<String> tags) {
|
public ReactionAdapter(List<Reaction> reactions) {
|
||||||
this.tags = tags;
|
this.reactions = reactions;
|
||||||
|
|
||||||
tagsEditAdapter = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
|
||||||
context = parent.getContext();
|
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
||||||
LayoutInflater layoutInflater = LayoutInflater.from(context);
|
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_reaction, parent, false));
|
||||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_tag_edit, parent, false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||||
final String[] tag = {tags.get(viewHolder.getAdapterPosition())};
|
final Reaction reaction = reactions.get(viewHolder.getAdapterPosition());
|
||||||
ViewHolder holder = (ViewHolder) viewHolder;
|
ViewHolder holder = (ViewHolder) viewHolder;
|
||||||
holder.tag_name.setText(String.format("#%s", tag[0]));
|
holder.reaction_name.setText(reaction.getName());
|
||||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
holder.reaction_count.setText(String.valueOf(reaction.getCount()));
|
||||||
holder.save_tag.setOnClickListener(v -> {
|
|
||||||
if (holder.tag_name.getText() != null && holder.tag_name.getText().toString().trim().replaceAll("#", "").length() > 0) {
|
|
||||||
String tagToInsert = holder.tag_name.getText().toString().trim().replaceAll("#", "");
|
|
||||||
boolean isPresent = new TagsCacheDAO(context, db).isPresent(tagToInsert);
|
|
||||||
if (isPresent)
|
|
||||||
Toasty.warning(context, context.getString(R.string.tags_already_stored), Toast.LENGTH_LONG).show();
|
|
||||||
else {
|
|
||||||
new TagsCacheDAO(context, db).update(tag[0], tagToInsert);
|
|
||||||
Toasty.success(context, context.getString(R.string.tags_renamed), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
holder.delete_tag.setOnClickListener(v -> {
|
|
||||||
holder.tag_name.clearFocus();
|
|
||||||
new TagsCacheDAO(context, db).removeTag(tag[0]);
|
|
||||||
tags.remove(tag[0]);
|
|
||||||
tagsEditAdapter.notifyItemRemoved(viewHolder.getAdapterPosition());
|
|
||||||
Toasty.success(context, context.getString(R.string.tags_deleted), Toast.LENGTH_LONG).show();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -96,19 +62,19 @@ public class TagsEditAdapter extends RecyclerView.Adapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return tags.size();
|
return reactions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tag_name;
|
TextView reaction_name, reaction_count;
|
||||||
ImageButton save_tag, delete_tag;
|
LinearLayout reaction_container;
|
||||||
|
|
||||||
public ViewHolder(@NonNull View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
tag_name = itemView.findViewById(R.id.tag_name);
|
reaction_name = itemView.findViewById(R.id.reaction_name);
|
||||||
delete_tag = itemView.findViewById(R.id.delete_tag);
|
reaction_count = itemView.findViewById(R.id.reaction_count);
|
||||||
save_tag = itemView.findViewById(R.id.save_tag);
|
reaction_container = itemView.findViewById(R.id.reaction_container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1012,17 +1012,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
||||||
holder.status_account_username.setVisibility(View.GONE);
|
holder.status_account_username.setVisibility(View.GONE);
|
||||||
holder.status_action_container.setVisibility(View.GONE);
|
holder.status_action_container.setVisibility(View.GONE);
|
||||||
holder.status_reactions.setVisibility(View.VISIBLE);
|
holder.status_reactions.setVisibility(View.VISIBLE);
|
||||||
if( status.getReactions() != null && status.getReactions().size() > 0 ){
|
ReactionAdapter reactionAdapter = new ReactionAdapter(status.getReactions());
|
||||||
for(Reaction reaction: status.getReactions()){
|
holder.reactions_view.setAdapter(reactionAdapter);
|
||||||
TextView textView = new TextView(context);
|
LinearLayoutManager layoutManager
|
||||||
textView.setText(reaction.getName() + " " + reaction.getCount());
|
= new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
|
||||||
holder.reactions_view.addView(textView);
|
holder.reactions_view.setLayoutManager(layoutManager);
|
||||||
}
|
|
||||||
}
|
|
||||||
LinearLayout status_reactions;
|
|
||||||
ImageView status_add_reaction;
|
|
||||||
HorizontalScrollView reactions_view;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.status_cardview_title.setTextColor(ContextCompat.getColor(context, R.color.dark_text_toot_header));
|
holder.status_cardview_title.setTextColor(ContextCompat.getColor(context, R.color.dark_text_toot_header));
|
||||||
|
@ -3993,7 +3987,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
||||||
|
|
||||||
LinearLayout status_reactions;
|
LinearLayout status_reactions;
|
||||||
ImageView status_add_reaction;
|
ImageView status_add_reaction;
|
||||||
LinearLayout reactions_view;
|
RecyclerView reactions_view;
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
|
|
|
@ -15,40 +15,18 @@
|
||||||
see <http://www.gnu.org/licenses>.
|
see <http://www.gnu.org/licenses>.
|
||||||
-->
|
-->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/account_container"
|
android:id="@+id/reaction_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
<TextView
|
||||||
<EditText
|
android:id="@+id/reaction_name"
|
||||||
android:id="@+id/tag_name"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:inputType="text"
|
|
||||||
android:padding="20dp" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/save_tag"
|
|
||||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_margin="5dp"
|
/>
|
||||||
android:gravity="center"
|
<TextView
|
||||||
android:src="@drawable/ic_save_white"
|
android:layout_width="wrap_content"
|
||||||
android:text="@string/set_save_changes" />
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/reaction_count"/>
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/delete_tag"
|
|
||||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_margin="5dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:src="@drawable/ic_delete"
|
|
||||||
android:text="@string/set_save_changes" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -878,16 +878,11 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
android:contentDescription="@string/add_reaction" />
|
android:contentDescription="@string/add_reaction" />
|
||||||
<HorizontalScrollView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/reactions_view"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"/>
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/reactions_view"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
</HorizontalScrollView>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/status_action_container"
|
android:id="@+id/status_action_container"
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:padding="20dp" />
|
android:padding="20dp" />
|
||||||
|
|
Loading…
Reference in New Issue