Skip to content

Commit

Permalink
Merge pull request javakam#63 from javakam/dev
Browse files Browse the repository at this point in the history
v2.4.0
  • Loading branch information
javakam authored Nov 29, 2021
2 parents 86c4a6a + 89b6c3e commit 0e7581f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ repositories {
mavenCentral()
}
implementation 'com.github.javakam:file.core:2.3.0@aar' //核心库必选(Core library required)
implementation 'com.github.javakam:file.selector:2.3.0@aar' //文件选择器(File selector)
implementation 'com.github.javakam:file.compressor:2.3.0@aar'//图片压缩, 修改自Luban(Image compression, based on Luban)
implementation 'com.github.javakam:file.core:2.4.0@aar' //核心库必选(Core library required)
implementation 'com.github.javakam:file.selector:2.4.0@aar' //文件选择器(File selector)
implementation 'com.github.javakam:file.compressor:2.4.0@aar'//图片压缩, 修改自Luban(Image compression, based on Luban)
```

#### 2. `Application`中初始化(Initialization in Application)
Expand Down
5 changes: 5 additions & 0 deletions README_VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 更新日志(Update log)

## v2.4.0
```
Fixed #62 👉 https://github.com/javakam/FileOperator/issues/62
```

## v2.3.0
```
1.移除`FileUri`中多于代码;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ando.file.sample.ui.selector.fragment

import ando.file.core.*
import ando.file.selector.*
import ando.file.selector.FileType.Companion.supplement
import android.content.Intent
import android.net.Uri
import android.os.Bundle
Expand Down Expand Up @@ -98,6 +99,11 @@ class FileSelectFragment : Fragment() {
if (it) {
mFileSelectorRequest = REQUEST_CHOOSE_FILE
mFileSelector = chooseFile(REQUEST_CHOOSE_FILE, mCallBack)

//Fixed At 2021年11月29日 星期一
//#62 https://github.com/javakam/FileOperator/issues/62
//testIssue62(REQUEST_CHOOSE_FILE)

}
}
}
Expand Down Expand Up @@ -204,7 +210,7 @@ class FileSelectFragment : Fragment() {
fun Fragment.chooseFile(requestCode: Int, callback: FileSelectCallBack): FileSelector {
val optionsWord = FileSelectOptions().apply {
fileType = FileType.WORD
singleFileMaxSize = 5242880
singleFileMaxSize = 5242880 //5M
}
val optionsExcel = FileSelectOptions().apply {
fileType = FileType.EXCEL
Expand Down Expand Up @@ -259,4 +265,46 @@ class FileSelectFragment : Fragment() {
.choose()
}

fun testIssue62(requestCode: Int) {
val optionsType = FileSelectOptions().apply {
fileType = FileType.TXT.supplement("jar", "apk", "doc")
singleFileMaxSize = 5242880 //5M
fileCondition = object : FileSelectCondition {
override fun accept(fileType: IFileType, uri: Uri?): Boolean {
return (fileType == this@apply.fileType && uri != null && !uri.path.isNullOrBlank())
}
}
}

val mimeTypes = arrayOf("text/*", "application/*")
mFileSelector = FileSelector
.with(this)
.setRequestCode(requestCode)
.setSingleFileMaxSize(5242880, "上传文件大小不能超过5M!")
.setOverLimitStrategy(FileGlobal.OVER_LIMIT_EXCEPT_ALL)
.setTypeMismatchTip("暂不支持上传此格式!")
.setMimeTypes(*mimeTypes)
.applyOptions(optionsType)
.filter(object : FileSelectCondition {
override fun accept(fileType: IFileType, uri: Uri?): Boolean {
FileLogger.w("${optionsType.fileType}")
FileType.TXT.getMimeTypeArray()?.forEach {
FileLogger.w(it)
}
return (fileType == optionsType.fileType && uri != null && !uri.path.isNullOrBlank())

}
}).callback(object : FileSelectCallBack {
override fun onSuccess(results: List<FileSelectResult>?) {
FileLogger.e("成功: ${results?.size}")
}

override fun onError(e: Throwable?) {
FileLogger.e("失败: ${e?.message}")
}
})
.choose()

}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
minSdkVersion = 21
targetSdkVersion = 30
versionCode = 13
versionName = "2.3.0"
versionName = "2.4.0"
}
repositories {
google()
Expand Down
37 changes: 30 additions & 7 deletions library_selector/src/main/java/ando/file/selector/FileSelector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class FileSelector private constructor(builder: Builder) {
private var mFileSelectOptions: MutableList<FileSelectOptions>? = null
private val mFileTypeComposite: MutableList<IFileType> by lazy { mutableListOf() }
private var isOptionsEmpty: Boolean = false
private val optionUnknown: FileSelectOptions by lazy { FileSelectOptions().apply { fileType = UNKNOWN } }

//onActivityResult
var requestCode: Int? = -1
Expand Down Expand Up @@ -118,7 +117,7 @@ class FileSelector private constructor(builder: Builder) {
isOptionsEmpty = mFileSelectOptions.isNullOrEmpty()
if (mFileSelectOptions == null) mFileSelectOptions = mutableListOf()
if (isOptionsEmpty) {
mFileSelectOptions?.add(optionUnknown)
mFileSelectOptions?.add(FileSelectOptions().apply { fileType = UNKNOWN })
mFileTypeComposite.add(UNKNOWN)
} else {
if (mFileTypeComposite.isNotEmpty()) mFileTypeComposite.clear()
Expand Down Expand Up @@ -151,11 +150,23 @@ class FileSelector private constructor(builder: Builder) {
}

filterUri(intentData) { o: FileSelectOptions?, t: IFileType, tf: Boolean, s: Long, sf: Boolean ->
val realOption: FileSelectOptions = o ?: optionUnknown
val realOption: FileSelectOptions = o ?: FileSelectOptions().apply {
fileType = UNKNOWN
fileTypeMismatchTip = mFileTypeMismatchTip
minCount = mMinCount
maxCount = mMaxCount
minCountTip = mMinCountTip
maxCountTip = mMaxCountTip
singleFileMaxSize = mSingleFileMaxSize
singleFileMaxSizeTip = mSingleFileMaxSizeTip
allFilesMaxSize = mAllFilesMaxSize
allFilesMaxSizeTip = mAllFilesMaxSizeTip
fileCondition = mFileSelectCondition
}
if (!(tf || isOptionsEmpty)) {
mFileSelectCallBack?.onError(
Throwable(
if (realOption.fileTypeMismatchTip?.isNotBlank() == true) realOption.fileTypeMismatchTip else mFileTypeMismatchTip
if (realOption.fileTypeMismatchTip.isNullOrBlank()) mFileTypeMismatchTip else realOption.fileTypeMismatchTip
)
)
return@filterUri
Expand Down Expand Up @@ -211,7 +222,19 @@ class FileSelector private constructor(builder: Builder) {
FileLogger.w("Multi-> filterUri=${o?.fileType} fileType=$t typeFit=$tf isCurrentType=$isCurrentType size=$s sizeFit=$sf")
}

val realOption: FileSelectOptions = o ?: optionUnknown
val realOption: FileSelectOptions = o ?: FileSelectOptions().apply {
fileType = UNKNOWN
fileTypeMismatchTip = mFileTypeMismatchTip
minCount = mMinCount
maxCount = mMaxCount
minCountTip = mMinCountTip
maxCountTip = mMaxCountTip
singleFileMaxSize = mSingleFileMaxSize
singleFileMaxSizeTip = mSingleFileMaxSizeTip
allFilesMaxSize = mAllFilesMaxSize
allFilesMaxSizeTip = mAllFilesMaxSizeTip
fileCondition = mFileSelectCondition
}

if (relationMap[realOption] == null) relationMap[realOption] = SelectResult(checkPass = true)
val selectResult: SelectResult = relationMap[realOption] ?: SelectResult(checkPass = true)
Expand All @@ -220,7 +243,7 @@ class FileSelector private constructor(builder: Builder) {
if (!(tf || isOptionsEmpty)) {
mFileSelectCallBack?.onError(
Throwable(
if (realOption.fileTypeMismatchTip?.isNotBlank() == true) realOption.fileTypeMismatchTip else mFileTypeMismatchTip
if (realOption.fileTypeMismatchTip.isNullOrBlank()) mFileTypeMismatchTip else realOption.fileTypeMismatchTip
)
)

Expand Down Expand Up @@ -530,7 +553,7 @@ class FileSelector private constructor(builder: Builder) {

private fun limitFileSize(fileSize: Long, sizeThreshold: Long): Boolean {
if (isDebug()) {
FileLogger.e("limitFileSize: $fileSize ${fileSize <= sizeThreshold}")
FileLogger.e("limitFileSize: $fileSize ; (fileSize <= sizeThreshold): ${fileSize <= sizeThreshold}")
}
return fileSize <= sizeThreshold
}
Expand Down

0 comments on commit 0e7581f

Please sign in to comment.