feat: support batch RAW DCP import
This commit is contained in:
1 parent
0d964f6b46
commit
5843dd9644
7 files changed
+93
-17
No files matched your search
@@ -241,17 +241,27 @@ fun PhotoEditScreen(
|
||||
}
|
||||
|
||||
val rawDcpLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenDocument()
|
||||
) { uri ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments()
|
||||
) { uris ->
|
||||
if (uris.isEmpty()) return@rememberLauncherForActivityResult
|
||||
val photo = currentPhoto ?: return@rememberLauncherForActivityResult
|
||||
scope.launch {
|
||||
val imported = viewModel.importRawDcp(uri)
|
||||
if (imported != null) {
|
||||
viewModel.saveRawDcpSelection(photo, imported.id)
|
||||
Toast.makeText(context, context.getString(R.string.raw_dcp_import_success, imported.getName()), Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
Toast.makeText(context, context.getString(R.string.raw_dcp_import_failed), Toast.LENGTH_SHORT).show()
|
||||
val importedDcps = viewModel.importRawDcps(uris)
|
||||
val failedCount = uris.size - importedDcps.size
|
||||
importedDcps.lastOrNull()?.let { viewModel.saveRawDcpSelection(photo, it.id) }
|
||||
when {
|
||||
importedDcps.size == 1 && failedCount == 0 -> {
|
||||
Toast.makeText(context, context.getString(R.string.raw_dcp_import_success, importedDcps.first().getName()), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
importedDcps.isNotEmpty() && failedCount == 0 -> {
|
||||
Toast.makeText(context, context.getString(R.string.raw_dcp_import_success_count, importedDcps.size), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
importedDcps.isNotEmpty() -> {
|
||||
Toast.makeText(context, context.getString(R.string.raw_dcp_import_partial, importedDcps.size, failedCount), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
else -> {
|
||||
Toast.makeText(context, context.getString(R.string.raw_dcp_import_failed), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,14 +242,39 @@ fun SettingsScreen(
|
||||
}
|
||||
|
||||
val importDcpLauncher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.OpenDocument()
|
||||
) { uri ->
|
||||
uri?.let {
|
||||
viewModel.importRawDcp(it) { success ->
|
||||
if (success) {
|
||||
android.widget.Toast.makeText(context, R.string.import_success, android.widget.Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
android.widget.Toast.makeText(context, R.string.import_failed, android.widget.Toast.LENGTH_SHORT).show()
|
||||
ActivityResultContracts.OpenMultipleDocuments()
|
||||
) { uris ->
|
||||
if (uris.isNotEmpty()) {
|
||||
viewModel.importRawDcps(uris) { importedDcps, failedCount ->
|
||||
when {
|
||||
importedDcps.size == 1 && failedCount == 0 -> {
|
||||
android.widget.Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.raw_dcp_import_success, importedDcps.first().getName()),
|
||||
android.widget.Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
importedDcps.isNotEmpty() && failedCount == 0 -> {
|
||||
android.widget.Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.raw_dcp_import_success_count, importedDcps.size),
|
||||
android.widget.Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
importedDcps.isNotEmpty() -> {
|
||||
android.widget.Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.raw_dcp_import_partial, importedDcps.size, failedCount),
|
||||
android.widget.Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
else -> {
|
||||
android.widget.Toast.makeText(
|
||||
context,
|
||||
R.string.raw_dcp_import_failed,
|
||||
android.widget.Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.SafeImage
|
||||
import com.hinnka.mycamera.phantom.PhantomWidgetProvider
|
||||
import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.DcpInfo
|
||||
import com.hinnka.mycamera.color.TransferCurve
|
||||
import com.hinnka.mycamera.raw.RawProfile
|
||||
import com.hinnka.mycamera.screencapture.PhantomPipCrop
|
||||
@@ -747,6 +748,24 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun importRawDcps(uris: List<Uri>, onComplete: (importedDcps: List<DcpInfo>, failedCount: Int) -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val importedIds = withContext(Dispatchers.IO) {
|
||||
uris.mapNotNull { uri ->
|
||||
contentRepository.getCustomImportManager().importDcp(uri)
|
||||
}
|
||||
}
|
||||
val importedDcps = if (importedIds.isNotEmpty()) {
|
||||
contentRepository.refreshCustomContent()
|
||||
val dcpById = contentRepository.getAvailableDcps().associateBy { it.id }
|
||||
importedIds.mapNotNull { dcpById[it] }
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
onComplete(importedDcps, uris.size - importedDcps.size)
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteRawDcp(dcpId: String, onComplete: (Boolean) -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val success = withContext(Dispatchers.IO) {
|
||||
|
||||
@@ -1807,6 +1807,22 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun importRawDcps(uris: List<Uri>): List<DcpInfo> {
|
||||
if (uris.isEmpty()) return emptyList()
|
||||
val importedIds = withContext(Dispatchers.IO) {
|
||||
uris.mapNotNull { uri ->
|
||||
contentRepository.getCustomImportManager().importDcp(uri)
|
||||
}
|
||||
}
|
||||
if (importedIds.isEmpty()) return emptyList()
|
||||
|
||||
contentRepository.refreshCustomContent()
|
||||
val dcpById = contentRepository.getAvailableDcps().associateBy { it.id }
|
||||
val importedDcps = importedIds.mapNotNull { dcpById[it] }
|
||||
importedDcps.lastOrNull()?.let { editRawDcpId.value = it.id }
|
||||
return importedDcps
|
||||
}
|
||||
|
||||
fun deleteRawDcp(mediaData: MediaData, dcpId: String, onComplete: (Boolean) -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val success = withContext(Dispatchers.IO) {
|
||||
|
||||
@@ -208,6 +208,8 @@
|
||||
<string name="raw_dcp_title">RAW DCP</string>
|
||||
<string name="raw_dcp_import">导入 DCP</string>
|
||||
<string name="raw_dcp_import_success">已导入 DCP:%1$s</string>
|
||||
<string name="raw_dcp_import_success_count">已导入 %1$d 个 DCP 配置</string>
|
||||
<string name="raw_dcp_import_partial">已导入 %1$d 个 DCP 配置,%2$d 个失败</string>
|
||||
<string name="raw_dcp_import_failed">导入 DCP 失败</string>
|
||||
<string name="raw_dcp_delete_success">已删除 DCP</string>
|
||||
<string name="raw_dcp_delete_failed">删除 DCP 失败</string>
|
||||
|
||||
@@ -413,6 +413,8 @@
|
||||
<string name="settings_raw_restore_lut_description">選擇用於 RAW 色彩還原的 LUT。選擇「無」以獲得 Log 風格輸出。</string>
|
||||
<string name="settings_raw_profile">RAW 風格方案</string>
|
||||
<string name="settings_raw_profile_description">統一設定 RAW 的色彩空間、Log 曲線與還原 LUT。</string>
|
||||
<string name="raw_dcp_import_success_count">已匯入 %1$d 個 DCP 設定檔</string>
|
||||
<string name="raw_dcp_import_partial">已匯入 %1$d 個 DCP 設定檔,%2$d 個失敗</string>
|
||||
<string name="raw_dcp_delete_success">已刪除 DCP</string>
|
||||
<string name="raw_dcp_delete_failed">刪除 DCP 失敗</string>
|
||||
<string name="settings_dro_mode">RAW 動態範圍最佳化 (DRO)</string>
|
||||
|
||||
@@ -210,6 +210,8 @@
|
||||
<string name="raw_dcp_title">RAW DCP</string>
|
||||
<string name="raw_dcp_import">Import DCP</string>
|
||||
<string name="raw_dcp_import_success">Imported DCP: %1$s</string>
|
||||
<string name="raw_dcp_import_success_count">Imported %1$d DCP profiles</string>
|
||||
<string name="raw_dcp_import_partial">Imported %1$d DCP profiles, %2$d failed</string>
|
||||
<string name="raw_dcp_import_failed">Failed to import DCP</string>
|
||||
<string name="raw_dcp_delete_success">Deleted DCP</string>
|
||||
<string name="raw_dcp_delete_failed">Failed to delete DCP</string>
|
||||
|
||||
Reference in new issue
Block a user