feat: support toggling deletion of exported photos

This commit is contained in:
Hinnka committed 2026-05-30 08:11:38 +08:00
1 parent 052349b44b
commit 4b2951336b
7 files changed
+95 -20

No files matched your search

@@ -158,7 +158,8 @@ data class UserPreferences(
val customLensIds: List<String> = emptyList(), // 自定义镜头 ID,逗号分隔存储
val lensIdBlacklist: List<String> = emptyList(), // 主动探测黑名单镜头 ID,逗号分隔存储
val hiddenFocalLengths: List<Float> = emptyList(), // 隐藏的焦段 (35mm等效)
val referencePhotoUrl: String? = null
val referencePhotoUrl: String? = null,
val deleteExported: Boolean = true
)
/**
@@ -276,6 +277,7 @@ class UserPreferencesRepository(private val context: Context) {
private val HIDDEN_FOCAL_LENGTHS = stringPreferencesKey("hidden_focal_lengths")
private val USE_HDR_SCREEN_MODE = booleanPreferencesKey("use_hdr_screen_mode")
private val REFERENCE_PHOTO_URL = stringPreferencesKey("reference_photo_url")
private val DELETE_EXPORTED = booleanPreferencesKey("delete_exported")
}
/**
@@ -422,7 +424,8 @@ class UserPreferencesRepository(private val context: Context) {
?.mapNotNull { it.toFloatOrNull() }
?: emptyList(),
useHdrScreenMode = preferences[USE_HDR_SCREEN_MODE] ?: true,
referencePhotoUrl = preferences[REFERENCE_PHOTO_URL]
referencePhotoUrl = preferences[REFERENCE_PHOTO_URL],
deleteExported = preferences[DELETE_EXPORTED] ?: true
)
}
@@ -538,6 +541,15 @@ class UserPreferencesRepository(private val context: Context) {
return AspectRatio.sanitizeTopSheetRatios(ratios)
}
/**
* 保存是否同时删除系统相册中的导出图选择
*/
suspend fun saveDeleteExported(enabled: Boolean) {
context.dataStore.edit { preferences ->
preferences[DELETE_EXPORTED] = enabled
}
}
/**
* 保存参考图 URL
*/
@@ -579,9 +579,12 @@ fun GalleryDetailScreen(
}
}
val deleteExportedPref by viewModel.deleteExported.collectAsState()
// 删除确认对话框
if (showDeleteDialog) {
// var deleteExported by remember { mutableStateOf(true) }
val exportedPhotosCount = remember(currentPhoto) { currentPhoto?.metadata?.exportedUris?.size ?: 0 }
var deleteExportedState by remember(showDeleteDialog) { mutableStateOf(deleteExportedPref) }
AlertDialog(
onDismissRequest = { showDeleteDialog = false },
@@ -590,13 +593,31 @@ fun GalleryDetailScreen(
Column {
Text(stringResource(R.string.delete_confirm))
if (viewModel.selectedTab == GalleryTab.PHOTON) {
Spacer(modifier = Modifier.height(12.dp))
Text(
text = stringResource(R.string.delete_system_warning),
color = Color.Red,
fontSize = 12.sp,
lineHeight = 16.sp
)
if (exportedPhotosCount > 0) {
Spacer(modifier = Modifier.height(12.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clickable { deleteExportedState = !deleteExportedState }
.padding(vertical = 4.dp)
) {
Checkbox(
checked = deleteExportedState,
onCheckedChange = { deleteExportedState = it },
colors = CheckboxDefaults.colors(
checkedColor = AccentOrange,
uncheckedColor = Color.White.copy(alpha = 0.6f)
)
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = stringResource(R.string.delete_exported_photos_count, exportedPhotosCount),
color = Color.White,
fontSize = 14.sp
)
}
}
}
}
},
@@ -604,7 +625,11 @@ fun GalleryDetailScreen(
TextButton(
onClick = {
currentPhoto?.let { photo ->
viewModel.requestDeletePhoto(photo, true)
val finalDeleteExported = if (viewModel.selectedTab == GalleryTab.PHOTON && exportedPhotosCount > 0) deleteExportedState else true
if (viewModel.selectedTab == GalleryTab.PHOTON && exportedPhotosCount > 0) {
viewModel.setDeleteExported(deleteExportedState)
}
viewModel.requestDeletePhoto(photo, finalDeleteExported)
}
showDeleteDialog = false
}
@@ -506,9 +506,12 @@ fun GalleryScreen(
}
}
val deleteExportedPref by viewModel.deleteExported.collectAsState()
// 删除确认对话框
if (showDeleteDialog) {
// var deleteExported by remember { mutableStateOf(true) }
val exportedPhotosCount = remember(selectedPhotos) { selectedPhotos.sumOf { it.metadata?.exportedUris?.size ?: 0 } }
var deleteExportedState by remember(showDeleteDialog) { mutableStateOf(deleteExportedPref) }
AlertDialog(
onDismissRequest = { showDeleteDialog = false },
@@ -519,20 +522,42 @@ fun GalleryScreen(
text = stringResource(R.string.delete_multiple_confirm, selectedPhotos.size)
)
if (viewModel.selectedTab == GalleryTab.PHOTON) {
Spacer(modifier = Modifier.height(12.dp))
Text(
text = stringResource(R.string.delete_system_warning),
color = Color.Red,
fontSize = 12.sp,
lineHeight = 16.sp
)
if (exportedPhotosCount > 0) {
Spacer(modifier = Modifier.height(12.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clickable { deleteExportedState = !deleteExportedState }
.padding(vertical = 4.dp)
) {
Checkbox(
checked = deleteExportedState,
onCheckedChange = { deleteExportedState = it },
colors = CheckboxDefaults.colors(
checkedColor = AccentOrange,
uncheckedColor = Color.White.copy(alpha = 0.6f)
)
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = stringResource(R.string.delete_exported_photos_count, exportedPhotosCount),
color = Color.White,
fontSize = 14.sp
)
}
}
}
}
},
confirmButton = {
TextButton(
onClick = {
viewModel.deleteSelectedPhotos(true)
val finalDeleteExported = if (viewModel.selectedTab == GalleryTab.PHOTON && exportedPhotosCount > 0) deleteExportedState else true
if (viewModel.selectedTab == GalleryTab.PHOTON && exportedPhotosCount > 0) {
viewModel.setDeleteExported(deleteExportedState)
}
viewModel.deleteSelectedPhotos(finalDeleteExported)
showDeleteDialog = false
}
) {
@@ -103,6 +103,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
val openAIApiKey = userPreferencesRepository.userPreferences.map { it.openAIApiKey }
.stateIn(viewModelScope, SharingStarted.Eagerly, "")
val deleteExported: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.deleteExported }
.stateIn(viewModelScope, SharingStarted.Eagerly, true)
// 计费管理器
private val billingManager = com.hinnka.mycamera.billing.BillingManagerImpl(application)
val isPurchased = billingManager.isPurchased
@@ -1302,6 +1306,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
}
}
fun setDeleteExported(enabled: Boolean) {
viewModelScope.launch {
userPreferencesRepository.saveDeleteExported(enabled)
}
}
/**
* 批量删除选中的照片
*
@@ -126,6 +126,7 @@
<string name="delete_confirm">删除这张照片吗?</string>
<string name="delete_multiple_confirm">删除 %d 张照片吗?</string>
<string name="delete_exported_photos">同时删除系统相册中的导出图</string>
<string name="delete_exported_photos_count">同时删除 %d 张已导出照片</string>
<string name="delete_system_warning">注意:此操作将同步删除已导出至系统相册的照片。系统会弹出删除确认,即使拒绝也不影响删除 App 内的照片。</string>
<string name="no_photos">暂无照片</string>
<string name="photo_info">照片信息</string>
@@ -68,6 +68,7 @@
<string name="delete_confirm">刪除這張照片嗎?</string>
<string name="delete_multiple_confirm">刪除 %d 張照片嗎?</string>
<string name="delete_exported_photos">同時刪除系統相冊中的導出圖</string>
<string name="delete_exported_photos_count">同時刪除 %d 張已導出照片</string>
<string name="delete_system_warning">注意:此操作將同步刪除已匯出至系統相簿的照片。系統會彈出刪除確認,即使拒絕也不影響刪除 App 內的相片。</string>
<string name="no_photos">暫無相片</string>
+1
View File
@@ -128,6 +128,7 @@
<string name="delete_confirm">Delete this photo?</string>
<string name="delete_multiple_confirm">Delete %d photos?</string>
<string name="delete_exported_photos">Also delete from system gallery</string>
<string name="delete_exported_photos_count">Also delete %d exported photos</string>
<string name="delete_system_warning">Note: Exported photos in the system gallery will also be removed. A system prompt will appear; declining it will only cancel the system deletion, while the app version will still be deleted.</string>
<string name="no_photos">No photos yet</string>
<string name="photo_info">Photo Info</string>