Skip to content

Offline gym log for Android. No account, no ads, no internet.

Update Android backup bridge and main activity

InlitXffa4480d9a38
diff --git a/android/app/src/main/kotlin/com/gymmane/app/BackupBridge.kt b/android/app/src/main/kotlin/com/gymmane/app/BackupBridge.kt
index 7a06d2f..2030419 100644
--- a/android/app/src/main/kotlin/com/gymmane/app/BackupBridge.kt
+++ b/android/app/src/main/kotlin/com/gymmane/app/BackupBridge.kt
@@ -34,6 +34,33 @@ object BackupBridge {
activity.runOnUiThread { result.success(ok) }
}.start()
}
+ "list" -> {
+ val uri = call.argument<String>("uri")
+ val prefix = call.argument<String>("prefix") ?: ""
+ if (uri == null) {
+ result.success(emptyList<String>())
+ return@setMethodCallHandler
+ }
+ val context = activity.applicationContext
+ Thread {
+ val names = list(context, Uri.parse(uri), prefix).map { it.second }
+ activity.runOnUiThread { result.success(names) }
+ }.start()
+ }
+ "read" -> {
+ val uri = call.argument<String>("uri")
+ val name = call.argument<String>("name")
+ val path = call.argument<String>("path")
+ if (uri == null || name == null || path == null) {
+ result.success(false)
+ return@setMethodCallHandler
+ }
+ val context = activity.applicationContext
+ Thread {
+ val ok = read(context, Uri.parse(uri), name, File(path))
+ activity.runOnUiThread { result.success(ok) }
+ }.start()
+ }
else -> result.notImplemented()
}
}
@@ -122,6 +149,43 @@ object BackupBridge {
return true
}
+ private fun list(context: Context, tree: Uri, prefix: String): List<Pair<String, String>> {
+ val parentId = try {
+ DocumentsContract.getTreeDocumentId(tree)
+ } catch (e: Exception) {
+ return emptyList()
+ }
+ val children = DocumentsContract.buildChildDocumentsUriUsingTree(tree, parentId)
+ val found = mutableListOf<Pair<String, String>>()
+ try {
+ context.contentResolver.query(
+ children,
+ arrayOf(DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME),
+ null, null, null,
+ )?.use {
+ while (it.moveToNext()) {
+ val id = it.getString(0) ?: continue
+ val name = it.getString(1) ?: continue
+ if (name.startsWith(prefix) && name.endsWith(".zip")) found.add(id to name)
+ }
+ }
+ } catch (e: Exception) {
+ }
+ return found
+ }
+
+ private fun read(context: Context, tree: Uri, name: String, target: File): Boolean {
+ val id = list(context, tree, name).firstOrNull { it.second == name }?.first ?: return false
+ return try {
+ val doc = DocumentsContract.buildDocumentUriUsingTree(tree, id)
+ context.contentResolver.openInputStream(doc)?.use { input ->
+ target.outputStream().use { input.copyTo(it) }
+ } != null
+ } catch (e: Exception) {
+ false
+ }
+ }
+
private fun prune(context: Context, tree: Uri, parentId: String, prefix: String, keep: Int) {
val resolver = context.contentResolver
val children = DocumentsContract.buildChildDocumentsUriUsingTree(tree, parentId)
diff --git a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
index 2c8b0ac..d2d5dd1 100644
--- a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
@@ -17,6 +17,7 @@ import android.view.ViewConfiguration
import android.view.WindowManager
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
+import io.flutter.embedding.engine.FlutterShellArgs
import io.flutter.plugin.common.MethodChannel
import java.io.File
import java.io.FileOutputStream
@@ -27,10 +28,30 @@ class MainActivity : FlutterActivity() {
private var rotaryChannel: MethodChannel? = null
private var openChannel: MethodChannel? = null
+ override fun getFlutterShellArgs(): FlutterShellArgs {
+ val args = super.getFlutterShellArgs()
+ if (GraphicsMode.compat(this)) args.add(GraphicsMode.DISABLE_IMPELLER)
+ return args
+ }
+
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
val messenger = flutterEngine.dartExecutor.binaryMessenger
+ MethodChannel(messenger, "gymmane/graphics").setMethodCallHandler { call, result ->
+ when (call.method) {
+ "state" -> result.success(
+ mapOf("compat" to GraphicsMode.compat(this), "detected" to GraphicsMode.detected(this)),
+ )
+ "set" -> {
+ result.success(null)
+ val on = call.argument<Boolean>("compat") ?: false
+ window.decorView.postDelayed({ GraphicsMode.setAndRestart(this, on) }, 150)
+ }
+ else -> result.notImplemented()
+ }
+ }
+
MethodChannel(messenger, "gymmane/haptics").setMethodCallHandler { call, result ->
if (call.method != "buzz") {
result.notImplemented()
@@ -150,6 +171,7 @@ class MainActivity : FlutterActivity() {
BackupBridge.attach(this, MethodChannel(messenger, BackupBridge.CHANNEL))
SoundBridge.attach(this, MethodChannel(messenger, SoundBridge.CHANNEL))
VoiceBridge.attach(this, MethodChannel(messenger, VoiceBridge.CHANNEL))
+ WearSurfaces.attach(this, MethodChannel(messenger, WearSurfaces.CHANNEL))
}
private fun currentDisplay(): android.view.Display? =