From 3c84c747fac94ecaac4c1aff9a9186603df1c5f5 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Tue, 30 Apr 2024 14:11:44 -0400 Subject: [PATCH] Add payment URL setting --- .../latin/uix/settings/Components.kt | 31 ++++++++++++++++++- .../latin/uix/settings/pages/DevSettings.kt | 6 ++++ .../latin/uix/settings/pages/Payment.kt | 12 +++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/Components.kt b/java/src/org/futo/inputmethod/latin/uix/settings/Components.kt index 498842bb4..36e06e0be 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/Components.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/Components.kt @@ -23,6 +23,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.ArrowForward import androidx.compose.material.icons.filled.Send +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.RadioButton @@ -30,6 +31,7 @@ import androidx.compose.material3.Slider import androidx.compose.material3.Surface import androidx.compose.material3.Switch import androidx.compose.material3.Text +import androidx.compose.material3.TextField import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -59,6 +61,7 @@ import androidx.navigation.compose.rememberNavController import kotlinx.coroutines.runBlocking import org.futo.inputmethod.latin.uix.SettingsKey import org.futo.inputmethod.latin.uix.getSetting +import org.futo.inputmethod.latin.uix.getSettingBlocking import org.futo.inputmethod.latin.uix.theme.Typography import kotlin.math.pow @@ -450,4 +453,30 @@ fun NavigationItem(title: String, style: NavigationItemStyle, navigate: () -> Un else -> {} } } -} \ No newline at end of file +} + +@Composable +fun SettingTextField(title: String, placeholder: String, field: SettingsKey) { + val context = LocalContext.current + + val personalDict = useDataStore(field) + val textFieldValue = remember { mutableStateOf(context.getSettingBlocking( + field.key, field.default)) } + + LaunchedEffect(textFieldValue.value) { + personalDict.setValue(textFieldValue.value) + } + + ScreenTitle(title) + + TextField( + value = textFieldValue.value, + onValueChange = { + textFieldValue.value = it + }, + placeholder = { Text(placeholder) }, + modifier = Modifier + .fillMaxWidth() + .padding(8.dp, 4.dp), + ) +} diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt index 997dba50c..c772afee4 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt @@ -6,6 +6,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.datastore.preferences.core.booleanPreferencesKey +import androidx.datastore.preferences.core.stringPreferencesKey import androidx.lifecycle.lifecycleScope import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController @@ -13,6 +14,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import org.futo.inputmethod.latin.BuildConfig import org.futo.inputmethod.latin.R import org.futo.inputmethod.latin.uix.HiddenKeysSetting import org.futo.inputmethod.latin.uix.SettingsKey @@ -20,6 +22,7 @@ import org.futo.inputmethod.latin.uix.settings.NavigationItem import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle import org.futo.inputmethod.latin.uix.settings.ScreenTitle import org.futo.inputmethod.latin.uix.settings.ScrollableList +import org.futo.inputmethod.latin.uix.settings.SettingTextField import org.futo.inputmethod.latin.uix.settings.SettingToggleDataStore import org.futo.inputmethod.latin.uix.settings.SettingToggleRaw import org.futo.inputmethod.latin.uix.settings.useDataStore @@ -28,6 +31,8 @@ import org.futo.inputmethod.updates.DISABLE_UPDATE_REMINDER val IS_DEVELOPER = SettingsKey(booleanPreferencesKey("isDeveloperMode"), false) +val TMP_PAYMENT_URL = SettingsKey(stringPreferencesKey("temporaryPaymentUrl"), BuildConfig.PAYMENT_URL) + @Preview(showBackground = true) @Composable fun DeveloperScreen(navController: NavHostController = rememberNavController()) { @@ -105,5 +110,6 @@ fun DeveloperScreen(navController: NavHostController = rememberNavController()) { } ) + SettingTextField("Payment URL", "https://example.com", TMP_PAYMENT_URL) } } \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt index 645849396..a07ee1241 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt @@ -52,10 +52,12 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import org.futo.inputmethod.latin.BuildConfig import org.futo.inputmethod.latin.R import org.futo.inputmethod.latin.payment.PaymentActivity import org.futo.inputmethod.latin.uix.SettingsKey +import org.futo.inputmethod.latin.uix.getSetting import org.futo.inputmethod.latin.uix.setSetting import org.futo.inputmethod.latin.uix.settings.NavigationItem import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle @@ -160,6 +162,9 @@ fun UnpaidNoticeCondition( showOnlyIfReminder: Boolean = false, inner: @Composable () -> Unit ) { + val paymentUrl = useDataStoreValueBlocking(TMP_PAYMENT_URL) + if(paymentUrl.isBlank()) return + val numDaysInstalled = useNumberOfDaysInstalled() val forceShowNotice = useDataStoreValueBlocking(FORCE_SHOW_NOTICE) val isAlreadyPaid = useDataStoreValueBlocking(IS_ALREADY_PAID) @@ -372,10 +377,11 @@ fun PaymentScreen( Row(modifier = Modifier.padding(8.dp, 0.dp)) { Button( onClick = { - if(BuildConfig.PAYMENT_URL.isNotBlank()) { - context.openURI(BuildConfig.PAYMENT_URL) + val url = runBlocking { context.getSetting(TMP_PAYMENT_URL) } + if(url.isNotBlank()) { + context.openURI(url) } else { - val toast = Toast.makeText(context, "Payment is unsupported on this build", Toast.LENGTH_SHORT) + val toast = Toast.makeText(context, "Payment is unsupported on this build (still WIP)", Toast.LENGTH_SHORT) toast.show() } }, modifier = Modifier