@@ -7,6 +7,7 @@ import android.os.Bundle
7
7
import android.widget.Toast
8
8
import androidx.activity.compose.setContent
9
9
import androidx.activity.enableEdgeToEdge
10
+ import androidx.activity.viewModels
10
11
import androidx.compose.foundation.background
11
12
import androidx.compose.foundation.clickable
12
13
import androidx.compose.foundation.gestures.detectTapGestures
@@ -30,7 +31,6 @@ import androidx.compose.material3.Text
30
31
import androidx.compose.material3.TextButton
31
32
import androidx.compose.runtime.Composable
32
33
import androidx.compose.runtime.LaunchedEffect
33
- import androidx.compose.runtime.MutableState
34
34
import androidx.compose.runtime.collectAsState
35
35
import androidx.compose.runtime.getValue
36
36
import androidx.compose.runtime.mutableIntStateOf
@@ -48,6 +48,7 @@ import androidx.compose.ui.res.stringResource
48
48
import androidx.compose.ui.unit.dp
49
49
import androidx.core.view.WindowCompat
50
50
import androidx.fragment.app.FragmentActivity
51
+ import androidx.lifecycle.lifecycleScope
51
52
import androidx.navigation.NavHostController
52
53
import androidx.navigation.compose.NavHost
53
54
import androidx.navigation.compose.composable
@@ -66,12 +67,14 @@ import com.bintianqi.owndroid.dpm.getReceiver
66
67
import com.bintianqi.owndroid.dpm.isDeviceAdmin
67
68
import com.bintianqi.owndroid.dpm.isDeviceOwner
68
69
import com.bintianqi.owndroid.dpm.isProfileOwner
70
+ import com.bintianqi.owndroid.dpm.setDefaultAffiliationID
69
71
import com.bintianqi.owndroid.dpm.toggleInstallAppActivity
70
72
import com.bintianqi.owndroid.ui.Animations
71
73
import com.bintianqi.owndroid.ui.theme.OwnDroidTheme
72
74
import com.rosan.dhizuku.api.Dhizuku
73
75
import kotlinx.coroutines.delay
74
76
import kotlinx.coroutines.flow.MutableStateFlow
77
+ import kotlinx.coroutines.launch
75
78
import org.lsposed.hiddenapibypass.HiddenApiBypass
76
79
import java.util.Locale
77
80
@@ -85,19 +88,19 @@ class MainActivity : FragmentActivity() {
85
88
enableEdgeToEdge()
86
89
WindowCompat .setDecorFitsSystemWindows(window, false )
87
90
super .onCreate(savedInstanceState)
88
- val sharedPref = applicationContext.getSharedPreferences(" data" , Context .MODE_PRIVATE )
91
+ val context = applicationContext
92
+ val sharedPref = context.getSharedPreferences(" data" , MODE_PRIVATE )
89
93
if (VERSION .SDK_INT >= 28 ) HiddenApiBypass .setHiddenApiExemptions(" " )
90
- if (sharedPref.getBoolean(" auth" , false )) {
91
- showAuth.value = true
92
- }
93
- val locale = applicationContext.resources?.configuration?.locale
94
+ if (sharedPref.getBoolean(" auth" , false )) showAuth.value = true
95
+ val locale = context.resources?.configuration?.locale
94
96
zhCN = locale == Locale .SIMPLIFIED_CHINESE || locale == Locale .CHINESE || locale == Locale .CHINA
95
97
toggleInstallAppActivity()
98
+ val vm by viewModels<MyViewModel >()
99
+ if (! vm.initialized) vm.initialize(context)
100
+ lifecycleScope.launch { delay(5000 ); setDefaultAffiliationID(context) }
96
101
setContent {
97
- val materialYou = remember { mutableStateOf(sharedPref.getBoolean(" material_you" , true )) }
98
- val blackTheme = remember { mutableStateOf(sharedPref.getBoolean(" black_theme" , false )) }
99
- OwnDroidTheme (materialYou.value, blackTheme.value) {
100
- Home (materialYou, blackTheme)
102
+ OwnDroidTheme (vm) {
103
+ Home (vm)
101
104
if (showAuth.value) {
102
105
AuthScreen (this , showAuth)
103
106
}
@@ -107,7 +110,7 @@ class MainActivity : FragmentActivity() {
107
110
108
111
override fun onResume () {
109
112
super .onResume()
110
- val sharedPref = applicationContext.getSharedPreferences(" data" , Context . MODE_PRIVATE )
113
+ val sharedPref = applicationContext.getSharedPreferences(" data" , MODE_PRIVATE )
111
114
if (
112
115
sharedPref.getBoolean(" auth" , false ) &&
113
116
sharedPref.getBoolean(" lock_in_background" , false )
@@ -128,7 +131,7 @@ class MainActivity : FragmentActivity() {
128
131
129
132
@ExperimentalMaterial3Api
130
133
@Composable
131
- fun Home (materialYou : MutableState < Boolean >, blackTheme : MutableState < Boolean > ) {
134
+ fun Home (vm : MyViewModel ) {
132
135
val navCtrl = rememberNavController()
133
136
val context = LocalContext .current
134
137
val dpm = context.getDPM()
@@ -154,14 +157,14 @@ fun Home(materialYou:MutableState<Boolean>, blackTheme:MutableState<Boolean>) {
154
157
popExitTransition = Animations .navHostPopExitTransition
155
158
) {
156
159
composable(route = " HomePage" ) { HomePage (navCtrl) }
157
- composable(route = " SystemManage " ) { SystemManage (navCtrl) }
160
+ composable(route = " System " ) { SystemManage (navCtrl) }
158
161
composable(route = " ManagedProfile" ) { ManagedProfile (navCtrl) }
159
162
composable(route = " Permissions" ) { DpmPermissions (navCtrl) }
160
- composable(route = " ApplicationManage " ) { ApplicationManage (navCtrl, dialogStatus) }
163
+ composable(route = " Applications " ) { ApplicationManage (navCtrl, dialogStatus) }
161
164
composable(route = " UserRestriction" ) { UserRestriction (navCtrl) }
162
- composable(route = " UserManage " ) { UserManage (navCtrl) }
165
+ composable(route = " Users " ) { UserManage (navCtrl) }
163
166
composable(route = " Password" ) { Password (navCtrl) }
164
- composable(route = " AppSetting " ) { AppSetting (navCtrl, materialYou, blackTheme ) }
167
+ composable(route = " Settings " ) { AppSetting (navCtrl, vm ) }
165
168
composable(route = " Network" ) { Network (navCtrl) }
166
169
composable(route = " PackageSelector" ) { PackageSelector (navCtrl) }
167
170
}
@@ -234,7 +237,7 @@ private fun HomePage(navCtrl:NavHostController) {
234
237
if (activateType != " " ) { Text (text = activateType, color = colorScheme.onPrimary) }
235
238
}
236
239
}
237
- HomePageItem (R .string.system_manage , R .drawable.mobile_phone_fill0 , " SystemManage " , navCtrl)
240
+ HomePageItem (R .string.system , R .drawable.android_fill0 , " System " , navCtrl)
238
241
if (deviceOwner || profileOwner) { HomePageItem (R .string.network, R .drawable.wifi_fill0, " Network" , navCtrl) }
239
242
if (
240
243
(VERSION .SDK_INT < 24 && ! deviceOwner) || (
@@ -244,13 +247,13 @@ private fun HomePage(navCtrl:NavHostController) {
244
247
) {
245
248
HomePageItem (R .string.work_profile, R .drawable.work_fill0, " ManagedProfile" , navCtrl)
246
249
}
247
- if (deviceOwner || profileOwner) HomePageItem (R .string.app_manager , R .drawable.apps_fill0, " ApplicationManage " , navCtrl)
250
+ if (deviceOwner || profileOwner) HomePageItem (R .string.applications , R .drawable.apps_fill0, " Applications " , navCtrl)
248
251
if (VERSION .SDK_INT >= 24 && (profileOwner || deviceOwner)) {
249
252
HomePageItem (R .string.user_restrict, R .drawable.person_off, " UserRestriction" , navCtrl)
250
253
}
251
- HomePageItem (R .string.user_manager ,R .drawable.manage_accounts_fill0," UserManage " , navCtrl)
254
+ HomePageItem (R .string.users ,R .drawable.manage_accounts_fill0," Users " , navCtrl)
252
255
HomePageItem (R .string.password_and_keyguard, R .drawable.password_fill0, " Password" , navCtrl)
253
- HomePageItem (R .string.setting , R .drawable.settings_fill0, " AppSetting " , navCtrl)
256
+ HomePageItem (R .string.settings , R .drawable.settings_fill0, " Settings " , navCtrl)
254
257
Spacer (Modifier .padding(vertical = 20 .dp))
255
258
}
256
259
}
0 commit comments