Getting background color from favicon to set it to the item activity toolbar and default color to the item activity title

This commit is contained in:
Shinokuni 2019-02-09 18:55:09 +00:00
parent bf2401a337
commit 20efc02d4e
12 changed files with 68 additions and 103 deletions

View File

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="vectorWizard">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipartAsset">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="url" value="jar:file:/Applications/Android%20Studio.app/Contents/plugins/android/lib/android.jar!/images/material_design_icons/device/ic_access_time_black_24dp.xml" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="outputName" value="ic_read_time" />
<entry key="sourceFile" value="$USER_HOME$" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</component>
</project>

Binary file not shown.

View File

@ -1,35 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="7">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="6">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -106,6 +106,8 @@ public class ItemActivity extends AppCompatActivity {
toolbarLayout.setTitle(itemWithFeed.getFeedName());
title.setText(item.getTitle());
if (itemWithFeed.getColor() != 0)
title.setTextColor(itemWithFeed.getColor());
if (item.getAuthor() != null) {
author.setText(getString(R.string.by_author, item.getAuthor()));
@ -124,6 +126,16 @@ public class ItemActivity extends AppCompatActivity {
readTimeLayout.setVisibility(View.VISIBLE);
}
if (itemWithFeed.getBgColor() != 0) {
toolbarLayout.setBackgroundColor(itemWithFeed.getBgColor());
toolbarLayout.setContentScrimColor(itemWithFeed.getBgColor());
toolbarLayout.setStatusBarScrimColor(itemWithFeed.getBgColor());
} else if (itemWithFeed.getColor() != 0) {
toolbarLayout.setBackgroundColor(itemWithFeed.getColor());
toolbarLayout.setContentScrimColor(itemWithFeed.getColor());
toolbarLayout.setStatusBarScrimColor(itemWithFeed.getColor());
}
webView.setItem(itemWithFeed, Utils.getDeviceWidth(this));
}
}

View File

@ -3,7 +3,6 @@ package com.readrops.app;
import android.app.Application;
import android.arch.lifecycle.LiveData;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.ColorInt;
import android.support.v7.graphics.Palette;
import android.util.Log;
@ -27,16 +26,11 @@ import org.joda.time.LocalDateTime;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.TreeMap;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class LocalFeedRepository extends ARepository implements QueryCallback {
private static final String TAG = LocalFeedRepository.class.getSimpleName();
@ -231,15 +225,18 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
String favUrl = HtmlParser.getFaviconLink(feed.getSiteUrl());
if (favUrl != null && Patterns.WEB_URL.matcher(favUrl).matches()) {
feed.setIconUrl(favUrl);
feed.setColor(getFaviconColor(favUrl));
setFeedColors(favUrl, feed);
}
}
private @ColorInt int getFaviconColor(String favUrl) throws IOException {
private void setFeedColors(String favUrl, Feed feed) throws IOException {
Bitmap favicon = Utils.getImageFromUrl(favUrl);
Palette palette = Palette.from(favicon).generate();
return palette.getDominantSwatch().getRgb();
feed.setTextColor(palette.getDominantSwatch().getRgb());
if (palette.getMutedSwatch() != null)
feed.setBackgroundColor(palette.getMutedSwatch().getRgb());
}

View File

@ -2,13 +2,10 @@ package com.readrops.app;
import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.support.annotation.NonNull;
import com.readrops.app.database.ItemWithFeed;
import com.readrops.app.database.entities.Item;
import com.readrops.readropslibrary.ParsingResult;
import java.util.List;

View File

@ -13,8 +13,8 @@ import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.Item;
@android.arch.persistence.room.Database(entities = {Feed.class, Item.class}, version = 1)
@TypeConverters(Converters.class)
@android.arch.persistence.room.Database(entities = {Feed.class, Item.class}, version = 1, exportSchema = false)
@TypeConverters({Converters.class})
public abstract class Database extends RoomDatabase {
public abstract FeedDao feedDao();

View File

@ -2,6 +2,7 @@ package com.readrops.app.database;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Embedded;
import android.support.annotation.ColorInt;
import com.readrops.app.database.entities.Item;
@ -13,7 +14,11 @@ public class ItemWithFeed {
@ColumnInfo(name = "name")
private String feedName;
private int color;
@ColumnInfo(name = "text_color")
private @ColorInt int color;
@ColumnInfo(name = "background_color")
private @ColorInt int bgColor;
@ColumnInfo(name = "icon_url")
private String feedIconUrl;
@ -34,11 +39,11 @@ public class ItemWithFeed {
this.feedName = feedName;
}
public int getColor() {
public @ColorInt int getColor() {
return color;
}
public void setColor(int color) {
public void setColor(@ColorInt int color) {
this.color = color;
}
@ -49,4 +54,14 @@ public class ItemWithFeed {
public void setFeedIconUrl(String feedIconUrl) {
this.feedIconUrl = feedIconUrl;
}
public @ColorInt int getBgColor() {
return bgColor;
}
public void setBgColor(@ColorInt int bgColor) {
this.bgColor = bgColor;
}
}

View File

@ -20,7 +20,7 @@ public interface ItemDao {
@Query("Select * from Item Order By pub_date DESC")
LiveData<List<Item>> getAll();
@Query("Select Item.id, title, clean_description, image_link, pub_date, name, color, icon_url, read_time from Item Inner Join Feed on Item.feed_id = Feed.id Order By Item.id DESC")
@Query("Select Item.id, title, clean_description, image_link, pub_date, name, text_color, background_color, icon_url, read_time from Item Inner Join Feed on Item.feed_id = Feed.id Order By Item.id DESC")
LiveData<List<ItemWithFeed>> getAllItemWithFeeds();
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")
@ -32,6 +32,6 @@ public interface ItemDao {
@Insert
void insertAll(List<Item> items);
@Query("Select title, Item.description, content, pub_date, image_link, author, color, read_time, name from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id")
@Query("Select title, Item.description, content, pub_date, image_link, author, text_color, background_color, read_time, name from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id")
LiveData<ItemWithFeed> getItemById(int id);
}

View File

@ -9,8 +9,6 @@ import com.readrops.readropslibrary.localfeed.json.JSONFeed;
import com.readrops.readropslibrary.localfeed.rss.RSSChannel;
import com.readrops.readropslibrary.localfeed.rss.RSSFeed;
import java.nio.channels.Channel;
@Entity
public class Feed {
@ -27,7 +25,11 @@ public class Feed {
private String lastUpdated;
private @ColorInt int color;
@ColumnInfo(name = "text_color")
private @ColorInt int textColor;
@ColumnInfo(name = "background_color")
private @ColorInt int backgroundColor;
@ColumnInfo(name = "icon_url")
private String iconUrl;
@ -96,12 +98,20 @@ public class Feed {
this.lastUpdated = lastUpdated;
}
public @ColorInt int getColor() {
return color;
public @ColorInt int getTextColor() {
return textColor;
}
public void setColor(@ColorInt int color) {
this.color = color;
public void setTextColor(@ColorInt int textColor) {
this.textColor = textColor;
}
public @ColorInt int getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(@ColorInt int backgroundColor) {
this.backgroundColor = backgroundColor;
}
public String getIconUrl() {

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
@ -20,8 +20,17 @@ allprojects {
google()
jcenter()
}
afterEvaluate {
tasks.withType(JavaCompile.class) {
options.compilerArgs << "-Xmaxerrs" << "1000"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
task wrapper(type: Wrapper) {
gradleVersion = '3.3.1'
}