1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-25 04:22:30 +01:00

Fixed some small issues

This commit is contained in:
Jared Fantaye 2023-02-28 17:30:17 +01:00
parent bc29f40d69
commit 1dd0930b83
3 changed files with 11 additions and 19 deletions

View File

@ -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<FeedState>() {
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<FeedState>() {
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<FeedState>() {
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<FeedState>() {
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<FeedState>() {
}
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)

View File

@ -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(

View File

@ -283,7 +283,7 @@
<string name="feed_update_threshold_key">feed_update_threshold_key</string>
<string name="feed_update_threshold_default_value">300</string>
<string name="feed_show_watched_items_key">feed_show_watched_items</string>
<string name="feed_show_watched_items_key">feed_show_played_items</string>
<string name="feed_show_partially_watched_items_key">feed_show_partially_watched_items</string>
<string name="feed_show_future_items_key">feed_show_future_items</string>