Skip to content

Commit

Permalink
Move Settings UI to separate composable function
Browse files Browse the repository at this point in the history
  • Loading branch information
nain-F49FF806 committed Oct 5, 2024
1 parent 9c838a4 commit 977318d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
3 changes: 2 additions & 1 deletion android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
applicationId = "alt.nainapps.sharepaste"
minSdk = 26
targetSdk = 34
versionCode = 1728150000
versionCode = 1728159000
versionName = "2024.10.05"
setProperty("archivesBaseName", "sharepaste.oo")

Expand Down Expand Up @@ -112,6 +112,7 @@ dependencies {
implementation(libs.composePrefs)
implementation(libs.androidx.preference.ktx)
implementation(libs.androidx.material.icons.extended)
implementation(libs.androidx.navigation.compose)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.content.ContextCompat.getString
import me.zhanghai.compose.preference.ProvidePreferenceLocals
import me.zhanghai.compose.preference.textFieldPreference

Expand All @@ -42,33 +45,42 @@ class SettingsActivity : ComponentActivity() {
)
}
) { innerPadding ->
ProvidePreferenceLocals {
LazyColumn(
modifier = Modifier.fillMaxSize().padding(innerPadding)
) {
textFieldPreference(
key = "privatebin_host_url",
defaultValue = getString(R.string.default_privatebin_host_url),
textToValue = { it },
title = { Text(text = "Privatebin host (server)") },
summary = {
Text(
text = if (looksValidUrl(it)) {
it
} else {
"Invalid looking url: " + it.ifBlank { "<empty>" }
}
)
}
)
}
Surface(modifier = Modifier.fillMaxSize().padding(innerPadding)) {
SettingsUI()
}
}
}
}
}
}

@Composable
fun SettingsUI() {
val context = LocalContext.current
ProvidePreferenceLocals {
LazyColumn(
) {
textFieldPreference(
key = "privatebin_host_url",
defaultValue = getString(context, R.string.default_privatebin_host_url),
textToValue = { it },
title = { Text(text = "Privatebin host (server)") },
summary = {
Text(
text = if (looksValidUrl(it)) {
it
} else {
"Invalid looking url: " + it.ifBlank { "<empty>" }
}
)
}
)
}
}
}



fun looksValidUrl(potentialUrl: String) = Patterns.WEB_URL.matcher(potentialUrl).matches()

@Composable
Expand Down

0 comments on commit 977318d

Please sign in to comment.