Categories colors in list

This commit is contained in:
Daniele 2021-09-22 09:24:11 +02:00
parent 63b60a46ae
commit 718c654056
5 changed files with 40 additions and 6 deletions

View File

@ -4,6 +4,7 @@
<option name="filePathToZoomLevelMap">
<map>
<entry key="../../../../layout/custom_preview.xml" value="0.5661458333333333" />
<entry key="app/src/main/res/drawable/category_listitem_background.xml" value="0.35104166666666664" />
<entry key="app/src/main/res/drawable/floating_semitransparent_button_background.xml" value="0.512962962962963" />
<entry key="app/src/main/res/drawable/ic_map_pin.xml" value="0.6425925925925926" />
<entry key="app/src/main/res/drawable/ic_more.xml" value="0.6166666666666667" />

View File

@ -21,6 +21,7 @@
package it.danieleverducci.nextcloudmaps.activity.main;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
@ -34,6 +35,7 @@ import android.widget.PopupMenu;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.RecyclerView;
import org.threeten.bp.format.DateTimeFormatter;
@ -104,6 +106,9 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.
public void onBindViewHolder(@NonNull GeofavoriteViewHolder holder, int position) {
Geofavorite geofavorite = geofavoriteListFiltered.get(position);
holder.tv_category.setText(geofavorite.categoryLetter());
holder.tv_category_background.setTint(
geofavorite.categoryColor() == 0 ? context.getColor(R.color.defaultBrand) : geofavorite.categoryColor());
holder.tv_title.setText(Html.fromHtml(geofavorite.getName()));
holder.tv_content.setText(geofavorite.getComment());
holder.tv_date.setText(geofavorite.getLocalDateCreated().format(dateFormatter));
@ -154,9 +159,10 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.
};
class GeofavoriteViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView tv_title, tv_content, tv_date;
TextView tv_category, tv_title, tv_content, tv_date;
ImageView bt_context_menu;
ImageView bt_nav;
Drawable tv_category_background;
ItemClickListener itemClickListener;
@ -164,11 +170,13 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.
GeofavoriteViewHolder(@NonNull View itemView, ItemClickListener itemClickListener) {
super(itemView);
tv_category = itemView.findViewById(R.id.tv_category);
tv_title = itemView.findViewById(R.id.title);
tv_content = itemView.findViewById(R.id.content);
tv_date = itemView.findViewById(R.id.date);
bt_context_menu = itemView.findViewById(R.id.geofav_context_menu_bt);
bt_nav = itemView.findViewById(R.id.geofav_nav_bt);
tv_category_background = DrawableCompat.wrap(tv_category.getBackground());
this.itemClickListener = itemClickListener;
itemView.setOnClickListener(this);

View File

@ -183,6 +183,14 @@ public class Geofavorite implements Serializable {
return Color.HSVToColor( new float[]{ Math.round(h), Math.round(s), Math.round(l) });
}
public String categoryLetter() {
if (category == null || category.length() == 0)
return "";
if (category.equals(DEFAULT_CATEGORY))
return "\u2022";
return category.substring(0,1);
}
@NonNull
@Override
public String toString() {

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="8dp"
android:right="8dp"
android:top="8dp"
android:bottom="8dp">
<shape
android:shape="oval">
<solid android:color="@color/defaultBrand"/>
</shape>
</item>
</layer-list>

View File

@ -26,13 +26,17 @@
android:clickable="true"
android:focusable="true">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
<TextView
android:id="@+id/tv_category"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginStart="12dp"
android:contentDescription="@null"
android:layout_weight="0"
android:src="@mipmap/ic_launcher"/>
android:background="@drawable/category_listitem_background"
android:gravity="center"
android:textSize="28dp"
android:textAllCaps="true"
android:textColor="@color/white"/>
<LinearLayout
android:orientation="vertical"