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