Skip to content

Commit

Permalink
feat: 更新 UI
Browse files Browse the repository at this point in the history
  • Loading branch information
xfqwdsj committed Jul 26, 2024
1 parent 410d8cb commit 7fde658
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 26 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ android {
}

dependencies {
implementation(libs.kotlin.reflect)
implementation(libs.lifecycle.runtime)
implementation(libs.lifecycle.viewmodel)
implementation(libs.activity.compose)
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand All @@ -11,7 +10,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.IAmNotADeveloper"
tools:targetApi="33">
android:windowSoftInputMode="adjustResize">
<activity
android:name=".ui.activities.MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,105 @@ import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.provider.Settings
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import xyz.xfqlittlefan.notdeveloper.ADB_ENABLED
import xyz.xfqlittlefan.notdeveloper.ADB_WIFI_ENABLED
import xyz.xfqlittlefan.notdeveloper.DEVELOPMENT_SETTINGS_ENABLED
import xyz.xfqlittlefan.notdeveloper.R
import xyz.xfqlittlefan.notdeveloper.ui.composables.rememberBooleanSharedPreference
import xyz.xfqlittlefan.notdeveloper.ui.theme.IAmNotADeveloperTheme
import xyz.xfqlittlefan.notdeveloper.util.allBars
import xyz.xfqlittlefan.notdeveloper.xposed.isModuleActive
import xyz.xfqlittlefan.notdeveloper.xposed.isPreferencesReady
import kotlin.reflect.full.declaredFunctions

class MainActivity : ComponentActivity() {
private val isMiui: Boolean
@SuppressLint("PrivateApi") get() {
val clazz = Class.forName("android.os.SystemProperties").kotlin
val method =
clazz.declaredFunctions.firstOrNull { it.name == "get" && it.parameters.size == 1 }
return method?.call("ro.miui.ui.version.name") != ""
}

@SuppressLint("WorldReadableFiles")
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
@Suppress("DEPRECATION") if (isMiui) {
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
)
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
)
}
super.onCreate(savedInstanceState)
// WindowCompat.setDecorFitsSystemWindows(window, false)

setContent {
IAmNotADeveloperTheme {
val scrollBehavior =
TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState())

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(
LargeTopAppBar(
title = {
Text(stringResource(R.string.app_name))
},
windowInsets = WindowInsets.allBars.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
windowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top),
scrollBehavior = scrollBehavior
)
}
) { padding ->
Column(
modifier = Modifier
.padding(padding)
.consumeWindowInsets(padding)
.fillMaxSize()
.verticalScroll(rememberScrollState())
.windowInsetsPadding(WindowInsets.allBars.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)),
.padding(padding)
.windowInsetsPadding(WindowInsets.displayCutout.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)),
horizontalAlignment = Alignment.CenterHorizontally
) {
var testResult by remember { mutableStateOf<List<Boolean>?>(null) }
Expand Down Expand Up @@ -108,6 +154,7 @@ class MainActivity : ComponentActivity() {
)
})
} else {
Spacer(Modifier.height(20.dp))
Text(
stringResource(R.string.unable_to_save_settings),
modifier = Modifier.padding(horizontal = 20.dp)
Expand Down Expand Up @@ -148,13 +195,14 @@ class MainActivity : ComponentActivity() {
color = MaterialTheme.colorScheme.error
)
}
Spacer(Modifier.height(20.dp))

if (testResult?.size == 3) {
fun getString(on: String, off: String, input: List<Boolean>) =
input.map { if (it) on else off }.toTypedArray()

AlertDialog(onDismissRequest = { testResult = null }, confirmButton = {
Button(onClick = { testResult = null }) {
TextButton(onClick = { testResult = null }) {
Text(stringResource(android.R.string.ok))
}
}, title = {
Expand All @@ -164,8 +212,8 @@ class MainActivity : ComponentActivity() {
Text(
stringResource(
R.string.dialog_test_content, *getString(
stringResource(R.string.on),
stringResource(R.string.off),
stringResource(R.string.status_on),
stringResource(R.string.status_off),
testResult ?: listOf(false, false, false)
)
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<string name="description">Todas as alterações entrarão em vigor imediatamente</string>
<string name="test">Testar</string>
<string name="dialog_test_content">Status das opções do desenvolvedor: %1$s\nStatus da depuração USB: %2$s\nStatus da depuração por Wi-Fi: %3$s</string>
<string name="on">Ativado</string>
<string name="off">Desativado</string>
<string name="status_on">Ativado</string>
<string name="status_off">Desativado</string>
<string name="module_not_activated">O módulo não está ativo</string>
<string name="unable_to_save_settings">Não foi possível salvar as configurações, todos os recursos estão ativados por padrão. Por favor, tente usar uma versão abaixo do Android 8.1 ou use o LSPosed para ativar o módulo.</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<string name="description">所有更改将即时生效</string>
<string name="test">测试</string>
<string name="dialog_test_content">开发者模式状态:%1$s\nUSB 调试状态:%2$s\n无线调试状态:%3$s</string>
<string name="on">开启</string>
<string name="off">关闭</string>
<string name="status_on">开启</string>
<string name="status_off">关闭</string>
<string name="module_not_activated">模块未激活</string>
<string name="unable_to_save_settings">无法保存设置,默认启用全部功能。请尝试降低 Android 版本至 Android 8.1 以下或使用 LSPosed 框架并激活本模块。</string>
</resources>
2 changes: 0 additions & 2 deletions app/src/main/res/values/colors.xml

This file was deleted.

6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">IAmNotADeveloper</string>
<string name="app_name" translatable="false">IAmNotADeveloper</string>
<string name="hide_development_mode">Hide development mode</string>
<string name="hide_usb_debugging">Hide USB debugging</string>
<string name="hide_wireless_debugging">Hide wireless debugging</string>
<string name="description">All changes will take effect immediately</string>
<string name="test">Test</string>
<string name="dialog_test_content">Development mode status: %1$s\nUSB debugging status: %2$s\nWireless debugging status: %3$s</string>
<string name="on">On</string>
<string name="off">Off</string>
<string name="status_on">On</string>
<string name="status_off">Off</string>
<string name="module_not_activated">Module not activated</string>
<string name="unable_to_save_settings">Unable to save settings, all features are enabled by default. Please try to lower your Android version to below Android 8.1 or use the LSPosed Framwork and activate this module.</string>
</resources>
2 changes: 0 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

<style name="Theme.IAmNotADeveloper" parent="Theme.Base">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ preference = "1.2.1"
xposed-api = "82"

[libraries]
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle" }
lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" }
activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity" }
Expand Down

0 comments on commit 7fde658

Please sign in to comment.