From 69aaa323e26c20fec40c017e0cd19cc1ce386321 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Mon, 29 Nov 2021 20:26:18 +0100 Subject: [PATCH] Theme (#375) * Fix sources colors * Fix issues with sources * Simplify card view theme * Simplify list item theming * Simplify article viewer theming * Fix issues with the color selection. * Correct the color of sources text in article reader --- .../bou/readerforselfoss/SourcesActivity.kt | 8 ++++---- .../adapters/ItemCardAdapter.kt | 11 ---------- .../adapters/ItemListAdapter.kt | 12 ----------- .../fragments/ArticleFragment.kt | 12 ----------- .../settings/SettingsActivity.kt | 13 ++++++++++-- .../bou/readerforselfoss/themes/AppColors.kt | 17 +--------------- .../main/res/layout/activity_add_source.xml | 20 +++++++++++++------ app/src/main/res/layout/activity_sources.xml | 2 +- app/src/main/res/layout/card_item.xml | 5 ++++- app/src/main/res/layout/fragment_article.xml | 3 ++- app/src/main/res/layout/list_item.xml | 13 +++++++++--- app/src/main/res/layout/source_list_item.xml | 1 + app/src/main/res/values/styles.xml | 5 +++++ 13 files changed, 53 insertions(+), 69 deletions(-) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt index 05687c0..1d8ba6d 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt @@ -29,16 +29,16 @@ class SourcesActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { appColors = AppColors(this@SourcesActivity) + val scoop = Scoop.getInstance() + scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) + scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) + super.onCreate(savedInstanceState) binding = ActivitySourcesBinding.inflate(layoutInflater) val view = binding.root setContentView(view) - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - setSupportActionBar(binding.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt index 2397d57..a3abce0 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView.ScaleType -import androidx.core.content.ContextCompat import apps.amine.bou.readerforselfoss.R import apps.amine.bou.readerforselfoss.api.selfoss.Item import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi @@ -61,10 +60,6 @@ class ItemCardAdapter( binding.favButton.isSelected = itm.starred binding.title.text = itm.getTitleDecoded() - binding.title.setTextColor(ContextCompat.getColor( - c, - appColors.textColor - )) binding.title.setOnTouchListener(LinkOnTouchListener()) @@ -72,11 +67,6 @@ class ItemCardAdapter( binding.sourceTitleAndDate.text = itm.sourceAndDateText() - binding.sourceTitleAndDate.setTextColor(ContextCompat.getColor( - c, - appColors.textColor - )) - if (!fullHeightCards) { binding.itemImage.maxHeight = imageMaxHeight binding.itemImage.scaleType = ScaleType.CENTER_CROP @@ -112,7 +102,6 @@ class ItemCardAdapter( inner class ViewHolder(val binding: CardItemBinding) : RecyclerView.ViewHolder(binding.root) { init { - binding.root.setCardBackgroundColor(appColors.cardBackgroundColor) handleClickListeners() handleCustomTabActions() } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt index 76f5455..f49de7f 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt @@ -5,7 +5,6 @@ import android.content.Context import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater import android.view.ViewGroup -import androidx.core.content.ContextCompat import apps.amine.bou.readerforselfoss.api.selfoss.Item import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.databinding.ListItemBinding @@ -49,25 +48,14 @@ class ItemListAdapter( with(holder) { val itm = items[position] - binding.title.text = itm.getTitleDecoded() - binding.title.setTextColor(ContextCompat.getColor( - c, - appColors.textColor - )) - binding.title.setOnTouchListener(LinkOnTouchListener()) binding.title.setLinkTextColor(appColors.colorAccent) binding.sourceTitleAndDate.text = itm.sourceAndDateText() - binding.sourceTitleAndDate.setTextColor(ContextCompat.getColor( - c, - appColors.textColor - )) - if (itm.getThumbnail(c).isEmpty()) { if (itm.getIcon(c).isEmpty()) { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt index d0ba5bb..8ea66b3 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt @@ -392,24 +392,12 @@ class ArticleFragment : Fragment() { binding.webcontent.visibility = View.VISIBLE val (textColor, backgroundColor) = if (appColors.isDarkTheme) { if (context != null) { - binding.webcontent.setBackgroundColor( - ContextCompat.getColor( - requireContext(), - R.color.dark_webview - ) - ) Pair(ContextCompat.getColor(requireContext(), R.color.dark_webview_text), ContextCompat.getColor(requireContext(), R.color.dark_webview)) } else { Pair(null, null) } } else { if (context != null) { - binding.webcontent.setBackgroundColor( - ContextCompat.getColor( - requireContext(), - R.color.light_webview - ) - ) Pair(ContextCompat.getColor(requireContext(), R.color.light_webview_text), ContextCompat.getColor(requireContext(), R.color.light_webview)) } else { Pair(null, null) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.kt index 6bbdd61..3bef30a 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.kt @@ -13,7 +13,10 @@ import androidx.core.widget.addTextChangedListener import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import apps.amine.bou.readerforselfoss.R +import apps.amine.bou.readerforselfoss.databinding.ActivitySettingsBinding +import apps.amine.bou.readerforselfoss.themes.Toppings import apps.amine.bou.readerforselfoss.utils.Config +import com.ftinc.scoop.Scoop import java.lang.NumberFormatException private const val TITLE_TAG = "settingsActivityTitle" @@ -26,7 +29,13 @@ class SettingsActivity : AppCompatActivity(), if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false)) { setTheme(R.style.NoBarDark) } - setContentView(R.layout.activity_settings) + val binding = ActivitySettingsBinding.inflate(layoutInflater) + + val scoop = Scoop.getInstance() + scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) + scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) + + setContentView(binding.root) if (savedInstanceState == null) { supportFragmentManager .beginTransaction() @@ -41,7 +50,7 @@ class SettingsActivity : AppCompatActivity(), } } - setSupportActionBar(findViewById(R.id.toolbar)) + setSupportActionBar(binding.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt index 7eaf998..95d0c13 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt @@ -1,14 +1,9 @@ package apps.amine.bou.readerforselfoss.themes import android.app.Activity -import android.content.Context -import androidx.preference.PreferenceManager import androidx.annotation.ColorInt -import androidx.appcompat.view.ContextThemeWrapper -import android.util.TypedValue +import androidx.preference.PreferenceManager import apps.amine.bou.readerforselfoss.R -import android.view.LayoutInflater -import android.view.ViewGroup class AppColors(a: Activity) { @@ -16,7 +11,6 @@ class AppColors(a: Activity) { @ColorInt val colorPrimaryDark: Int @ColorInt val colorAccent: Int @ColorInt val colorAccentDark: Int - @ColorInt val cardBackgroundColor: Int @ColorInt val colorBackground: Int @ColorInt val textColor: Int val isDarkTheme: Boolean @@ -63,14 +57,5 @@ class AppColors(a: Activity) { } else { R.color.grey_900 } - - val wrapper = Context::class.java - val method = wrapper!!.getMethod("getThemeResId") - method.isAccessible = true - - val typedCardBackground = TypedValue() - a.theme.resolveAttribute(R.attr.cardBackgroundColor, typedCardBackground, true) - - cardBackgroundColor = typedCardBackground.data } } diff --git a/app/src/main/res/layout/activity_add_source.xml b/app/src/main/res/layout/activity_add_source.xml index c9166c0..df87241 100644 --- a/app/src/main/res/layout/activity_add_source.xml +++ b/app/src/main/res/layout/activity_add_source.xml @@ -7,7 +7,7 @@ tools:context="apps.amine.bou.readerforselfoss.AddSourceActivity"> + android:layout_marginLeft="16dp" + android:gravity="center_horizontal" /> + android:hint="@string/add_source_hint_name" + android:textColorHint="?android:textColorPrimary" + android:autofillHints="false" /> + app:layout_constraintLeft_toLeftOf="parent" + android:autofillHints="false" /> + android:textColorHint="?android:textColorPrimary" + android:inputType="text" + android:autofillHints="false" /> + android:layout_height="40dp" + android:theme="@style/App.Spinner"/>