Skip to content

Commit

Permalink
perf: toast
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Feb 27, 2024
1 parent 4c1eb30 commit f9d0692
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 65 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,6 @@ dependencies {
implementation(libs.coil.gif)

implementation(libs.exp4j)

implementation(libs.toaster)
}
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# self
-keep class li.songe.**{*;}
-keep interface li.songe.**{*;}
-keep class com.hjq.toast.** {*;}

-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import android.content.Context
import android.os.Build
import com.blankj.utilcode.util.LogUtils
import com.hjq.toast.Toaster
import com.tencent.mmkv.MMKV
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.Dispatchers
Expand All @@ -18,6 +19,7 @@ import li.songe.gkd.util.initSubsState
import li.songe.gkd.util.launchTry
import org.lsposed.hiddenapibypass.HiddenApiBypass


val appScope by lazy { MainScope() }

private lateinit var innerApp: Application
Expand All @@ -43,7 +45,7 @@ class App : Application() {
LogUtils.d("UncaughtExceptionHandler", t, e)
errorHandler?.uncaughtException(t, e)
}

Toaster.init(this)
MMKV.initialize(this)
LogUtils.getConfig().apply {
setConsoleSwitch(BuildConfig.DEBUG)
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import androidx.activity.viewModels
import androidx.compose.runtime.CompositionLocalProvider
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.rememberNavController
import com.blankj.utilcode.util.LogUtils
import com.dylanc.activityresult.launcher.PickContentLauncher
import com.dylanc.activityresult.launcher.RequestPermissionLauncher
import com.dylanc.activityresult.launcher.StartActivityLauncher
import com.ramcosta.composedestinations.DestinationsNavHost
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import li.songe.gkd.composition.CompositionActivity
import li.songe.gkd.composition.CompositionExt.useLifeCycleLog
Expand Down Expand Up @@ -71,8 +74,21 @@ class MainActivity : CompositionActivity({
}
}) {
val mainVm by viewModels<MainViewModel>()

override fun onStart() {
super.onStart()
activityVisibleFlow.update { it + 1 }
}

override fun onStop() {
super.onStop()
activityVisibleFlow.update { it - 1 }
LogUtils.d(activityVisibleFlow.value)
}
}

val activityVisibleFlow = MutableStateFlow(0)




3 changes: 2 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/notif/Notif.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import li.songe.gkd.util.APP_NAME

data class Notif(
val id: Int,
@Suppress("UNRESOLVED_REFERENCE")
val icon: Int = R.drawable.ic_launcher,
val title: String = APP_NAME,
val text: String,
val ongoing: Boolean,
val autoCancel: Boolean,
)


val abNotif by lazy {
Notif(
id = 100,
Expand All @@ -21,6 +21,7 @@ val abNotif by lazy {
autoCancel = false,
)
}

val screenshotNotif by lazy {
Notif(
id = 101,
Expand Down
67 changes: 41 additions & 26 deletions app/src/main/kotlin/li/songe/gkd/ui/AboutPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.HorizontalDivider
Expand All @@ -17,8 +19,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -39,37 +43,48 @@ import li.songe.gkd.util.launchTry
fun AboutPage() {
val navController = LocalNavController.current
val context = LocalContext.current
Scaffold(topBar = {
TopAppBar(navigationIcon = {
IconButton(onClick = {
navController.popBackStack()
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null,
)
}
}, title = { Text(text = "关于") }, actions = {})
}, content = { contentPadding ->

val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(
scrollBehavior = scrollBehavior,
navigationIcon = {
IconButton(onClick = {
navController.popBackStack()
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null,
)
}
},
title = { Text(text = "关于") }
)
}
) { contentPadding ->
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState())
.padding(contentPadding),
) {
Column(modifier = Modifier
.clickable {
appScope.launchTry {
// ActivityNotFoundException
// https://bugly.qq.com/v2/crash-reporting/crashes/d0ce46b353/117002?pid=1
context.startActivity(
Intent(
Intent.ACTION_VIEW, Uri.parse(REPOSITORY_URL)
Column(
modifier = Modifier
.clickable {
appScope.launchTry {
// ActivityNotFoundException
// https://bugly.qq.com/v2/crash-reporting/crashes/d0ce46b353/117002?pid=1
context.startActivity(
Intent(
Intent.ACTION_VIEW, Uri.parse(REPOSITORY_URL)
)
)
)
}
}
}
.fillMaxWidth()
.padding(10.dp)) {
.fillMaxWidth()
.padding(10.dp)) {
Text(
text = "开源地址", fontSize = 18.sp
)
Expand Down Expand Up @@ -166,7 +181,7 @@ fun AboutPage() {
fontSize = 14.sp,
)
}
Spacer(modifier = Modifier.height(40.dp))
}
})

}
}
29 changes: 17 additions & 12 deletions app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
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.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -67,20 +69,22 @@ fun useControlPage(): ScaffoldExt {
val canNotif by usePollState {
NotificationManagerCompat.from(context).areNotificationsEnabled()
}

return ScaffoldExt(navItem = controlNav, topBar = {
TopAppBar(title = {
Text(
text = controlNav.label,
)
})
}, content = { padding ->
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
val scrollState = rememberScrollState()
return ScaffoldExt(navItem = controlNav,
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(scrollBehavior = scrollBehavior, title = {
Text(
text = controlNav.label,
)
})
}
) { padding ->
Column(
modifier = Modifier
.verticalScroll(scrollState)
.padding(padding)
.verticalScroll(
state = rememberScrollState()
)
) {
if (!gkdAccessRunning) {
AuthCard(
Expand Down Expand Up @@ -253,6 +257,7 @@ fun useControlPage(): ScaffoldExt {
}
}

Spacer(modifier = Modifier.height(40.dp))
}
})
}
}
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun HomePage() {
val controlPage = useControlPage()
val settingsPage = useSettingsPage()

val pages = arrayOf(appListPage, subsPage, controlPage, settingsPage)
val pages = arrayOf(controlPage, subsPage, appListPage, settingsPage)

val currentPage = pages.find { p -> p.navItem === tab }
?: controlPage
Expand Down
26 changes: 21 additions & 5 deletions app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -33,6 +35,7 @@ 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.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -319,15 +322,28 @@ fun useSettingsPage(): ScaffoldExt {
else -> {}
}

return ScaffoldExt(navItem = settingsNav) { padding ->
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
val scrollState = rememberScrollState()
return ScaffoldExt(
navItem = settingsNav,
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(scrollBehavior = scrollBehavior,
title = {
Text(
text = settingsNav.label,
)
}
)
},
) { padding ->
Column(
modifier = Modifier
.verticalScroll(scrollState)
.padding(padding)
.verticalScroll(
state = rememberScrollState()
)
) {
TextSwitch(name = "后台隐藏",
TextSwitch(
name = "后台隐藏",
desc = "在[最近任务]界面中隐藏本应用",
checked = store.excludeFromRecents,
onCheckedChange = {
Expand Down
34 changes: 23 additions & 11 deletions app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.pullrefresh.PullRefreshIndicator
import androidx.compose.material3.pullrefresh.pullRefresh
import androidx.compose.material3.pullrefresh.rememberPullRefreshState
Expand All @@ -44,6 +46,7 @@ import androidx.compose.runtime.rememberCoroutineScope
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.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -181,15 +184,13 @@ fun useSubsManagePage(): ScaffoldExt {
HorizontalDivider()
}
if (menuSubItemVal.id != -2L) {
Text(text = "删除订阅",
modifier = Modifier
.clickable {
deleteSubItem = menuSubItemVal
menuSubItem = null
}
.fillMaxWidth()
.padding(16.dp),
color = MaterialTheme.colorScheme.error)
Text(text = "删除订阅", modifier = Modifier
.clickable {
deleteSubItem = menuSubItemVal
menuSubItem = null
}
.fillMaxWidth()
.padding(16.dp), color = MaterialTheme.colorScheme.error)
}
}
}
Expand Down Expand Up @@ -256,8 +257,20 @@ fun useSubsManagePage(): ScaffoldExt {
})
}

val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
return ScaffoldExt(
navItem = subsNav,
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(
scrollBehavior = scrollBehavior,
title = {
Text(
text = subsNav.label,
)
}
)
},
floatingActionButton = {
FloatingActionButton(onClick = {
if (!vm.refreshingFlow.value) {
Expand Down Expand Up @@ -319,8 +332,7 @@ fun useSubsManagePage(): ScaffoldExt {
elevation = CardDefaults.cardElevation(draggedElevation = 10.dp),
shape = RoundedCornerShape(8.dp),
border = if (isDragging) BorderStroke(
width,
MaterialTheme.colorScheme.primary
width, MaterialTheme.colorScheme.primary
) else null,
interactionSource = interactionSource,
) {
Expand Down
Loading

0 comments on commit f9d0692

Please sign in to comment.