articles_list: add AppBarPresenter
authorDa Risk <da_risk@geekorum.com>
Thu, 06 Feb 2020 11:39:22 -0400
changeset 605 c8b28059e4c9
parent 604 db9a5f3c00c5
child 606 38d0a51dda85
articles_list: add AppBarPresenter
app/src/main/java/com/geekorum/ttrss/articles_list/AppBarPresenter.kt
app/src/main/java/com/geekorum/ttrss/articles_list/ArticleListActivity.kt
app/src/main/res/values/strings.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/src/main/java/com/geekorum/ttrss/articles_list/AppBarPresenter.kt	Thu Feb 06 11:39:22 2020 -0400
@@ -0,0 +1,56 @@
+/*
+ * Geekttrss is a RSS feed reader application on the Android Platform.
+ *
+ * Copyright (C) 2017-2019 by Frederic-Charles Barthelery.
+ *
+ * This file is part of Geekttrss.
+ *
+ * Geekttrss is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Geekttrss is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Geekttrss.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.geekorum.ttrss.articles_list
+
+import androidx.navigation.NavController
+import androidx.navigation.dynamicfeatures.DynamicGraphNavigator
+import com.geekorum.ttrss.R
+import com.google.android.material.appbar.AppBarLayout
+import com.google.android.material.appbar.MaterialToolbar
+
+/**
+ * Controls the behavior of the AppBar
+ */
+internal class AppBarPresenter(
+    private val appBarLayout: AppBarLayout,
+    private val toolbar: MaterialToolbar,
+    private val navController: NavController
+){
+
+    init {
+        setup()
+    }
+
+    private fun setup() {
+        navController.addOnDestinationChangedListener { controller, destination, arguments ->
+            val progressDestinationId = (controller.graph as? DynamicGraphNavigator.DynamicNavGraph)?.progressDestination ?: 0
+            when (destination.id) {
+                R.id.articlesListFragment,
+                R.id.articlesSearchFragment -> appBarLayout.setExpanded(true)
+
+                progressDestinationId -> {
+                    appBarLayout.setExpanded(true)
+                    toolbar.title = toolbar.resources.getString(R.string.lbl_install_feature_title)
+                }
+            }
+        }
+    }
+}
--- a/app/src/main/java/com/geekorum/ttrss/articles_list/ArticleListActivity.kt	Thu Feb 06 11:07:52 2020 -0400
+++ b/app/src/main/java/com/geekorum/ttrss/articles_list/ArticleListActivity.kt	Thu Feb 06 11:39:22 2020 -0400
@@ -80,6 +80,7 @@
 
     private lateinit var inAppUpdatePresenter: InAppUpdatePresenter
     private lateinit var searchToolbarPresenter: SearchToolbarPresenter
+    private lateinit var appBarPresenter: AppBarPresenter
     private lateinit var feedNavigationPresenter: FeedsNavigationMenuPresenter
     private lateinit var accountHeaderPresenter: AccountHeaderPresenter
     private lateinit var drawerLayoutPresenter: DrawerLayoutPresenter
@@ -133,11 +134,9 @@
             addOnDestinationChangedListener { controller, destination, arguments ->
                 when (destination.id) {
                     R.id.articlesListFragment -> {
-                        binding.appBar.setExpanded(true)
                         binding.fab.show()
                     }
                     R.id.articlesSearchFragment -> {
-                        binding.appBar.setExpanded(true)
                         //TODO hide fab. but fab has scrollaware behavior that get it shown back when scrolling
                     }
                 }
@@ -185,16 +184,17 @@
     private fun setupToolbar() {
         setupSearch()
         binding.toolbar.setupWithNavController(navController, drawerLayout)
+        appBarPresenter = AppBarPresenter(binding.appBar, binding.toolbar, navController)
     }
 
     private fun setUpNavigationView() {
         binding.navigationView.setNavigationItemSelectedListener {
-            when {
-                it.itemId == R.id.manage_feeds -> {
+            when(it.itemId) {
+                R.id.manage_feeds -> {
                     navController.navigate(ArticlesListFragmentDirections.actionManageFeeds())
                     true
                 }
-                it.itemId == R.id.settings -> {
+                R.id.settings -> {
                     navController.navigate(ArticlesListFragmentDirections.actionShowSettings())
                     true
                 }
--- a/app/src/main/res/values/strings.xml	Thu Feb 06 11:07:52 2020 -0400
+++ b/app/src/main/res/values/strings.xml	Thu Feb 06 11:39:22 2020 -0400
@@ -71,6 +71,7 @@
     <string name="btn_uninstall_feature">Uninstall</string>
 
     <!-- Install feature -->
+    <string name="lbl_install_feature_title">Module installation</string>
     <string name="lbl_download_in_progress">Downloading</string>
     <string name="lbl_install_in_progress">Installing</string>
     <string name="lbl_failed_to_install">Installation failed</string>