feat: 本地订阅支持分享文件

This commit is contained in:
lisonge 2023-10-27 14:27:52 +08:00
parent dd206f968c
commit e1b69e08e8
4 changed files with 56 additions and 33 deletions

View File

@ -1,7 +1,6 @@
package li.songe.gkd.ui package li.songe.gkd.ui
import android.Manifest import android.Manifest
import android.content.Intent
import android.graphics.Bitmap import android.graphics.Bitmap
import android.os.Build import android.os.Build
import androidx.activity.ComponentActivity 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.text.font.FontFamily
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
import androidx.core.content.FileProvider
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ClipboardUtils 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.format
import li.songe.gkd.util.launchAsFn import li.songe.gkd.util.launchAsFn
import li.songe.gkd.util.navigate import li.songe.gkd.util.navigate
import li.songe.gkd.util.shareFile
import li.songe.gkd.util.snapshotZipDir import li.songe.gkd.util.snapshotZipDir
import java.io.File import java.io.File
@ -194,21 +193,7 @@ fun SnapshotPage() {
modifier = Modifier modifier = Modifier
.clickable(onClick = vm.viewModelScope.launchAsFn { .clickable(onClick = vm.viewModelScope.launchAsFn {
val zipFile = SnapshotExt.getSnapshotZipFile(snapshotVal.id) val zipFile = SnapshotExt.getSnapshotZipFile(snapshotVal.id)
val uri = FileProvider.getUriForFile( context.shareFile(zipFile, "分享快照文件")
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, "分享快照文件"
)
)
selectedSnapshot = null selectedSnapshot = null
}) })
.then(modifier) .then(modifier)

View File

@ -64,6 +64,7 @@ import li.songe.gkd.util.SafeR
import li.songe.gkd.util.formatTimeAgo import li.songe.gkd.util.formatTimeAgo
import li.songe.gkd.util.launchAsFn import li.songe.gkd.util.launchAsFn
import li.songe.gkd.util.navigate import li.songe.gkd.util.navigate
import li.songe.gkd.util.shareFile
import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsIdToRawFlow
import li.songe.gkd.util.subsItemsFlow import li.songe.gkd.util.subsItemsFlow
import org.burnoutcrew.reorderable.ReorderableItem import org.burnoutcrew.reorderable.ReorderableItem
@ -224,6 +225,16 @@ fun SubsManagePage() {
.padding(16.dp)) .padding(16.dp))
Divider() 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) { if (menuSubItemVal.updateUrl != null) {
Text(text = "复制链接", modifier = Modifier Text(text = "复制链接", modifier = Modifier
.clickable { .clickable {
@ -235,13 +246,17 @@ fun SubsManagePage() {
.padding(16.dp)) .padding(16.dp))
Divider() Divider()
} }
Text(text = "删除订阅", modifier = Modifier if (menuSubItemVal.id != -2L) {
Text(text = "删除订阅",
modifier = Modifier
.clickable { .clickable {
deleteSubItem = menuSubItemVal deleteSubItem = menuSubItemVal
menuSubItem = null menuSubItem = null
} }
.fillMaxWidth() .fillMaxWidth()
.padding(16.dp), color = MaterialTheme.colorScheme.error) .padding(16.dp),
color = MaterialTheme.colorScheme.error)
}
} }
} }
} }

View File

@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.MoreVert
@ -92,7 +91,7 @@ fun SubsItemCard(
) )
} else { } else {
Text( Text(
text = "无规则", fontSize = 14.sp text = "无规则", fontSize = 14.sp
) )
} }
} }
@ -107,14 +106,12 @@ fun SubsItemCard(
} }
Spacer(modifier = Modifier.width(5.dp)) Spacer(modifier = Modifier.width(5.dp))
if (subsItem.id != -2L) { // 本地订阅不要显示菜单按钮
IconButton(onClick = { onMenuClick?.invoke() }) { IconButton(onClick = { onMenuClick?.invoke() }) {
Icon( Icon(
imageVector = Icons.Default.MoreVert, imageVector = Icons.Default.MoreVert,
contentDescription = "more", contentDescription = "more",
) )
} }
}
Spacer(modifier = Modifier.width(10.dp)) Spacer(modifier = Modifier.width(10.dp))
Switch( Switch(

View 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
)
)
}