From f8f710df99135d0e1fdda71b301b4ceaba8b7341 Mon Sep 17 00:00:00 2001 From: Amine Date: Sun, 2 Jul 2017 17:12:02 +0200 Subject: [PATCH] Working themes. Needs some cleaning. Closes #37 . --- app/build.gradle | 5 +- app/src/main/AndroidManifest.xml | 5 +- .../bou/readerforselfoss/AddSourceActivity.kt | 8 +- .../bou/readerforselfoss/HomeActivity.kt | 223 +++++++++++------- .../bou/readerforselfoss/LoginActivity.kt | 7 +- .../apps/amine/bou/readerforselfoss/MyApp.kt | 22 +- .../bou/readerforselfoss/ReaderActivity.kt | 4 +- .../bou/readerforselfoss/SourcesActivity.kt | 8 +- .../adapters/ItemCardAdapter.kt | 8 +- .../adapters/ItemListAdapter.kt | 3 +- .../settings/AppCompatPreferenceActivity.java | 18 ++ .../settings/SettingsActivity.java | 10 + .../bou/readerforselfoss/themes/AppColors.kt | 53 +++++ .../ic_color_lens_black_24dp.png | Bin 0 -> 458 bytes .../ic_color_lens_black_24dp.png | Bin 0 -> 268 bytes .../ic_color_lens_black_24dp.png | Bin 0 -> 504 bytes .../ic_color_lens_black_24dp.png | Bin 0 -> 741 bytes .../ic_color_lens_black_24dp.png | Bin 0 -> 966 bytes .../main/res/layout-land/activity_home.xml | 130 ---------- .../main/res/layout/activity_add_source.xml | 214 +++++++++-------- app/src/main/res/layout/activity_home.xml | 20 +- app/src/main/res/layout/activity_login.xml | 213 +++++++++-------- app/src/main/res/layout/activity_reader.xml | 7 +- app/src/main/res/layout/activity_sources.xml | 17 +- app/src/main/res/layout/card_item.xml | 56 +++-- app/src/main/res/layout/list_item.xml | 42 ++-- app/src/main/res/layout/settings_toolbar.xml | 14 ++ app/src/main/res/layout/source_list_item.xml | 2 +- app/src/main/res/values-fr/strings.xml | 15 ++ app/src/main/res/values-nl/strings.xml | 15 ++ app/src/main/res/values/attrs.xml | 6 + app/src/main/res/values/strings.xml | 15 ++ app/src/main/res/values/styles.xml | 169 ++++++++++++- app/src/main/res/xml/pref_headers.xml | 5 + 34 files changed, 804 insertions(+), 510 deletions(-) create mode 100644 app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt create mode 100644 app/src/main/res/drawable-hdpi/ic_color_lens_black_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_color_lens_black_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_color_lens_black_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_color_lens_black_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_color_lens_black_24dp.png delete mode 100644 app/src/main/res/layout-land/activity_home.xml create mode 100644 app/src/main/res/layout/settings_toolbar.xml create mode 100644 app/src/main/res/values/attrs.xml diff --git a/app/build.gradle b/app/build.gradle index f239ea4..c3b0ac2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -115,7 +115,7 @@ dependencies { compile 'com.burgstaller:okhttp-digest:1.12' // Material-ish things - compile 'com.roughike:bottom-bar:2.3.1' + compile 'com.ashokvarma.android:bottom-navigation-bar:2.0.1' compile 'com.melnykov:floatingactionbutton:1.3.0' compile 'com.github.jd-alexander:LikeButton:0.2.1' compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' @@ -136,6 +136,9 @@ dependencies { } compile 'com.anupcowkur:reservoir:3.1.0' + // Themes + compile 'com.52inc:scoops:1.0.0' + } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e779c4c..b5cf3cf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,7 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/NoBar"> @@ -31,8 +31,7 @@ - + - if (listenerAlreadySet[0]) { - if (tabId == R.id.tab_new) { - getUnRead() - } else if (tabId == R.id.tab_archive) { - getRead() - } else if (tabId == R.id.tab_fav) { - getStarred() - } - getElementsAccordingToTab() - } else { - listenerAlreadySet[0] = true - } - } - - mCoordinatorLayout = findViewById(R.id.coordLayout) - mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout) - mRecyclerView = findViewById(R.id.my_recycler_view) + coordinatorLayout = findViewById(R.id.coordLayout) + swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout) + recyclerView = findViewById(R.id.my_recycler_view) emptyText = findViewById(R.id.emptyText) reloadLayoutManager() - mSwipeRefreshLayout.setColorSchemeResources( + swipeRefreshLayout.setColorSchemeResources( R.color.refresh_progress_1, R.color.refresh_progress_2, R.color.refresh_progress_3) - mSwipeRefreshLayout.setOnRefreshListener { + swipeRefreshLayout.setOnRefreshListener { handleDrawerItems() getElementsAccordingToTab() } @@ -188,11 +179,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { val position = items.indexOf(i) if (shouldBeCardView) { - (mRecyclerView.adapter as ItemCardAdapter).removeItemAtIndex(position) + (recyclerView.adapter as ItemCardAdapter).removeItemAtIndex(position) } else { - (mRecyclerView.adapter as ItemListAdapter).removeItemAtIndex(position) + (recyclerView.adapter as ItemListAdapter).removeItemAtIndex(position) } - tabNew.setBadgeCount(items.size - 1) + //tabNew.setBadgeCount(items.size - 1) mayBeEmpty() @@ -201,12 +192,51 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { } } - ItemTouchHelper(simpleItemTouchCallback).attachToRecyclerView(mRecyclerView) + ItemTouchHelper(simpleItemTouchCallback).attachToRecyclerView(recyclerView) this@HomeActivity.checkAndDisplayStoreApk() } + private fun handleBottomBar() { + + bottomBar = findViewById(R.id.bottomBar) + + tabNewBadge = TextBadgeItem().setText("") + tabArchiveBadge = TextBadgeItem().setText("") + tabStarredBadge = TextBadgeItem().setText("") + + val tabNew = + BottomNavigationItem( + R.drawable.ic_fiber_new_black_24dp, + getString(R.string.tab_new) + ).setActiveColor(appColors.accent) + //.setBadgeItem(tabNewBadge) + val tabArchive = + BottomNavigationItem( + R.drawable.ic_archive_black_24dp, + getString(R.string.tab_read) + ).setActiveColor(appColors.dark) + // .setBadgeItem(tabArchiveBadge) + val tabStarred = + BottomNavigationItem( + R.drawable.ic_favorite_black_24dp, + getString(R.string.tab_favs) + ).setActiveColorResource(R.color.pink) + // .setBadgeItem(tabStarredBadge) + + bottomBar + .addItem(tabNew) + .addItem(tabArchive) + .addItem(tabStarred) + .setFirstSelectedPosition(0) + .initialise() + + bottomBar.setMode(BottomNavigationBar.MODE_SHIFTING) + bottomBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC) + + } + override fun onResume() { super.onResume() @@ -218,22 +248,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { editor = settings.edit() if (BuildConfig.GITHUB_VERSION) { - this@HomeActivity.checkApkVersion(settings, editor, mFirebaseRemoteConfig) + this@HomeActivity.checkApkVersion(settings, editor, firebaseRemoteConfig) } handleSharedPrefs() - tabNew = mBottomBar.getTabWithId(R.id.tab_new) - tabArchive = mBottomBar.getTabWithId(R.id.tab_archive) - tabStarred = mBottomBar.getTabWithId(R.id.tab_fav) - - getElementsAccordingToTab() } override fun onStop() { super.onStop() - mCustomTabActivityHelper.unbindCustomTabsService(this) + customTabActivityHelper.unbindCustomTabsService(this) } @@ -258,15 +283,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { .withShowDrawerOnFirstLaunch(true) .withOnDrawerListener(object: Drawer.OnDrawerListener { override fun onDrawerSlide(v: View?, p1: Float) { - mBottomBar.alpha = (1 - p1) + bottomBar.alpha = (1 - p1) } override fun onDrawerClosed(v: View?) { - mBottomBar.shySettings.showBar() + bottomBar.show() } override fun onDrawerOpened(v: View?) { - mBottomBar.shySettings.hideBar() + bottomBar.hide() } }) @@ -277,9 +302,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { .withName(R.string.action_about) .withSelectable(false) .withIcon(R.drawable.ic_info_outline) + .withIconTintingEnabled(true) .withOnDrawerItemClickListener { _, _, _ -> LibsBuilder() - .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR) + .withActivityStyle( + if (appColors.isDarkTheme) + Libs.ActivityStyle.LIGHT_DARK_TOOLBAR + else + Libs.ActivityStyle.DARK + ) .withAboutIconShown(true) .withAboutVersionShown(true) .start(this@HomeActivity) @@ -289,6 +320,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { PrimaryDrawerItem() .withName(R.string.title_activity_settings) .withIcon(R.drawable.ic_settings) + .withIconTintingEnabled(true) .withOnDrawerItemClickListener { _, _, _ -> startActivityForResult( Intent( @@ -328,7 +360,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { .withBadge("${tag.unread}") .withBadgeStyle( BadgeStyle().withTextColor(Color.WHITE) - .withColorRes(R.color.colorAccent) + .withColor(appColors.accent) ) .withOnDrawerItemClickListener { _, _, _ -> maybeTagFilter = tag @@ -484,33 +516,45 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { mLayoutManager = GridLayoutManager(this, calculateNoOfColumns()) } - mRecyclerView.layoutManager = mLayoutManager - mRecyclerView.setHasFixedSize(true) + recyclerView.layoutManager = mLayoutManager + recyclerView.setHasFixedSize(true) - mBottomBar.setOnTabReselectListener { - if (shouldBeCardView) { - if ((mLayoutManager as StaggeredGridLayoutManager).findFirstCompletelyVisibleItemPositions(null)[0] == 0) { - getElementsAccordingToTab() + bottomBar.setTabSelectedListener(object: BottomNavigationBar.OnTabSelectedListener { + override fun onTabUnselected(position: Int) = Unit + + override fun onTabReselected(position: Int) = + if (shouldBeCardView) { + if ((mLayoutManager as StaggeredGridLayoutManager).findFirstCompletelyVisibleItemPositions(null)[0] == 0) { + getElementsAccordingToTab() + } else { + mLayoutManager.scrollToPositionWithOffset(0, 0) + } } else { - mLayoutManager.scrollToPositionWithOffset(0, 0) + if ((mLayoutManager as GridLayoutManager).findFirstCompletelyVisibleItemPosition() == 0) { + getElementsAccordingToTab() + } else { + mLayoutManager.scrollToPositionWithOffset(0, 0) + } } - } else { - if ((mLayoutManager as GridLayoutManager).findFirstCompletelyVisibleItemPosition() == 0) { - getElementsAccordingToTab() - } else { - mLayoutManager.scrollToPositionWithOffset(0, 0) + + override fun onTabSelected(position: Int) = + when(position) { + 0 -> getUnRead() + 1 -> getRead() + 2 -> getStarred() + else -> Unit } - } - } + + }) } fun mayBeEmpty() = if (items.isEmpty()) { emptyText.visibility = View.VISIBLE - mRecyclerView.visibility = View.GONE + recyclerView.visibility = View.GONE } else { emptyText.visibility = View.GONE - mRecyclerView.visibility = View.VISIBLE + recyclerView.visibility = View.VISIBLE } private fun getElementsAccordingToTab() = @@ -534,11 +578,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { if (didUpdate) handleListResult() mayBeEmpty() - mSwipeRefreshLayout.isRefreshing = false + swipeRefreshLayout.isRefreshing = false } - if (!mSwipeRefreshLayout.isRefreshing) - mSwipeRefreshLayout.post { mSwipeRefreshLayout.isRefreshing = true } + if (!swipeRefreshLayout.isRefreshing) + swipeRefreshLayout.post { swipeRefreshLayout.isRefreshing = true } call(maybeTagFilter?.tag, maybeSourceFilter?.id?.toLong(), maybeSearchFilter) .enqueue(object : Callback> { @@ -547,7 +591,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { } override fun onFailure(call: Call>, t: Throwable) { - mSwipeRefreshLayout.isRefreshing = false + swipeRefreshLayout.isRefreshing = false Toast.makeText(this@HomeActivity, toastMessage, Toast.LENGTH_SHORT).show() } }) @@ -578,22 +622,23 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { this, items, api, - mCustomTabActivityHelper, + customTabActivityHelper, internalBrowser, articleViewer, - fullHeightCards) + fullHeightCards, + appColors) } else { mAdapter = ItemListAdapter( this, items, api, - mCustomTabActivityHelper, + customTabActivityHelper, clickBehavior, internalBrowser, articleViewer) } - mRecyclerView.adapter = mAdapter + recyclerView.adapter = mAdapter mAdapter.notifyDataSetChanged() reloadBadges() @@ -604,24 +649,24 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { api.stats.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { if (response.body() != null) { - tabNew.setBadgeCount(response.body()!!.unread) + tabStarredBadge.setText(response.body()!!.unread.toString()) if (displayAllCount) { - tabArchive.setBadgeCount(response.body()!!.total) - tabStarred.setBadgeCount(response.body()!!.starred) - } else { + tabStarredBadge.setText(response.body()!!.total.toString()) + tabStarredBadge.setText(response.body()!!.starred.toString()) + }/* else { tabArchive.removeBadge() tabStarred.removeBadge() - } + }*/ } } override fun onFailure(call: Call, t: Throwable) {} }) - } else { + }/* else { tabNew.removeBadge() tabArchive.removeBadge() tabStarred.removeBadge() - } + }*/ } private fun calculateNoOfColumns(): Int { @@ -692,7 +737,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { } R.id.readAll -> { if (elementsShown == UNREAD_SHOWN) { - mSwipeRefreshLayout.isRefreshing = false + swipeRefreshLayout.isRefreshing = false val ids = items.map { it.id } api.readAll(ids).enqueue(object : Callback { @@ -702,12 +747,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { else Toast.makeText(this@HomeActivity, R.string.all_posts_not_read, Toast.LENGTH_SHORT).show() - mSwipeRefreshLayout.isRefreshing = false + swipeRefreshLayout.isRefreshing = false } override fun onFailure(call: Call, t: Throwable) { Toast.makeText(this@HomeActivity, R.string.all_posts_not_read, Toast.LENGTH_SHORT).show() - mSwipeRefreshLayout.isRefreshing = false + swipeRefreshLayout.isRefreshing = false } }) items = ArrayList() 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 17d8427..26ef700 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -9,6 +9,7 @@ import android.os.Bundle import android.support.design.widget.TextInputLayout import android.support.v7.app.AlertDialog import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.Toolbar import android.text.TextUtils import android.view.Menu import android.view.MenuItem @@ -31,7 +32,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.checkAndDisplayStoreApk import apps.amine.bou.readerforselfoss.utils.isUrlValid - +import com.ftinc.scoop.Scoop class LoginActivity : AppCompatActivity() { @@ -54,8 +55,12 @@ class LoginActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + Scoop.getInstance().apply(this) setContentView(R.layout.activity_login) + val toolbar: Toolbar = findViewById(R.id.toolbar) + setSupportActionBar(toolbar) + if (intent.getBooleanExtra("baseUrlFail", false)) { val alertDialog = AlertDialog.Builder(this).create() alertDialog.setTitle(getString(R.string.warning_wrong_url)) 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 a1fc39a..43e9e02 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -3,11 +3,13 @@ package apps.amine.bou.readerforselfoss import android.content.Context import android.graphics.drawable.Drawable import android.net.Uri +import android.preference.PreferenceManager import android.support.multidex.MultiDexApplication import android.widget.ImageView import com.anupcowkur.reservoir.Reservoir import com.bumptech.glide.Glide import com.crashlytics.android.Crashlytics +import com.ftinc.scoop.Scoop import com.github.stkent.amplify.tracking.Amplify import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader @@ -42,8 +44,26 @@ class MyApp : MultiDexApplication() { } override fun placeholder(ctx: Context?, tag: String?): Drawable { - return applicationContext.resources.getDrawable(R.mipmap.ic_launcher) + return baseContext.resources.getDrawable(R.mipmap.ic_launcher) } }) + Scoop.waffleCone() + .addFlavor(getString(R.string.default_theme), R.style.NoBar, true) + .addFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark) + .addFlavor(getString(R.string.teal_orange_theme), R.style.NoBarTealOrange) + .addFlavor(getString(R.string.teal_orange_dark_theme), R.style.NoBarTealOrangeDark) + .addFlavor(getString(R.string.cyan_pink_theme), R.style.NoBarCyanPink) + .addFlavor(getString(R.string.cyan_pink_dark_theme), R.style.NoBarCyanPinkDark) + .addFlavor(getString(R.string.grey_orange_theme), R.style.NoBarGreyOrange) + .addFlavor(getString(R.string.grey_orange_dark_theme), R.style.NoBarGreyOrangeDark) + .addFlavor(getString(R.string.blue_amber_theme), R.style.NoBarBlueAmber) + .addFlavor(getString(R.string.blue_amber_dark_theme), R.style.NoBarBlueAmberDark) + .addFlavor(getString(R.string.indigo_pink_theme), R.style.NoBarIndigoPink) + .addFlavor(getString(R.string.indigo_pink_dark_theme), R.style.NoBarIndigoPinkDark) + .addFlavor(getString(R.string.red_teal_theme), R.style.NoBarRedTeal) + .addFlavor(getString(R.string.red_teal_dark_theme), R.style.NoBarRedTealDark) + .setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this)) + .initialize() + } } \ No newline at end of file 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 022440f..ef99bf5 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -23,6 +23,7 @@ import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.shareLink +import com.ftinc.scoop.Scoop class ReaderActivity : DragDismissActivity() { @@ -39,6 +40,7 @@ class ReaderActivity : DragDismissActivity() { } override fun onCreateContent(inflater: LayoutInflater, parent: ViewGroup, savedInstanceState: Bundle?): View { + Scoop.getInstance().apply(this) val v = inflater.inflate(R.layout.activity_reader, parent, false) showProgressBar() @@ -71,7 +73,7 @@ class ReaderActivity : DragDismissActivity() { } if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) Glide - .with(applicationContext) + .with(baseContext) .load(response.body()!!.lead_image_url) .asBitmap() .fitCenter() 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 c592998..c020457 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView +import android.support.v7.widget.Toolbar import android.widget.Toast import com.melnykov.fab.FloatingActionButton @@ -15,14 +16,19 @@ import retrofit2.Response import apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.Sources - +import com.ftinc.scoop.Scoop class SourcesActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + Scoop.getInstance().apply(this) setContentView(R.layout.activity_sources) + val toolbar: Toolbar = findViewById(R.id.toolbar) + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDisplayShowHomeEnabled(true) } override fun onResume() { 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 11a1d07..aebc070 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,6 +7,7 @@ import android.graphics.Color import android.support.constraint.ConstraintLayout import android.support.design.widget.Snackbar import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory +import android.support.v7.widget.CardView import android.support.v7.widget.RecyclerView import android.text.Html import android.text.format.DateUtils @@ -35,6 +36,7 @@ import apps.amine.bou.readerforselfoss.R 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.themes.AppColors import apps.amine.bou.readerforselfoss.utils.* import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper @@ -44,8 +46,9 @@ class ItemCardAdapter(private val app: Activity, private val helper: CustomTabActivityHelper, private val internalBrowser: Boolean, private val articleViewer: Boolean, - private val fullHeightCards: Boolean) : RecyclerView.Adapter() { - private val c: Context = app.applicationContext + private val fullHeightCards: Boolean, + private val appColors: AppColors) : RecyclerView.Adapter() { + private val c: Context = app.baseContext private val generator: ColorGenerator = ColorGenerator.MATERIAL override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -150,6 +153,7 @@ class ItemCardAdapter(private val app: Activity, lateinit var sourceTitleAndDate: TextView init { + (mView.findViewById(R.id.card)).setCardBackgroundColor(appColors.cardBackground) 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 ba56a4e..5fa27cc 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 @@ -36,6 +36,7 @@ import apps.amine.bou.readerforselfoss.R 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.themes.AppColors import apps.amine.bou.readerforselfoss.utils.* import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper @@ -48,7 +49,7 @@ class ItemListAdapter(private val app: Activity, private val internalBrowser: Boolean, private val articleViewer: Boolean) : RecyclerView.Adapter() { private val generator: ColorGenerator = ColorGenerator.MATERIAL - private val c: Context = app.applicationContext + private val c: Context = app.baseContext private val bars: ArrayList = ArrayList(Collections.nCopies(items.size + 1, false)) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 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 ef49cfd..1a77cee 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 @@ -6,12 +6,19 @@ import android.preference.PreferenceActivity; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.AppBarLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatDelegate; import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; + +import apps.amine.bou.readerforselfoss.R; +import com.ftinc.scoop.Scoop; + /** * A {@link PreferenceActivity} which implements and proxies the necessary calls @@ -25,12 +32,23 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity { protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); + Scoop.getInstance().apply(this); super.onCreate(savedInstanceState); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); + + 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); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + root.addView(bar, 0); + getDelegate().onPostCreate(savedInstanceState); } 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 2801eaa..1314af0 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 @@ -20,6 +20,7 @@ import android.view.MenuItem; import java.util.List; import apps.amine.bou.readerforselfoss.R; +import com.ftinc.scoop.ui.ScoopSettingsActivity; /** @@ -201,6 +202,15 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } } + @Override + public void onHeaderClick(Header header, int position) { + super.onHeaderClick(header, position); + if (header.id == R.id.theme_change) { + getBaseContext().startActivity(ScoopSettingsActivity.createIntent(getApplicationContext())); + finish(); + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); 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 new file mode 100644 index 0000000..e9ca76a --- /dev/null +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt @@ -0,0 +1,53 @@ +package apps.amine.bou.readerforselfoss.themes + +import android.app.Activity +import android.content.Context +import android.support.annotation.ColorInt +import android.util.TypedValue +import apps.amine.bou.readerforselfoss.R +import java.lang.reflect.AccessibleObject.setAccessible + + + +class AppColors(a: Activity) { + @ColorInt val accent: Int + @ColorInt val dark: Int + @ColorInt val primary: Int + @ColorInt val cardBackground: Int + @ColorInt val windowBackground: Int + val isDarkTheme: Boolean + + init { + 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 + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_color_lens_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_color_lens_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..783e78767dc08478f1b1f2fb66e55ceebb0c383f GIT binary patch literal 458 zcmV;*0X6=KP)6G4 z#2Hh=@E54zFT-+%4u(5$18xI(%fK@K8BR0E5;kTERAUx2lo43_AG^0;ss#DNl<`IrV};EWwqsD=`oHJAof;fWn&coLW}5V4ts%OFyr z87{Ap25&GhVjAQ`hCusdBNHF9lLpkm&8$^^5-x;m|-J*!E2w`Nn zh*SGj20c=WSSw)e!ETT(sfB(e4uj-LuRkVYHK>7{s;B~s2mdfglVg+x!+8v&Ov$Tb z85shB<=-!)s*#zJDw~_ZfgueT0a?)EZWK@i0NV+{ua#N`mH+?%07*qoM6N<$f|b~| A>i_@% literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_color_lens_black_24dp.png b/app/src/main/res/drawable-mdpi/ic_color_lens_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..b5671f1964c056a4a42b23209205c9e4f48f2c5a GIT binary patch literal 268 zcmV+n0rUQeP)Q=AP&F(;aWgW6iC#k0a1YJR z2nZAXj;i4onwt?2Ci)ds!%u>KIDo3*EY5PcemQAi?!+6jJi{sgfRK`d-isrduO6VuoUc7lb7ij5#vk|LF@rG+7&#x$ZP zqF6dndgdM#+@!(^_C6*YnS-iPdbH<_#A1LG>rsb4_DeiA2h-?)cg z=KH_KEVDj`*_Xy)lDQg|X@RJ+HAQ%&_jg)bz`}%>euVJ82z>3PSim5C?hL;6R4kB? z_}mG6Z9y!MmH6BVd~I1QP?Y+d2VZN71u6mJDz`ju6)vb%iByJo9O77ile3-?V u!;#=}3}OLCxWo(FwF%T#1 z34OqA9Wdp1uK;tZ8C(h$rv?8qz&X};R0lVS2a-x}qeo2FEEJ;`anHd1*#kTZ0w+g2 z?&JZlpUK{E4Jyw%7|i_X%(zPSxUT4DWREqR8PI^IpnGpAVPsQ7v!=4QT$byaY)1A( z|52~H&{M6fV%JrrjO?j4QK$lxdf(}FUGb zdlLo6zrs@*P?+US=_IT0h6dEl^d`Av6+Y5{#+cqDm#o4M8qhM^n`Dwz*rfrjD|nN? zWEJ*kKrtn6aumFe_{#Q`yvb4Uz7-W9oqEB4WqMW1pVT__Q~c48;+-L&KB~2j8o}8> zJ{9PJ5ugV8*HG91&P(3k>Xv4lIgi7oi3!b5hlvAJX`IRpP>2vdYuR`D=qt+|oq=KO z2@72jCQ(b>2K{~%zbXxXh#_1NMyerNm4KRbp1JZZ(+r^3CR!~ym|`F`o9X^MW1MJQHq(;2D~6&WwVUdam0>B^57S^;FzF4Y z&1_>c7ajN{!TF7X^XRr#VqAPocySKUc%Dt*tGJI5EFy|c@sY8O1ytDHxD6XNYy=)h XfOQ4wec)>j00000NkvXXu0mjft?E`B literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_color_lens_black_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_color_lens_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..de8d7613b33df8104d80321e5b340d241f2e8114 GIT binary patch literal 966 zcmV;%13CPOP)*_kAjws&a1;){fGdN(Y^eS{=l8H?eyL8q*%gPjVi|yqDjM7^kD$LLHmOKGb6{Pb)24x6T%|r)Xz?k^QH$?4G2f26J5b zqIDzK=9T$Z4SXW!4=IK49vXKO?g@;$cdxxZ*6*QGOzay_9T-=7R}e=|g` z%j69mku87b;oaz3PJ0xs%Wl4hRSonO3;=Uk(rWQlsVWhrqO*tftE97}`ijDg~-awOLo)@LqxFLB19m;W7jAG-? z$Qu~7%0NusKu|-T7opg=>+%L7TJn5hijBJ_Z(u=7o)<~7BI8Eo4a7C&`Gl7JL|ERy zhNe89(6XPH&||*GyX6sU3=GruV;z>r zUqB_zK$9f~TBsZPa<*40+3B;1=f>qfL79qyPUG_ZYUiRy3{RdiDC3o}&eH-dXf^WK zxiZNvaRb~zB!aK!N2jd7}S?L{s1vrI2r8|W-ai06ZlNhhV z3S1;xShnLHB<})sBE2>7buND`P?vKjEJ1*H==B=bz>mA7`7}t!aeOGnr$OeM83~w;c?5wk; oJH;lC4-O6v4h{|u4i4J!4>8YweZqG7dH?_b07*qoM6N<$g2U_7Hvj+t literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout-land/activity_home.xml b/app/src/main/res/layout-land/activity_home.xml deleted file mode 100644 index 8cb7791..0000000 --- a/app/src/main/res/layout-land/activity_home.xml +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_add_source.xml b/app/src/main/res/layout/activity_add_source.xml index 1c8749a..a308508 100644 --- a/app/src/main/res/layout/activity_add_source.xml +++ b/app/src/main/res/layout/activity_add_source.xml @@ -1,118 +1,136 @@ - + tools:context="apps.amine.bou.readerforselfoss.AddSourceActivity" + android:orientation="vertical"> + + + + + + - - + - - - - - - + app:layout_constraintBottom_toBottomOf="parent" + android:id="@+id/formContainer" + android:visibility="gone" + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintVertical_bias="0.0"> - + -