From 1dd0930b835ae4bc7182f4f05ee3a69060f5db4b Mon Sep 17 00:00:00 2001 From: Jared Fantaye Date: Tue, 28 Feb 2023 17:30:17 +0100 Subject: [PATCH] Fixed some small issues --- .../schabi/newpipe/local/feed/FeedFragment.kt | 26 ++++++------------- .../newpipe/local/feed/FeedViewModel.kt | 2 ++ app/src/main/res/values/settings_keys.xml | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 3ca3bd320..9fe90969f 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -40,7 +40,6 @@ import androidx.appcompat.app.AlertDialog import androidx.core.content.edit import androidx.core.math.MathUtils import androidx.core.os.bundleOf -import androidx.core.view.MenuItemCompat import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider import androidx.preference.PreferenceManager @@ -99,9 +98,6 @@ class FeedFragment : BaseStateFragment() { private var oldestSubscriptionUpdate: OffsetDateTime? = null private lateinit var groupAdapter: GroupieAdapter - @State @JvmField var showPlayedItems: Boolean = true - @State @JvmField var showPartiallyPlayedItems: Boolean = true - @State @JvmField var showFutureItems: Boolean = true private var onSettingsChangeListener: SharedPreferences.OnSharedPreferenceChangeListener? = null private var updateListViewModeOnResume = false @@ -140,9 +136,6 @@ class FeedFragment : BaseStateFragment() { val factory = FeedViewModel.getFactory(requireContext(), groupId) viewModel = ViewModelProvider(this, factory)[FeedViewModel::class.java] - showPlayedItems = viewModel.getShowPlayedItemsFromPreferences() - showPartiallyPlayedItems = viewModel.getShowPartiallyPlayedItemsFromPreferences() - showFutureItems = viewModel.getShowFutureItemsFromPreferences() viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(::handleResult) } groupAdapter = GroupieAdapter().apply { @@ -217,10 +210,6 @@ class FeedFragment : BaseStateFragment() { activity.supportActionBar?.subtitle = groupName inflater.inflate(R.menu.menu_feed_fragment, menu) - MenuItemCompat.setTooltipText( - menu.findItem(R.id.menu_item_feed_toggle_played_items), - getString(R.string.feed_show_hide_streams) - ) } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -259,7 +248,11 @@ class FeedFragment : BaseStateFragment() { getString(R.string.feed_show_upcoming) ) - val checkedDialogItems = booleanArrayOf(showPlayedItems, showPartiallyPlayedItems, showFutureItems) + val checkedDialogItems = booleanArrayOf( + viewModel.getShowPlayedItemsFromPreferences(), + viewModel.getShowPartiallyPlayedItemsFromPreferences(), + viewModel.getShowFutureItemsFromPreferences() + ) val builder = AlertDialog.Builder(context!!) builder.setTitle(R.string.feed_hide_streams_title) @@ -268,14 +261,11 @@ class FeedFragment : BaseStateFragment() { } builder.setPositiveButton(R.string.ok) { _, _ -> - showPlayedItems = checkedDialogItems[0] - viewModel.setSaveShowPlayedItems(showPlayedItems) + viewModel.setSaveShowPlayedItems(checkedDialogItems[0]) - showPartiallyPlayedItems = checkedDialogItems[1] - viewModel.setSaveShowPartiallyPlayedItems(showPartiallyPlayedItems) + viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1]) - showFutureItems = checkedDialogItems[2] - viewModel.setSaveShowFutureItems(showFutureItems) + viewModel.setSaveShowFutureItems(checkedDialogItems[2]) } builder.setNegativeButton(R.string.cancel, null) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt index 015b72160..58f9e9edc 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt @@ -157,9 +157,11 @@ class FeedViewModel( private fun getShowPartiallyPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(context.getString(R.string.feed_show_partially_watched_items_key), true) + private fun getShowFutureItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(context.getString(R.string.feed_show_future_items_key), true) + fun getFactory(context: Context, groupId: Long) = viewModelFactory { initializer { FeedViewModel( diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 281d3bf40..57d1abc5c 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -283,7 +283,7 @@ feed_update_threshold_key 300 - feed_show_watched_items + feed_show_played_items feed_show_partially_watched_items feed_show_future_items