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

OpenSourceDonation: Set default time value on page load in case user skips the page #1276

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ class OpenSourcePage @Inject constructor(
*/
val donationPopupIntervalOptions = listOf(1, 3, 9)

init {
// Set default value on page load, in case user skips the page
setDontShowFor()
}

/**
* Set the next time the donation popup should be shown.
* @param dontShowFor Number of months (30 days) to hide the donation popup for.
*/
fun setDontShowFor(dontShowFor: Int) {
fun setDontShowFor(dontShowFor: Int? = null) {
val dontShowFor = dontShowFor ?: donationPopupIntervalOptions.first()
logger.info("Setting next donation popup to $dontShowFor months")
val month = 30*86400000L // 30 days (~ 1 month)
val nextReminder = month * dontShowFor + System.currentTimeMillis()
Expand All @@ -91,7 +97,7 @@ class OpenSourcePage @Inject constructor(
@Composable
fun OpenSourcePage(
donationPopupIntervalOptions: List<Int>,
onChangeDontShowFor: (Int) -> Unit = {}
onChangeDontShowFor: (Int?) -> Unit = {}
) {
val uriHandler = LocalUriHandler.current

Expand Down Expand Up @@ -142,8 +148,7 @@ fun OpenSourcePage(
RadioButtons(
radioOptions = radioOptions.keys.toList(),
onOptionSelected = { option ->
val months = radioOptions[option] ?: radioOptions.values.first()
onChangeDontShowFor(months)
onChangeDontShowFor(radioOptions[option])
},
modifier = Modifier.padding(bottom = 12.dp)
)
Expand Down