-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add confirm dialog to download asset
- Loading branch information
Showing
6 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/materiiapps/gloom/domain/manager/DialogManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.materiiapps.gloom.domain.manager | ||
|
||
import android.content.Context | ||
import com.materiiapps.gloom.domain.manager.base.BasePreferenceManager | ||
|
||
class DialogManager(context: Context): BasePreferenceManager(context.getSharedPreferences("dialogs", Context.MODE_PRIVATE)) { | ||
|
||
var downloadAsset by enumPreference("release_asset_download", DialogState.UNKNOWN) | ||
|
||
} | ||
|
||
enum class DialogState { | ||
UNKNOWN, | ||
CONFIRMED, | ||
DENIED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...c/main/java/com/materiiapps/gloom/ui/widgets/release/dialog/ReleaseAssetDownloadDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.materiiapps.gloom.ui.widgets.release.dialog | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Download | ||
import androidx.compose.material.icons.outlined.Download | ||
import androidx.compose.material.icons.rounded.Download | ||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.Checkbox | ||
import androidx.compose.material3.FilledTonalButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.semantics.Role | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import com.materiiapps.gloom.R | ||
import com.materiiapps.gloom.utils.getFileSizeString | ||
|
||
@Composable | ||
fun ReleaseAssetDownloadDialog( | ||
fileName: String, | ||
fileSize: Int, | ||
onClose: () -> Unit, | ||
onConfirm: (dontShowAgain: Boolean) -> Unit | ||
) { | ||
var checked by remember { | ||
mutableStateOf(false) | ||
} | ||
|
||
AlertDialog( | ||
onDismissRequest = onClose, | ||
confirmButton = { | ||
FilledTonalButton(onClick = { onConfirm(checked) }) { | ||
Text("Download") | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton(onClick = onClose) { | ||
Text("Cancel") | ||
} | ||
}, | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Rounded.Download, | ||
contentDescription = null, | ||
modifier = Modifier.size(30.dp) | ||
) | ||
}, | ||
title = { | ||
Text( | ||
text = "Confirm download", | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier.fillMaxWidth() | ||
) | ||
}, | ||
text = { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(16.dp), | ||
) { | ||
Text( | ||
text = "You are about to download $fileName (${getFileSizeString(fileSize)}), are you sure you want to do that?", | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier.fillMaxWidth() | ||
) | ||
|
||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = Modifier | ||
.clickable(role = Role.Checkbox) { checked = !checked } | ||
.fillMaxWidth() | ||
) { | ||
Checkbox(checked = checked, onCheckedChange = { checked = it }) | ||
Text("Don't show this again") | ||
} | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters