Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] delegate platform calls by method prefix

Priyanshu Dangare35b446ead059
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt
index 8dc7f2cb09..eb2e6b211d 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt
@@ -12,7 +12,9 @@ import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
-internal class DeviceHealthChannelAdapter : EventChannel.StreamHandler {
+internal class DeviceHealthChannelAdapter :
+ MethodChannel.MethodCallHandler,
+ EventChannel.StreamHandler {
private lateinit var eventChannel: EventChannel
private lateinit var service: DeviceHealthService
private var eventSink: EventChannel.EventSink? = null
@@ -23,19 +25,14 @@ internal class DeviceHealthChannelAdapter : EventChannel.StreamHandler {
eventChannel.setStreamHandler(this)
}
- fun handleMethodCall(call: MethodCall, result: MethodChannel.Result): Boolean =
+ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) =
when (call.method) {
- "deviceHealth.getSnapshot" -> {
- result.success(service.snapshot().toChannelMap())
- true
- }
+ "deviceHealth.getSnapshot" -> result.success(service.snapshot().toChannelMap())
- "deviceHealth.getMemorySnapshot" -> {
+ "deviceHealth.getMemorySnapshot" ->
result.success(service.memorySnapshot().toMemoryChannelMap())
- true
- }
- else -> false
+ else -> result.notImplemented()
}
override fun onListen(arguments: Any?, events: EventChannel.EventSink) {
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt
index de42c52e5a..b54ce9061d 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt
@@ -6,37 +6,34 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
-internal class DeviceTrashChannelAdapter {
+internal class DeviceTrashChannelAdapter : MethodChannel.MethodCallHandler {
private lateinit var service: DeviceTrashService
fun attach(binding: FlutterPlugin.FlutterPluginBinding) {
service = DeviceTrashService(binding.applicationContext)
}
- fun handleMethodCall(call: MethodCall, result: MethodChannel.Result): Boolean =
+ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) =
when (call.method) {
- "deviceTrash.getFiles" -> {
- service.getFiles { filesResult ->
- filesResult.fold(
- onSuccess = { files -> result.success(files.map { it.toChannelMap() }) },
- onFailure = { error ->
- result.error(
- when (error) {
- is UnsupportedOperationException ->
- "device_trash_unsupported"
-
- else -> "device_trash_query_failed"
- },
- error.message,
- null,
- )
- },
- )
- }
- true
+ "deviceTrash.getFiles" -> service.getFiles { filesResult ->
+ filesResult.fold(
+ onSuccess = { files -> result.success(files.map { it.toChannelMap() }) },
+ onFailure = { error ->
+ result.error(
+ when (error) {
+ is UnsupportedOperationException ->
+ "device_trash_unsupported"
+
+ else -> "device_trash_query_failed"
+ },
+ error.message,
+ null,
+ )
+ },
+ )
}
- else -> false
+ else -> result.notImplemented()
}
fun detach() {
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/PhotosPlatformChannelAdapter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/PhotosPlatformChannelAdapter.kt
index 30670333ee..549e38dcfc 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/PhotosPlatformChannelAdapter.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/PhotosPlatformChannelAdapter.kt
@@ -5,27 +5,31 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
internal class PhotosPlatformChannelAdapter : MethodChannel.MethodCallHandler {
- private val deviceHealthAdapter = DeviceHealthChannelAdapter()
- private val deviceTrashAdapter = DeviceTrashChannelAdapter()
+ private val healthAdapter = DeviceHealthChannelAdapter()
+ private val trashAdapter = DeviceTrashChannelAdapter()
private lateinit var methodChannel: MethodChannel
fun attach(binding: FlutterPlugin.FlutterPluginBinding) {
- deviceHealthAdapter.attach(binding)
- deviceTrashAdapter.attach(binding)
+ healthAdapter.attach(binding)
+ trashAdapter.attach(binding)
methodChannel = MethodChannel(binding.binaryMessenger, METHOD_CHANNEL)
methodChannel.setMethodCallHandler(this)
}
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
- if (deviceHealthAdapter.handleMethodCall(call, result)) return
- if (deviceTrashAdapter.handleMethodCall(call, result)) return
- result.notImplemented()
+ when {
+ call.method.startsWith("deviceHealth.") -> healthAdapter.onMethodCall(call, result)
+
+ call.method.startsWith("deviceTrash.") -> trashAdapter.onMethodCall(call, result)
+
+ else -> result.notImplemented()
+ }
}
fun detach() {
methodChannel.setMethodCallHandler(null)
- deviceHealthAdapter.detach()
- deviceTrashAdapter.detach()
+ healthAdapter.detach()
+ trashAdapter.detach()
}
private companion object {