Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Rename system trash to device trash

Priyanshu Dangarebf9eb58923b7
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/systemtrash/SystemTrashChannelAdapter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/devicetrash/DeviceTrashChannelAdapter.kt
similarity index 77%
rename from mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/systemtrash/SystemTrashChannelAdapter.kt
rename to mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/devicetrash/DeviceTrashChannelAdapter.kt
index 80acf316f7..2e3013bf9b 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/systemtrash/SystemTrashChannelAdapter.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/devicetrash/DeviceTrashChannelAdapter.kt
@@ -1,11 +1,11 @@
-package io.ente.photos.platform.systemtrash
+package io.ente.photos.platform.devicetrash
import android.os.Handler
import android.os.Looper
import io.flutter.plugin.common.MethodChannel
import java.util.concurrent.Executors
-class SystemTrashChannelAdapter(private val service: SystemTrashService) {
+class DeviceTrashChannelAdapter(private val service: DeviceTrashService) {
private val mainHandler = Handler(Looper.getMainLooper())
private val executor = Executors.newSingleThreadExecutor()
@@ -15,7 +15,7 @@ class SystemTrashChannelAdapter(private val service: SystemTrashService) {
fun getFiles(result: MethodChannel.Result) {
executor.execute {
try {
- val files = service.getFiles().map { it.toChannelMap() }
+ val files = service.getFiles().map { it.toChannelTuple() }
mainHandler.post {
if (!closed) result.success(files)
}
@@ -39,10 +39,6 @@ class SystemTrashChannelAdapter(private val service: SystemTrashService) {
executor.shutdownNow()
}
- private fun SystemTrashFile.toChannelMap(): Map<String, Any> =
- mapOf(
- "localID" to localID,
- "deleteBy" to deleteBy,
- "deviceFolder" to deviceFolder,
- )
+ private fun DeviceTrashFile.toChannelTuple(): List<Any> =
+ listOf(localID, deleteBy, deviceFolder)
}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/systemtrash/SystemTrashService.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/systemtrash/SystemTrashService.kt
deleted file mode 100644
index 866b97e23b..0000000000
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/systemtrash/SystemTrashService.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-package io.ente.photos.platform.systemtrash
-
-import android.content.ContentResolver
-import android.os.Build
-import android.os.Bundle
-import android.provider.MediaStore
-
-class SystemTrashService(private val contentResolver: ContentResolver) {
- fun getFiles(): List<SystemTrashFile> {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return emptyList()
-
- val queryArgs = Bundle().apply {
- putInt(MediaStore.QUERY_ARG_MATCH_TRASHED, MediaStore.MATCH_ONLY)
- putString(
- ContentResolver.QUERY_ARG_SQL_SELECTION,
- "${MediaStore.Files.FileColumns.MEDIA_TYPE} IN " +
- "(${MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE}, " +
- "${MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO})",
- )
- putString(
- ContentResolver.QUERY_ARG_SQL_SORT_ORDER,
- "${MediaStore.Files.FileColumns.DATE_EXPIRES} DESC",
- )
- }
- return buildList {
- contentResolver.query(
- MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL),
- arrayOf(
- MediaStore.Files.FileColumns._ID,
- MediaStore.Files.FileColumns.DATE_EXPIRES,
- MediaStore.Files.FileColumns.BUCKET_DISPLAY_NAME,
- ),
- queryArgs,
- null,
- )?.use { cursor ->
- while (cursor.moveToNext()) {
- add(
- SystemTrashFile(
- localID = cursor.getLong(0),
- deleteBy = cursor.getLong(1) * 1_000_000L,
- deviceFolder = cursor.getString(2) ?: "Unknown Folder",
- ),
- )
- }
- }
- }
- }
-}
-
-data class SystemTrashFile(
- val localID: Long,
- val deleteBy: Long,
- val deviceFolder: String,
-)
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/system_trash.dart b/mobile/apps/photos/plugins/ente_photos_platform/lib/src/system_trash.dart
deleted file mode 100644
index ff25cd47b8..0000000000
--- a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/system_trash.dart
+++ /dev/null
@@ -1,67 +0,0 @@
-import 'package:flutter/foundation.dart';
-import 'package:flutter/services.dart';
-
-class SystemTrashFile {
- const SystemTrashFile({
- required this.localID,
- required this.deleteBy,
- required this.deviceFolder,
- });
-
- factory SystemTrashFile.fromMap(Map<dynamic, dynamic> map) {
- return SystemTrashFile(
- localID: _requiredInt(map['localID'], 'localID'),
- deleteBy: _requiredInt(map['deleteBy'], 'deleteBy'),
- deviceFolder: _requiredString(map['deviceFolder'], 'deviceFolder'),
- );
- }
-
- final int localID;
- final int deleteBy;
- final String deviceFolder;
-}
-
-abstract interface class SystemTrashSource {
- Future<List<SystemTrashFile>> getFiles();
-}
-
-class SystemTrashClient implements SystemTrashSource {
- SystemTrashClient({MethodChannel? methodChannel, TargetPlatform? platform})
- : _methodChannel =
- methodChannel ?? const MethodChannel('io.ente.photos.platform'),
- _platform = platform ?? defaultTargetPlatform;
-
- static final instance = SystemTrashClient();
-
- final MethodChannel _methodChannel;
- final TargetPlatform _platform;
-
- @override
- Future<List<SystemTrashFile>> getFiles() async {
- if (_platform != TargetPlatform.android) return const [];
-
- final result =
- await _methodChannel.invokeListMethod<Object?>(
- 'systemTrash.getFiles',
- ) ??
- const [];
- return result.map((file) {
- if (file is! Map<dynamic, dynamic>) {
- throw const FormatException('System trash file is not a map');
- }
- return SystemTrashFile.fromMap(file);
- }).toList();
- }
-}
-
-int _requiredInt(Object? value, String name) {
- if (value is! int) throw FormatException('$name must be an integer');
- return value;
-}
-
-String _requiredString(Object? value, String name) {
- if (value is! String || value.isEmpty) {
- throw FormatException('$name must be a non-empty string');
- }
- return value;
-}