-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,640 additions
and
926 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
package li.songe.gkd.data | ||
|
||
import android.content.pm.ApplicationInfo | ||
import android.content.pm.PackageInfo | ||
import android.graphics.drawable.Drawable | ||
import android.os.Build | ||
import li.songe.gkd.app | ||
|
||
data class AppInfo( | ||
val id: String, | ||
val name: String, | ||
val icon: Drawable?, | ||
val versionCode: Int, | ||
val versionCode: Long, | ||
val versionName: String?, | ||
val isSystem: Boolean, | ||
) | ||
val mtime: Long, | ||
) | ||
|
||
fun PackageInfo.toAppInfo(): AppInfo? { | ||
applicationInfo ?: return null | ||
return AppInfo( | ||
id = packageName, | ||
name = applicationInfo.loadLabel(app.packageManager).toString(), | ||
icon = applicationInfo.loadIcon(app.packageManager), | ||
versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
longVersionCode | ||
} else { | ||
@Suppress("DEPRECATION") | ||
versionCode.toLong() | ||
}, | ||
versionName = versionName, | ||
isSystem = (ApplicationInfo.FLAG_SYSTEM and applicationInfo.flags) != 0, | ||
mtime = lastUpdateTime | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package li.songe.gkd.ui | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
import androidx.compose.material.icons.filled.MoreVert | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Switch | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.ramcosta.composedestinations.annotation.Destination | ||
import com.ramcosta.composedestinations.annotation.RootNavGraph | ||
import li.songe.gkd.util.LocalNavController | ||
import li.songe.gkd.util.ProfileTransitions | ||
import li.songe.gkd.util.appInfoCacheFlow | ||
import li.songe.gkd.util.ruleSummaryFlow | ||
|
||
@RootNavGraph | ||
@Destination(style = ProfileTransitions::class) | ||
@Composable | ||
fun AppConfigPage(appId: String) { | ||
val navController = LocalNavController.current | ||
val vm = hiltViewModel<AppConfigVm>() | ||
val appInfoCache by appInfoCacheFlow.collectAsState() | ||
val appInfo = appInfoCache[appId] | ||
val ruleSummary by ruleSummaryFlow.collectAsState() | ||
|
||
val globalGroups = ruleSummary.globalGroups | ||
|
||
val appGroups = ruleSummary.appIdToAllGroups[appId] ?: emptyList() | ||
|
||
Scaffold(topBar = { | ||
TopAppBar(navigationIcon = { | ||
IconButton(onClick = { | ||
navController.popBackStack() | ||
}) { | ||
Icon( | ||
imageVector = Icons.AutoMirrored.Filled.ArrowBack, | ||
contentDescription = null, | ||
) | ||
} | ||
}, title = { | ||
Text( | ||
text = appInfo?.name ?: appId, | ||
maxLines = 1, | ||
softWrap = false, | ||
overflow = TextOverflow.Ellipsis, | ||
) | ||
}, actions = {}) | ||
}, content = { contentPadding -> | ||
LazyColumn( | ||
modifier = Modifier.padding(contentPadding) | ||
) { | ||
items(appGroups) { (group, enable) -> | ||
Row( | ||
modifier = Modifier | ||
.padding(10.dp, 6.dp) | ||
.fillMaxWidth() | ||
.height(45.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.weight(1f) | ||
.fillMaxHeight(), | ||
verticalArrangement = Arrangement.SpaceBetween | ||
) { | ||
Text( | ||
text = group.name, | ||
maxLines = 1, | ||
softWrap = false, | ||
overflow = TextOverflow.Ellipsis, | ||
modifier = Modifier.fillMaxWidth() | ||
) | ||
if (group.valid) { | ||
Text( | ||
text = group.desc ?: "", | ||
maxLines = 1, | ||
softWrap = false, | ||
overflow = TextOverflow.Ellipsis, | ||
modifier = Modifier.fillMaxWidth(), | ||
fontSize = 14.sp | ||
) | ||
} else { | ||
Text( | ||
text = "非法选择器", | ||
modifier = Modifier.fillMaxWidth(), | ||
fontSize = 14.sp, | ||
color = MaterialTheme.colorScheme.error | ||
) | ||
} | ||
} | ||
Spacer(modifier = Modifier.width(10.dp)) | ||
IconButton(onClick = {}) { | ||
Icon( | ||
imageVector = Icons.Default.MoreVert, | ||
contentDescription = "more", | ||
) | ||
} | ||
Spacer(modifier = Modifier.width(10.dp)) | ||
Switch(checked = enable, modifier = Modifier, onCheckedChange = {}) | ||
} | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package li.songe.gkd.ui | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class AppConfigVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.