Skip to content

Commit

Permalink
feat: 允许复制远程订阅的规则组
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Sep 12, 2023
1 parent d44555e commit 2f87ec3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
38 changes: 33 additions & 5 deletions app/src/main/java/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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.defaultMinSize
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -18,6 +19,7 @@ import androidx.compose.material.AlertDialog
import androidx.compose.material.Scaffold
import androidx.compose.material.Switch
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -31,14 +33,18 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.ToastUtils
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph
import kotlinx.serialization.encodeToString
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.SubscriptionRaw
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.SimpleTopAppBar
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.Singleton
import li.songe.gkd.util.appInfoCacheFlow
import li.songe.gkd.util.launchAsFn

Expand Down Expand Up @@ -147,11 +153,33 @@ fun AppItemPage(


showGroupItem?.let { showGroupItemVal ->
AlertDialog(onDismissRequest = { showGroupItem = null }, title = {
Text(text = showGroupItemVal.name ?: "-")
}, text = {
Text(text = showGroupItemVal.desc ?: "-")
}, buttons = { })
AlertDialog(modifier = Modifier.defaultMinSize(300.dp),
onDismissRequest = { showGroupItem = null },
title = {
Text(text = showGroupItemVal.name ?: "-")
},
text = {
Column {
if (showGroupItemVal.enable == false) {
Text(text = "该规则组默认不启用", color = Color.Blue)
Spacer(modifier = Modifier.height(10.dp))
}
Text(text = showGroupItemVal.desc ?: "-")
}
},
confirmButton = {
TextButton(onClick = {
val groupAppText = Singleton.omitJson.encodeToString(
subsApp?.copy(
groups = listOf(showGroupItemVal)
)
)
ClipboardUtils.copyText(groupAppText)
ToastUtils.showShort("复制成功")
}) {
Text(text = "复制规则组")
}
})
}
}

8 changes: 7 additions & 1 deletion app/src/main/java/li/songe/gkd/util/Singleton.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package li.songe.gkd.util

import blue.endless.jankson.Jankson
import com.journeyapps.barcodescanner.BarcodeEncoder
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
Expand All @@ -21,6 +20,13 @@ object Singleton {
encodeDefaults = true
}
}
val omitJson by lazy {
Json {
isLenient = true
ignoreUnknownKeys = true
encodeDefaults = false
}
}

val client by lazy {
HttpClient(OkHttp) {
Expand Down

0 comments on commit 2f87ec3

Please sign in to comment.