Add home page

This commit is contained in:
Nullptr 2022-03-06 20:27:28 +08:00
parent ff01a6209c
commit 775bfb1078
6 changed files with 135 additions and 13 deletions

View File

@ -14,15 +14,25 @@ buildscript {
}
}
val commitCount = run {
val repo = FileRepository(rootProject.file(".git"))
val refId = repo.refDatabase.exactRef("refs/remotes/origin/lsp").objectId!!
val commitCount = Git(repo).log().add(refId).call().count()
Git(repo).log().add(refId).call().count()
}
val coreCommitCount = run {
val repo = FileRepository(rootProject.file("core/.git"))
val refId = repo.refDatabase.exactRef("refs/remotes/origin/lspatch").objectId!!
Git(repo).log().add(refId).call().count()
}
// sync from https://github.com/LSPosed/LSPosed/blob/master/build.gradle.kts
val defaultManagerPackageName by extra("org.lsposed.lspatch")
val apiCode by extra(93)
val verCode by extra(commitCount)
val verName by extra("0.3")
val coreVerCode by extra(coreCommitCount + 4200)
val coreVerName by extra("1.7.2")
val androidMinSdkVersion by extra(28)
val androidTargetSdkVersion by extra(32)
val androidCompileSdkVersion by extra(32)

View File

@ -5,8 +5,11 @@ val androidMinSdkVersion: Int by rootProject.extra
val androidTargetSdkVersion: Int by rootProject.extra
val defaultManagerPackageName: String by rootProject.extra
val apiCode: Int by rootProject.extra
val verCode: Int by rootProject.extra
val verName: String by rootProject.extra
val coreVerCode: Int by rootProject.extra
val coreVerName: String by rootProject.extra
val androidSourceCompatibility: JavaVersion by rootProject.extra
val androidTargetCompatibility: JavaVersion by rootProject.extra
@ -26,6 +29,10 @@ android {
targetSdk = androidTargetSdkVersion
versionCode = verCode
versionName = verName
buildConfigField("int", "API_CODE", """$apiCode""")
buildConfigField("int", "CORE_VERSION_CODE", """$coreVerCode""")
buildConfigField("String", "CORE_VERSION_NAME", """"$coreVerName"""")
}
buildTypes {

View File

@ -70,7 +70,7 @@ private fun MainNavHost(navController: NavHostController, modifier: Modifier) {
@Composable
private fun MainNavigationBar(page: PageList, onClick: (PageList) -> Unit) {
NavigationBar(tonalElevation = 8.dp) {
arrayOf(PageList.Home, PageList.Manage, PageList.Repo, PageList.Settings).forEach {
arrayOf(PageList.Repo, PageList.Manage, PageList.Home, PageList.Logs, PageList.Settings).forEach {
NavigationBarItem(
selected = page == it,
onClick = { onClick(it) },

View File

@ -1,26 +1,122 @@
package org.lsposed.lspatch.ui.page
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SmallTopAppBar
import androidx.compose.material3.Text
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import org.lsposed.lspatch.BuildConfig
import org.lsposed.lspatch.R
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomePage() {
val snackbarHostState = remember { SnackbarHostState() }
Scaffold(
topBar = { TopBar() }
topBar = { TopBar() },
snackbarHost = { SnackbarHost(snackbarHostState) }
) { innerPadding ->
Column(
modifier = Modifier
.padding(innerPadding)
.padding(horizontal = 16.dp)
.verticalScroll(rememberScrollState())
) {
InfoCard(snackbarHostState)
}
}
}
@Preview
@Composable
private fun TopBar() {
SmallTopAppBar(
title = { Text(stringResource(R.string.app_name)) }
CenterAlignedTopAppBar(
title = {
Text(
text = stringResource(R.string.app_name),
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.Bold,
fontFamily = FontFamily.Monospace,
style = MaterialTheme.typography.titleMedium
)
},
)
}
private val apiVersion = if (Build.VERSION.PREVIEW_SDK_INT != 0) {
"${Build.VERSION.CODENAME} Preview (API ${Build.VERSION.PREVIEW_SDK_INT})"
} else {
"${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})"
}
private val device = buildString {
append(Build.MANUFACTURER[0].uppercaseChar().toString() + Build.MANUFACTURER.substring(1))
if (Build.BRAND != Build.MANUFACTURER) {
append(" " + Build.BRAND[0].uppercaseChar() + Build.BRAND.substring(1))
}
append(" " + Build.MODEL + " ")
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun InfoCard(snackbarHostState: SnackbarHostState) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
Card {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(start = 24.dp, top = 24.dp, end = 24.dp, bottom = 16.dp)
) {
val contents = StringBuilder()
val infoCardContent: @Composable (Pair<String, String>) -> Unit = { texts ->
contents.appendLine(texts.first).appendLine(texts.second).appendLine()
Text(text = texts.first, style = MaterialTheme.typography.bodyLarge)
Text(text = texts.second, style = MaterialTheme.typography.bodyMedium)
}
infoCardContent(stringResource(R.string.home_api_version) to "${BuildConfig.API_CODE}")
Spacer(Modifier.height(24.dp))
infoCardContent(stringResource(R.string.home_lspatch_version) to BuildConfig.VERSION_NAME + " (${BuildConfig.VERSION_CODE})")
Spacer(Modifier.height(24.dp))
infoCardContent(stringResource(R.string.home_framework_version) to BuildConfig.CORE_VERSION_NAME + " (${BuildConfig.CORE_VERSION_CODE})")
Spacer(Modifier.height(24.dp))
infoCardContent(stringResource(R.string.home_system_version) to apiVersion)
Spacer(Modifier.height(24.dp))
infoCardContent(stringResource(R.string.home_device) to device)
Spacer(Modifier.height(24.dp))
infoCardContent(stringResource(R.string.home_system_abi) to Build.SUPPORTED_ABIS[0])
val copiedMessage = stringResource(R.string.home_info_copied)
TextButton(
modifier = Modifier.align(Alignment.End),
onClick = {
val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
cm.setPrimaryClip(ClipData.newPlainText("LSPatch", contents.toString()))
scope.launch { snackbarHostState.showSnackbar(copiedMessage) }
},
content = { Text(stringResource(android.R.string.copy)) }
)
}
}
}

View File

@ -35,7 +35,7 @@ enum class PageList(
body = { HomePage() }
),
Logs(
iconSelected = Icons.Filled.Assessment,
iconSelected = Icons.Filled.Assignment,
iconNotSelected = Icons.Outlined.Assignment,
body = {}
),

View File

@ -6,6 +6,15 @@
<string name="page_logs">Logs</string>
<string name="page_settings">Settings</string>
<!-- Home Page -->
<string name="home_api_version">API Version</string>
<string name="home_lspatch_version">LSPatch Version</string>
<string name="home_framework_version">Framework Version</string>
<string name="home_system_version">System Version</string>
<string name="home_device">Device</string>
<string name="home_system_abi">System ABI</string>
<string name="home_info_copied">Copied to clipboard</string>
<!-- Manage Page -->
<string name="page_manage">Manage</string>