Skip to content

Commit

Permalink
[feature] Supports copying the current sticker
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Nov 17, 2023
1 parent d3707df commit 8baca2a
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk 24
targetSdk 34
versionCode 43
versionName "1.6-beta29"
versionName "1.6-rc01"
flavorDimensions = ["versionName"]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/skyd/rays/ui/screen/add/AddScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ fun AddScreen(
(if (isEdit) pickStickerLauncher else pickStickersLauncher)
.launch("image/*")
},
contentDescription = stringResource(R.string.add_screen_select_sticker),
contentDescription = if (isEdit) stringResource(R.string.add_screen_update_sticker)
else stringResource(R.string.add_screen_add_stickers),
imageVector = if (isEdit) Icons.Default.Image else Icons.Default.AddPhotoAlternate,
)
RaysIconButton(
Expand Down Expand Up @@ -252,7 +253,7 @@ fun AddScreen(
)
}
},
contentDescription = stringResource(R.string.add_screen_save),
contentDescription = stringResource(R.string.add_screen_save_current_sticker),
imageVector = Icons.Default.Save,
)
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/skyd/rays/ui/screen/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import com.skyd.rays.base.LoadUiIntent
import com.skyd.rays.config.refreshStickerData
import com.skyd.rays.ext.dateTime
import com.skyd.rays.ext.isCompact
import com.skyd.rays.ext.showSnackbar
import com.skyd.rays.ext.showSnackbarWithLaunchedEffect
import com.skyd.rays.model.bean.StickerWithTags
import com.skyd.rays.model.bean.UriWithStickerUuidBean
Expand Down Expand Up @@ -173,6 +174,9 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
},
stickerWithTags = (stickerDetailUiState as? StickerDetailUiState.Success)
?.stickerWithTags,
onShowSnackbar = {
snackbarHostState.showSnackbar(scope = scope, message = it)
},
uiState = uiState,
)
when (stickerDetailUiState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.skyd.rays.ui.screen.home.searchbar

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ManageSearch
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Edit
Expand Down Expand Up @@ -72,6 +73,7 @@ fun HomeMenu(
onDismissRequest: () -> Unit,
onDeleteClick: () -> Unit,
onExportClick: () -> Unit,
onCopyClick: () -> Unit,
onStickerInfoClick: () -> Unit,
onClearScreen: () -> Unit,
) {
Expand Down Expand Up @@ -147,6 +149,20 @@ fun HomeMenu(
)
}
)
DropdownMenuItem(
enabled = stickerMenuItemEnabled,
text = { Text(stringResource(R.string.home_screen_copy)) },
onClick = {
onDismissRequest()
onCopyClick()
},
leadingIcon = {
Icon(
Icons.Default.ContentCopy,
contentDescription = null
)
}
)
DropdownMenuItem(
enabled = stickerMenuItemEnabled,
text = { Text(stringResource(R.string.home_screen_sticker_info)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import com.skyd.rays.ui.screen.home.PopularTagsUiState
import com.skyd.rays.ui.screen.home.SearchResultUiState
import com.skyd.rays.ui.screen.home.StickerDetailInfo
import com.skyd.rays.ui.screen.home.StickerDetailUiState
import com.skyd.rays.util.copyStickerToClipboard


@Composable
Expand All @@ -99,9 +100,11 @@ fun RaysSearchBar(
active: Boolean,
onActiveChange: (Boolean) -> Unit = {},
stickerWithTags: StickerWithTags?,
onShowSnackbar: (String) -> Unit,
uiState: HomeState,
viewModel: HomeViewModel = hiltViewModel()
) {
val context = LocalContext.current
var menuExpanded by rememberSaveable { mutableStateOf(false) }
var multiSelect by rememberSaveable { mutableStateOf(false) }
val selectedStickers = remember { mutableStateListOf<StickerWithTags>() }
Expand Down Expand Up @@ -199,6 +202,10 @@ fun RaysSearchBar(
onDismissRequest = { menuExpanded = false },
onDeleteClick = { openDeleteWarningDialog = true },
onExportClick = { openExportPathDialog = true },
onCopyClick = {
context.copyStickerToClipboard(uuid = currentStickerUuid)
onShowSnackbar(context.getString(R.string.home_screen_copied))
},
onStickerInfoClick = { openStickerInfoDialog = true },
onClearScreen = {
viewModel.sendUiIntent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private fun RaysSearchBarPreview() {
onDismissRequest = { menuExpanded = false },
onDeleteClick = {},
onExportClick = {},
onCopyClick = {},
onStickerInfoClick = {},
onClearScreen = {},
)
Expand Down
41 changes: 28 additions & 13 deletions app/src/main/java/com/skyd/rays/util/StickerUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,15 @@ fun Bitmap.shareToFile(outputDir: File = File(appContext.cacheDir, "TempSticker"
}

/**
* 针对外部应用
* 把表情包复制到临时目录
*/
fun externalShareStickerUuidToFile(uuid: String): File {
val originFile = stickerUuidToFile(uuid)
fun File.copyStickerToTempFolder(fileExtension: Boolean): File {
val outputDir = File(appContext.cacheDir, "TempSticker")
if (appContext.dataStore.get(StickerExtNamePreference.key) == false ||
(!outputDir.exists() && !outputDir.mkdirs())
) {
return originFile
}
val extensionName = originFile.inputStream().use {
ImageFormatChecker.check(it).toString()
}
val resultFileName = uuid + "_" + Random.nextInt(0, Int.MAX_VALUE) + extensionName
val resultFile = originFile.copyTo(
check(outputDir.exists() || outputDir.mkdirs())
val resultFileName = name + "_" + Random.nextInt(0, Int.MAX_VALUE) + if (fileExtension) {
inputStream().use { ImageFormatChecker.check(it).toString() }
} else ""
val resultFile = copyTo(
target = File(outputDir, resultFileName),
overwrite = true
)
Expand All @@ -189,6 +183,14 @@ fun externalShareStickerUuidToFile(uuid: String): File {
return resultFile
}

/**
* 针对外部应用
*/
fun externalShareStickerUuidToFile(uuid: String): File =
stickerUuidToFile(uuid).copyStickerToTempFolder(
fileExtension = appContext.dataStore.get(StickerExtNamePreference.key) ?: true
)

/**
* 针对内部操作,针对原图片本身
*/
Expand Down Expand Up @@ -235,7 +237,20 @@ private fun List<Uri>.shareStickerUriString(context: Context, packages: List<Str
)
}

/**
* 注意:此 uri 需要使用 FileProvider 提供
*/
fun Context.copyStickerToClipboard(uri: Uri) {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(ClipData.newUri(contentResolver, "Sticker", uri))
}

fun Context.copyStickerToClipboard(uuid: String) {
copyStickerToClipboard(
FileProvider.getUriForFile(
this,
"${packageName}.fileprovider",
stickerUuidToFile(uuid).copyStickerToTempFolder(fileExtension = true)
)
)
}
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<string name="home_screen_name">首页</string>
<string name="home_screen_search_hint">输入关键词搜索</string>
<string name="home_screen_add">添加</string>
<string name="add_screen_save">保存</string>
<string name="add_screen_save_current_sticker">保存当前项</string>
<string name="add_screen_title">标题(可选)</string>
<string name="add_screen_add_tags">添加标签(可选)</string>
<string name="add_screen_name">添加表情包</string>
Expand All @@ -31,6 +31,8 @@
<string name="home_screen_edit">编辑</string>
<string name="home_screen_delete">删除</string>
<string name="home_screen_export">导出</string>
<string name="home_screen_copy">复制</string>
<string name="home_screen_copied">已复制</string>
<string name="info">提示</string>
<string name="dialog_ok">确定</string>
<string name="dialog_close">关闭</string>
Expand Down Expand Up @@ -148,6 +150,8 @@
<string name="home_screen_empty_tip">新建表情包或从搜索结果中选择一个表情包吧~</string>
<string name="home_screen_no_search_result_tip">空空如也呢~</string>
<string name="add_screen_select_sticker">选择表情包</string>
<string name="add_screen_add_stickers">添加表情包</string>
<string name="add_screen_update_sticker">选择新表情包</string>
<string name="import_export_screen_name">导入与导出</string>
<string name="home_screen_send_sticker">发送</string>
<string name="send_sticker">发送表情包</string>
Expand Down
16 changes: 10 additions & 6 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<string name="home_screen_name">首頁</string>
<string name="home_screen_search_hint">搜尋</string>
<string name="home_screen_add">添加</string>
<string name="add_screen_save">存檔</string>
<string name="add_screen_save_current_sticker">儲存目前項</string>
<string name="add_screen_title">標題(可選)</string>
<string name="add_screen_add_tags">新增標籤(可選)</string>
<string name="add_screen_name">添加</string>
Expand Down Expand Up @@ -46,7 +46,7 @@
<string name="appearance_screen_sticker_color_theme">表情包顏色主題</string>
<string name="webdav_screen_password">密碼</string>
<string name="data_screen_delete_all_description">刪除 Rays 管理的所有本地數據,包括圖片、標題、標籤等。此操作無法撤銷</string>
<string name="classification_screen_description">選擇表情包分類模型,設置置信閾值等</string>
<string name="classification_screen_description">選擇表情包分類模型,設定置信閾值等</string>
<string name="home_screen_delete_warning">刪除?此操作無法還原!</string>
<string name="webdav_screen_password_entered">密碼已輸入</string>
<string name="selfie_segmentation_screen_name">自拍分割</string>
Expand Down Expand Up @@ -97,11 +97,11 @@
</plurals>
<string name="export_files_screen_description">匯出表情包、標籤等至本地文件</string>
<string name="home_style_screen_share_button_alignment_vert">垂直</string>
<string name="import_export_screen_name">導入與導出</string>
<string name="import_export_screen_name">導入與匯出</string>
<string name="appearance_screen_dark_mode">深色模式</string>
<string name="search_config_screen_use_regex">正則表達式</string>
<string name="home_screen_sticker_info_click_count">點擊次數</string>
<string name="classification_screen_threshold_description">只有置信度高于此門檻值的標籤才會被建議,建議設置在 0.5 左右。</string>
<string name="classification_screen_threshold_description">只有置信度高于此門檻值的標籤才會被建議,建議設定在 0.5 左右。</string>
<string name="webdav_screen_server">伺服器</string>
<string name="about_screen_join_discord">加入 Discord 伺服器</string>
<string name="webdav_screen_download">拉取</string>
Expand All @@ -115,7 +115,7 @@
<string name="auto_share_screen_ignore_description">忽略匹配页面的存在</string>
<string name="export_files_screen_successful">匯出成功</string>
<string name="about_screen_description_1">一個用於在手機上記錄、搜尋和管理表情包的工具。</string>
<string name="appearance_screen_dark_mode_description">設置深色模式策略</string>
<string name="appearance_screen_dark_mode_description">設定深色模式策略</string>
<string name="import_files_screen_description">從本地文件導入表情包、標籤等</string>
<string name="appearance_screen_name">外觀和風格</string>
<string name="webdav_screen_clear_remote_recycle_bin">清空回收站</string>
Expand Down Expand Up @@ -172,6 +172,8 @@
<string name="search_config_screen_domain_category">搜尋領域(未選擇時搜索全部)</string>
<string name="uri_string_share_screen_name">URI 字符串分享</string>
<string name="home_screen_export">匯出</string>
<string name="home_screen_copy">複製</string>
<string name="home_screen_copied">已複製</string>
<string name="dark_mode_light">亮色</string>
<string name="home_screen_edit">編輯</string>
<string name="about">關於</string>
Expand Down Expand Up @@ -240,7 +242,7 @@
<string name="home_style_screen_sticker_card">表情包卡片</string>
<string name="webdav_screen_progress_download_data">更新本地數據</string>
<string name="search_config_screen_name">搜尋</string>
<string name="settings">設置</string>
<string name="settings">設定</string>
<string name="appearance_screen_style_category">風格</string>
<string name="setting_screen_appearance_description">主題、深色模式、風格等</string>
<string name="home_screen_send_sticker">發送</string>
Expand All @@ -249,6 +251,8 @@
<string name="import_export_screen_webdav_description">透過 WebDAV 同步數據</string>
<string name="db_tag_table_tag">標籤</string>
<string name="add_screen_select_sticker">選擇表情包</string>
<string name="add_screen_add_stickers">添加表情包</string>
<string name="add_screen_update_sticker">選擇新表情包</string>
<string name="about_screen_other_works_night_screen_description">當您在晚上🌙使用手機時,Night Screen 可以幫助您降低屏幕的亮度,減少對眼睛的損害。</string>
<string name="webdav_screen_remote_recycle_bin">遠端回收站</string>
<string name="data_screen_name">數據</string>
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<string name="home_screen_name">Home</string>
<string name="home_screen_search_hint">Search</string>
<string name="home_screen_add">Add</string>
<string name="add_screen_save">Save</string>
<string name="add_screen_save_current_sticker">Save current sticker</string>
<string name="add_screen_title">Title (Optional)</string>
<string name="add_screen_add_tags">Add tags (Optional)</string>
<string name="add_screen_name">Add</string>
Expand All @@ -31,6 +31,8 @@
<string name="home_screen_edit">Edit</string>
<string name="home_screen_delete">Delete</string>
<string name="home_screen_export">Export</string>
<string name="home_screen_copy">Copy</string>
<string name="home_screen_copied">Copied</string>
<string name="info">Info</string>
<string name="dialog_ok">OK</string>
<string name="dialog_close">Close</string>
Expand Down Expand Up @@ -154,6 +156,8 @@
<string name="home_screen_empty_tip">Create a new sticker or select a sticker from the search results~</string>
<string name="home_screen_no_search_result_tip">It\'s empty~</string>
<string name="add_screen_select_sticker">Select stickers</string>
<string name="add_screen_add_stickers">Add stickers</string>
<string name="add_screen_update_sticker">Select a new sticker</string>
<string name="import_export_screen_name">Sync data</string>
<string name="home_screen_send_sticker">Send</string>
<string name="send_sticker">Send sticker</string>
Expand Down Expand Up @@ -204,13 +208,13 @@
<string name="home_style_screen_share_button_alignment">Share button position</string>
<string name="home_style_screen_share_button_alignment_horiz">Horizontal</string>
<string name="home_style_screen_share_button_alignment_vert">Vertical</string>
<string name="webdav_screen_progress_upload_data_sticker">Update remote data + sticker</string>
<string name="webdav_screen_progress_logical_delete_remote">Move to remote recycle bin</string>
<string name="webdav_screen_progress_upload_data">Update remote data</string>
<string name="webdav_screen_progress_download_data_sticker">Update local data + sticker</string>
<string name="webdav_screen_progress_download_data">Update local data</string>
<string name="webdav_screen_progress_delete">Delete local data + sticker</string>
<string name="webdav_screen_progress_refresh_backup_info">Update backup information</string>
<string name="webdav_screen_progress_upload_data_sticker">Updating remote data + sticker</string>
<string name="webdav_screen_progress_logical_delete_remote">Moving to remote recycle bin</string>
<string name="webdav_screen_progress_upload_data">Updating remote data</string>
<string name="webdav_screen_progress_download_data_sticker">Updating local data + sticker</string>
<string name="webdav_screen_progress_download_data">Updating local data</string>
<string name="webdav_screen_progress_delete">Deleting local data + sticker</string>
<string name="webdav_screen_progress_refresh_backup_info">Updating backup information</string>
<string name="data_sync_warning">Please do not force kill the app or disconnect the network when pushing and pulling, as this may corrupt the data!</string>
<string name="home_screen_sticker_info">Sticker info</string>
<string name="home_screen_sticker_info_uuid">UUID</string>
Expand Down

0 comments on commit 8baca2a

Please sign in to comment.