Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Project] Manage Downloaded Episodes - Display Modal when running on low storage and turn on Auto Download #3151

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
10 changes: 5 additions & 5 deletions app/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.6.1" type="baseline" client="gradle" dependencies="true" name="AGP (8.6.1)" variant="all" version="8.6.1">
<issues format="6" by="lint 8.7.1" type="baseline" client="gradle" dependencies="true" name="AGP (8.7.1)" variant="all" version="8.7.1">

<issue
id="MissingSuperCall"
Expand Down Expand Up @@ -140,7 +140,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/AndroidManifest.xml"
line="529"
line="528"
column="33"/>
</issue>

Expand All @@ -151,7 +151,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/AndroidManifest.xml"
line="531"
line="530"
column="33"/>
</issue>

Expand Down Expand Up @@ -206,7 +206,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt"
line="1005"
line="1009"
column="55"/>
</issue>

Expand All @@ -217,7 +217,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt"
line="1012"
line="1016"
column="55"/>
</issue>

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
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@
<string name="player_play_failed_check_internet">Could not load podcast. Please check your internet connection and try again.</string>
<string name="player_played_up_to">Played up to %s</string>
<string name="player_time_remaining">Time remaining %s</string>
<string name="swipe_affordance_content_description">Swipe Affordance</string>
<string name="drag_down_to_dismiss_content_description">Drag down to dismiss</string>

<!-- Chapters -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package au.com.shiftyjelly.pocketcasts.views.lowstorage

import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -86,69 +84,64 @@ internal fun LowStorageDialog(
) {
val formattedTotalDownloadSize = Util.formattedBytes(bytes = totalDownloadSize, context = LocalContext.current)

Box(
modifier = modifier
.fillMaxWidth(),
contentAlignment = Alignment.Center,
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier.fillMaxWidth(),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier.fillMaxWidth(),
) {
Image(
painterResource(IR.drawable.swipe_affordance),
contentDescription = stringResource(LR.string.swipe_affordance_content_description),
modifier = modifier
.width(56.dp)
.padding(top = 8.dp, bottom = 24.dp),
)
Icon(
painter = painterResource(IR.drawable.swipe_affordance),
contentDescription = stringResource(LR.string.drag_down_to_dismiss_content_description),
tint = MaterialTheme.theme.colors.primaryIcon02,
modifier = Modifier
.width(56.dp)
.padding(top = 8.dp, bottom = 24.dp),
)

Icon(
painterResource(IR.drawable.pencil_cleanup),
contentDescription = stringResource(LR.string.pencil_clean_up_icon_content_description),
modifier = modifier
.padding(bottom = 16.dp)
.size(40.dp),
tint = MaterialTheme.theme.colors.primaryInteractive01,
)
Icon(
painterResource(IR.drawable.pencil_cleanup),
contentDescription = stringResource(LR.string.pencil_clean_up_icon_content_description),
modifier = Modifier
.padding(bottom = 16.dp)
.size(40.dp),
tint = MaterialTheme.theme.colors.primaryInteractive01,
)

TextH20(
text = stringResource(LR.string.need_to_free_up_space),
textAlign = TextAlign.Center,
modifier = modifier.padding(bottom = 10.dp, start = 21.dp, end = 21.dp),
)
TextH20(
text = stringResource(LR.string.need_to_free_up_space),
textAlign = TextAlign.Center,
modifier = modifier.padding(bottom = 10.dp, start = 21.dp, end = 21.dp),
)

TextH50(
text = stringResource(LR.string.save_space_by_managing_downloaded_episodes, formattedTotalDownloadSize),
fontWeight = FontWeight.W500,
textAlign = TextAlign.Center,
modifier = modifier.padding(bottom = 57.dp, start = 21.dp, end = 21.dp),
)
TextH50(
text = stringResource(LR.string.save_space_by_managing_downloaded_episodes, formattedTotalDownloadSize),
fontWeight = FontWeight.W500,
textAlign = TextAlign.Center,
modifier = modifier.padding(bottom = 57.dp, start = 21.dp, end = 21.dp),
)

RowButton(
text = stringResource(LR.string.manage_downloads),
onClick = { onManageDownloadsClick.invoke() },
includePadding = false,
textColor = MaterialTheme.theme.colors.primaryInteractive02,
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.theme.colors.primaryInteractive01,
),
modifier = modifier
.padding(horizontal = 21.dp)
.padding(bottom = 12.dp),
)
RowButton(
text = stringResource(LR.string.manage_downloads),
onClick = { onManageDownloadsClick.invoke() },
includePadding = false,
textColor = MaterialTheme.theme.colors.primaryInteractive02,
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.theme.colors.primaryInteractive01,
),
modifier = modifier
.padding(horizontal = 21.dp)
.padding(bottom = 12.dp),
)

RowOutlinedButton(
text = stringResource(LR.string.maybe_later),
onClick = { onMaybeLaterClick.invoke() },
includePadding = false,
modifier = modifier
.padding(bottom = 12.dp)
.padding(horizontal = 21.dp),
border = null,
colors = ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.theme.colors.primaryText01),
)
}
RowOutlinedButton(
text = stringResource(LR.string.maybe_later),
onClick = { onMaybeLaterClick.invoke() },
includePadding = false,
modifier = modifier
.padding(bottom = 12.dp)
.padding(horizontal = 21.dp),
border = null,
colors = ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.theme.colors.primaryText01),
)
}
}

Expand Down