Skip to content

Commit 4152f07

Browse files
authored
Fix: AlreadyRunning Method for DocumentFile actions
- chore: code cleanup - bugfix: #7 Signed-off-by: Alex Yackers <7115964+yackers@users.noreply.github.com>
1 parent aed269f commit 4152f07

19 files changed

Lines changed: 74 additions & 58 deletions

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ body:
2020
- **Flutter**: 2.5.2
2121
- **Dart**: 2.14.3
2222
- **DocMan version**: 1.0.2
23+
2324
Android information (optional):
2425
- **OS**: Android 11
2526
- **Device**: Pixel 5

android/src/main/kotlin/devdf/plugins/docman/DocManDocumentsProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class DocManDocumentsProvider : DocumentsProvider() {
265265
)
266266
removeDocument(sourceDocumentId, sourceParentDocumentId)
267267
return newDocumentId
268-
} catch (e: FileNotFoundException) {
268+
} catch (_: FileNotFoundException) {
269269
throw FileNotFoundException("Couldn't move document '$sourceDocumentId'")
270270
}
271271
}

android/src/main/kotlin/devdf/plugins/docman/channels/DocManActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ internal class DocManActivity(private val plugin: DocManPlugin) : EngineBase,
4242

4343

4444
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
45-
return plugin.queue.methodCast<ActivityMethodBase>(requestCode)
46-
?.onActivityResult(resultCode, data) ?: false
45+
return plugin.queue.methodCast<ActivityMethodBase>(requestCode.toString())
46+
?.onActivityResult(resultCode, data) == true
4747
}
4848

4949
override fun onAttach() {

android/src/main/kotlin/devdf/plugins/docman/definitions/DocManInterface.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ interface MethodMeta {
128128
get() = meta.errorCode
129129
val method: String
130130
get() = meta.methodName
131-
val requestCode: Int
132-
get() = meta.requestCode
131+
val requestCode: String
132+
get() = meta.requestCode.toString()
133133
}
134134

135135

android/src/main/kotlin/devdf/plugins/docman/extensions/DocumentFileExt.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fun DocumentFile.canCreate(context: Context): Boolean =
156156
*/
157157
//TODO: add additional thumbnail types like docx, xls, maybe others
158158
fun DocumentFile.canThumbnailAlternate(context: Context): Boolean =
159-
canRead() && (type == "application/pdf" || isVideo(context) || isImage(context))
159+
canRead() && (isPDF() || isVideo(context) || isImage(context))
160160

161161
/** Get the persisted URI of the [DocumentFile]
162162
*
@@ -320,6 +320,9 @@ fun DocumentFile.isVideo(context: Context): Boolean =
320320
fun DocumentFile.isVisualMedia(context: Context): Boolean =
321321
isImage(context) || isVideo(context)
322322

323+
/** Check if the [DocumentFile] is a PDF file */
324+
fun DocumentFile.isPDF(): Boolean = type == "application/pdf"
325+
323326
/** Copy the [DocumentFile] to the cache directory.
324327
*
325328
* Must be called from a coroutine.

android/src/main/kotlin/devdf/plugins/docman/extensions/StringExt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fun String.toUri(): Uri {
1313
return if (parsedScheme.isNullOrEmpty() || ("${this[0]}" == "/")) {
1414
try {
1515
Uri.fromFile(File(this))
16-
} catch (e: Exception) {
16+
} catch (_: Exception) {
1717
parsed
1818
}
1919
} else parsed

android/src/main/kotlin/devdf/plugins/docman/methods/AppDirsAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class AppDirsAction(
5959
dirPath?.let { success(it) } ?: dirPathError()
6060
}
6161

62+
6263
private fun clear() {
6364
// Clear the cache directory, currently only cache directory is supported
6465
if (dir == AppDirType.Cache) DocManFiles.clearCacheDirectories(plugin.context)

android/src/main/kotlin/devdf/plugins/docman/methods/DocumentFileAction.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class DocumentFileAction(
4040

4141
override val meta: DocManMethod = DocManMethod.DocumentFileAction
4242

43+
/// Override the requestCode, to allow multiple actions on different documents
44+
override val requestCode: String = call.argument<String>("uri") ?: meta.requestCode.toString()
4345
private lateinit var doc: DocumentFile
4446

4547
override fun oMethodCall() {

android/src/main/kotlin/devdf/plugins/docman/methods/DocumentFileActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class DocumentFileActivity(
5353
}
5454

5555
try {
56-
plugin.binding?.activity?.startActivityForResult(intent, requestCode)
57-
} catch (e: Exception) {
56+
plugin.binding?.activity?.startActivityForResult(intent, requestCode.toInt())
57+
} catch (_: Exception) {
5858
plugin.queue.finishWithError(requestCode, "no_activity", action, null)
5959
}
6060
}
@@ -79,7 +79,7 @@ class DocumentFileActivity(
7979
}
8080

8181
private fun actionCreateDocumentIntent(): Intent {
82-
val localOnly = call.argument<Boolean>("localOnly") ?: false
82+
val localOnly = call.argument<Boolean>("localOnly") == true
8383
val initDir = call.argument<String>("initDir")
8484
return Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
8585
addCategory(Intent.CATEGORY_OPENABLE)
@@ -104,7 +104,7 @@ class DocumentFileActivity(
104104
}
105105

106106
private fun processSaveTo(data: Intent?) {
107-
val deleteSource = call.argument<Boolean>("deleteSource") ?: false
107+
val deleteSource = call.argument<Boolean>("deleteSource") == true
108108
if (data != null && data.data != null) {
109109
CoroutineScope(Dispatchers.IO).launch {
110110
val newDoc = doc.saveToUri(data.data!!, deleteSource, plugin.context)

android/src/main/kotlin/devdf/plugins/docman/methods/PermissionsAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class PermissionsAction(
3232

3333
private val uri: Uri? = call.argument<String>("uri")?.toUri()
3434

35-
private val dirs: Boolean = call.argument<Boolean>("dirs") ?: true
35+
private val dirs: Boolean = call.argument<Boolean>("dirs") != false
3636

37-
private val files: Boolean = call.argument<Boolean>("files") ?: true
37+
private val files: Boolean = call.argument<Boolean>("files") != false
3838

3939
override fun oMethodCall() {
4040
//Validate the action

0 commit comments

Comments
 (0)