Skip to content

Commit

Permalink
feat: 移除二维码相关功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 16, 2023
1 parent d31f3ae commit 4d07d46
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 128 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ dependencies {
implementation(libs.others.jankson)
implementation(libs.others.utilcodex)
implementation(libs.others.activityResultLauncher)
implementation(libs.others.zxing.android.embedded)
implementation(libs.others.floating.bubble.view)

implementation(libs.destinations.core)
Expand Down
99 changes: 20 additions & 79 deletions app/src/main/java/li/songe/gkd/ui/SubsManagePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.webkit.URLUtil
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -51,31 +50,27 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.ToastUtils
import com.google.zxing.BarcodeFormat
import li.songe.gkd.util.navigate
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import li.songe.gkd.data.SubsItem
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.SubsItemCard
import li.songe.gkd.ui.destinations.SubsPageDestination
import li.songe.gkd.util.DEFAULT_SUBS_UPDATE_URL
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.SafeR
import li.songe.gkd.util.Singleton
import li.songe.gkd.util.getImportUrl
import li.songe.gkd.util.launchAsFn
import li.songe.gkd.util.navigate
import li.songe.gkd.util.subsIdToRawFlow
import li.songe.gkd.util.subsItemsFlow
import li.songe.gkd.util.useNavigateForQrcodeResult
import org.burnoutcrew.reorderable.ReorderableItem
import org.burnoutcrew.reorderable.detectReorderAfterLongPress
import org.burnoutcrew.reorderable.rememberReorderableLazyListState
Expand All @@ -90,7 +85,6 @@ val subsNav = BottomNavItem(
fun SubsManagePage() {
val scope = rememberCoroutineScope()
val navController = LocalNavController.current
val navigateForQrcodeResult = useNavigateForQrcodeResult()

val vm = hiltViewModel<SubsManageVm>()
val homeVm = hiltViewModel<HomePageVm>()
Expand All @@ -114,8 +108,6 @@ fun SubsManagePage() {
})


var shareSubItem: SubsItem? by remember { mutableStateOf(null) }
var shareQrcode: ImageBitmap? by remember { mutableStateOf(null) }
var deleteSubItem: SubsItem? by remember { mutableStateOf(null) }
var menuSubItem: SubsItem? by remember { mutableStateOf(null) }

Expand Down Expand Up @@ -156,7 +148,13 @@ fun SubsManagePage() {
})
},
floatingActionButton = {
FloatingActionButton(onClick = { showAddDialog = true }) {
FloatingActionButton(onClick = {
if (subItems.any { it.id == 0L }) {
showAddLinkDialog = true
} else {
showAddDialog = true
}
}) {
Icon(
imageVector = Icons.Filled.Add,
contentDescription = "info",
Expand Down Expand Up @@ -220,47 +218,6 @@ fun SubsManagePage() {
}


shareSubItem?.let { shareSubItemVal ->
Dialog(onDismissRequest = { shareSubItem = null }) {
Column(
modifier = Modifier
.width(250.dp)
.background(Color.White)
.padding(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = "显示链接二维码", modifier = Modifier
.clickable {
shareSubItem = null
scope.launch(Dispatchers.Default) {
shareQrcode = Singleton.barcodeEncoder
.encodeBitmap(
shareSubItemVal.updateUrl, BarcodeFormat.QR_CODE, 500, 500
)
.asImageBitmap()
}
}
.fillMaxWidth()
.padding(8.dp))
Text(text = "复制链接至剪切板", modifier = Modifier
.clickable {
shareSubItem = null
ClipboardUtils.copyText(shareSubItemVal.updateUrl)
ToastUtils.showShort("复制成功")
}
.fillMaxWidth()
.padding(8.dp))
}
}
}

shareQrcode?.let { shareQrcodeVal ->
Dialog(onDismissRequest = { shareQrcode = null }) {
Image(
bitmap = shareQrcodeVal, contentDescription = null, modifier = Modifier.size(400.dp)
)
}
}

menuSubItem?.let { menuSubItemVal ->

Expand All @@ -274,10 +231,11 @@ fun SubsManagePage() {
.padding(8.dp)
) {
if (menuSubItemVal.updateUrl != null) {
Text(text = "分享链接", modifier = Modifier
Text(text = "复制链接", modifier = Modifier
.clickable {
shareSubItem = menuSubItemVal
menuSubItem = null
ClipboardUtils.copyText(menuSubItemVal.updateUrl)
ToastUtils.showShort("复制成功")
}
.fillMaxWidth()
.padding(8.dp))
Expand Down Expand Up @@ -325,32 +283,15 @@ fun SubsManagePage() {
.padding(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
if (subItems.all { it.id != 0L }) {
Text(text = "导入默认订阅", modifier = Modifier
.clickable {
showAddDialog = false
vm.addSubsFromUrl("https://registry.npmmirror.com/@gkd-kit/subscription/latest/files")
}
.fillMaxWidth()
.padding(8.dp))
}
Text(text = "导入默认订阅", modifier = Modifier
.clickable {
showAddDialog = false
vm.addSubsFromUrl(DEFAULT_SUBS_UPDATE_URL)
}
.fillMaxWidth()
.padding(8.dp))

Text(
text = "扫描二维码导入",
modifier = Modifier
.clickable(onClick = scope.launchAsFn {
showAddDialog = false
val qrCode = navigateForQrcodeResult()
val contents = qrCode.contents
if (contents != null) {
showAddLinkDialog = true
link = contents
}
})
.fillMaxWidth()
.padding(8.dp)
)
Text(text = "输入链接导入", modifier = Modifier
Text(text = "导入其它订阅", modifier = Modifier
.clickable {
showAddDialog = false
showAddLinkDialog = true
Expand Down
43 changes: 0 additions & 43 deletions app/src/main/java/li/songe/gkd/util/HookExt.kt

This file was deleted.

3 changes: 0 additions & 3 deletions 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 com.journeyapps.barcodescanner.BarcodeEncoder
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
Expand Down Expand Up @@ -39,6 +38,4 @@ object Singleton {
}
}

val barcodeEncoder by lazy { BarcodeEncoder() }

}
5 changes: 3 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ dependencyResolutionManagement {
// 工具集合类
// https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/README-CN.md
library("others.utilcodex", "com.blankj:utilcodex:1.31.0")

// https://dylancaicoding.github.io/ActivityResultLauncher/#/
library(
"others.activityResultLauncher",
Expand All @@ -92,8 +93,7 @@ dependencyResolutionManagement {
// json5
// https://github.com/falkreon/Jankson
library("others.jankson", "blue.endless:jankson:1.2.3")
// https://github.com/journeyapps/zxing-android-embedded
library("others.zxing.android.embedded", "com.journeyapps:zxing-android-embedded:4.3.0")

// https://github.com/TorryDo/Floating-Bubble-View
library("others.floating.bubble.view", "io.github.torrydo:floating-bubble-view:0.6.1")

Expand Down Expand Up @@ -151,6 +151,7 @@ dependencyResolutionManagement {
"kotlinx.serialization.json",
"org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0"
)

// https://github.com/Kotlin/kotlinx.collections.immutable
library(
"kotlinx.collections.immutable",
Expand Down

0 comments on commit 4d07d46

Please sign in to comment.