--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/src/main/java/com/geekorum/ttrss/articles_list/AccountHeaderPresenter.kt Thu Oct 03 13:07:28 2019 -0700
@@ -0,0 +1,52 @@
+/*
+ * 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 android.view.View
+import android.widget.TextView
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.observe
+import com.geekorum.ttrss.R
+
+/**
+ * Presenter for the Account Header view in NavigationView
+ */
+class AccountHeaderPresenter(
+ private val headerView: View,
+ private val lifecycleOwner: LifecycleOwner,
+ private val accountViewModel: TtrssAccountViewModel
+) {
+ init {
+ setUpViewModels()
+ }
+
+ private fun setUpViewModels() {
+ accountViewModel.selectedAccount.observe(lifecycleOwner) { account ->
+ val login = headerView.findViewById<TextView>(R.id.drawer_header_login)
+ login.text = account.name
+ }
+
+ accountViewModel.selectedAccountHost.observe(lifecycleOwner) { host ->
+ val server = headerView.findViewById<TextView>(R.id.drawer_header_server)
+ server.text = host
+ }
+ }
+}
--- a/app/src/main/java/com/geekorum/ttrss/articles_list/FeedListFragment.kt Thu Oct 03 15:13:45 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/articles_list/FeedListFragment.kt Thu Oct 03 13:07:28 2019 -0700
@@ -30,7 +30,6 @@
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
-import android.widget.TextView
import androidx.core.app.ActivityCompat
import androidx.core.view.get
import androidx.core.view.updatePadding
@@ -62,6 +61,7 @@
private lateinit var binding: FragmentFeedsBinding
private lateinit var feedNavigationPresenter: FeedsNavigationMenuPresenter
+ private lateinit var accountHeaderPresenter: AccountHeaderPresenter
private val feedsViewModel: FeedsViewModel by viewModels()
private val activityViewModel: ActivityViewModel by activityViewModels()
@@ -90,8 +90,12 @@
binding.navigationView.inflateMenu(R.menu.fragment_feed_list)
feedNavigationPresenter =
- FeedsNavigationMenuPresenter(viewLifecycleOwner, binding.navigationView, feedsViewModel,
- activityViewModel, feedsMenu)
+ FeedsNavigationMenuPresenter(binding.navigationView, feedsMenu, viewLifecycleOwner, feedsViewModel,
+ activityViewModel)
+
+ val headerView = binding.navigationView.getHeaderView(0)
+ accountHeaderPresenter = AccountHeaderPresenter(headerView, viewLifecycleOwner,
+ accountViewModel)
}
private fun setUpEdgeToEdge() {
@@ -111,18 +115,6 @@
activityViewModel.selectedFeed.observe(viewLifecycleOwner) { feed ->
feed?.let { feedsViewModel.setSelectedFeed(it.id) }
}
-
- accountViewModel.selectedAccount.observe(viewLifecycleOwner) { account ->
- val headerView = binding.navigationView.getHeaderView(0)
- val login = headerView.findViewById<TextView>(R.id.drawer_header_login)
- login.text = account.name
- }
-
- accountViewModel.selectedAccountHost.observe(viewLifecycleOwner) { host ->
- val headerView = binding.navigationView.getHeaderView(0)
- val server = headerView.findViewById<TextView>(R.id.drawer_header_server)
- server.text = host
- }
}
private fun navigateToSettings() {
--- a/app/src/main/java/com/geekorum/ttrss/articles_list/FeedsNavigationMenuPresenter.kt Thu Oct 03 15:13:45 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/articles_list/FeedsNavigationMenuPresenter.kt Thu Oct 03 13:07:28 2019 -0700
@@ -38,11 +38,11 @@
* Display the feeds in a NavigationView menu.
*/
class FeedsNavigationMenuPresenter(
+ view: NavigationView,
+ private val menu: Menu,
private val lifeCycleOwner: LifecycleOwner,
- view: NavigationView,
private val feedsViewModel: FeedsViewModel,
- private val activityViewModel: ActivityViewModel,
- private val menu: Menu
+ private val activityViewModel: ActivityViewModel
) {
private val layoutInflater = LayoutInflater.from(view.context)