Add payment URL setting

This commit is contained in:
Aleksandras Kostarevas 2024-04-30 14:11:44 -04:00
parent 57cb64f8bd
commit 3c84c747fa
3 changed files with 45 additions and 4 deletions

View File

@ -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
@ -451,3 +454,29 @@ fun NavigationItem(title: String, style: NavigationItemStyle, navigate: () -> Un
}
}
}
@Composable
fun SettingTextField(title: String, placeholder: String, field: SettingsKey<String>) {
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),
)
}

View File

@ -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)
}
}

View File

@ -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