Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ body:
- **Flutter**: 2.5.2
- **Dart**: 2.14.3
- **DocMan version**: 1.0.2

Android information (optional):
- **OS**: Android 11
- **Device**: Pixel 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class DocManDocumentsProvider : DocumentsProvider() {
)
removeDocument(sourceDocumentId, sourceParentDocumentId)
return newDocumentId
} catch (e: FileNotFoundException) {
} catch (_: FileNotFoundException) {
throw FileNotFoundException("Couldn't move document '$sourceDocumentId'")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ internal class DocManActivity(private val plugin: DocManPlugin) : EngineBase,


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

override fun onAttach() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ interface MethodMeta {
get() = meta.errorCode
val method: String
get() = meta.methodName
val requestCode: Int
get() = meta.requestCode
val requestCode: String
get() = meta.requestCode.toString()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fun DocumentFile.canCreate(context: Context): Boolean =
*/
//TODO: add additional thumbnail types like docx, xls, maybe others
fun DocumentFile.canThumbnailAlternate(context: Context): Boolean =
canRead() && (type == "application/pdf" || isVideo(context) || isImage(context))
canRead() && (isPDF() || isVideo(context) || isImage(context))

/** Get the persisted URI of the [DocumentFile]
*
Expand Down Expand Up @@ -320,6 +320,9 @@ fun DocumentFile.isVideo(context: Context): Boolean =
fun DocumentFile.isVisualMedia(context: Context): Boolean =
isImage(context) || isVideo(context)

/** Check if the [DocumentFile] is a PDF file */
fun DocumentFile.isPDF(): Boolean = type == "application/pdf"

/** Copy the [DocumentFile] to the cache directory.
*
* Must be called from a coroutine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fun String.toUri(): Uri {
return if (parsedScheme.isNullOrEmpty() || ("${this[0]}" == "/")) {
try {
Uri.fromFile(File(this))
} catch (e: Exception) {
} catch (_: Exception) {
parsed
}
} else parsed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class AppDirsAction(
dirPath?.let { success(it) } ?: dirPathError()
}


private fun clear() {
// Clear the cache directory, currently only cache directory is supported
if (dir == AppDirType.Cache) DocManFiles.clearCacheDirectories(plugin.context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class DocumentFileAction(

override val meta: DocManMethod = DocManMethod.DocumentFileAction

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

override fun oMethodCall() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class DocumentFileActivity(
}

try {
plugin.binding?.activity?.startActivityForResult(intent, requestCode)
} catch (e: Exception) {
plugin.binding?.activity?.startActivityForResult(intent, requestCode.toInt())
} catch (_: Exception) {
plugin.queue.finishWithError(requestCode, "no_activity", action, null)
}
}
Expand All @@ -79,7 +79,7 @@ class DocumentFileActivity(
}

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

private fun processSaveTo(data: Intent?) {
val deleteSource = call.argument<Boolean>("deleteSource") ?: false
val deleteSource = call.argument<Boolean>("deleteSource") == true
if (data != null && data.data != null) {
CoroutineScope(Dispatchers.IO).launch {
val newDoc = doc.saveToUri(data.data!!, deleteSource, plugin.context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class PermissionsAction(

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

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

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

override fun oMethodCall() {
//Validate the action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class PermissionsEvents(

override val meta: DocManMethod = DocManMethod.PermissionsEvent

private val dirs = call.argument<Boolean>("dirs") ?: true
private val files = call.argument<Boolean>("files") ?: true
private val dirs = call.argument<Boolean>("dirs") != false
private val files = call.argument<Boolean>("files") != false

override suspend fun onListen() {
when (val action = call.argument<String>("action")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ internal data class PickActivityArgs(
call.argAsListString("mimeTypes"),
call.argAsListString("extensions")
),
localOnly = call.argument<Boolean>("localOnly") ?: false,
grantPermissions = call.argument<Boolean>("grantPermissions") ?: true,
localOnly = call.argument<Boolean>("localOnly") == true,
grantPermissions = call.argument<Boolean>("grantPermissions") != false,
limit = call.argument<Int>("limit") ?: 1,
limitResult = PickLimitResult.fromString(call.argument("limitType")),
limitToast = call.argument("limitToast") ?: "Pick limit reached",
imageQuality = call.argument<Int>("imageQuality") ?: 100,
usePhotoPicker = call.argument<Boolean>("usePhotoPicker") ?: true,
usePhotoPicker = call.argument<Boolean>("usePhotoPicker") != false,
initDir = call.argument<String>("initDir")
)
}
Expand Down Expand Up @@ -135,8 +135,8 @@ class PickActivity(

//2. Start the activity
try {
plugin.binding?.activity?.startActivityForResult(activityIntent(), requestCode)
} catch (e: Exception) {
plugin.binding?.activity?.startActivityForResult(activityIntent(), requestCode.toInt())
} catch (_: Exception) {
plugin.queue.finishWithError(
requestCode,
"no_activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import devdf.plugins.docman.extensions.getFileExtension
import devdf.plugins.docman.extensions.isAppFile
import devdf.plugins.docman.extensions.isImage
import devdf.plugins.docman.extensions.isMediaMimeType
import devdf.plugins.docman.extensions.isPDF
import devdf.plugins.docman.extensions.isVideo
import devdf.plugins.docman.extensions.isVisualMedia
import devdf.plugins.docman.extensions.nameAsFileName
Expand Down Expand Up @@ -179,7 +180,7 @@ class DocManFiles {
/** Read the content of the [DocumentFile] as a byte array */
fun readDocumentFile(doc: DocumentFile, context: Context): ByteArray? = try {
context.contentResolver.openInputStream(doc.uri)?.use { it.readBytes() }
} catch (e: Exception) {
} catch (_: Exception) {
null
}

Expand Down Expand Up @@ -239,7 +240,7 @@ class DocManFiles {
}
targetFile.path
}
} catch (e: Exception) {
} catch (_: Exception) {
null
}
}
Expand All @@ -256,7 +257,7 @@ class DocManFiles {

when {
doc.isVideo(context) -> DocManMedia.videoThumbnail(doc, thumbSize, context)
doc.type == "application/pdf" -> DocManMedia.pdfThumbnail(
doc.isPDF() -> DocManMedia.pdfThumbnail(
doc,
thumbSize,
context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.util.Size
import androidx.documentfile.provider.DocumentFile
import devdf.plugins.docman.extensions.canThumbnailAlternate
import devdf.plugins.docman.extensions.isImage
import devdf.plugins.docman.extensions.isPDF
import devdf.plugins.docman.extensions.isVideo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -73,13 +74,17 @@ class DocManMedia {
size: Size,
context: Context,
): Bitmap? = runCatching {
//1. Check if we can get thumbnail from the document fastest way
DocumentsContract.getDocumentThumbnail(
context.contentResolver,
doc.uri,
Point(size.width, size.height),
null
)
//1. If document is local file just skip this section
//1.1. Check if we can get thumbnail from the document fastest way
if (doc.uri.scheme != "file") {
DocumentsContract.getDocumentThumbnail(
context.contentResolver,
doc.uri,
Point(size.width, size.height),
null
)
} else null

}.getOrNull() ?: runCatching {
//2. If not, try to load thumbnail from content resolver if allowed
if (DocManBuild.loadThumbnail()) {
Expand All @@ -90,7 +95,7 @@ class DocManMedia {
when {
doc.isImage(context) -> imageThumbnail(doc, size, context)
doc.isVideo(context) -> videoThumbnail(doc, size, context)
doc.type == "application/pdf" -> pdfThumbnail(doc, size, context)
doc.isPDF() -> pdfThumbnail(doc, size, context)
else -> null
}
} else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DocManMimeType {
cursor.getString(cursor.getColumnIndexOrThrow(column))
} else null
}
} catch (e: Exception) {
} catch (_: Exception) {
null
}
}
Expand All @@ -87,7 +87,7 @@ class DocManMimeType {
return try {
retriever.setDataSource(context, uri)
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE)
} catch (e: Exception) {
} catch (_: Exception) {
null
} finally {
retriever.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ data class DirectoryFlags(
) {
companion object {
fun fromJson(resultMap: Map<String, Any?>?): DirectoryFlags = DirectoryFlags(
create = resultMap?.get("create") as? Boolean ?: true,
delete = resultMap?.get("delete") as? Boolean ?: true,
move = resultMap?.get("move") as? Boolean ?: true,
rename = resultMap?.get("rename") as? Boolean ?: true,
copy = resultMap?.get("copy") as? Boolean ?: true,
create = resultMap?.get("create") as? Boolean != false,
delete = resultMap?.get("delete") as? Boolean != false,
move = resultMap?.get("move") as? Boolean != false,
rename = resultMap?.get("rename") as? Boolean != false,
copy = resultMap?.get("copy") as? Boolean != false,
)
}
}
Expand All @@ -33,12 +33,12 @@ data class FileFlags(
) {
companion object {
fun fromJson(resultMap: Map<String, Any?>?): FileFlags = FileFlags(
write = resultMap?.get("write") as? Boolean ?: true,
delete = resultMap?.get("delete") as? Boolean ?: true,
move = resultMap?.get("move") as? Boolean ?: true,
rename = resultMap?.get("rename") as? Boolean ?: true,
copy = resultMap?.get("copy") as? Boolean ?: true,
thumbnail = resultMap?.get("thumbnail") as? Boolean ?: true,
write = resultMap?.get("write") as? Boolean != false,
delete = resultMap?.get("delete") as? Boolean != false,
move = resultMap?.get("move") as? Boolean != false,
rename = resultMap?.get("rename") as? Boolean != false,
copy = resultMap?.get("copy") as? Boolean != false,
thumbnail = resultMap?.get("thumbnail") as? Boolean != false,
)
}
}
Expand Down Expand Up @@ -79,9 +79,9 @@ class DocManProviderSettings(
providerName = map["providerName"] as? String,
providerSubtitle = map["providerSubtitle"] as? String,
mimeTypes = mimeTypes,
showInSystemUI = map["showInSystemUI"] as? Boolean ?: true,
supportRecent = map["supportRecent"] as? Boolean ?: true,
supportSearch = map["supportSearch"] as? Boolean ?: true,
showInSystemUI = map["showInSystemUI"] as? Boolean != false,
supportRecent = map["supportRecent"] as? Boolean != false,
supportSearch = map["supportSearch"] as? Boolean != false,
maxRecentFiles = map["maxRecentFiles"] as? Int ?: 15,
maxSearchResults = map["maxSearchResults"] as? Int ?: 10,
directoryFlags = dirFlags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import devdf.plugins.docman.extensions.alreadyRunning

/** Queue for the method calls, and manages the method calls in it. */
class DocManQueueManager {
val queue: MutableMap<Int, MethodBase> = mutableMapOf()
/** The queue used for all methods for activity channel, */
val queue: MutableMap<String, MethodBase> = mutableMapOf()

/** Adds method to the queue with validation.
* If the method is already in the queue, set result as error,
Expand Down Expand Up @@ -33,7 +34,7 @@ class DocManQueueManager {
* @param result Any data to send as result.
* @return true if the method call is removed from the queue, false otherwise.
*/
fun finishWithSuccess(requestCode: Int, result: Any?): Boolean {
fun finishWithSuccess(requestCode: String, result: Any?): Boolean {
//1. Send the result
method(requestCode)?.result?.success(result)
//2. Remove the method call from the queue
Expand All @@ -51,7 +52,7 @@ class DocManQueueManager {
* @return true if the method call is removed from the queue, false otherwise.
*/
fun finishWithError(
request: Int,
request: String,
code: String,
message: String?,
details: Any?
Expand All @@ -71,7 +72,7 @@ class DocManQueueManager {
* It's `ordinal` from the `DocManMethod` enum.
* @return true if the method call is removed from the queue, false otherwise.
*/
fun finishNotImplemented(requestCode: Int): Boolean {
fun finishNotImplemented(requestCode: String): Boolean {
//1. Send the error
method(requestCode)?.result?.notImplemented()
//2. Remove the method call from the queue
Expand All @@ -85,7 +86,7 @@ class DocManQueueManager {
* It's `ordinal` from the `DocManMethod` enum.
* @return The method that was removed from the queue.
*/
fun remove(requestCode: Int): MethodBase? =
fun remove(requestCode: String): MethodBase? =
queue.remove(requestCode)

/** Get the method call from the queue with the [requestCode]
Expand All @@ -94,15 +95,15 @@ class DocManQueueManager {
* It's `ordinal` from the `DocManMethod` enum.
* @return The method call.
* */
fun method(requestCode: Int): MethodBase? = queue[requestCode]
fun method(requestCode: String): MethodBase? = queue[requestCode]

/** Get the method call from the queue with the [requestCode]
*
* @param requestCode The request code of the method call.
* It's `ordinal` from the `DocManMethod` enum.
* @return The method call casted to the [T] type.
* */
inline fun <reified T : MethodBase> methodCast(requestCode: Int): T? {
inline fun <reified T : MethodBase> methodCast(requestCode: String): T? {
return queue[requestCode] as? T
}
}
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
sha256: c35bb79562d980e9a453fc715854e1ed39e24e7d0297a880ef54e17f9874a9d7
url: "https://pub.dev"
source: hosted
version: "5.0.0"
version: "5.1.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -271,5 +271,5 @@ packages:
source: hosted
version: "3.0.4"
sdks:
dart: ">=3.5.2 <4.0.0"
dart: ">=3.6.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
Loading
Loading