fix: bugs
This commit is contained in:
1 parent
1b044ae2dc
commit
e9d34263ff
13 files changed
+288
-271
No files matched your search
@@ -16,7 +16,8 @@ data class PhotoData(
|
||||
val height: Int = 0,
|
||||
var isMotionPhoto: Boolean = false,
|
||||
var isBurstPhoto: Boolean = false,
|
||||
var metadata: PhotoMetadata? = null
|
||||
var metadata: PhotoMetadata? = null,
|
||||
var relatedPhoto: PhotoData? = null
|
||||
) {
|
||||
/**
|
||||
* 格式化的拍摄时间
|
||||
|
||||
@@ -1309,7 +1309,6 @@ object PhotoManager {
|
||||
uri: Uri,
|
||||
lutId: String?,
|
||||
photoId: String? = null,
|
||||
sourceUri: String? = null
|
||||
): String? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
@@ -1320,12 +1319,20 @@ object PhotoManager {
|
||||
val metadataFile = File(photoDir, METADATA_FILE)
|
||||
val thumbnailFile = File(photoDir, THUMBNAIL_FILE)
|
||||
|
||||
if (photoFile.exists()) {
|
||||
val bakPhotoFile = File(photoDir, "original.${photoFile.lastModified()}.jpg")
|
||||
photoFile.renameTo(bakPhotoFile)
|
||||
}
|
||||
|
||||
if (dngFile.exists()) {
|
||||
val bakPhotoFile = File(photoDir, "original.${photoFile.lastModified()}.dng")
|
||||
dngFile.renameTo(bakPhotoFile)
|
||||
}
|
||||
|
||||
// 2. 读取元数据以获取旋转信息
|
||||
val metadata = PhotoMetadata.fromUri(context, uri).copy(
|
||||
lutId = lutId,
|
||||
sourceUri = sourceUri ?: metadataFile.takeIf { it.exists() }
|
||||
?.let { PhotoMetadata.fromJson(it.readText())?.sourceUri }
|
||||
sourceUri = uri.toString()
|
||||
)
|
||||
|
||||
// 1. 检测是否为 RAW 文件
|
||||
|
||||
@@ -164,6 +164,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
OpenableColumns.DISPLAY_NAME,
|
||||
MediaStore.MediaColumns.DATA,
|
||||
MediaStore.MediaColumns.SIZE,
|
||||
MediaStore.MediaColumns.DATE_TAKEN,
|
||||
MediaStore.MediaColumns.IS_PENDING,
|
||||
MediaStore.MediaColumns.IS_TRASHED,
|
||||
MediaStore.MediaColumns.RELATIVE_PATH,
|
||||
@@ -176,6 +177,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
||||
val pendingIndex = cursor.getColumnIndex(MediaStore.Images.Media.IS_PENDING)
|
||||
val sizeIndex = cursor.getColumnIndex(MediaStore.MediaColumns.SIZE)
|
||||
val dateTakenIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATE_TAKEN)
|
||||
val dataIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATA)
|
||||
val isTrashedIndex = cursor.getColumnIndex(MediaStore.MediaColumns.IS_TRASHED)
|
||||
val relativePathIndex =
|
||||
@@ -184,6 +186,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
val name = if (nameIndex != -1) cursor.getString(nameIndex) else "Unknown"
|
||||
val isPending = if (pendingIndex != -1) cursor.getInt(pendingIndex) else 0
|
||||
val size = if (sizeIndex != -1) cursor.getLong(sizeIndex) else 0L
|
||||
val dateTaken = if (dateTakenIndex != -1) cursor.getLong(dateTakenIndex) else 0L
|
||||
val data = if (dataIndex != -1) cursor.getString(dataIndex) else ""
|
||||
val isTrashed = if (isTrashedIndex != -1) cursor.getInt(isTrashedIndex) else 0
|
||||
val relativePath =
|
||||
@@ -192,6 +195,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
if (isPending != 0) return
|
||||
if (isTrashed != 0) return
|
||||
if (size <= MIN_IMPORT_SIZE) return
|
||||
if (dateTaken < System.currentTimeMillis() - 300 * 1000L) return
|
||||
if (!relativePath.contains(
|
||||
"DCIM/Camera",
|
||||
ignoreCase = true
|
||||
@@ -320,7 +324,7 @@ class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryO
|
||||
val saveAsNew = preferences?.phantomSaveAsNew ?: false
|
||||
val existingPhotoId = if (processingInfo?.uri == uri) processingInfo?.photoId else null
|
||||
val photoId =
|
||||
PhotoManager.importPhoto(context, uri, lutId, existingPhotoId, uri.toString()) ?: run {
|
||||
PhotoManager.importPhoto(context, uri, lutId, existingPhotoId) ?: run {
|
||||
return@withContext
|
||||
}
|
||||
val metadata = PhotoManager.loadMetadata(context, photoId) ?: run {
|
||||
|
||||
@@ -54,16 +54,6 @@ fun LutEditBottomSheet(
|
||||
.fillMaxWidth()
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
// 备注栏 (最上面单独起一行)
|
||||
com.hinnka.mycamera.ui.components.ColorRecipeRemarksBar(
|
||||
remarks = editingParams.remarks,
|
||||
onRemarksChange = {
|
||||
editingParams = editingParams.copy(remarks = it)
|
||||
viewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
},
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
)
|
||||
|
||||
LutIntensitySlider(
|
||||
intensity = editingParams.lutIntensity,
|
||||
onIntensityChange = {
|
||||
@@ -79,6 +69,10 @@ fun LutEditBottomSheet(
|
||||
editingParams = param.setValue(editingParams, value)
|
||||
viewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
},
|
||||
onRemarksChange = {
|
||||
editingParams = editingParams.copy(remarks = it)
|
||||
viewModel.saveLutColorRecipe(lutId, editingParams)
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 16.dp)
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.hinnka.mycamera.model.RecipeParam
|
||||
fun ColorRecipePanel(
|
||||
currentParams: ColorRecipeParams,
|
||||
onParamChange: (RecipeParam, Float) -> Unit,
|
||||
onRemarksChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var selectedTabIndex by remember { mutableIntStateOf(0) }
|
||||
@@ -54,6 +55,7 @@ fun ColorRecipePanel(
|
||||
R.string.recipe_tab_color,
|
||||
R.string.recipe_tab_texture,
|
||||
R.string.recipe_tab_lens,
|
||||
R.string.recipe_tab_remarks,
|
||||
)
|
||||
val parameterGroups = listOf(
|
||||
listOf(
|
||||
@@ -113,7 +115,7 @@ fun ColorRecipePanel(
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(title),
|
||||
fontSize = 12.sp,
|
||||
fontSize = 11.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
|
||||
color = if (isSelected) Color.White else Color.White.copy(alpha = 0.6f)
|
||||
)
|
||||
@@ -124,8 +126,8 @@ fun ColorRecipePanel(
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
// 当前选中的参数组
|
||||
Column(
|
||||
// 当前选中的内容
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
@@ -133,21 +135,35 @@ fun ColorRecipePanel(
|
||||
RoundedCornerShape(8.dp)
|
||||
)
|
||||
.padding(8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||
contentAlignment = Alignment.TopCenter
|
||||
) {
|
||||
parameterGroups[selectedTabIndex].forEach { param ->
|
||||
key(param) {
|
||||
ColorRecipeSlider(
|
||||
param = param,
|
||||
value = param.getValue(currentParams),
|
||||
onValueChange = { newValue ->
|
||||
onParamChange(param, newValue)
|
||||
},
|
||||
onDoubleTap = {
|
||||
onParamChange(param, param.defaultValue)
|
||||
if (selectedTabIndex < parameterGroups.size) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
parameterGroups[selectedTabIndex].forEach { param ->
|
||||
key(param) {
|
||||
ColorRecipeSlider(
|
||||
param = param,
|
||||
value = param.getValue(currentParams),
|
||||
onValueChange = { newValue ->
|
||||
onParamChange(param, newValue)
|
||||
},
|
||||
onDoubleTap = {
|
||||
onParamChange(param, param.defaultValue)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 备注 Tab
|
||||
ColorRecipeRemarksBar(
|
||||
remarks = currentParams.remarks,
|
||||
onRemarksChange = onRemarksChange,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,105 +178,36 @@ fun ColorRecipeRemarksBar(
|
||||
onRemarksChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var isEditing by remember { mutableStateOf(false) }
|
||||
var text by remember(remarks) { mutableStateOf(remarks) }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
LaunchedEffect(isEditing) {
|
||||
if (isEditing) {
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color.White.copy(alpha = 0.05f)) // 极简半透明白
|
||||
.border(
|
||||
width = 0.5.dp,
|
||||
color = if (isEditing) Color(0xFFFFD700).copy(alpha = 0.5f) else Color.White.copy(alpha = 0.1f),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
.clickable(enabled = !isEditing) { isEditing = true }
|
||||
.padding(horizontal = 14.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// 左侧提示图标
|
||||
Icon(
|
||||
imageVector = Icons.Default.Edit,
|
||||
contentDescription = null,
|
||||
tint = Color.White.copy(alpha = 0.3f),
|
||||
modifier = Modifier.size(14.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(10.dp))
|
||||
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
if (isEditing) {
|
||||
BasicTextField(
|
||||
value = text,
|
||||
onValueChange = { text = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.focusRequester(focusRequester),
|
||||
textStyle = TextStyle(
|
||||
color = Color.White,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
),
|
||||
cursorBrush = SolidColor(Color.White),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
onRemarksChange(text)
|
||||
isEditing = false
|
||||
focusManager.clearFocus()
|
||||
}
|
||||
),
|
||||
decorationBox = { innerTextField ->
|
||||
if (text.isEmpty()) {
|
||||
Text(
|
||||
text = stringResource(R.string.recipe_placeholder_remarks),
|
||||
color = Color.White.copy(alpha = 0.25f),
|
||||
fontSize = 13.sp
|
||||
)
|
||||
}
|
||||
innerTextField()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
BasicTextField(
|
||||
value = text,
|
||||
onValueChange = {
|
||||
text = it
|
||||
onRemarksChange(it) // 实时保存
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 120.dp, max = 300.dp),
|
||||
textStyle = TextStyle(
|
||||
color = Color.White,
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 15.sp,
|
||||
),
|
||||
cursorBrush = SolidColor(Color.White),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
imeAction = ImeAction.Default // 允许换行
|
||||
),
|
||||
decorationBox = { innerTextField ->
|
||||
if (text.isEmpty()) {
|
||||
Text(
|
||||
text = if (remarks.isEmpty()) stringResource(R.string.recipe_placeholder_remarks) else remarks,
|
||||
color = if (remarks.isEmpty()) Color.White.copy(alpha = 0.3f) else Color.White,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
maxLines = 1,
|
||||
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis
|
||||
text = stringResource(R.string.recipe_placeholder_remarks),
|
||||
color = Color.White.copy(alpha = 0.25f),
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 15.sp,
|
||||
)
|
||||
}
|
||||
innerTextField()
|
||||
}
|
||||
|
||||
// 状态切换按钮
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (isEditing) {
|
||||
onRemarksChange(text)
|
||||
focusManager.clearFocus()
|
||||
}
|
||||
isEditing = !isEditing
|
||||
},
|
||||
modifier = Modifier.size(20.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (isEditing) Icons.Default.Check else Icons.Default.Edit,
|
||||
contentDescription = null,
|
||||
tint = if (isEditing) Color(0xFFFFD700) else Color.White.copy(alpha = 0.5f),
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -342,27 +342,6 @@ private fun LutItem(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义标识
|
||||
if (isCustom) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopStart)
|
||||
.background(
|
||||
color = Color(0xFF4CAF50), // 绿色表示自定义
|
||||
shape = RoundedCornerShape(bottomEnd = 4.dp)
|
||||
)
|
||||
.padding(horizontal = 4.dp, vertical = 2.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.custom_tag),
|
||||
color = Color.White,
|
||||
fontSize = 8.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
lineHeight = 8.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
@@ -623,7 +623,7 @@ private fun PhotoGridItem(
|
||||
}
|
||||
|
||||
// 关联标记 (System Tab 专用,表示该照片在 App 内有对应版本)
|
||||
if (viewModel.selectedTab == GalleryTab.SYSTEM && photo.metadata != null) {
|
||||
if (viewModel.selectedTab == GalleryTab.SYSTEM && photo.relatedPhoto != null) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
|
||||
@@ -340,7 +340,7 @@ fun PhotoDetailScreen(
|
||||
}
|
||||
|
||||
// 导出
|
||||
if (viewModel.selectedTab == GalleryTab.PHOTON || currentPhoto?.metadata?.sourceUri != null) {
|
||||
if (viewModel.selectedTab == GalleryTab.PHOTON || currentPhoto?.relatedPhoto != null) {
|
||||
IconButton(
|
||||
onClick = { currentPhoto?.let { showExportDialog = true } },
|
||||
modifier = Modifier
|
||||
@@ -700,8 +700,8 @@ private fun ZoomableImage(
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
// 使用 hashCode() 代替 toJson() 序列化,避免 composition 时做 JSON 序列化
|
||||
val metadataHash = remember(photo.metadata) {
|
||||
photo.metadata?.hashCode() ?: 0
|
||||
val metadataHash = remember(photo.metadata, photo.relatedPhoto?.metadata) {
|
||||
photo.metadata?.hashCode() ?: photo.relatedPhoto?.metadata?.hashCode() ?: 0
|
||||
}
|
||||
|
||||
var bitmap by remember { mutableStateOf<Bitmap?>(null) }
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.hinnka.mycamera.ui.settings
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
@@ -37,6 +41,7 @@ import androidx.compose.material.icons.filled.ChevronRight
|
||||
import androidx.compose.material.icons.filled.ExpandLess
|
||||
import androidx.compose.material.icons.filled.ExpandMore
|
||||
import androidx.compose.material.icons.filled.FilterNone
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@@ -48,11 +53,12 @@ import androidx.compose.material3.SwitchDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ScrollableTabRow
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.TabRow
|
||||
import androidx.compose.material3.TabRowDefaults
|
||||
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -76,6 +82,9 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.compose.LifecycleEventEffect
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.data.VolumeKeyAction
|
||||
import com.hinnka.mycamera.frame.FrameInfo
|
||||
@@ -83,6 +92,7 @@ import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.LogCurve
|
||||
import com.hinnka.mycamera.ui.camera.autoRotate
|
||||
import com.hinnka.mycamera.ui.components.LogViewerDialog
|
||||
import com.hinnka.mycamera.ui.components.PaymentDialog
|
||||
import com.hinnka.mycamera.ui.components.SliderSettingItem
|
||||
import com.hinnka.mycamera.ui.components.rememberBackgroundPainter
|
||||
import com.hinnka.mycamera.utils.DeviceUtil
|
||||
@@ -162,9 +172,18 @@ fun SettingsScreen(
|
||||
var softwareProcessingExpanded by remember { mutableStateOf(false) }
|
||||
var calibrationExpanded by remember { mutableStateOf(false) }
|
||||
var availableRawLutMap by remember { mutableStateOf(listOf<Pair<String, String>>()) }
|
||||
var showGhostPermissionDialog by remember { mutableStateOf(false) }
|
||||
var isGhostPermissionFlowActive by remember { mutableStateOf(false) }
|
||||
|
||||
val noneStr = stringResource(R.string.none)
|
||||
|
||||
val ghostLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.StartActivityForResult(),
|
||||
onResult = { _ ->
|
||||
// Results are handled via the ON_RESUME lifecycle effect to avoid self-reference issues
|
||||
}
|
||||
)
|
||||
|
||||
LaunchedEffect(logCurve) {
|
||||
availableRawLutMap = listOf("none" to noneStr) + viewModel.getAvailableRawLutList(context, logCurve)
|
||||
.map {
|
||||
@@ -172,6 +191,121 @@ fun SettingsScreen(
|
||||
}
|
||||
}
|
||||
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
|
||||
if (isGhostPermissionFlowActive) {
|
||||
val hasOverlay = Settings.canDrawOverlays(context)
|
||||
val hasFiles = Environment.isExternalStorageManager()
|
||||
|
||||
if (hasOverlay && !hasFiles) {
|
||||
// Overlay granted, now request files
|
||||
ghostLauncher.launch(
|
||||
Intent(
|
||||
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
||||
("package:${context.packageName}").toUri()
|
||||
)
|
||||
)
|
||||
} else if (hasOverlay) {
|
||||
// All permissions granted
|
||||
isGhostPermissionFlowActive = false
|
||||
if (!phantomMode) {
|
||||
viewModel.togglePhantomMode()
|
||||
}
|
||||
} else {
|
||||
// If overlay is still missing after returning, user might have cancelled
|
||||
// We stop the automatic flow to avoid getting stuck
|
||||
isGhostPermissionFlowActive = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(viewModel.showGhostPermissions) {
|
||||
if (viewModel.showGhostPermissions) {
|
||||
showGhostPermissionDialog = true
|
||||
viewModel.showGhostPermissions = false
|
||||
}
|
||||
}
|
||||
|
||||
if (viewModel.showPaymentDialog) {
|
||||
val activity = context.findActivity()
|
||||
PaymentDialog(
|
||||
onDismiss = { viewModel.showPaymentDialog = false },
|
||||
onPurchase = {
|
||||
if (activity != null) {
|
||||
viewModel.purchase(activity)
|
||||
}
|
||||
viewModel.showPaymentDialog = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showGhostPermissionDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showGhostPermissionDialog = false },
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(R.string.ghost_mode_dialog_title),
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.ghost_mode_dialog_description),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.ghost_mode_permissions_required),
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.ghost_mode_overlay_permission),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.ghost_mode_file_permission),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showGhostPermissionDialog = false
|
||||
isGhostPermissionFlowActive = true
|
||||
if (!Settings.canDrawOverlays(context)) {
|
||||
ghostLauncher.launch(
|
||||
Intent(
|
||||
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
("package:${context.packageName}").toUri()
|
||||
)
|
||||
)
|
||||
} else if (!Environment.isExternalStorageManager()) {
|
||||
ghostLauncher.launch(
|
||||
Intent(
|
||||
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
||||
("package:${context.packageName}").toUri()
|
||||
)
|
||||
)
|
||||
} else {
|
||||
isGhostPermissionFlowActive = false
|
||||
viewModel.togglePhantomMode()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.ghost_mode_dialog_confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showGhostPermissionDialog = false }) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val backgroundPainter = rememberBackgroundPainter(viewModel)
|
||||
Column(
|
||||
modifier = modifier
|
||||
@@ -206,15 +340,20 @@ fun SettingsScreen(
|
||||
)
|
||||
)
|
||||
|
||||
val general = stringResource(R.string.general)
|
||||
val imaging = stringResource(R.string.imaging)
|
||||
val phantom = stringResource(R.string.phantom)
|
||||
val about = stringResource(R.string.about)
|
||||
|
||||
// Tab 选择器
|
||||
val tabs = remember {
|
||||
mutableStateListOf<Pair<SettingsTab, String>>().apply {
|
||||
add(SettingsTab.GENERAL to "常用")
|
||||
add(SettingsTab.IMAGING to "影像")
|
||||
add(SettingsTab.GENERAL to general)
|
||||
add(SettingsTab.IMAGING to imaging)
|
||||
if (DeviceUtil.isChinaFlavor) {
|
||||
add(SettingsTab.PHANTOM to "幻影")
|
||||
add(SettingsTab.PHANTOM to phantom)
|
||||
}
|
||||
add(SettingsTab.ABOUT to "关于")
|
||||
add(SettingsTab.ABOUT to about)
|
||||
}
|
||||
}
|
||||
val selectedTabIndex = tabs.indexOfFirst { it.first == selectedTab }.coerceAtLeast(0)
|
||||
@@ -723,7 +862,13 @@ fun SettingsScreen(
|
||||
title = stringResource(R.string.ghost_mode),
|
||||
description = stringResource(R.string.ghost_mode_dialog_description),
|
||||
checked = phantomMode,
|
||||
onCheckedChange = { viewModel.togglePhantomMode() }
|
||||
onCheckedChange = {
|
||||
if (it && (!Settings.canDrawOverlays(context) || !Environment.isExternalStorageManager())) {
|
||||
showGhostPermissionDialog = true
|
||||
} else {
|
||||
viewModel.togglePhantomMode()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
@@ -1528,7 +1673,8 @@ fun <T> QualityLevelSetting(
|
||||
levels.forEach { (level, label) ->
|
||||
val isSelected = currentLevel == level
|
||||
Box(
|
||||
modifier = Modifier.height(36.dp)
|
||||
modifier = Modifier
|
||||
.height(36.dp)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(
|
||||
if (isSelected) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.1f)
|
||||
@@ -1542,7 +1688,9 @@ fun <T> QualityLevelSetting(
|
||||
fontSize = 12.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(horizontal = 4.dp).widthIn(min = 44.dp)
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 4.dp)
|
||||
.widthIn(min = 44.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -862,6 +862,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
fun setUseBuiltInAiService(use: Boolean) {
|
||||
if (use && !isPurchased.value) {
|
||||
showPaymentDialog = true
|
||||
return
|
||||
}
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveUseBuiltInAiService(use)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.graphics.scale
|
||||
|
||||
/**
|
||||
* 相册 Tab
|
||||
@@ -112,21 +114,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val photonMap = mutableMapOf<String, PhotoData>()
|
||||
p.forEach { photo ->
|
||||
photo.metadata?.sourceUri?.let { photonMap[it] = photo }
|
||||
photo.metadata?.exportedUris?.forEach { exportedUri ->
|
||||
photonMap[exportedUri] = photo
|
||||
}
|
||||
}
|
||||
|
||||
s.map { systemPhoto ->
|
||||
photonMap[systemPhoto.uri.toString()]?.let { photonPhoto ->
|
||||
systemPhoto.copy(
|
||||
uri = photonPhoto.uri,
|
||||
metadata = photonPhoto.metadata,
|
||||
thumbnailUri = photonPhoto.thumbnailUri,
|
||||
isMotionPhoto = systemPhoto.isMotionPhoto || photonPhoto.isMotionPhoto,
|
||||
isBurstPhoto = systemPhoto.isBurstPhoto || photonPhoto.isBurstPhoto,
|
||||
width = if (systemPhoto.width > 0) systemPhoto.width else photonPhoto.width,
|
||||
height = if (systemPhoto.height > 0) systemPhoto.height else photonPhoto.height
|
||||
relatedPhoto = photonPhoto
|
||||
)
|
||||
} ?: systemPhoto
|
||||
}
|
||||
@@ -410,7 +403,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
private suspend fun loadSpecificPhotoMetadata(context: Context, photo: PhotoData): PhotoData =
|
||||
withContext(Dispatchers.IO) {
|
||||
var metadata = PhotoManager.loadMetadata(context, photo.id)
|
||||
val metadata = PhotoManager.loadMetadata(context, photo.id)
|
||||
var updatedPhoto = if (metadata != null) {
|
||||
photo.copy(
|
||||
metadata = metadata,
|
||||
@@ -553,15 +546,19 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
return
|
||||
}
|
||||
|
||||
photo.relatedPhoto?.metadata?.let { m ->
|
||||
currentPhotoMetadataId = photo.id
|
||||
applyMetadataToEditState(m)
|
||||
return
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
val context = getApplication<Application>()
|
||||
|
||||
// 在 IO 线程加载元数据
|
||||
val metadata = withContext(Dispatchers.IO) {
|
||||
if (selectedTab == GalleryTab.SYSTEM) {
|
||||
val associatedPhoto =
|
||||
_photos.value.find { it.metadata?.sourceUri == photo.uri.toString() }
|
||||
associatedPhoto?.metadata ?: PhotoMetadata.fromUri(context, photo.uri)
|
||||
PhotoMetadata.fromUri(context, photo.uri)
|
||||
} else {
|
||||
PhotoManager.loadMetadata(context, photo.id)
|
||||
}
|
||||
@@ -733,9 +730,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
pendingDeleteSystemPhoto = photo
|
||||
systemDeletePendingIntent = pendingIntent
|
||||
PLog.d(TAG, "Set system delete pending intent for photo ${photo.id}")
|
||||
} else {
|
||||
// TODO: Handle Android 10- or direct deletion if needed, but usually createSystemDeleteRequest covers API 30+
|
||||
PLog.w(TAG, "Failed to create system delete request for ${photo.id}")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -746,22 +740,17 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
return
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// Android 11+: 检查是否有导出的照片
|
||||
val pendingIntent = getDeleteRequest(photo)
|
||||
// Android 11+: 检查是否有导出的照片
|
||||
val pendingIntent = getDeleteRequest(photo)
|
||||
|
||||
if (pendingIntent != null) {
|
||||
// 有导出的照片,需要用户确认
|
||||
pendingDeletePhoto = photo
|
||||
deletePendingIntent = pendingIntent
|
||||
PLog.d(TAG, "Set delete pending intent for photo ${photo.id}")
|
||||
} else {
|
||||
// 没有导出的照片,直接删除应用内照片
|
||||
deletePhotoOnlyInternal(photo)
|
||||
}
|
||||
if (pendingIntent != null) {
|
||||
// 有导出的照片,需要用户确认
|
||||
pendingDeletePhoto = photo
|
||||
deletePendingIntent = pendingIntent
|
||||
PLog.d(TAG, "Set delete pending intent for photo ${photo.id}")
|
||||
} else {
|
||||
// Android 10 及以下: 直接删除所有照片
|
||||
deletePhotoDirectly(photo)
|
||||
// 没有导出的照片,直接删除应用内照片
|
||||
deletePhotoOnlyInternal(photo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,21 +792,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
batchDeletePendingIntent = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接删除照片(不检查系统相册)
|
||||
*/
|
||||
private fun deletePhotoDirectly(photo: PhotoData) {
|
||||
viewModelScope.launch {
|
||||
val success = repository.deletePhoto(photo)
|
||||
if (success) {
|
||||
loadPhotos()
|
||||
PLog.d(TAG, "Photo deleted: ${photo.id}")
|
||||
} else {
|
||||
PLog.e(TAG, "Failed to delete photo: ${photo.id}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅删除应用内部的照片(在用户确认删除系统相册照片后调用)
|
||||
*/
|
||||
@@ -845,7 +819,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
* 系统相册照片删除确认后的回调
|
||||
*/
|
||||
fun deleteSystemPhotoAfterConfirmation(onComplete: (Boolean) -> Unit = {}) {
|
||||
val photo = pendingDeleteSystemPhoto ?: return
|
||||
viewModelScope.launch {
|
||||
// 系统照片已经被 MediaStore 删除,我们只需要刷新列表
|
||||
loadSystemPhotos(reset = true)
|
||||
@@ -860,15 +833,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前照片
|
||||
*/
|
||||
fun deleteCurrentPhoto() {
|
||||
getCurrentPhoto()?.let { photo ->
|
||||
requestDeletePhoto(photo)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设为连拍主图
|
||||
*/
|
||||
@@ -902,8 +866,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
viewModelScope.launch {
|
||||
val context = getApplication<Application>()
|
||||
val uris = toDelete.mapNotNull { photo ->
|
||||
// 如果是本地关联的照片,优先取 sourceUri;否则直接取 photo.uri
|
||||
val uri = photo.metadata?.sourceUri?.let { Uri.parse(it) } ?: photo.uri
|
||||
val uri = photo.uri
|
||||
if (uri.scheme == "content") uri else {
|
||||
PLog.w(TAG, "Ignoring non-content URI in system delete: $uri")
|
||||
null
|
||||
@@ -949,7 +912,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val metadata = PhotoManager.loadMetadata(context, photo.id)
|
||||
metadata?.exportedUris?.forEach { uriString ->
|
||||
try {
|
||||
allExportedUris.add(Uri.parse(uriString))
|
||||
allExportedUris.add(uriString.toUri())
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Invalid URI: $uriString", e)
|
||||
}
|
||||
@@ -1004,18 +967,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接批量删除照片(不检查系统相册)
|
||||
*/
|
||||
private fun deleteBatchPhotosDirectly(photos: List<PhotoData>) {
|
||||
viewModelScope.launch {
|
||||
val deletedCount = repository.deletePhotos(photos)
|
||||
exitSelectionMode()
|
||||
loadPhotos()
|
||||
PLog.d(TAG, "Batch deleted $deletedCount photos")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除确认后的回调(在用户确认删除系统相册照片后调用)
|
||||
*/
|
||||
@@ -1299,13 +1250,6 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有预览缓存
|
||||
*/
|
||||
fun invalidateAllPreviewCache() {
|
||||
previewBitmapCache.evictAll()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用 LUT 和边框后的预览 Bitmap
|
||||
*/
|
||||
@@ -1325,8 +1269,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
val finalCNR: Float
|
||||
|
||||
val metadata =
|
||||
photo.metadata ?: PhotoManager.loadMetadata(getApplication(), photo.id)
|
||||
?: PhotoMetadata()
|
||||
photo.metadata
|
||||
?: photo.relatedPhoto?.metadata
|
||||
?: PhotoManager.loadMetadata(getApplication(), photo.id)
|
||||
?: PhotoMetadata()
|
||||
|
||||
if (useGlobalEdit) {
|
||||
finalMetadata = (currentPhotoMetadata ?: metadata).copy(
|
||||
@@ -1424,18 +1370,19 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
try {
|
||||
val context = getApplication<Application>()
|
||||
|
||||
// 处理系统相册照片:自动导入并关联
|
||||
val targetPhotoId = if (selectedTab == GalleryTab.SYSTEM) {
|
||||
// 检查是否已经导入过
|
||||
val existing =
|
||||
_photos.value.find { it.uri == photo.uri }
|
||||
existing?.id ?: PhotoManager.importPhoto(
|
||||
context,
|
||||
photo.uri,
|
||||
editLutId.value,
|
||||
photo.uri.lastPathSegment,
|
||||
sourceUri = photo.uri.toString()
|
||||
)
|
||||
photo.relatedPhoto?.id ?: run {
|
||||
val importedId = PhotoManager.importPhoto(
|
||||
context,
|
||||
photo.uri,
|
||||
editLutId.value
|
||||
)
|
||||
if (importedId != null) {
|
||||
photo.metadata = PhotoManager.loadMetadata(context, importedId)
|
||||
currentPhotoMetadata = photo.metadata
|
||||
}
|
||||
importedId
|
||||
}
|
||||
} else {
|
||||
photo.id
|
||||
}
|
||||
@@ -1539,7 +1486,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
viewModelScope.launch {
|
||||
var photoId = photo.id
|
||||
if (selectedTab == GalleryTab.SYSTEM) {
|
||||
photoId = _photos.value.find { it.metadata?.sourceUri == photo.uri.toString() }?.id ?: photoId
|
||||
photoId = photo.relatedPhoto?.id ?: photoId
|
||||
}
|
||||
val metadata = PhotoManager.loadMetadata(getApplication(), photoId) ?: photo.metadata
|
||||
?: PhotoMetadata()
|
||||
@@ -1639,40 +1586,18 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
billingManager.purchase(activity)
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新购买状态
|
||||
*/
|
||||
fun refreshPurchases() {
|
||||
billingManager.refresh()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义导入管理器
|
||||
*/
|
||||
fun getCustomImportManager() = contentRepository.getCustomImportManager()
|
||||
|
||||
/**
|
||||
* 刷新自定义内容(在导入新的LUT或边框后调用)
|
||||
* StateFlow 会自动通知订阅者更新
|
||||
*/
|
||||
fun refreshCustomContent() {
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
// 重新初始化内容仓库
|
||||
// StateFlow 会自动更新 availableLuts 和 availableFrames
|
||||
contentRepository.refreshCustomContent()
|
||||
}
|
||||
PLog.d(TAG, "Custom content refreshed via ContentRepository")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 估计 Bitmap 的平均亮度(调试用)
|
||||
*/
|
||||
private fun estimateAverageBrightness(bitmap: Bitmap): Float {
|
||||
return try {
|
||||
// 缩小尺寸以快速计算
|
||||
val scaledBitmap = Bitmap.createScaledBitmap(bitmap, 64, 64, false)
|
||||
val scaledBitmap = bitmap.scale(64, 64, false)
|
||||
val pixels = IntArray(64 * 64)
|
||||
scaledBitmap.getPixels(pixels, 0, 64, 0, 0, 64, 64)
|
||||
|
||||
|
||||
@@ -384,4 +384,8 @@
|
||||
<string name="settings_ai_model_select">点此选择模型…</string>
|
||||
<string name="settings_ai_model_fetching">正在请求列表…</string>
|
||||
<string name="settings_ai_model_empty">未找到任何可用模型</string>
|
||||
<string name="general">常用</string>
|
||||
<string name="imaging">影像</string>
|
||||
<string name="phantom">幻影</string>
|
||||
<string name="about">关于</string>
|
||||
</resources>
|
||||
@@ -384,4 +384,8 @@
|
||||
<string name="settings_ai_model_select">Select a model…</string>
|
||||
<string name="settings_ai_model_fetching">Fetching…</string>
|
||||
<string name="settings_ai_model_empty">No models found</string>
|
||||
<string name="general">General</string>
|
||||
<string name="imaging">Imaging</string>
|
||||
<string name="phantom">Phantom</string>
|
||||
<string name="about">About</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user