feat: revamp about and attribution pages
This commit is contained in:
parent
a1b26d7ba5
commit
a882c5d27b
|
|
@ -1,17 +1,19 @@
|
||||||
package chat.revolt.screens.about
|
package chat.revolt.screens.about
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.ElevatedButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.ClipboardManager
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
@ -22,9 +24,12 @@ import androidx.navigation.NavController
|
||||||
import chat.revolt.BuildConfig
|
import chat.revolt.BuildConfig
|
||||||
import chat.revolt.R
|
import chat.revolt.R
|
||||||
import chat.revolt.api.REVOLT_BASE
|
import chat.revolt.api.REVOLT_BASE
|
||||||
|
import chat.revolt.api.RevoltJson
|
||||||
import chat.revolt.api.routes.misc.Root
|
import chat.revolt.api.routes.misc.Root
|
||||||
import chat.revolt.api.routes.misc.getRootRoute
|
import chat.revolt.api.routes.misc.getRootRoute
|
||||||
|
import chat.revolt.components.generic.PageHeader
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
class AboutViewModel(
|
class AboutViewModel(
|
||||||
|
|
@ -33,6 +38,21 @@ class AboutViewModel(
|
||||||
val root: State<Root?>
|
val root: State<Root?>
|
||||||
get() = _root
|
get() = _root
|
||||||
|
|
||||||
|
fun getDebugInformation(): Map<String, String> {
|
||||||
|
return mapOf(
|
||||||
|
"App ID" to BuildConfig.APPLICATION_ID,
|
||||||
|
"App Version" to BuildConfig.VERSION_NAME,
|
||||||
|
"API Host" to URI(REVOLT_BASE).host,
|
||||||
|
"API Version" to (root.value?.revolt ?: "Unknown"),
|
||||||
|
"Runtime SDK" to Build.VERSION.SDK_INT.toString(),
|
||||||
|
"Model" to "${Build.MANUFACTURER} ${
|
||||||
|
Build.DEVICE.replaceFirstChar {
|
||||||
|
if (it.isLowerCase()) it.titlecase() else it.toString()
|
||||||
|
}
|
||||||
|
} (${Build.MODEL})"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_root.value = getRootRoute().copy()
|
_root.value = getRootRoute().copy()
|
||||||
|
|
@ -50,7 +70,7 @@ fun VersionItem(
|
||||||
Text(
|
Text(
|
||||||
text = key,
|
text = key,
|
||||||
color = MaterialTheme.colorScheme.onBackground.copy(
|
color = MaterialTheme.colorScheme.onBackground.copy(
|
||||||
alpha = 0.5f
|
alpha = 1.0f
|
||||||
),
|
),
|
||||||
style = MaterialTheme.typography.titleMedium.copy(
|
style = MaterialTheme.typography.titleMedium.copy(
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
|
|
@ -62,7 +82,7 @@ fun VersionItem(
|
||||||
Text(
|
Text(
|
||||||
text = value,
|
text = value,
|
||||||
color = MaterialTheme.colorScheme.onBackground.copy(
|
color = MaterialTheme.colorScheme.onBackground.copy(
|
||||||
alpha = 0.5f
|
alpha = 0.9f
|
||||||
),
|
),
|
||||||
style = MaterialTheme.typography.titleMedium.copy(
|
style = MaterialTheme.typography.titleMedium.copy(
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
|
|
@ -75,25 +95,17 @@ fun VersionItem(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ComponentVersions(
|
fun DebugInfo(viewModel: AboutViewModel) {
|
||||||
apiVersion: String
|
Column(
|
||||||
) {
|
modifier = Modifier
|
||||||
// App Info
|
.fillMaxWidth()
|
||||||
VersionItem(key = BuildConfig.APPLICATION_ID, value = BuildConfig.VERSION_NAME)
|
.padding(horizontal = 20.dp, vertical = 30.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
// API Info
|
) {
|
||||||
VersionItem(key = URI(REVOLT_BASE).host, value = apiVersion)
|
viewModel.getDebugInformation().forEach { (key, value) ->
|
||||||
|
VersionItem(key, value)
|
||||||
// Device Info
|
}
|
||||||
VersionItem(key = "Runtime SDK", value = Build.VERSION.SDK_INT.toString())
|
}
|
||||||
VersionItem(
|
|
||||||
key = "Model",
|
|
||||||
value = "${Build.MANUFACTURER} ${
|
|
||||||
Build.DEVICE.replaceFirstChar {
|
|
||||||
if (it.isLowerCase()) it.titlecase() else it.toString()
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -101,6 +113,19 @@ fun AboutScreen(
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
viewModel: AboutViewModel = viewModel()
|
viewModel: AboutViewModel = viewModel()
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val clipboardManager: ClipboardManager =
|
||||||
|
LocalClipboardManager.current
|
||||||
|
|
||||||
|
fun copyDebugInformation() {
|
||||||
|
clipboardManager.setText(AnnotatedString(RevoltJson.encodeToString(viewModel.getDebugInformation())))
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.copied),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|
@ -108,6 +133,11 @@ fun AboutScreen(
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
PageHeader(
|
||||||
|
text = stringResource(R.string.about),
|
||||||
|
showBackButton = true,
|
||||||
|
onBackButtonClicked = { navController.popBackStack() })
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|
@ -129,18 +159,10 @@ fun AboutScreen(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Text(
|
DebugInfo(viewModel)
|
||||||
text = stringResource(R.string.about),
|
TextButton(onClick = ::copyDebugInformation) {
|
||||||
style = MaterialTheme.typography.displaySmall.copy(
|
Text(text = stringResource(id = R.string.copy))
|
||||||
fontWeight = FontWeight.Black,
|
}
|
||||||
textAlign = TextAlign.Center
|
|
||||||
),
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(horizontal = 20.dp, vertical = 10.dp)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
|
|
||||||
ComponentVersions(apiVersion = viewModel.root.value!!.revolt)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,37 +2,24 @@ package chat.revolt.screens.about
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
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.unit.sp
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import chat.revolt.R
|
import chat.revolt.R
|
||||||
|
import chat.revolt.components.generic.PageHeader
|
||||||
import com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer
|
import com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer
|
||||||
import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults
|
import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AttributionScreen(navController: NavController) {
|
fun AttributionScreen(navController: NavController) {
|
||||||
Column() {
|
Column() {
|
||||||
Text(
|
PageHeader(
|
||||||
text = stringResource(R.string.oss_attribution),
|
text = stringResource(R.string.oss_attribution),
|
||||||
style = MaterialTheme.typography.displaySmall.copy(
|
showBackButton = true,
|
||||||
fontWeight = FontWeight.Bold,
|
onBackButtonClicked = { navController.popBackStack() })
|
||||||
textAlign = TextAlign.Left,
|
|
||||||
fontSize = 24.sp
|
|
||||||
),
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(horizontal = 15.dp, vertical = 15.dp)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
LibrariesContainer(
|
LibrariesContainer(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
|
@ -44,14 +31,6 @@ fun AttributionScreen(navController: NavController) {
|
||||||
badgeContentColor = MaterialTheme.colorScheme.onPrimary
|
badgeContentColor = MaterialTheme.colorScheme.onPrimary
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
Button(
|
|
||||||
onClick = { navController.popBackStack() },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(bottom = 30.dp, top = 5.dp, start = 20.dp, end = 20.dp)
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(id = R.string.back))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -108,6 +108,9 @@
|
||||||
<string name="scroll_to_bottom">Scroll to bottom</string>
|
<string name="scroll_to_bottom">Scroll to bottom</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
|
|
||||||
|
<string name="copy">Copy</string>
|
||||||
|
<string name="copied">Copied to clipboard</string>
|
||||||
|
|
||||||
<string name="settings_appearance">Appearance</string>
|
<string name="settings_appearance">Appearance</string>
|
||||||
<string name="settings_appearance_theme">Theme</string>
|
<string name="settings_appearance_theme">Theme</string>
|
||||||
<string name="settings_appearance_theme_none">System</string>
|
<string name="settings_appearance_theme_none">System</string>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue