Skip to content

Commit 2ed784c

Browse files
author
lask
authored
Merge pull request #19 from lakscastro/v0.3.0
Full featured `SAF` support
2 parents a21c4b9 + f801691 commit 2ed784c

58 files changed

Lines changed: 2345 additions & 1351 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
## 0.3.0
2+
3+
Major release focused on support for `Storage Access Framework`.
4+
5+
### Breaking Changes
6+
7+
- New `minSdkVersion` set to `19`.
8+
- `getMediaStoreContentDirectory` return type set to `Uri`.
9+
10+
### Deprecation Notices
11+
12+
- `getExternalStoragePublicDirectory` was marked as deprecated and should be replaced with an equivalent API depending on your use-case, see [how to migrate `getExternalStoragePublicDirectory`](https://stackoverflow.com/questions/56468539/getexternalstoragepublicdirectory-deprecated-in-android-q).
13+
114
## 0.2.0
215

3-
Add basic support for `Storage Access Framework` and `targetSdk 31`
16+
Add basic support for `Storage Access Framework` and `targetSdk 31`.
417

5-
- The package now supports basic intents from `Storage Access Framework`
6-
- Your App needs update the `build.gradle` by targeting the current sdk to `31`
18+
- The package now supports basic intents from `Storage Access Framework`.
19+
- Your App needs update the `build.gradle` by targeting the current sdk to `31`.
720

821
## 0.1.1
922

10-
Minor improvements on `pub.dev` documentation
23+
Minor improvements on `pub.dev` documentation.
1124

12-
- Add `example/` folder
13-
- Add missing `pubspec.yaml` properties
25+
- Add `example/` folder.
26+
- Add missing `pubspec.yaml` properties.
1427

1528
## 0.1.0
1629

17-
Initial release
30+
Initial release.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
#### See the website for [documentation](https://lakscastro.github.io/shared-storage)
2626

27-
All documentation is also available under `/docs` to each released version which is the data source of the website
27+
All documentation is also available under `/docs` to each released version which is the data source of the website.
2828

29-
You can contribute to the docs by just editing these files through the GitHub web editor!
29+
You can contribute to the documentation by just editing these files through the GitHub web editor!
3030

31-
Latest changes are available on `master` branch and the actual latest published package version lives under `release` branch
31+
Latest changes are available on `master` branch and the actual latest published package version lives under `release` branch.
3232

33-
All other branches are derivated from issues, new features or bug fixes
33+
All other branches are derivated from issues, new features or bug fixes.
3434

3535
## Contributors
3636

android/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:4.1.0'
12+
classpath "com.android.tools.build:gradle:4.1.0"
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}
1515
}
@@ -31,15 +31,17 @@ android {
3131
main.java.srcDirs += 'src/main/kotlin'
3232
}
3333
defaultConfig {
34-
minSdkVersion 16
34+
minSdkVersion 19
3535
}
3636
}
3737

3838
dependencies {
3939
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4040
implementation "androidx.documentfile:documentfile:1.0.1"
4141

42-
/// Allow usage of `CoroutineScope` to run heavy
43-
// computation and queries outside the Main (UI) Thread
42+
/**
43+
* Allow usage of `CoroutineScope` to run heavy
44+
* computation and queries outside the Main (UI) Thread
45+
*/
4446
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
4547
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="io.lakscastro.sharedstorage">
3-
</manifest>
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="io.lakscastro.sharedstorage">
2+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
3+
</manifest>

android/src/main/kotlin/io/lakscastro/sharedstorage/SharedStoragePlugin.kt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,30 @@ import io.flutter.embedding.engine.plugins.activity.ActivityAware
88
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
99
import io.lakscastro.sharedstorage.environment.EnvironmentApi
1010
import io.lakscastro.sharedstorage.mediastore.MediaStoreApi
11-
import io.lakscastro.sharedstorage.saf.StorageAccessFramework
11+
import io.lakscastro.sharedstorage.storageaccessframework.StorageAccessFrameworkApi
1212

1313
const val ROOT_CHANNEL = "io.lakscastro.plugins/sharedstorage"
1414

15-
/**
16-
* Flutter plugin Kotlin implementation `SharedStoragePlugin`
17-
*/
15+
/** Flutter plugin Kotlin implementation `SharedStoragePlugin` */
1816
class SharedStoragePlugin : FlutterPlugin, ActivityAware {
19-
/**
20-
* `Environment` API channel
21-
*/
17+
/** `Environment` API channel */
2218
private val environmentApi = EnvironmentApi(this)
2319

24-
/**
25-
* `MediaStore` API channel
26-
*/
20+
/** `MediaStore` API channel */
2721
private val mediaStoreApi = MediaStoreApi(this)
2822

29-
/**
30-
* `DocumentFile` API channel
31-
*/
32-
private val storageAccessFrameworkApi = StorageAccessFramework(this)
23+
/** `DocumentFile` API channel */
24+
private val storageAccessFrameworkApi = StorageAccessFrameworkApi(this)
3325

3426
lateinit var context: Context
3527
var binding: ActivityPluginBinding? = null
3628

29+
/** Setup all APIs */
3730
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPluginBinding) {
3831
context = flutterPluginBinding.applicationContext
3932

40-
/** Setup `Environment` API */
4133
environmentApi.startListening(flutterPluginBinding.binaryMessenger)
42-
43-
/** Setup `MediaStore` API */
4434
mediaStoreApi.startListening(flutterPluginBinding.binaryMessenger)
45-
46-
/** Setup `StorageAccessFramework` API */
4735
storageAccessFrameworkApi.startListening(flutterPluginBinding.binaryMessenger)
4836
}
4937

android/src/main/kotlin/io/lakscastro/sharedstorage/environment/EnvironmentApi.kt

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ import io.lakscastro.sharedstorage.plugin.Listenable
1212
import io.lakscastro.sharedstorage.plugin.notSupported
1313
import java.io.File
1414

15-
class EnvironmentApi(val plugin: SharedStoragePlugin) : MethodChannel.MethodCallHandler,
16-
Listenable {
15+
class EnvironmentApi(val plugin: SharedStoragePlugin) :
16+
MethodChannel.MethodCallHandler, Listenable {
1717
private var channel: MethodChannel? = null
1818

1919
companion object {
20-
const val GET_EXTERNAL_STORAGE_PUBLIC_DIRECTORY =
21-
"getExternalStoragePublicDirectory"
20+
const val GET_EXTERNAL_STORAGE_PUBLIC_DIRECTORY = "getExternalStoragePublicDirectory"
2221
const val GET_ROOT_DIRECTORY = "getRootDirectory"
2322
const val GET_EXTERNAL_STORAGE_DIRECTORY = "getExternalStorageDirectory"
2423
const val GET_DATA_DIRECTORY = "getDataDirectory"
@@ -28,14 +27,10 @@ class EnvironmentApi(val plugin: SharedStoragePlugin) : MethodChannel.MethodCall
2827
const val CHANNEL = "environment"
2928
}
3029

31-
3230
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
3331
when (call.method) {
3432
GET_EXTERNAL_STORAGE_PUBLIC_DIRECTORY ->
35-
getExternalStoragePublicDirectory(
36-
result,
37-
call.argument<String?>("directory") as String
38-
)
33+
getExternalStoragePublicDirectory(result, call.argument<String?>("directory") as String)
3934
GET_EXTERNAL_STORAGE_DIRECTORY -> getExternalStorageDirectory(result)
4035
GET_ROOT_DIRECTORY -> getRootDirectory(result)
4136
GET_DATA_DIRECTORY -> getDataDirectory(result)
@@ -45,16 +40,12 @@ class EnvironmentApi(val plugin: SharedStoragePlugin) : MethodChannel.MethodCall
4540
}
4641
}
4742

48-
/**
49-
* Deprecated Android API, use only if you know exactly what you need
50-
*/
51-
private fun getExternalStoragePublicDirectory(
52-
result: MethodChannel.Result,
53-
directory: String
54-
) = result.success(environmentDirectoryOf(directory).absolutePath)
43+
/** Deprecated Android API, use only if you know exactly what you need */
44+
private fun getExternalStoragePublicDirectory(result: MethodChannel.Result, directory: String) =
45+
result.success(environmentDirectoryOf(directory).absolutePath)
5546

5647
private fun getDataDirectory(result: MethodChannel.Result) =
57-
result.success(Environment.getDataDirectory().absolutePath)
48+
result.success(Environment.getDataDirectory().absolutePath)
5849

5950
private fun getStorageDirectory(result: MethodChannel.Result) {
6051
if (Build.VERSION.SDK_INT >= API_30) {
@@ -65,29 +56,28 @@ class EnvironmentApi(val plugin: SharedStoragePlugin) : MethodChannel.MethodCall
6556
}
6657

6758
private fun getDownloadCacheDirectory(result: MethodChannel.Result) =
68-
result.success(Environment.getDownloadCacheDirectory().absolutePath)
59+
result.success(Environment.getDownloadCacheDirectory().absolutePath)
6960

70-
/**
71-
* Deprecated Android API, use only if you know exactly what you need
72-
*/
61+
/** Deprecated Android API, use only if you know exactly what you need */
7362
private fun getExternalStorageDirectory(result: MethodChannel.Result) =
74-
result.success(Environment.getExternalStorageDirectory().absolutePath)
63+
result.success(Environment.getExternalStorageDirectory().absolutePath)
7564

7665
private fun getRootDirectory(result: MethodChannel.Result) =
77-
result.success(Environment.getRootDirectory().absolutePath)
66+
result.success(Environment.getRootDirectory().absolutePath)
7867

7968
private fun environmentDirectoryOf(directory: String): File {
80-
val mapper = mapOf(
81-
"EnvironmentDirectory.Alarms" to Environment.DIRECTORY_ALARMS,
82-
"EnvironmentDirectory.DCIM" to Environment.DIRECTORY_DCIM,
83-
"EnvironmentDirectory.Downloads" to Environment.DIRECTORY_DOWNLOADS,
84-
"EnvironmentDirectory.Movies" to Environment.DIRECTORY_MOVIES,
85-
"EnvironmentDirectory.Music" to Environment.DIRECTORY_MUSIC,
86-
"EnvironmentDirectory.Notifications" to Environment.DIRECTORY_NOTIFICATIONS,
87-
"EnvironmentDirectory.Pictures" to Environment.DIRECTORY_PICTURES,
88-
"EnvironmentDirectory.Podcasts" to Environment.DIRECTORY_PODCASTS,
89-
"EnvironmentDirectory.Ringtones" to Environment.DIRECTORY_RINGTONES
90-
)
69+
val mapper =
70+
mapOf(
71+
"EnvironmentDirectory.Alarms" to Environment.DIRECTORY_ALARMS,
72+
"EnvironmentDirectory.DCIM" to Environment.DIRECTORY_DCIM,
73+
"EnvironmentDirectory.Downloads" to Environment.DIRECTORY_DOWNLOADS,
74+
"EnvironmentDirectory.Movies" to Environment.DIRECTORY_MOVIES,
75+
"EnvironmentDirectory.Music" to Environment.DIRECTORY_MUSIC,
76+
"EnvironmentDirectory.Notifications" to Environment.DIRECTORY_NOTIFICATIONS,
77+
"EnvironmentDirectory.Pictures" to Environment.DIRECTORY_PICTURES,
78+
"EnvironmentDirectory.Podcasts" to Environment.DIRECTORY_PODCASTS,
79+
"EnvironmentDirectory.Ringtones" to Environment.DIRECTORY_RINGTONES
80+
)
9181

9282
return Environment.getExternalStoragePublicDirectory(mapper[directory] ?: directory)
9383
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.lakscastro.sharedstorage.plugin
22

3-
/// Interface shared across API classes to make
4-
/// intuitive and clean [init] and [dispose] plugin lifecycle of [Activity] listener resources
3+
/**
4+
* Interface shared across API classes to make intuitive and clean [init] and [dispose] plugin
5+
* lifecycle of [Activity] listener resources
6+
*/
57
interface ActivityListener {
68
fun startListeningToActivity()
79
fun stopListeningToActivity()
8-
}
10+
}

android/src/main/kotlin/io/lakscastro/sharedstorage/plugin/Common.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ fun MethodChannel.Result.notSupported(
1414
mapOf("method" to method, *debug.toList().toTypedArray())
1515
)
1616
}
17+
18+
inline fun <reified T : Enum<T>> valueOf(type: String?): T? {
19+
if (type == null) return null
20+
21+
return try {
22+
java.lang.Enum.valueOf(T::class.java, type)
23+
} catch (e: Exception) {
24+
null
25+
}
26+
}
27+
28+
inline fun <reified T : Enum<T>> valueOf(type: String?, default: T): T = valueOf<T>(type) ?: default

android/src/main/kotlin/io/lakscastro/sharedstorage/plugin/Listenable.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.lakscastro.sharedstorage.plugin
22

33
import io.flutter.plugin.common.BinaryMessenger
44

5-
/// Interface shared across API classes to make
6-
/// intuitive and clean [init] and [dispose] plugin lifecycle of [MethodCallHandler] resources
5+
/**
6+
* Interface shared across API classes to make intuitive and clean [init] and [dispose] plugin
7+
* lifecycle of [MethodCallHandler] resources
8+
*/
79
interface Listenable {
8-
fun startListening(binaryMessenger: BinaryMessenger);
9-
fun stopListening();
10-
}
10+
fun startListening(binaryMessenger: BinaryMessenger)
11+
fun stopListening()
12+
}

android/src/main/kotlin/io/lakscastro/sharedstorage/plugin/PluginConstant.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package io.lakscastro.sharedstorage.plugin
22

33
import android.os.Build
44

5-
/// Generic exceptions
5+
/** Generic exceptions */
66
const val EXCEPTION_NOT_SUPPORTED = "EXCEPTION_NOT_SUPPORTED"
77

8-
/// API level constants by version codes
8+
/** API level constants by version codes */
99
const val API_18 = Build.VERSION_CODES.JELLY_BEAN_MR2
1010
const val API_19 = Build.VERSION_CODES.KITKAT
1111
const val API_20 = Build.VERSION_CODES.KITKAT_WATCH

0 commit comments

Comments
 (0)