Fix issue #1017 - Usage frequency of tags when composing

This commit is contained in:
Thomas 2024-01-15 17:25:52 +01:00
parent 892bb521e5
commit a9e17fb5d6
3 changed files with 40 additions and 1 deletions

View file

@ -890,6 +890,13 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
Tag tag = new Tag();
tag.name = camelTag;
if (!results.hashtags.contains(tag)) {
for(Tag realTag: results.hashtags) {
if(realTag.name.equalsIgnoreCase(camelTag)) {
tag.history = realTag.history;
break;
}
}
results.hashtags.add(0, tag);
}
}

View file

@ -11,10 +11,14 @@ import android.widget.Filterable;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.github.mikephil.charting.data.Entry;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.databinding.DrawerTagSearchBinding;
import app.fedilab.android.mastodon.client.entities.api.History;
import app.fedilab.android.mastodon.client.entities.api.Tag;
/* Copyright 2021 Thomas Schneider
@ -37,6 +41,7 @@ public class TagsSearchAdapter extends ArrayAdapter<Tag> implements Filterable {
private final List<Tag> tags;
private final List<Tag> tempTags;
private final List<Tag> suggestions;
private final Context context;
private final Filter searchFilter = new Filter() {
@Override
@ -75,6 +80,7 @@ public class TagsSearchAdapter extends ArrayAdapter<Tag> implements Filterable {
public TagsSearchAdapter(Context context, List<Tag> tags) {
super(context, android.R.layout.simple_list_item_1, tags);
this.context = context;
this.tags = tags;
this.tempTags = new ArrayList<>(tags);
this.suggestions = new ArrayList<>(tags);
@ -110,6 +116,21 @@ public class TagsSearchAdapter extends ArrayAdapter<Tag> implements Filterable {
holder = (TagSearchViewHolder) convertView.getTag();
}
holder.binding.tagName.setText(String.format("#%s", tag.name));
List<History> historyList = tag.history;
int stat = 0;
if (historyList != null) {
for (History history : historyList) {
stat += Integer.parseInt(history.accounts);
}
}
if(stat > 0 ) {
holder.binding.tagCount.setText("(" + context.getString(R.string.talking_about, stat) + ")");
holder.binding.tagCount.setVisibility(View.VISIBLE);
} else {
holder.binding.tagCount.setVisibility(View.GONE);
}
return holder.view;
}

View file

@ -15,6 +15,7 @@
see <http://www.gnu.org/licenses>
-->
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tag_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -22,9 +23,19 @@
<TextView
android:id="@+id/tag_name"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
tools:text="@tools:sample/lorem"
android:padding="10dp" />
<TextView
android:id="@+id/tag_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
android:layout_marginStart="20dp"
android:padding="10dp" />
</androidx.appcompat.widget.LinearLayoutCompat>