Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bb5f751 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Use Chip for category in grid view and adjust font size

parent de80cde1
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
@@ -10,6 +11,8 @@ import android.view.ViewGroup;
import androidx.annotation.ColorInt;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Px;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
@@ -22,6 +25,7 @@ import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithExcerpt
import it.niedermann.owncloud.notes.databinding.ItemNotesListSectionItemBinding;

import static it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithoutExcerptBinding.inflate;
import static it.niedermann.owncloud.notes.util.NoteUtil.getFontSizeFromPreferences;

public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements Branded {

@@ -37,6 +41,9 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
    private boolean showCategory = true;
    private CharSequence searchQuery;
    private final List<Integer> selected = new ArrayList<>();
    @Px
    private final float fontSize;
    private final boolean monospace;
    @ColorInt
    private int mainColor;
    @ColorInt
@@ -47,6 +54,9 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
        this.gridView = gridView;
        this.mainColor = context.getResources().getColor(R.color.defaultBrand);
        this.textColor = Color.WHITE;
        final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
        this.fontSize = getFontSizeFromPreferences(context, sp);
        this.monospace = sp.getBoolean(context.getString(R.string.pref_key_font), false);
        // FIXME see getItemId()
        // setHasStableIds(true);
    }
@@ -101,7 +111,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
                }
                case TYPE_NOTE_WITH_EXCERPT:
                case TYPE_NOTE_WITHOUT_EXCERPT: {
                    return new NoteViewGridHolder(ItemNotesListNoteItemGridBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false), noteClickListener);
                    return new NoteViewGridHolder(ItemNotesListNoteItemGridBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false), noteClickListener, monospace, fontSize);
                }
                default: {
                    throw new IllegalArgumentException("Not supported viewType: " + viewType);
+11 −1
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.model;

import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;

import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridBinding;

@@ -17,9 +20,16 @@ public class NoteViewGridHolder extends NoteViewHolder {
    @NonNull
    private final ItemNotesListNoteItemGridBinding binding;

    public NoteViewGridHolder(@NonNull ItemNotesListNoteItemGridBinding binding, @NonNull NoteClickListener noteClickListener) {
    public NoteViewGridHolder(@NonNull ItemNotesListNoteItemGridBinding binding, @NonNull NoteClickListener noteClickListener, boolean monospace, @Px float fontSize) {
        super(binding.getRoot(), noteClickListener);
        this.binding = binding;

        binding.noteTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 1.1f);
        binding.noteExcerpt.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * .8f);
        if (monospace) {
            binding.noteTitle.setTypeface(Typeface.MONOSPACE);
            binding.noteExcerpt.setTypeface(Typeface.MONOSPACE);
        }
    }

    public void showSwipe(boolean left) {
+14 −6
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.model;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
@@ -19,6 +20,8 @@ import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.chip.Chip;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -74,6 +77,11 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
            }
        }

        noteCategory.setTextColor(categoryForeground);
        if (noteCategory instanceof Chip) {
            ((Chip) noteCategory).setChipStrokeColor(ColorStateList.valueOf(categoryBackground));
            ((Chip) noteCategory).setChipBackgroundColor(ColorStateList.valueOf(isDarkThemeActive ? categoryBackground : Color.TRANSPARENT));
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                DrawableCompat.setTint(noteCategory.getBackground(), categoryBackground);
            } else {
@@ -81,7 +89,7 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
                drawable.setStroke(1, categoryBackground);
                drawable.setColor(isDarkThemeActive ? categoryBackground : Color.TRANSPARENT);
            }
        noteCategory.setTextColor(categoryForeground);
        }
    }

    protected void bindFavorite(@NonNull ImageView noteFavorite, boolean isFavorite) {
+43 −48
Original line number Diff line number Diff line
@@ -15,59 +15,69 @@
        android:orientation="vertical"
        android:paddingBottom="@dimen/spacer_1x">

        <TextView
            android:id="@+id/noteTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/spacer_2x"
            android:layout_marginLeft="@dimen/spacer_2x"
            android:layout_marginTop="@dimen/spacer_2x"
            android:layout_marginEnd="@dimen/spacer_2x"
            android:layout_marginRight="@dimen/spacer_2x"
            android:layout_marginBottom="@dimen/spacer_1x"
            android:textAppearance="?attr/textAppearanceHeadline5"
            android:textColor="@color/fg_default"
            tools:maxLength="50"
            tools:text="@tools:sample/lorem/random" />


        <TextView
            android:id="@+id/noteExcerpt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/spacer_2x"
            android:layout_marginLeft="@dimen/spacer_2x"
            android:layout_marginEnd="@dimen/spacer_2x"
            android:layout_marginRight="@dimen/spacer_2x"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/fg_default"
            tools:maxLength="200"
            tools:text="@tools:sample/lorem/random" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="false"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <LinearLayout
            <FrameLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                android:layout_weight="1">

                <TextView
                <com.google.android.material.chip.Chip
                    android:id="@+id/noteCategory"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/spacer_1x"
                    android:layout_marginLeft="@dimen/spacer_1x"
                    android:layout_marginTop="@dimen/spacer_1x"
                    android:background="@drawable/border"
                    android:maxLines="1"
                    android:paddingLeft="@dimen/spacer_1x"
                    android:paddingTop="1dp"
                    android:paddingRight="@dimen/spacer_1x"
                    android:paddingBottom="1dp"
                    android:singleLine="true"
                    android:textColor="?android:textColorPrimary"
                    android:textSize="@dimen/secondary_font_size"
                    tools:maxLength="15"
                    tools:text="@tools:sample/lorem/random" />

                <TextView
                    android:id="@+id/noteTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/spacer_2x"
                    android:layout_marginLeft="@dimen/spacer_2x"
                    android:layout_marginTop="@dimen/spacer_1x"
                    android:layout_marginEnd="0dp"
                    android:layout_marginRight="0dp"
                    android:layout_marginBottom="@dimen/spacer_1x"
                    android:textAppearance="?attr/textAppearanceHeadline5"
                    android:textColor="@color/fg_default"
                    android:theme="@style/textViewStyle"
                    android:ellipsize="middle"
                    android:textColor="?android:textColorPrimary"
                    android:textSize="@dimen/secondary_font_size"
                    app:chipBackgroundColor="@color/primary"
                    app:chipStrokeColor="@color/defaultBrand"
                    app:chipStrokeWidth="1dp"
                    tools:maxLength="50"
                    tools:text="@tools:sample/lorem/random" />
            </LinearLayout>

            </FrameLayout>

            <FrameLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="top">
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/noteFavorite"
@@ -75,7 +85,7 @@
                    android:layout_height="wrap_content"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:contentDescription="@string/menu_favorite"
                    android:padding="@dimen/spacer_1x"
                    android:padding="@dimen/spacer_2x"
                    tools:src="@drawable/ic_star_yellow_24dp" />

                <androidx.appcompat.widget.AppCompatImageView
@@ -90,20 +100,5 @@
                    app:srcCompat="@drawable/ic_sync_blue_18dp" />
            </FrameLayout>
        </LinearLayout>

        <TextView
            android:id="@+id/noteExcerpt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/spacer_2x"
            android:layout_marginLeft="@dimen/spacer_2x"
            android:layout_marginEnd="@dimen/spacer_2x"
            android:layout_marginRight="@dimen/spacer_2x"
            android:layout_marginBottom="@dimen/spacer_1x"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/fg_default"
            android:theme="@style/textViewStyle"
            tools:maxLength="200"
            tools:text="@tools:sample/lorem/random" />
    </LinearLayout>
</com.google.android.material.card.MaterialCardView>
 No newline at end of file