From 3aaff612afe0d40b9ff897d39933ec3d27b202af Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Sun, 8 Apr 2018 14:16:16 +0200 Subject: [PATCH] WIP. All activities dynamic themes. --- .../bou/readerforselfoss/AddSourceActivity.kt | 11 ++++++++++- .../amine/bou/readerforselfoss/HomeActivity.kt | 2 +- .../amine/bou/readerforselfoss/LoginActivity.kt | 14 +++++++++++++- .../amine/bou/readerforselfoss/ReaderActivity.kt | 11 ++++++++++- .../amine/bou/readerforselfoss/SourcesActivity.kt | 10 +++++++++- .../settings/AppCompatPreferenceActivity.java | 10 +++++++++- 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt index 0bf3de9..6411d34 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt @@ -16,6 +16,8 @@ import android.widget.Toast import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.Spout import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse +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.isBaseUrlValid import com.ftinc.scoop.Scoop @@ -31,9 +33,16 @@ class AddSourceActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Scoop.getInstance().apply(this) + + AppColors(this@AddSourceActivity) + setContentView(R.layout.activity_add_source) + // TODO: add buttons and inputs + Scoop.getInstance() + .bind(this, Toppings.PRIMARY.value, toolbar) + .bindStatusBar(this, Toppings.PRIMARY_DARK.value) + setSupportActionBar(toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) 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 3eea4e3..5184394 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -146,7 +146,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - sharedPref = PreferenceManager.getDefaultSharedPreferences(this) appColors = AppColors(this@HomeActivity) setContentView(R.layout.activity_home) @@ -163,6 +162,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { customTabActivityHelper = CustomTabActivityHelper() + sharedPref = PreferenceManager.getDefaultSharedPreferences(this) settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) api = SelfossApi( diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt index 1617e82..8c515a8 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -6,6 +6,7 @@ import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.os.Bundle +import android.preference.PreferenceManager import android.support.v7.app.AlertDialog import android.support.v7.app.AppCompatActivity import android.text.TextUtils @@ -17,6 +18,8 @@ import android.widget.TextView import android.widget.Toast import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse +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.isBaseUrlValid import com.crashlytics.android.Crashlytics @@ -41,12 +44,21 @@ class LoginActivity : AppCompatActivity() { private lateinit var firebaseAnalytics: FirebaseAnalytics private lateinit var userIdentifier: String private var logErrors: Boolean = false + private lateinit var appColors: AppColors override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Scoop.getInstance().apply(this) + + appColors = AppColors(this@LoginActivity) + setContentView(R.layout.activity_login) + // TODO: add input + switch colors + Scoop.getInstance() + .bind(this, Toppings.PRIMARY.value, toolbar) + .bindStatusBar(this, Toppings.PRIMARY_DARK.value) + + setSupportActionBar(toolbar) handleBaseUrlFail() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index 1a937e0..6b2f1df 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -14,6 +14,8 @@ import apps.amine.bou.readerforselfoss.api.selfoss.Item import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.fragments.ArticleFragment +import apps.amine.bou.readerforselfoss.themes.AppColors +import apps.amine.bou.readerforselfoss.themes.Toppings import apps.amine.bou.readerforselfoss.transformers.DepthPageTransformer import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.succeeded @@ -52,9 +54,16 @@ class ReaderActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Scoop.getInstance().apply(this) + + AppColors(this@ReaderActivity) + setContentView(R.layout.activity_reader) + // TODO: fab + Scoop.getInstance() + .bind(this, Toppings.PRIMARY.value, toolBar) + .bindStatusBar(this, Toppings.PRIMARY_DARK.value) + setSupportActionBar(toolBar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) 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 a6748ec..5199b6e 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt @@ -9,6 +9,8 @@ import android.widget.Toast import apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.Sources +import apps.amine.bou.readerforselfoss.themes.AppColors +import apps.amine.bou.readerforselfoss.themes.Toppings import com.ftinc.scoop.Scoop import kotlinx.android.synthetic.main.activity_sources.* import retrofit2.Call @@ -19,9 +21,15 @@ class SourcesActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Scoop.getInstance().apply(this) + + AppColors(this@SourcesActivity) + setContentView(R.layout.activity_sources) + Scoop.getInstance() + .bind(this, Toppings.PRIMARY.value, toolbar) + .bindStatusBar(this, Toppings.PRIMARY_DARK.value) + setSupportActionBar(toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/AppCompatPreferenceActivity.java b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/AppCompatPreferenceActivity.java index 83bd033..03f443a 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/AppCompatPreferenceActivity.java +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/AppCompatPreferenceActivity.java @@ -19,6 +19,8 @@ import android.widget.LinearLayout; import com.ftinc.scoop.Scoop; import apps.amine.bou.readerforselfoss.R; +import apps.amine.bou.readerforselfoss.themes.AppColors; +import apps.amine.bou.readerforselfoss.themes.Toppings; /** @@ -33,7 +35,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity { protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); - Scoop.getInstance().apply(this); + new AppColors(this); super.onCreate(savedInstanceState); } @@ -44,6 +46,12 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity { LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent(); AppBarLayout bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); Toolbar toolbar = bar.findViewById(R.id.toolbar); + + // TODO: all switches + Scoop.getInstance() + .bind(this, Toppings.PRIMARY.getValue(), toolbar) + .bindStatusBar(this, Toppings.PRIMARY_DARK.getValue()); + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);