Skip to content

Commit

Permalink
[Manage Downloads] Allow users to dismiss low storage banner in downl…
Browse files Browse the repository at this point in the history
…oad screen (#3385)

Co-authored-by: Philip Simpson <[email protected]>
  • Loading branch information
mebarbosa and geekygecko authored Dec 26, 2024
1 parent 0760957 commit db30b20
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
([#3387](https://github.com/Automattic/pocket-casts-android/pull/3387))
* Fix sleep timer was not stopping as expected
([#3377](https://github.com/Automattic/pocket-casts-android/pull/3377))
* Updates
* Add the ability to dismiss the low storage banner in download screen
([#3385](https://github.com/Automattic/pocket-casts-android/pull/3385))

7.79
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class ProfileEpisodeListFragment : BaseFragment(), Toolbar.OnMenuItemClickListen

private suspend fun updateManageDownloadsCard(downloadedEpisodesSize: Long) {
binding?.manageDownloadsCard?.apply {
isVisible = downloadedEpisodesSize != 0L && isDeviceRunningOnLowStorage()
isVisible = downloadedEpisodesSize != 0L && isDeviceRunningOnLowStorage() && settings.shouldShowLowStorageBannerAfterSnooze()
if (isVisible) {
setContent {
AppTheme(theme.activeTheme) {
Expand All @@ -443,6 +443,10 @@ class ProfileEpisodeListFragment : BaseFragment(), Toolbar.OnMenuItemClickListen
analyticsTracker.track(AnalyticsEvent.FREE_UP_SPACE_MANAGE_DOWNLOADS_TAPPED, mapOf("source" to SourceView.DOWNLOADS.analyticsValue))
showFragment(ManualCleanupFragment.newInstance())
},
onMoreOptionsClick = {
analyticsTracker.track(AnalyticsEvent.FREE_UP_SPACE_MANAGE_DOWNLOADS_MORE_OPTIONS_TAPPED, mapOf("source" to SourceView.DOWNLOADS.analyticsValue))
onManageDownloadsMoreOptions()
},
)
}
}
Expand All @@ -451,6 +455,22 @@ class ProfileEpisodeListFragment : BaseFragment(), Toolbar.OnMenuItemClickListen
}
}

private fun onManageDownloadsMoreOptions() {
OptionsDialog()
.setTitle(resources.getString(LR.string.need_to_free_up_space))
.addTextOption(LR.string.dismiss_manage_download_banner, click = this::onDismissManageDownloadTapped)
.show(parentFragmentManager, "manage_downloads_more_options")
}

private fun onDismissManageDownloadTapped() {
analyticsTracker.track(
AnalyticsEvent.FREE_UP_SPACE_MANAGE_DOWNLOADS_MORE_OPTIONS_DISMISS_TAPPED,
mapOf("source" to SourceView.DOWNLOADS.analyticsValue),
)
settings.setDismissLowStorageBannerTime(System.currentTimeMillis())
binding?.manageDownloadsCard?.isVisible = false
}

override fun onMenuItemClick(item: MenuItem): Boolean {
return if (item.itemId == R.id.more_options) {
val dialog = OptionsDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -37,6 +40,7 @@ import au.com.shiftyjelly.pocketcasts.localization.R as LR
fun ManageDownloadsCard(
totalDownloadSize: Long,
onManageDownloadsClick: () -> Unit,
onMoreOptionsClick: () -> Unit,
modifier: Modifier = Modifier,
) {
val formattedTotalDownloadSize = Util.formattedBytes(bytes = totalDownloadSize, context = LocalContext.current)
Expand All @@ -52,36 +56,47 @@ fun ManageDownloadsCard(
.padding(horizontal = 16.dp).padding(top = 16.dp),

) {
Icon(
painter = painterResource(id = IR.drawable.pencil_cleanup),
contentDescription = stringResource(LR.string.pencil_clean_up_icon_content_description),
modifier = Modifier
.padding(end = 12.dp)
.size(24.dp),
// The icon isn't clickable so the design matches the title color
tint = MaterialTheme.theme.colors.primaryText01,
)

Column(
modifier = Modifier.padding(end = 16.dp),
) {
TextH40(
text = stringResource(LR.string.need_to_free_up_space),
fontWeight = FontWeight.Bold,
color = MaterialTheme.theme.colors.primaryText01,
Row(modifier = Modifier.weight(1f)) {
Icon(
painter = painterResource(id = IR.drawable.pencil_cleanup),
contentDescription = stringResource(LR.string.pencil_clean_up_icon_content_description),
modifier = Modifier
.padding(end = 12.dp)
.size(24.dp),
// The icon isn't clickable so the design matches the title color
tint = MaterialTheme.theme.colors.primaryText01,
)

Spacer(modifier = Modifier.height(2.dp))
Column {
TextH40(
text = stringResource(LR.string.need_to_free_up_space),
fontWeight = FontWeight.Bold,
color = MaterialTheme.theme.colors.primaryText01,
)

TextP50(
text = stringResource(LR.string.save_space_by_managing_downloaded_episodes, formattedTotalDownloadSize),
color = MaterialTheme.theme.colors.primaryText02,
)
Spacer(modifier = Modifier.height(2.dp))

TextP50(
text = stringResource(LR.string.save_space_by_managing_downloaded_episodes, formattedTotalDownloadSize),
color = MaterialTheme.theme.colors.primaryText02,
)

TextButton(onClick = { onManageDownloadsClick.invoke() }, contentPadding = PaddingValues()) {
TextH50(text = stringResource(LR.string.manage_downloads), color = MaterialTheme.theme.colors.primaryIcon01)
TextButton(onClick = { onManageDownloadsClick.invoke() }, contentPadding = PaddingValues()) {
TextH50(text = stringResource(LR.string.manage_downloads), color = MaterialTheme.theme.colors.primaryIcon01)
}
}
}

IconButton(
onClick = { onMoreOptionsClick.invoke() },
modifier = Modifier.size(24.dp),
) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = stringResource(LR.string.manage_download_more_options_content_description),
tint = MaterialTheme.theme.colors.primaryIcon02,
)
}
}
}

Expand All @@ -91,6 +106,6 @@ fun ManageDownloadsCardPreview(
@PreviewParameter(ThemePreviewParameterProvider::class) themeType: Theme.ThemeType,
) {
AppThemeWithBackground(themeType) {
ManageDownloadsCard(totalDownloadSize = 15023232, onManageDownloadsClick = {})
ManageDownloadsCard(totalDownloadSize = 15023232, onManageDownloadsClick = {}, onMoreOptionsClick = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -668,5 +668,7 @@ enum class AnalyticsEvent(val key: String) {
FREE_UP_SPACE_BANNER_SHOWN("free_up_space_banner_shown"),
FREE_UP_SPACE_MODAL_SHOWN("free_up_space_modal_shown"),
FREE_UP_SPACE_MANAGE_DOWNLOADS_TAPPED("free_up_space_manage_downloads_tapped"),
FREE_UP_SPACE_MANAGE_DOWNLOADS_MORE_OPTIONS_TAPPED("free_up_space_manage_downloads_more_options_tapped"),
FREE_UP_SPACE_MANAGE_DOWNLOADS_MORE_OPTIONS_DISMISS_TAPPED("free_up_space_manage_downloads_more_options_dismiss_tapped"),
FREE_UP_SPACE_MAYBE_LATER_TAPPED("free_up_space_maybe_later_tapped"),
}
2 changes: 2 additions & 0 deletions modules/services/localization/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,8 @@
<string name="save_space_by_managing_downloaded_episodes">Save %1$s – by managing downloaded episodes.</string>
<string name="manage_downloads">Manage downloads</string>
<string name="maybe_later">Maybe Later</string>
<string name="dismiss_manage_download_banner">Dismiss</string>
<string name="manage_download_more_options_content_description">Manage Download Banner More Options</string>

<!-- Up Next Shuffle -->
<string name="up_next_shuffle_button_content_description">Up Next shuffle</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ interface Settings {
const val SYNC_API_MODEL = "mobile"
const val LAST_UPDATE_TIME = "LastUpdateTime"
const val LAST_DISMISS_LOW_STORAGE_MODAL_TIME = "LastDismissLowStorageModalTime"
const val LAST_DISMISS_LOW_STORAGE_BANNER_TIME = "LastDismissLowStorageBannerTime"
const val PREFERENCE_SKIP_FORWARD = "skipForward"
const val PREFERENCE_SKIP_BACKWARD = "skipBack"
const val PREFERENCE_STORAGE_CHOICE = "storageChoice"
Expand Down Expand Up @@ -327,6 +328,9 @@ interface Settings {
fun setDismissLowStorageModalTime(lastUpdateTime: Long)
fun shouldShowLowStorageModalAfterSnooze(): Boolean

fun setDismissLowStorageBannerTime(lastUpdateTime: Long)
fun shouldShowLowStorageBannerAfterSnooze(): Boolean

val hideNotificationOnPause: UserSetting<Boolean>

val streamingMode: UserSetting<Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@ class SettingsImpl @Inject constructor(
return timeSinceDismiss >= 7.days
}

override fun setDismissLowStorageBannerTime(lastUpdateTime: Long) {
sharedPreferences.edit {
putLong(Settings.LAST_DISMISS_LOW_STORAGE_BANNER_TIME, lastUpdateTime)
}
}

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

if (lastSnoozeTime == 0L) return true

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

return timeSinceDismiss >= 14.days
}

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

0 comments on commit db30b20

Please sign in to comment.