Skip to content

Commit

Permalink
show modal when turn auto download on
Browse files Browse the repository at this point in the history
  • Loading branch information
mebarbosa committed Nov 1, 2024
1 parent bbbb0de commit e51f01e
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.com.shiftyjelly.pocketcasts.settings

import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
Expand Down Expand Up @@ -33,12 +34,14 @@ import au.com.shiftyjelly.pocketcasts.settings.viewmodel.AutoDownloadSettingsVie
import au.com.shiftyjelly.pocketcasts.ui.theme.Theme
import au.com.shiftyjelly.pocketcasts.utils.featureflag.Feature
import au.com.shiftyjelly.pocketcasts.utils.featureflag.FeatureFlag
import au.com.shiftyjelly.pocketcasts.utils.isDeviceRunningOnLowStorage
import au.com.shiftyjelly.pocketcasts.views.extensions.setup
import au.com.shiftyjelly.pocketcasts.views.fragments.FilterSelectFragment
import au.com.shiftyjelly.pocketcasts.views.fragments.PodcastSelectFragment
import au.com.shiftyjelly.pocketcasts.views.fragments.PodcastSelectFragmentSource
import au.com.shiftyjelly.pocketcasts.views.helper.HasBackstack
import au.com.shiftyjelly.pocketcasts.views.helper.NavigationIcon.BackArrow
import au.com.shiftyjelly.pocketcasts.views.lowstorage.LowStorageBottomSheetListener
import dagger.hilt.android.AndroidEntryPoint
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
Expand Down Expand Up @@ -99,6 +102,8 @@ class AutoDownloadSettingsFragment :

private val viewModel: AutoDownloadSettingsViewModel by viewModels()

private var lowStorageListener: LowStorageBottomSheetListener? = null

private var podcastsCategory: PreferenceCategory? = null
private lateinit var upNextPreference: SwitchPreference
private var newEpisodesPreference: SwitchPreference? = null
Expand Down Expand Up @@ -158,6 +163,10 @@ class AutoDownloadSettingsFragment :
if (newValue is Boolean) {
viewModel.onNewEpisodesChange(newValue)
handleNewEpisodesToggle(newValue)

viewLifecycleOwner.lifecycleScope.launch {
if (newValue && isDeviceRunningOnLowStorage()) lowStorageListener?.showModal()
}
}
true
}
Expand Down Expand Up @@ -236,6 +245,16 @@ class AutoDownloadSettingsFragment :
updateView()
}

override fun onAttach(context: Context) {
super.onAttach(context)
lowStorageListener = context as? LowStorageBottomSheetListener
}

override fun onDetach() {
super.onDetach()
lowStorageListener = null
}

private fun handleNewEpisodesToggle(isEnabled: Boolean) {
lifecycleScope.launch {
updateNewEpisodesSwitch(isEnabled)
Expand Down

0 comments on commit e51f01e

Please sign in to comment.