Skip to content

Commit

Permalink
feat: 使用 viewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Aug 10, 2023
1 parent 912c77e commit b087a25
Show file tree
Hide file tree
Showing 105 changed files with 2,443 additions and 1,737 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ replace default "Embedded JDK" with download jdk by `File->Project Structrue...-

## Layout Inspector not working

开发者选项 - 启用视图属性检查功能
开发者选项 - 启用视图属性检查功能

## 开发辅助文档

- <https://foso.github.io/Jetpack-Compose-Playground/>
- <https://google.github.io/accompanist/>
-
14 changes: 10 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import java.util.Locale
plugins {
id("com.android.application")
id("kotlin-parcelize")
kotlin("android")
kotlin("plugin.serialization")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.serialization")
id("org.jetbrains.kotlin.kapt")
id("com.google.devtools.ksp")
id("dev.rikka.tools.refine")
id("com.google.dagger.hilt.android")
}


Expand Down Expand Up @@ -113,6 +115,9 @@ android {
}
}

kapt {
correctErrorTypes = true
}

dependencies {

Expand All @@ -132,7 +137,6 @@ dependencies {
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso)


compileOnly(project(mapOf("path" to ":hidden_api")))
implementation(libs.rikka.shizuku.api)
implementation(libs.rikka.shizuku.provider)
Expand Down Expand Up @@ -172,5 +176,7 @@ dependencies {
implementation(libs.destinations.animations)
ksp(libs.destinations.ksp)


implementation(libs.google.hilt.android)
kapt(libs.google.hilt.android.compiler)
implementation(libs.androidx.hilt.navigation.compose)
}
51 changes: 25 additions & 26 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,37 @@

<intent-filter>
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="i"
android:host="import-subs"
android:path="/"
android:scheme="gkd" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<provider
android:name="rikka.shizuku.ShizukuProvider"
android:authorities="${applicationId}.shizuku"
android:enabled="true"
android:exported="true"
android:multiprocess="false"
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

<service
android:name=".accessibility.GkdAbService"
android:name=".service.GkdAbService"
android:exported="false"
android:label="@string/ab_label"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
Expand All @@ -78,6 +94,10 @@
android:name="android.accessibilityservice"
android:resource="@xml/ab_desc" />
</service>
<service
android:name=".service.ManageService"
android:exported="false"
android:process=":remote" />
<service
android:name=".debug.ScreenshotService"
android:exported="false"
Expand All @@ -92,31 +112,10 @@
android:exported="false"
android:process=":remote" />
<service
android:name=".accessibility.KeepAliveService"
android:exported="false"
android:process=":remote" />
<service
android:name=".accessibility.ShizukuService"
android:name=".service.ShizukuService"
android:exported="false"
android:process=":remote" />

<provider
android:name="rikka.shizuku.ShizukuProvider"
android:authorities="${applicationId}.shizuku"
android:enabled="true"
android:exported="true"
android:multiprocess="false"
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

</application>

Expand Down
39 changes: 27 additions & 12 deletions app/src/main/java/li/songe/gkd/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@ package li.songe.gkd
import android.app.Application
import android.content.Context
import android.os.Build
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import com.blankj.utilcode.util.LogUtils
import com.tencent.bugly.crashreport.CrashReport
import com.tencent.mmkv.MMKV
import li.songe.gkd.utils.Storage
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import li.songe.gkd.data.getAppInfo
import li.songe.gkd.db.DbSet
import li.songe.gkd.util.isMainProcess
import org.lsposed.hiddenapibypass.HiddenApiBypass
import rikka.shizuku.ShizukuProvider

lateinit var app: Application
var appScope = MainScope()

@HiltAndroidApp
class App : Application() {
companion object {
lateinit var context: Application
override fun onLowMemory() {
super.onLowMemory()
appScope.cancel("onLowMemory() called by system")
appScope = MainScope()
}

override fun attachBaseContext(base: Context?) {
Expand All @@ -26,18 +37,22 @@ class App : Application() {

override fun onCreate() {
super.onCreate()
context = this
app = this
MMKV.initialize(this)
LogUtils.d(Storage.settings)
if (!Storage.settings.enableConsoleLogOut) {
LogUtils.d("关闭日志控制台输出")
}
LogUtils.getConfig().apply {
isLog2FileSwitch = true
saveDays = 30
LogUtils.getConfig().setConsoleSwitch(Storage.settings.enableConsoleLogOut)
saveDays = 7
}
ShizukuProvider.enableMultiProcessSupport(true)
CrashReport.initCrashReport(applicationContext, "d0ce46b353", false)

if (isMainProcess) {
appScope.launch(Dispatchers.IO) {
// 提前获取 appInfo 缓存
DbSet.subsItemDao.query().collect {
it.forEach { s -> s.subscriptionRaw?.apps?.forEach { app -> getAppInfo(app.id) } }
}
}
}
}
}
90 changes: 48 additions & 42 deletions app/src/main/java/li/songe/gkd/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,87 @@ package li.songe.gkd
import android.os.Build
import android.view.WindowManager
import androidx.activity.compose.setContent
import androidx.compose.material.icons.materialIcon
import androidx.compose.material.icons.materialPath
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import com.dylanc.activityresult.launcher.StartActivityLauncher
import com.ramcosta.composedestinations.DestinationsNavHost
import dagger.hilt.android.AndroidEntryPoint
import li.songe.gkd.composition.CompositionActivity
import li.songe.gkd.composition.CompositionExt.useLifeCycleLog
import li.songe.gkd.ui.NavGraphs
import li.songe.gkd.ui.theme.AppTheme
import li.songe.gkd.utils.LocalLauncher
import li.songe.gkd.utils.LocalNavController
import li.songe.gkd.utils.StackCacheProvider
import li.songe.gkd.utils.Storage

import li.songe.gkd.util.LocalLauncher
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.storeFlow

@AndroidEntryPoint
class MainActivity : CompositionActivity({
useLifeCycleLog()

val launcher = StartActivityLauncher(this)
onFinish { fs ->
if (Storage.settings.excludeFromRecents) {
if (storeFlow.value.excludeFromRecents) {
finishAndRemoveTask() // 会让miui桌面回退动画失效
} else {
fs()
}
}

// https://juejin.cn/post/7169147194400833572
// https://juejin.cn/post/7169147194400833572
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window.attributes.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
// TextView[a==1||b==1||a==1||(a==1&&b==true)]
// lifecycleScope.launchTry {
// delay(1000)
// WindowCompat.setDecorFitsSystemWindows(window, false)
// val insetsController = WindowCompat.getInsetsController(window, window.decorView)
// insetsController.hide(WindowInsetsCompat.Type.statusBars())
// }

// var shizukuIsOK = false
// val receivedListener: () -> Unit = {
// shizukuIsOK = true
// }
// Shizuku.addBinderReceivedListenerSticky(receivedListener)
// onDestroy {
// Shizuku.removeBinderReceivedListener(receivedListener)
// }
// lifecycleScope.launchWhile {
// if (shizukuIsOK) {
// val top = activityTaskManager.getTasks(1, false, true)?.firstOrNull()
// if (top!=null) {
// LogUtils.d(top.topActivity?.packageName, top.topActivity?.className, top.topActivity?.shortClassName)
// lifecycleScope.launchTry {
// delay(1000)
// WindowCompat.setDecorFitsSystemWindows(window, false)
// val insetsController = WindowCompat.getInsetsController(window, window.decorView)
// insetsController.hide(WindowInsetsCompat.Type.statusBars())
// }

// var shizukuIsOK = false
// val receivedListener: () -> Unit = {
// shizukuIsOK = true
// }
// Shizuku.addBinderReceivedListenerSticky(receivedListener)
// onDestroy {
// Shizuku.removeBinderReceivedListener(receivedListener)
// }
// lifecycleScope.launchWhile {
// if (shizukuIsOK) {
// val top = activityTaskManager.getTasks(1, false, true)?.firstOrNull()
// if (top!=null) {
// LogUtils.d(top.topActivity?.packageName, top.topActivity?.className, top.topActivity?.shortClassName)
// }
// }
// delay(5000)
// }

// lifecycleScope.launchTry(IO) {
// File("/sdcard/Android/data/${packageName}/files/snapshot").walk().maxDepth(1)
// .filter { it.isDirectory && !it.name.endsWith("snapshot") }.forEach { folder ->
// val snapshot = Singleton.json.decodeFromString<Snapshot>(File(folder.absolutePath + "/${folder.name}.json").readText())
// try {
// DbSet.snapshotDao.insert(snapshot)
// }catch (e:Exception){
// e.printStackTrace()
// LogUtils.d("insert failed, ${snapshot.id}")
// return@launchTry
// }
// }
// }
// delay(5000)
// }


setContent {
val navController = rememberNavController()
AppTheme(false) {
CompositionLocalProvider(
LocalLauncher provides launcher,
LocalNavController provides navController
LocalLauncher provides launcher, LocalNavController provides navController
) {
StackCacheProvider(navController = navController) {
DestinationsNavHost(
navGraph = NavGraphs.root,
navController = navController,
)
}
DestinationsNavHost(
navGraph = NavGraphs.root, navController = navController, modifier = Modifier
)
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions app/src/main/java/li/songe/gkd/accessibility/KeepAliveService.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import li.songe.gkd.utils.Singleton
import li.songe.gkd.util.Singleton
import kotlin.coroutines.CoroutineContext

object CompositionExt {
Expand Down
Loading

0 comments on commit b087a25

Please sign in to comment.