Skip to content
Merged
Show file tree
Hide file tree
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 @@ -595,6 +595,7 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang
const val PREF_SAVED_APP_SUBTYPE_PREFIX = "saved_app_subtype_"
const val PREF_DONT_SHOW_SPONSOR_DIALOG = "dont_show_sponsor_dialog"
const val PREF_LAST_SPONSOR_DIALOG_SHOWN = "last_sponsor_dialog_shown"
const val PREF_LAST_WHATS_NEW_VERSION = "last_whats_new_version"

private val sInstance = Settings()

Expand All @@ -612,6 +613,7 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang
PREF_SELECTED_SUBTYPE,
PREF_USER_DICT_SORT_ORDER,
PREF_LAST_SPONSOR_DIALOG_SHOWN,
PREF_LAST_WHATS_NEW_VERSION,
"last_shown_emoticon_group",
"last_shown_unicode_symbol_group",
"last_dismissed_clipboard_text",
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/helium314/keyboard/settings/SettingsJump.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.core.content.edit
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import androidx.navigation.NavBackStackEntry
Expand Down Expand Up @@ -56,6 +57,13 @@ fun jumpOpenedSections(): Set<String> {
fun fineTuneExpanded(prefs: SharedPreferences, key: String, default: Boolean): Boolean =
prefs.getBoolean(key, default) || key in jumpOpenedSections()

/** Closes all fine-tune sections, so the next opened settings page starts with them closed */
fun collapseFineTuneSections(prefs: SharedPreferences) {
val open = prefs.all.keys.filter { it.startsWith(FINE_TUNE_SECTION_PREFIX) }
if (open.isEmpty()) return
prefs.edit { open.forEach { remove(it) } }
}

/** Changes of this screen's jump state, for use outside of composition */
class JumpState internal constructor(private val state: SavedStateHandle?) {
fun setOpenedSections(sections: Collection<String>) { state?.set(JUMP_OPENED_SECTIONS, ArrayList(sections)) }
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import androidx.compose.animation.slideOutHorizontally
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.IntOffset
Expand All @@ -20,6 +24,8 @@ import androidx.navigation.compose.rememberNavController
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.settings.SettingsSubtype.Companion.toSettingsSubtype
import helium314.keyboard.latin.settings.getTransitionAnimationScale
import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.screens.AIIntegrationScreen
import helium314.keyboard.settings.screens.AboutScreen
import helium314.keyboard.settings.screens.AdvancedSettingsScreen
Expand Down Expand Up @@ -66,6 +72,19 @@ fun SettingsNavHost(
}
}

// fine-tune sections start closed on every page opened from the main page (and on a fresh settings start);
// moving between a page and its sub-pages keeps them as the user left them
val ctx = LocalContext.current
var collapsedAtStart by rememberSaveable { mutableStateOf(false) }
LaunchedEffect(navController) {
navController.currentBackStackEntryFlow.collect { entry ->
if (collapsedAtStart && entry.destination.route != SettingsDestination.Settings) return@collect
collapsedAtStart = true
collapseFineTuneSections(ctx.prefs())
(ctx.getActivity() as? SettingsActivity)?.prefChanged()
}
}

// duration does not change when system setting changes, but that's rare enough to not care
val duration = (250 * getTransitionAnimationScale(LocalContext.current)).toInt()
val animation = tween<IntOffset>(durationMillis = duration)
Expand Down
176 changes: 78 additions & 98 deletions app/src/main/java/helium314/keyboard/settings/dialogs/SponsorDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package helium314.keyboard.settings.dialogs

import android.content.SharedPreferences
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -15,37 +14,24 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Surface
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.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import androidx.core.content.edit
import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Settings
Expand All @@ -60,129 +46,123 @@ fun SponsorDialog(
onSponsorOpenCollective: () -> Unit,
prefs: SharedPreferences
) {
var neverShowAgain by remember { mutableStateOf(false) }

val onDismiss = {
if (neverShowAgain)
prefs.edit { putBoolean(Settings.PREF_DONT_SHOW_SPONSOR_DIALOG, true) }
val onNeverShowAgain = {
prefs.edit { putBoolean(Settings.PREF_DONT_SHOW_SPONSOR_DIALOG, true) }
onDismissRequest()
}

PreferenceDialog(
onDismissRequest = onDismiss,
title = stringResource(R.string.sponsor_dialog_title),
properties = DialogProperties(usePlatformDefaultWidth = false),
buttons = {
Column(
onDismissRequest = onDismissRequest,
showCloseButton = false,
icon = {
Box(
modifier = Modifier
.size(36.dp)
.background(MaterialTheme.colorScheme.primaryContainer, CircleShape),
contentAlignment = Alignment.Center
) {
Icon(
painter = painterResource(R.drawable.ic_heart),
contentDescription = null,
modifier = Modifier.size(20.dp),
tint = MaterialTheme.colorScheme.onPrimaryContainer
)
}
},
titleComposable = {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.sponsor_dialog_title),
modifier = Modifier.weight(1f)
)
TextButton(
onClick = onNeverShowAgain,
modifier = Modifier.widthIn(max = 96.dp),
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp),
colors = ButtonDefaults.textButtonColors(
contentColor = MaterialTheme.colorScheme.onSurfaceVariant
)
) {
Text(
text = stringResource(R.string.sponsor_dialog_never_show_again),
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center,
maxLines = 2
)
}
}
},
buttons = {
Column(modifier = Modifier.fillMaxWidth()) {
Button(
onClick = {
if (neverShowAgain)
prefs.edit { putBoolean(Settings.PREF_DONT_SHOW_SPONSOR_DIALOG, true) }
onSponsorGitHub()
},
onClick = onSponsorGitHub,
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(20.dp),
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.primary
),
contentPadding = PaddingValues(vertical = 12.dp)
shape = RoundedCornerShape(16.dp),
contentPadding = PaddingValues(vertical = 14.dp)
) {
Icon(
painter = painterResource(R.drawable.ic_settings_about_github),
contentDescription = null,
modifier = Modifier.size(20.dp),
tint = MaterialTheme.colorScheme.onPrimary
modifier = Modifier.size(20.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Spacer(modifier = Modifier.width(10.dp))
Text(
text = stringResource(R.string.sponsor_github_button),
fontWeight = FontWeight.Bold
fontWeight = FontWeight.SemiBold
)
}

Spacer(modifier = Modifier.height(10.dp))
Spacer(modifier = Modifier.height(8.dp))

OutlinedButton(
onClick = {
if (neverShowAgain)
prefs.edit { putBoolean(Settings.PREF_DONT_SHOW_SPONSOR_DIALOG, true) }
onSponsorOpenCollective()
},
FilledTonalButton(
onClick = onSponsorOpenCollective,
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(20.dp),
contentPadding = PaddingValues(vertical = 12.dp)
shape = RoundedCornerShape(16.dp),
contentPadding = PaddingValues(vertical = 14.dp)
) {
Icon(
painter = painterResource(R.drawable.ic_opencollective),
contentDescription = null,
modifier = Modifier.size(20.dp),
tint = MaterialTheme.colorScheme.primary
modifier = Modifier.size(20.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Spacer(modifier = Modifier.width(10.dp))
Text(
text = stringResource(R.string.sponsor_opencollective_button),
fontWeight = FontWeight.Bold
fontWeight = FontWeight.SemiBold
)
}

Spacer(modifier = Modifier.height(10.dp))
Spacer(modifier = Modifier.height(12.dp))

TextButton(
onClick = onDismiss,
colors = ButtonDefaults.textButtonColors(
contentColor = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.sponsor_dialog_not_now),
fontWeight = FontWeight.SemiBold
)
TextButton(onClick = onDismissRequest) {
Text(
text = stringResource(R.string.sponsor_dialog_not_now),
fontWeight = FontWeight.SemiBold
)
}
}
}
}
) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
Surface(
shape = RoundedCornerShape(20.dp),
color = MaterialTheme.colorScheme.surfaceContainerHigh,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = stringResource(R.string.sponsor_dialog_message),
style = MaterialTheme.typography.bodyMedium,
lineHeight = MaterialTheme.typography.bodyMedium.lineHeight * 1.25f,
textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurfaceVariant
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(16.dp)
)

Spacer(modifier = Modifier.height(20.dp))

HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.4f))

Spacer(modifier = Modifier.height(8.dp))

Row(
modifier = Modifier
.fillMaxWidth()
.offset(x = (-12).dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start
) {
Checkbox(
checked = neverShowAgain,
onCheckedChange = { neverShowAgain = it },
colors = CheckboxDefaults.colors(
checkedColor = MaterialTheme.colorScheme.primary
)
)
Spacer(modifier = Modifier.width(4.dp))
Text(
text = stringResource(R.string.sponsor_dialog_never_show_again),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium
)
}
}
}
}
}
Loading
Loading