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 fa7fddb commit b8b29b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.Toolbar
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.ComposeView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
Expand Down
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 b8b29b0

Please sign in to comment.