Tweak feed colors rules

This commit is contained in:
Shinokuni 2019-05-17 11:52:07 +02:00
parent 062e5a6050
commit 1302d8306d
2 changed files with 14 additions and 27 deletions

View File

@ -1,7 +1,6 @@
package com.readrops.app.utils;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
@ -10,10 +9,7 @@ import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
@ -34,18 +30,6 @@ public final class Utils {
public static final int AVERAGE_WORDS_PER_MINUTE = 250;
public static void displayErrorInMainThread(Context context, String message) {
Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
if (!(Looper.myLooper() == Looper.getMainLooper())) {
Handler handler = new Handler(Looper.getMainLooper());
Looper.prepare();
handler.post(toast::show);
} else
toast.show();
}
public static Bitmap getImageFromUrl(String url) {
try {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
@ -74,7 +58,7 @@ public final class Utils {
public static double readTimeFromString(String value) {
int nbWords = value.split("\\s+").length;
double minutes = (double)nbWords / AVERAGE_WORDS_PER_MINUTE;
double minutes = (double) nbWords / AVERAGE_WORDS_PER_MINUTE;
return minutes;
}
@ -92,7 +76,7 @@ public final class Utils {
|| type.equals("image/png");
}
public static void setDrawableColor(Drawable drawable, int color) {
public static void setDrawableColor(Drawable drawable, @ColorInt int color) {
drawable.mutate().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
}

View File

@ -132,19 +132,22 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
viewHolder.feedIcon.setImageResource(R.drawable.ic_rss_feed);
Resources resources = viewHolder.itemView.getResources();
if (itemWithFeed.getColor() != 0) {
if (itemWithFeed.getBgColor() != 0) {
viewHolder.feedName.setTextColor(itemWithFeed.getBgColor());
Utils.setDrawableColor(viewHolder.dateLayout.getBackground(), itemWithFeed.getBgColor());
} else if (itemWithFeed.getColor() != 0) {
viewHolder.feedName.setTextColor(itemWithFeed.getColor());
Utils.setDrawableColor(viewHolder.dateLayout.getBackground(), itemWithFeed.getColor());
} else
viewHolder.feedName.setTextColor(resources.getColor(android.R.color.tab_indicator_text));
if (itemWithFeed.getBgColor() != 0)
Utils.setDrawableColor(viewHolder.dateLayout.getBackground(), itemWithFeed.getBgColor());
else if (itemWithFeed.getBgColor() == 0 && itemWithFeed.getColor() == 0)
} else if (itemWithFeed.getBgColor() == 0 && itemWithFeed.getColor() == 0) {
viewHolder.feedName.setTextColor(resources.getColor(android.R.color.tab_indicator_text));
Utils.setDrawableColor(viewHolder.dateLayout.getBackground(),
ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.colorPrimary));
}
int minutes = (int)Math.round(itemWithFeed.getItem().getReadTime());
int minutes = (int) Math.round(itemWithFeed.getItem().getReadTime());
if (minutes < 1)
viewHolder.itemReadTime.setText(resources.getString(R.string.read_time_lower_than_1));
else if (minutes > 1)
@ -162,7 +165,6 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
}
@Override
public long getItemId(int position) {
return getItem(position).getItem().getId();
@ -241,6 +243,7 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
public interface OnItemClickListener {
void onItemClick(ItemWithFeed itemWithFeed, int position);
void onItemLongClick(ItemWithFeed itemWithFeed, int position);
}
@ -291,7 +294,7 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
itemFolderName = itemView.findViewById(R.id.item_folder_name);
dateLayout = itemView.findViewById(R.id.item_date_layout);
alphaViews = new View[] {
alphaViews = new View[]{
dateLayout,
itemFolderName,
feedIcon,