Skip to content

Commit e0d828f

Browse files
committed
refactor(dive_profile_chart): centralize chart layout constants
1 parent bd6c72f commit e0d828f

168 files changed

Lines changed: 312765 additions & 312746 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 119 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,119 @@
1-
package app.submersion
2-
3-
import android.content.Context
4-
import android.content.Intent
5-
import android.net.Uri
6-
import androidx.documentfile.provider.DocumentFile
7-
import io.flutter.plugin.common.MethodCall
8-
import io.flutter.plugin.common.MethodChannel
9-
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
10-
11-
/**
12-
* Handles persistable URI permission management for the Media Source
13-
* Extension feature.
14-
*
15-
* Methods (channel: com.submersion.app/local_media):
16-
* - takePersistableUri(uri: String): String
17-
* Calls ContentResolver.takePersistableUriPermission with read flag
18-
* and returns the URI string itself (which Dart-side stores as
19-
* MediaItem.bookmarkRef).
20-
* - resolveBookmark(bookmarkRef: String): String?
21-
* Returns the URI as a string if the resource still exists, null if
22-
* the underlying file is gone.
23-
* - releaseBookmark(bookmarkRef: String): Unit
24-
* Calls ContentResolver.releasePersistableUriPermission.
25-
* - listPersistedUris(): List<String>
26-
* Returns all persisted URI permissions for the Settings UI's URI
27-
* budget display (Android caps at 128 per app).
28-
*/
29-
class LocalMediaHandler(
30-
private val context: Context,
31-
private val channel: MethodChannel,
32-
) : MethodCallHandler {
33-
34-
init {
35-
channel.setMethodCallHandler(this)
36-
}
37-
38-
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
39-
when (call.method) {
40-
"takePersistableUri" -> takePersistableUri(call, result)
41-
"resolveBookmark" -> resolveBookmark(call, result)
42-
"releaseBookmark" -> releaseBookmark(call, result)
43-
"listPersistedUris" -> listPersistedUris(result)
44-
"readUriBytes" -> readUriBytes(call, result)
45-
else -> result.notImplemented()
46-
}
47-
}
48-
49-
private fun takePersistableUri(call: MethodCall, result: MethodChannel.Result) {
50-
val uriStr = call.argument<String>("uri")
51-
?: return result.error("INVALID_ARGS", "uri required", null)
52-
val uri = Uri.parse(uriStr)
53-
try {
54-
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
55-
context.contentResolver.takePersistableUriPermission(uri, flags)
56-
result.success(uriStr)
57-
} catch (e: SecurityException) {
58-
result.error("PERMISSION_DENIED", e.localizedMessage, null)
59-
}
60-
}
61-
62-
private fun resolveBookmark(call: MethodCall, result: MethodChannel.Result) {
63-
val ref = call.argument<String>("bookmarkRef")
64-
?: return result.error("INVALID_ARGS", "bookmarkRef required", null)
65-
val uri = Uri.parse(ref)
66-
// DocumentFile.fromSingleUri / .exists() can throw SecurityException
67-
// (permission revoked) or IllegalArgumentException (malformed URI);
68-
// both mean "file is gone from this device's perspective", which the
69-
// Dart side already handles via the `null` result.
70-
val exists = try {
71-
val df = DocumentFile.fromSingleUri(context, uri)
72-
df != null && df.exists()
73-
} catch (_: SecurityException) {
74-
false
75-
} catch (_: IllegalArgumentException) {
76-
false
77-
}
78-
result.success(if (exists) uri.toString() else null)
79-
}
80-
81-
private fun releaseBookmark(call: MethodCall, result: MethodChannel.Result) {
82-
val ref = call.argument<String>("bookmarkRef")
83-
?: return result.error("INVALID_ARGS", "bookmarkRef required", null)
84-
val uri = Uri.parse(ref)
85-
try {
86-
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
87-
context.contentResolver.releasePersistableUriPermission(uri, flags)
88-
} catch (_: SecurityException) {
89-
// Already released -- harmless.
90-
}
91-
result.success(null)
92-
}
93-
94-
private fun listPersistedUris(result: MethodChannel.Result) {
95-
val uris = context.contentResolver.persistedUriPermissions
96-
.map { it.uri.toString() }
97-
result.success(uris)
98-
}
99-
100-
private fun readUriBytes(call: MethodCall, result: MethodChannel.Result) {
101-
val uriStr = call.argument<String>("uri")
102-
?: return result.error("INVALID_ARGS", "uri required", null)
103-
try {
104-
val uri = Uri.parse(uriStr)
105-
val stream = context.contentResolver.openInputStream(uri)
106-
?: return result.error("READ_FAILED", "openInputStream returned null", null)
107-
val bytes = stream.use { it.readBytes() }
108-
result.success(bytes)
109-
} catch (e: SecurityException) {
110-
result.error("PERMISSION_DENIED", e.localizedMessage, null)
111-
} catch (e: Exception) {
112-
result.error("READ_FAILED", e.localizedMessage, null)
113-
}
114-
}
115-
116-
companion object {
117-
const val CHANNEL = "com.submersion.app/local_media"
118-
}
119-
}
1+
package app.submersion
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.net.Uri
6+
import androidx.documentfile.provider.DocumentFile
7+
import io.flutter.plugin.common.MethodCall
8+
import io.flutter.plugin.common.MethodChannel
9+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
10+
11+
/**
12+
* Handles persistable URI permission management for the Media Source
13+
* Extension feature.
14+
*
15+
* Methods (channel: com.submersion.app/local_media):
16+
* - takePersistableUri(uri: String): String
17+
* Calls ContentResolver.takePersistableUriPermission with read flag
18+
* and returns the URI string itself (which Dart-side stores as
19+
* MediaItem.bookmarkRef).
20+
* - resolveBookmark(bookmarkRef: String): String?
21+
* Returns the URI as a string if the resource still exists, null if
22+
* the underlying file is gone.
23+
* - releaseBookmark(bookmarkRef: String): Unit
24+
* Calls ContentResolver.releasePersistableUriPermission.
25+
* - listPersistedUris(): List<String>
26+
* Returns all persisted URI permissions for the Settings UI's URI
27+
* budget display (Android caps at 128 per app).
28+
*/
29+
class LocalMediaHandler(
30+
private val context: Context,
31+
private val channel: MethodChannel,
32+
) : MethodCallHandler {
33+
34+
init {
35+
channel.setMethodCallHandler(this)
36+
}
37+
38+
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
39+
when (call.method) {
40+
"takePersistableUri" -> takePersistableUri(call, result)
41+
"resolveBookmark" -> resolveBookmark(call, result)
42+
"releaseBookmark" -> releaseBookmark(call, result)
43+
"listPersistedUris" -> listPersistedUris(result)
44+
"readUriBytes" -> readUriBytes(call, result)
45+
else -> result.notImplemented()
46+
}
47+
}
48+
49+
private fun takePersistableUri(call: MethodCall, result: MethodChannel.Result) {
50+
val uriStr = call.argument<String>("uri")
51+
?: return result.error("INVALID_ARGS", "uri required", null)
52+
val uri = Uri.parse(uriStr)
53+
try {
54+
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
55+
context.contentResolver.takePersistableUriPermission(uri, flags)
56+
result.success(uriStr)
57+
} catch (e: SecurityException) {
58+
result.error("PERMISSION_DENIED", e.localizedMessage, null)
59+
}
60+
}
61+
62+
private fun resolveBookmark(call: MethodCall, result: MethodChannel.Result) {
63+
val ref = call.argument<String>("bookmarkRef")
64+
?: return result.error("INVALID_ARGS", "bookmarkRef required", null)
65+
val uri = Uri.parse(ref)
66+
// DocumentFile.fromSingleUri / .exists() can throw SecurityException
67+
// (permission revoked) or IllegalArgumentException (malformed URI);
68+
// both mean "file is gone from this device's perspective", which the
69+
// Dart side already handles via the `null` result.
70+
val exists = try {
71+
val df = DocumentFile.fromSingleUri(context, uri)
72+
df != null && df.exists()
73+
} catch (_: SecurityException) {
74+
false
75+
} catch (_: IllegalArgumentException) {
76+
false
77+
}
78+
result.success(if (exists) uri.toString() else null)
79+
}
80+
81+
private fun releaseBookmark(call: MethodCall, result: MethodChannel.Result) {
82+
val ref = call.argument<String>("bookmarkRef")
83+
?: return result.error("INVALID_ARGS", "bookmarkRef required", null)
84+
val uri = Uri.parse(ref)
85+
try {
86+
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
87+
context.contentResolver.releasePersistableUriPermission(uri, flags)
88+
} catch (_: SecurityException) {
89+
// Already released -- harmless.
90+
}
91+
result.success(null)
92+
}
93+
94+
private fun listPersistedUris(result: MethodChannel.Result) {
95+
val uris = context.contentResolver.persistedUriPermissions
96+
.map { it.uri.toString() }
97+
result.success(uris)
98+
}
99+
100+
private fun readUriBytes(call: MethodCall, result: MethodChannel.Result) {
101+
val uriStr = call.argument<String>("uri")
102+
?: return result.error("INVALID_ARGS", "uri required", null)
103+
try {
104+
val uri = Uri.parse(uriStr)
105+
val stream = context.contentResolver.openInputStream(uri)
106+
?: return result.error("READ_FAILED", "openInputStream returned null", null)
107+
val bytes = stream.use { it.readBytes() }
108+
result.success(bytes)
109+
} catch (e: SecurityException) {
110+
result.error("PERMISSION_DENIED", e.localizedMessage, null)
111+
} catch (e: Exception) {
112+
result.error("READ_FAILED", e.localizedMessage, null)
113+
}
114+
}
115+
116+
companion object {
117+
const val CHANNEL = "com.submersion.app/local_media"
118+
}
119+
}

0 commit comments

Comments
 (0)