Skip to content

Commit

Permalink
Merge pull request #253 from GuoXiCheng/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GuoXiCheng authored Sep 25, 2024
2 parents 7e30193 + d7a0c6d commit cad615d
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ android {
}

dependencies {
implementation(libs.coil.compose)
implementation(libs.androidx.work.runtime.ktx)
implementation(libs.androidx.work.runtime)
implementation(libs.converter.scalars)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />


<application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.skip.ui.record.list

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
Expand All @@ -13,6 +14,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.paging.LoadState
Expand Down Expand Up @@ -78,8 +80,11 @@ fun InspectListColumn(
when {
loadState.refresh is LoadState.Loading -> {
item {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "加载中...")
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = stringResource(id = R.string.loading))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
package com.android.skip.ui.whitelist

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.android.skip.MyApp
import com.android.skip.R
import com.android.skip.util.dataStore
import com.blankj.utilcode.util.StringUtils.getString
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class WhiteListRepository @Inject constructor() {
private val _whiteList: MutableList<String> = mutableListOf()
private val _whiteList: MutableList<String> by lazy {
runBlocking {
initWhitelist().toMutableList()
}
}

private suspend fun initWhitelist() = withContext(Dispatchers.IO) {
val allPreferences = MyApp.context.dataStore.data.first()
allPreferences.asMap()
.filter {
it.key.name.startsWith(getString(R.string.whitelist_dot)) && it.value == true
}.keys.map {
it.name.substringAfter(
getString(R.string.whitelist_dot)
)
}
}

fun updateWhiteList(packageName: String, checked: Boolean) {
if (checked) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package com.android.skip.ui.whitelist

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.android.skip.R
import com.android.skip.util.DataStoreUtils
import com.blankj.utilcode.util.StringUtils.getString
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltViewModel
class WhiteListViewModel @Inject constructor(
private val whiteListRepository: WhiteListRepository
) : ViewModel() {
fun updateWhiteList(packageName: String, checked: Boolean) =
fun updateWhiteList(packageName: String, checked: Boolean) {
whiteListRepository.updateWhiteList(packageName, checked)
viewModelScope.launch {
withContext(Dispatchers.IO) {
DataStoreUtils.putData(getString(R.string.whitelist_dot) + packageName, checked)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package com.android.skip.ui.whitelist.list

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import androidx.paging.compose.collectAsLazyPagingItems
import coil.annotation.ExperimentalCoilApi
import coil.compose.rememberImagePainter
import com.android.skip.R
import com.android.skip.ui.components.FlatButton
import com.android.skip.ui.components.RowContent
import com.android.skip.ui.whitelist.WhiteListViewModel
import com.google.accompanist.drawablepainter.rememberDrawablePainter

@OptIn(ExperimentalCoilApi::class)
@Composable
fun AppListColumn(
appListViewModel: AppListViewModel,
Expand All @@ -36,10 +43,10 @@ fun AppListColumn(
title = item.appName,
subTitle = item.packageName,
{
Icon(
painter = rememberDrawablePainter(drawable = item.appIcon),
Image(
painter = rememberImagePainter(data = item.appIcon),
contentDescription = null,
tint = Color.Unspecified
modifier = Modifier.size(40.dp)
)
}, checked.value, {
checked.value = it
Expand All @@ -54,8 +61,11 @@ fun AppListColumn(
when {
loadState.refresh is LoadState.Loading -> {
item {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "加载中...")
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = stringResource(id = R.string.loading))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
package com.android.skip.ui.whitelist.list

import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import com.android.skip.MyApp
import com.android.skip.dataclass.AppListItem
import com.android.skip.ui.whitelist.WhiteListRepository
import com.blankj.utilcode.util.AppUtils
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AppListRepository @Inject constructor() {

@Inject
lateinit var whiteListRepository: WhiteListRepository

private var appInfos: MutableList<AppUtils.AppInfo> = mutableListOf()
private val appInfos: MutableList<ApplicationInfo> by lazy {
MyApp.context.packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
}

fun getData(currentPage: Int, pageSize: Int, isShowSystem: Boolean): List<AppListItem> {
try {
if (appInfos.isEmpty()) appInfos = AppUtils.getAppsInfo()
val pkgManager = MyApp.context.packageManager

val apps = if (isShowSystem) {
appInfos
} else {
appInfos.filterNot { it.isSystem }
appInfos.filter { (it.flags and ApplicationInfo.FLAG_SYSTEM) == 0 }
}
val fromIndex = currentPage * pageSize
val toIndex = minOf(fromIndex + pageSize, apps.size)

return apps.subList(fromIndex, toIndex)
.map {
AppListItem(
it.name,
it.loadLabel(pkgManager).toString(),
it.packageName,
it.icon,
it.loadIcon(pkgManager),
whiteListRepository.isAppInWhiteList(it.packageName)
)
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<string name="whitelist_show_system">显示系统应用</string>
<string name="whitelist_function_intro">功能介绍</string>
<string name="whitelist_function_intro_url">https://skip.guoxicheng.top/guide/white-list/intro</string>
<string name="whitelist_dot">WHITELIST_DOT</string>

<string name="settings">设置</string>
<string name="settings_tip">是否允许提示</string>
Expand Down Expand Up @@ -107,4 +108,6 @@

<string name="notification_accessibility_service_running">无障碍服务运行中</string>
<string name="notification_inspect_service_running">布局检查服务运行中</string>

<string name="loading">加载中…</string>
</resources>
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
accompanistDrawablepainter = "0.34.0"
activityCompose = "1.9.0"
agp = "8.5.1"
coilCompose = "1.3.2"
converterScalars = "2.5.0"
datastorePreferences = "1.0.0"
gson = "2.10.1"
Expand Down Expand Up @@ -42,6 +43,7 @@ androidx-paging-runtime = { module = "androidx.paging:paging-runtime", version.r
androidx-ui = { module = "androidx.compose.ui:ui", version.ref = "ui" }
androidx-work-runtime = { module = "androidx.work:work-runtime", version.ref = "workRuntime" }
androidx-work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "workRuntime" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" }
converter-scalars = { module = "com.squareup.retrofit2:converter-scalars", version.ref = "converterScalars" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hiltAndroid" }
Expand Down

0 comments on commit cad615d

Please sign in to comment.