Skip to content

Commit

Permalink
snooze low storage modal
Browse files Browse the repository at this point in the history
  • Loading branch information
mebarbosa committed Nov 1, 2024
1 parent bbbb0de commit b038d94
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ class MainActivity :
val downloadedEpisodesState by viewModel.downloadedEpisodeState.collectAsState()

val shouldShow = downloadedEpisodesState.downloadedEpisodes != 0L &&
settings.shouldShowLowStorageModalAfterSnooze() &&
FeatureFlag.isEnabled(Feature.MANAGE_DOWNLOADED_EPISODES)

AppTheme(theme.activeTheme) {
Expand All @@ -758,6 +759,7 @@ class MainActivity :
onExpanded = {
},
onMaybeLaterClick = {
settings.setDismissLowStorageModalTime(System.currentTimeMillis())
},
totalDownloadSize = downloadedEpisodesState.downloadedEpisodes,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ interface Settings {
const val SYNC_HISTORY_VERSION = 1
const val SYNC_API_MODEL = "mobile"
const val LAST_UPDATE_TIME = "LastUpdateTime"
const val LAST_DISMISS_LOW_STORAGE_MODAL_TIME = "LastDismissLowStorageModalTime"
const val PREFERENCE_SKIP_FORWARD = "skipForward"
const val PREFERENCE_SKIP_BACKWARD = "skipBack"
const val PREFERENCE_STORAGE_CHOICE = "storageChoice"
Expand Down Expand Up @@ -323,6 +324,9 @@ interface Settings {

fun clearPlusPreferences()

fun setDismissLowStorageModalTime(lastUpdateTime: Long)
fun shouldShowLowStorageModalAfterSnooze(): Boolean

val hideNotificationOnPause: UserSetting<Boolean>

val streamingMode: UserSetting<Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import javax.crypto.spec.PBEKeySpec
import javax.crypto.spec.PBEParameterSpec
import javax.inject.Inject
import kotlin.math.max
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
Expand Down Expand Up @@ -320,6 +322,22 @@ class SettingsImpl @Inject constructor(
refreshStateObservable.accept(refreshState)
}

override fun setDismissLowStorageModalTime(lastUpdateTime: Long) {
val editor = sharedPreferences.edit()
editor.putLong(Settings.LAST_DISMISS_LOW_STORAGE_MODAL_TIME, lastUpdateTime)
editor.apply()
}

override fun shouldShowLowStorageModalAfterSnooze(): Boolean {
val lastSnoozeTime = sharedPreferences.getLong(Settings.LAST_DISMISS_LOW_STORAGE_MODAL_TIME, 0)

if (lastSnoozeTime == 0L) return true

val timeSinceDismiss = (System.currentTimeMillis() - lastSnoozeTime).milliseconds

return timeSinceDismiss >= 7.days
}

override fun getRefreshState(): RefreshState? {
return refreshStateObservable.value
}
Expand Down

0 comments on commit b038d94

Please sign in to comment.