feat: photo batch import

This commit is contained in:
zhoubinjia committed 2026-01-15 14:38:50 +08:00
1 parent 59df8b09dd
commit 119c6e092f
2 files changed
+38 -3

No files matched your search

@@ -68,9 +68,11 @@ fun GalleryScreen(
val selectedPhotos = viewModel.selectedPhotos
val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.GetContent()
) { uri ->
uri?.let { viewModel.importPhoto(it) }
contract = ActivityResultContracts.GetMultipleContents()
) { uris ->
if (uris.isNotEmpty()) {
viewModel.importPhotos(uris)
}
}
// Activity Result Launcher for batch delete confirmation
@@ -1097,6 +1097,39 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
_isLoading.value = false
}
}
/**
* 批量导入照片
*/
fun importPhotos(uris: List<Uri>) {
if (uris.isEmpty()) return
viewModelScope.launch {
_isLoading.value = true
try {
val context = getApplication<Application>()
var successCount = 0
withContext(Dispatchers.IO) {
uris.forEach { uri ->
val photoId = PhotoManager.importPhoto(context, uri)
if (photoId != null) {
successCount++
}
}
}
if (successCount > 0) {
loadPhotos()
}
PLog.d(TAG, "Imported $successCount of ${uris.size} photos")
} catch (e: Exception) {
PLog.e(TAG, "Failed to import photos", e)
} finally {
_isLoading.value = false
}
}
}
override fun onCleared() {
super.onCleared()