diff --git a/app/build.gradle b/app/build.gradle index afcb47f..f4a2f62 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ ext { buildDate: new Date() ] // This will make me able to build multiple times a day. May break thinks. I may forget it. - todaysBuilds = "4" + todaysBuilds = "1" } def gitVersion() { @@ -172,6 +172,7 @@ dependencies { // Themes implementation 'com.52inc:scoops:1.0.0' + implementation'com.jrummyapps:colorpicker:2.1.7' // Github issues reporter implementation 'com.heinrichreimersoftware:android-issue-reporter:1.3.1' diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index 8b21dc1..3eea4e3 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -33,6 +33,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.api.selfoss.Tag import apps.amine.bou.readerforselfoss.settings.SettingsActivity import apps.amine.bou.readerforselfoss.themes.AppColors +import apps.amine.bou.readerforselfoss.themes.Toppings import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.bottombar.maybeShow import apps.amine.bou.readerforselfoss.utils.bottombar.removeBadge @@ -90,6 +91,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private var items: ArrayList = ArrayList() private var allItems: ArrayList = ArrayList() + private var clickBehavior = false private var debugReadingItems = false private var shouldLogEverything = false @@ -109,6 +111,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private var infiniteScroll: Boolean = false private var lastFetchDone: Boolean = false + private lateinit var tabNewBadge: TextBadgeItem private lateinit var tabArchiveBadge: TextBadgeItem private lateinit var tabStarredBadge: TextBadgeItem @@ -142,9 +145,14 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Scoop.getInstance().apply(this) + + sharedPref = PreferenceManager.getDefaultSharedPreferences(this) + appColors = AppColors(this@HomeActivity) + setContentView(R.layout.activity_home) + handleThemeBinding() + setSupportActionBar(toolBar) if (savedInstanceState == null) { Amplify.getSharedInstance().promptIfReady(promptView) @@ -156,7 +164,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { customTabActivityHelper = CustomTabActivityHelper() settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) - sharedPref = PreferenceManager.getDefaultSharedPreferences(this) api = SelfossApi( this, @@ -167,8 +174,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { items = ArrayList() allItems = ArrayList() - appColors = AppColors(this@HomeActivity) - handleBottomBar() handleDrawer() @@ -272,27 +277,27 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { tabNewBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.primary) + .setBackgroundColor(appColors.colorPrimary) tabArchiveBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.primary) + .setBackgroundColor(appColors.colorPrimary) tabStarredBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.primary) + .setBackgroundColor(appColors.colorPrimary) val tabNew = BottomNavigationItem( R.drawable.ic_fiber_new_black_24dp, getString(R.string.tab_new) - ).setActiveColor(appColors.accent) + ).setActiveColor(appColors.colorAccent) .setBadgeItem(tabNewBadge) val tabArchive = BottomNavigationItem( R.drawable.ic_archive_black_24dp, getString(R.string.tab_read) - ).setActiveColor(appColors.dark) + ).setActiveColor(appColors.colorAccentDark) .setBadgeItem(tabArchiveBadge) val tabStarred = BottomNavigationItem( @@ -315,6 +320,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { override fun onResume() { super.onResume() + // TODO: Make this the only appcolors init + appColors = AppColors(this@HomeActivity) + handleDrawerItems() sharedPref = PreferenceManager.getDefaultSharedPreferences(this) @@ -327,6 +335,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { handleSharedPrefs() + handleThemeUpdate() + reloadLayoutManager() if (!infiniteScroll) { @@ -361,6 +371,26 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { infiniteScroll = sharedPref.getBoolean("infinite_loading", false) } + private fun handleThemeBinding() { + Scoop.getInstance() + .bind(this, Toppings.PRIMARY.value, toolBar) + .bindStatusBar(this, Toppings.PRIMARY_DARK.value) + } + + private fun handleThemeUpdate() { + + Scoop.getInstance() + .update(Toppings.PRIMARY.value, appColors.colorPrimary) + .update(Toppings.PRIMARY_DARK.value, appColors.colorPrimaryDark) + /*.update(Toppings.ACCENT.value, colorAccent) + .update(Toppings.ACCENT_DARK.value, colorAccentDark) + .update(Toppings.BACKGROUND.value, colorBackground) + .update(Toppings.CARD_BACKGROUND.value, cardBackgroundColor) + .update(Toppings.TEXT_PRIMARY.value, textColorPrimary) + .update(Toppings.TEXT_SECONDARY.value, textColorSecondary) + .update(Toppings.HEADER_DRAWER_TEXT.value, materialDrawerHeaderSelectionText)*/ + } + private fun handleDrawer() { displayAccountHeader = PreferenceManager.getDefaultSharedPreferences(this) @@ -449,7 +479,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { val color = try { Color.parseColor(it.color) } catch (e: IllegalArgumentException) { - resources.getColor(R.color.primary) + appColors.colorPrimary } gd.setColor(color) @@ -464,7 +494,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { .withBadge("${it.unread}") .withBadgeStyle( BadgeStyle().withTextColor(Color.WHITE) - .withColor(appColors.accent) + .withColor(appColors.colorAccent) ) .withOnDrawerItemClickListener { _, _, _ -> allItems = ArrayList() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt index 8df1934..e0eb4de 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -87,31 +87,6 @@ class MyApp : MultiDexApplication() { private fun initTheme() { Scoop.waffleCone() .addFlavor(getString(R.string.default_theme), R.style.NoBar, true) - .addDayNightFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark) - .addFlavor(getString(R.string.teal_orange_theme), R.style.NoBarTealOrange) - .addDayNightFlavor( - getString(R.string.teal_orange_dark_theme), - R.style.NoBarTealOrangeDark - ) - .addFlavor(getString(R.string.cyan_pink_theme), R.style.NoBarCyanPink) - .addDayNightFlavor(getString(R.string.cyan_pink_dark_theme), R.style.NoBarCyanPinkDark) - .addFlavor(getString(R.string.grey_orange_theme), R.style.NoBarGreyOrange) - .addDayNightFlavor( - getString(R.string.grey_orange_dark_theme), - R.style.NoBarGreyOrangeDark - ) - .addFlavor(getString(R.string.blue_amber_theme), R.style.NoBarBlueAmber) - .addDayNightFlavor( - getString(R.string.blue_amber_dark_theme), - R.style.NoBarBlueAmberDark - ) - .addFlavor(getString(R.string.indigo_pink_theme), R.style.NoBarIndigoPink) - .addDayNightFlavor( - getString(R.string.indigo_pink_dark_theme), - R.style.NoBarIndigoPinkDark - ) - .addFlavor(getString(R.string.red_teal_theme), R.style.NoBarRedTeal) - .addDayNightFlavor(getString(R.string.red_teal_dark_theme), R.style.NoBarRedTealDark) .setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this)) .initialize() } 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 cd77af3..65f536e 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 @@ -101,7 +101,7 @@ class ItemCardAdapter( inner class ViewHolder(val mView: CardView) : RecyclerView.ViewHolder(mView) { init { - mView.setCardBackgroundColor(appColors.cardBackground) + mView.setCardBackgroundColor(appColors.cardBackgroundColor) handleClickListeners() handleCustomTabActions() } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java index aa9fce3..eaac2a3 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java @@ -24,6 +24,8 @@ import android.text.Editable; import android.text.InputFilter; import android.text.Spanned; import android.text.TextWatcher; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; @@ -135,7 +137,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { || GeneralPreferenceFragment.class.getName().equals(fragmentName) || ArticleViewerPreferenceFragment.class.getName().equals(fragmentName) || DebugPreferenceFragment.class.getName().equals(fragmentName) - || LinksPreferenceFragment.class.getName().equals(fragmentName); + || LinksPreferenceFragment.class.getName().equals(fragmentName) + || ThemePreferenceFragment.class.getName().equals(fragmentName); } /** @@ -336,14 +339,38 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } } - @Override - public void onHeaderClick(Header header, int position) { - super.onHeaderClick(header, position); - if (header.id == R.id.theme_change) { - Intent intent = ScoopSettingsActivity.createIntent(getApplicationContext()); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - getApplicationContext().startActivity(intent); - finish(); + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public static class ThemePreferenceFragment extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref_theme); + setHasOptionsMenu(true); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == android.R.id.home) { + getActivity().finish(); + return true; + } else if (id == R.id.clear) { + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); + SharedPreferences.Editor editor = pref.edit(); + editor.remove("color_primary"); + editor.remove("color_primary_dark"); + editor.remove("color_accent"); + editor.remove("color_accent_dark"); + editor.remove("dark_theme"); + editor.apply(); + getActivity().finish(); + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.settings_theme, menu); } } 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 8632f58..06e0731 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 @@ -2,49 +2,62 @@ package apps.amine.bou.readerforselfoss.themes import android.app.Activity import android.content.Context +import android.preference.PreferenceManager import android.support.annotation.ColorInt import android.util.TypedValue import apps.amine.bou.readerforselfoss.R class AppColors(a: Activity) { - @ColorInt val accent: Int - @ColorInt val dark: Int - @ColorInt val primary: Int - @ColorInt val cardBackground: Int - @ColorInt val windowBackground: Int + + @ColorInt val colorPrimary: Int + @ColorInt val colorPrimaryDark: Int + @ColorInt val colorAccent: Int + @ColorInt val colorAccentDark: Int + @ColorInt val cardBackgroundColor: Int val isDarkTheme: Boolean init { + val sharedPref = PreferenceManager.getDefaultSharedPreferences(a) + + colorPrimary = + sharedPref.getInt( + "color_primary", + a.resources.getColor(R.color.colorPrimary) + ) + colorPrimaryDark = + sharedPref.getInt( + "color_primary_dark", + a.resources.getColor(R.color.colorPrimaryDark) + ) + colorAccent = + sharedPref.getInt( + "color_accent", + a.resources.getColor(R.color.colorAccent) + ) + colorAccentDark = + sharedPref.getInt( + "color_accent_dark", + a.resources.getColor(R.color.colorAccentDark) + ) + isDarkTheme = + sharedPref.getBoolean( + "dark_theme", + false + ) + + if (isDarkTheme) { + a.setTheme(R.style.NoBarDark) + } else { + a.setTheme(R.style.NoBar) + } + val wrapper = Context::class.java val method = wrapper!!.getMethod("getThemeResId") method.isAccessible = true - isDarkTheme = when (method.invoke(a.baseContext)) { - R.style.NoBarTealOrangeDark, - R.style.NoBarDark, - R.style.NoBarBlueAmberDark, - R.style.NoBarGreyOrangeDark, - R.style.NoBarIndigoPinkDark, - R.style.NoBarRedTealDark, - R.style.NoBarCyanPinkDark -> true - else -> false - } - - val typedAccent = TypedValue() - val typedAccentDark = TypedValue() - val typedPrimary = TypedValue() val typedCardBackground = TypedValue() - val typedWindowBackground = TypedValue() - - a.theme.resolveAttribute(R.attr.colorAccent, typedAccent, true) - a.theme.resolveAttribute(R.attr.colorAccent, typedAccent, true) - a.theme.resolveAttribute(R.attr.colorPrimary, typedPrimary, true) a.theme.resolveAttribute(R.attr.cardBackgroundColor, typedCardBackground, true) - a.theme.resolveAttribute(android.R.attr.colorBackground, typedWindowBackground, true) - accent = typedAccent.data - dark = typedAccentDark.data - primary = typedPrimary.data - cardBackground = typedCardBackground.data - windowBackground = typedWindowBackground.data + + cardBackgroundColor = typedCardBackground.data } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/themes/Toppings.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/themes/Toppings.kt new file mode 100644 index 0000000..cca5107 --- /dev/null +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/themes/Toppings.kt @@ -0,0 +1,8 @@ +package apps.amine.bou.readerforselfoss.themes + +enum class Toppings(val value: Int) { + PRIMARY(1), + PRIMARY_DARK(2), + ACCENT(3), + ACCENT_DARK(4) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/ic_history.png b/app/src/main/res/drawable-hdpi/ic_history.png new file mode 100644 index 0000000..c41edb7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_history.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_history.png b/app/src/main/res/drawable-mdpi/ic_history.png new file mode 100644 index 0000000..b33a842 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_history.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_history.png b/app/src/main/res/drawable-xhdpi/ic_history.png new file mode 100644 index 0000000..3ea9dd6 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_history.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_history.png b/app/src/main/res/drawable-xxhdpi/ic_history.png new file mode 100644 index 0000000..abe5f3e Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_history.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_history.png b/app/src/main/res/drawable-xxxhdpi/ic_history.png new file mode 100644 index 0000000..289d64b Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_history.png differ diff --git a/app/src/main/res/menu/settings_theme.xml b/app/src/main/res/menu/settings_theme.xml new file mode 100644 index 0000000..ea3ea42 --- /dev/null +++ b/app/src/main/res/menu/settings_theme.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c52e6d6..b999fc5 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -16,4 +16,7 @@ @color/md_white_1000 @color/md_grey_50 @color/md_grey_900 + + #FFFFFFFF + @color/md_grey_900 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ac6e730..3f9c443 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -43,182 +43,6 @@ @style/DrawerArrowStyle--> - - - - - - - - - - - - - - - - - - - - - - - - - -