mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
feat: 本地订阅支持分享文件
This commit is contained in:
parent
dd206f968c
commit
e1b69e08e8
|
@ -1,7 +1,6 @@
|
|||
package li.songe.gkd.ui
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import androidx.activity.ComponentActivity
|
||||
|
@ -45,7 +44,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.blankj.utilcode.util.ClipboardUtils
|
||||
|
@ -71,6 +69,7 @@ import li.songe.gkd.util.ProfileTransitions
|
|||
import li.songe.gkd.util.format
|
||||
import li.songe.gkd.util.launchAsFn
|
||||
import li.songe.gkd.util.navigate
|
||||
import li.songe.gkd.util.shareFile
|
||||
import li.songe.gkd.util.snapshotZipDir
|
||||
import java.io.File
|
||||
|
||||
|
@ -194,21 +193,7 @@ fun SnapshotPage() {
|
|||
modifier = Modifier
|
||||
.clickable(onClick = vm.viewModelScope.launchAsFn {
|
||||
val zipFile = SnapshotExt.getSnapshotZipFile(snapshotVal.id)
|
||||
val uri = FileProvider.getUriForFile(
|
||||
context, "${context.packageName}.provider", zipFile
|
||||
)
|
||||
val intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
type = "application/zip"
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
context.startActivity(
|
||||
Intent.createChooser(
|
||||
intent, "分享快照文件"
|
||||
)
|
||||
)
|
||||
context.shareFile(zipFile, "分享快照文件")
|
||||
selectedSnapshot = null
|
||||
})
|
||||
.then(modifier)
|
||||
|
|
|
@ -64,6 +64,7 @@ import li.songe.gkd.util.SafeR
|
|||
import li.songe.gkd.util.formatTimeAgo
|
||||
import li.songe.gkd.util.launchAsFn
|
||||
import li.songe.gkd.util.navigate
|
||||
import li.songe.gkd.util.shareFile
|
||||
import li.songe.gkd.util.subsIdToRawFlow
|
||||
import li.songe.gkd.util.subsItemsFlow
|
||||
import org.burnoutcrew.reorderable.ReorderableItem
|
||||
|
@ -224,6 +225,16 @@ fun SubsManagePage() {
|
|||
.padding(16.dp))
|
||||
Divider()
|
||||
}
|
||||
if (menuSubItemVal.id < 0 && subsRawVal != null && menuSubItemVal.subsFile.exists()) {
|
||||
Text(text = "分享文件", modifier = Modifier
|
||||
.clickable {
|
||||
menuSubItem = null
|
||||
context.shareFile(menuSubItemVal.subsFile, "分享订阅文件")
|
||||
}
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp))
|
||||
Divider()
|
||||
}
|
||||
if (menuSubItemVal.updateUrl != null) {
|
||||
Text(text = "复制链接", modifier = Modifier
|
||||
.clickable {
|
||||
|
@ -235,13 +246,17 @@ fun SubsManagePage() {
|
|||
.padding(16.dp))
|
||||
Divider()
|
||||
}
|
||||
Text(text = "删除订阅", modifier = Modifier
|
||||
.clickable {
|
||||
deleteSubItem = menuSubItemVal
|
||||
menuSubItem = null
|
||||
}
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp), color = MaterialTheme.colorScheme.error)
|
||||
if (menuSubItemVal.id != -2L) {
|
||||
Text(text = "删除订阅",
|
||||
modifier = Modifier
|
||||
.clickable {
|
||||
deleteSubItem = menuSubItemVal
|
||||
menuSubItem = null
|
||||
}
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ 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.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
|
@ -92,7 +91,7 @@ fun SubsItemCard(
|
|||
)
|
||||
} else {
|
||||
Text(
|
||||
text = "无规则", fontSize = 14.sp
|
||||
text = "暂无规则", fontSize = 14.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -107,13 +106,11 @@ fun SubsItemCard(
|
|||
}
|
||||
Spacer(modifier = Modifier.width(5.dp))
|
||||
|
||||
if (subsItem.id != -2L) { // 本地订阅不要显示菜单按钮
|
||||
IconButton(onClick = { onMenuClick?.invoke() }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = "more",
|
||||
)
|
||||
}
|
||||
IconButton(onClick = { onMenuClick?.invoke() }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = "more",
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(10.dp))
|
||||
|
|
26
app/src/main/java/li/songe/gkd/util/IntentExt.kt
Normal file
26
app/src/main/java/li/songe/gkd/util/IntentExt.kt
Normal file
|
@ -0,0 +1,26 @@
|
|||
package li.songe.gkd.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
|
||||
fun Context.shareFile(file: File, tile: String) {
|
||||
val context = this
|
||||
val uri = FileProvider.getUriForFile(
|
||||
context, "${context.packageName}.provider", file
|
||||
)
|
||||
val intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(file.extension)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
context.startActivity(
|
||||
Intent.createChooser(
|
||||
intent, tile
|
||||
)
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user