-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from rosuH/dev
Improved custom file type.
- Loading branch information
Showing
10 changed files
with
145 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,19 +10,39 @@ import me.rosuh.filepicker.filetype.* | |
*/ | ||
class DefaultFileDetector : AbstractFileDetector() { | ||
|
||
var enableCustomTypes: Boolean = false | ||
private set | ||
|
||
private val allDefaultFileType: ArrayList<FileType> by lazy { | ||
val fileTypes = ArrayList<FileType>() | ||
fileTypes.add(AudioFileType()) | ||
fileTypes.add(RasterImageFileType()) | ||
fileTypes.add(CompressedFileType()) | ||
fileTypes.add(DataBaseFileType()) | ||
fileTypes.add(ExecutableFileType()) | ||
fileTypes.add(FontFileType()) | ||
fileTypes.add(PageLayoutFileType()) | ||
fileTypes.add(TextFileType()) | ||
fileTypes.add(VideoFileType()) | ||
fileTypes.add(WebFileType()) | ||
fileTypes | ||
ArrayList<FileType>() | ||
} | ||
|
||
fun registerDefaultTypes() { | ||
with(allDefaultFileType) { | ||
clear() | ||
add(AudioFileType()) | ||
add(RasterImageFileType()) | ||
add(CompressedFileType()) | ||
add(DataBaseFileType()) | ||
add(ExecutableFileType()) | ||
add(FontFileType()) | ||
add(PageLayoutFileType()) | ||
add(TextFileType()) | ||
add(VideoFileType()) | ||
add(WebFileType()) | ||
} | ||
enableCustomTypes = false | ||
} | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2020/9/16 | ||
* save user's custom file types | ||
*/ | ||
fun registerCustomTypes(customFileTypes: ArrayList<FileType>) { | ||
allDefaultFileType.clear() | ||
allDefaultFileType.addAll(customFileTypes) | ||
enableCustomTypes = true | ||
} | ||
|
||
override fun fillFileType(itemBeanImpl: FileItemBeanImpl): FileItemBeanImpl { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import android.support.annotation.StringRes | |
import me.rosuh.filepicker.FilePickerActivity | ||
import me.rosuh.filepicker.R | ||
import me.rosuh.filepicker.engine.ImageEngine | ||
import me.rosuh.filepicker.filetype.FileType | ||
|
||
/** | ||
* | ||
|
@@ -14,6 +15,12 @@ import me.rosuh.filepicker.engine.ImageEngine | |
*/ | ||
class FilePickerConfig(private val pickerManager: FilePickerManager) { | ||
|
||
var isAutoFilter: Boolean = false | ||
|
||
private val customFileTypes: ArrayList<FileType> by lazy { | ||
ArrayList<FileType>(2) | ||
} | ||
|
||
private val contextRes = pickerManager.contextRef!!.get()!!.resources | ||
|
||
/** | ||
|
@@ -77,9 +84,14 @@ class FilePickerConfig(private val pickerManager: FilePickerManager) { | |
/** | ||
* 自定文件类型甄别器和默认类型甄别器 | ||
*/ | ||
@Deprecated( | ||
"Use 'register' function instead.", | ||
ReplaceWith("registerFileType(types)"), | ||
level = DeprecationLevel.WARNING | ||
) | ||
var customDetector: AbstractFileDetector? = null | ||
private set | ||
val defaultFileDetector: DefaultFileDetector by lazy { DefaultFileDetector() } | ||
|
||
val defaultFileDetector: DefaultFileDetector by lazy { DefaultFileDetector().also { it.registerDefaultTypes() } } | ||
|
||
/** | ||
* 点击操作接口,采用默认实现 | ||
|
@@ -140,7 +152,10 @@ class FilePickerConfig(private val pickerManager: FilePickerManager) { | |
} | ||
|
||
@JvmOverloads | ||
fun storageType(volumeName: String = "", @StorageMediaType storageMediaType: String): FilePickerConfig { | ||
fun storageType( | ||
volumeName: String = "", | ||
@StorageMediaType storageMediaType: String | ||
): FilePickerConfig { | ||
mediaStorageName = volumeName | ||
mediaStorageType = storageMediaType | ||
return this | ||
|
@@ -157,11 +172,19 @@ class FilePickerConfig(private val pickerManager: FilePickerManager) { | |
} | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2020/9/15 | ||
* custom file type had upgrade to [registerFileType], which can simplify your usage. | ||
* 实现 [AbstractFileDetector] 以自定义您自己的文件类型检测器 | ||
* Custom your file detector by implementing [AbstractFileDetector] | ||
*/ | ||
@Deprecated( | ||
"Use 'register' function instead.", | ||
ReplaceWith("registerFileType(types)"), | ||
level = DeprecationLevel.WARNING | ||
) | ||
fun customDetector(detector: AbstractFileDetector): FilePickerConfig { | ||
customDetector = detector | ||
this.customDetector = detector | ||
return this | ||
} | ||
|
||
|
@@ -227,6 +250,28 @@ class FilePickerConfig(private val pickerManager: FilePickerManager) { | |
this.customImageEngine = ie | ||
return this | ||
} | ||
/** | ||
* @author [email protected] | ||
* @date 2020/9/15 | ||
* 用于注册你自定义的文件类型。 | ||
* 库将自动调用你的自定义类型里的[FileType.verify]来识别文件。如果识别成功,就会自动填充到 [me.rosuh.filepicker.bean.FileItemBeanImpl.fileType] 中 | ||
* 如果[autoFilter]为 true,那么库将自动过滤掉不符合你自定义类型的文件。不会在结果中显示出来。 | ||
* 如果为 false,那么就只是检测类型。不会对结果列表做修改 | ||
* 你不需要再调用[fileType]方法,否则将默认使用[fileType] | ||
* --- | ||
* Pass your custom [FileType] instances list and all done! This lib would auto detect file type | ||
* by using [FileType.verify]. | ||
* If [autoFilter] is true, this lib will filter result by using your custom file types. | ||
* If [autoFilter] is true, the library will automatically filter out files that do not meet your custom type. | ||
* Will not show up in the results. * If it is false, then only the detection type. No changes to the result list | ||
* You don't need to call [fileType] again ! | ||
*/ | ||
fun registerFileType(types: List<FileType>, autoFilter: Boolean = true): FilePickerConfig { | ||
this.customFileTypes.addAll(types) | ||
this.defaultFileDetector.registerCustomTypes(customFileTypes) | ||
this.isAutoFilter = autoFilter | ||
return this | ||
} | ||
|
||
fun forResult(requestCode: Int) { | ||
val activity = pickerManager.contextRef?.get()!! | ||
|
@@ -246,16 +291,19 @@ class FilePickerConfig(private val pickerManager: FilePickerManager) { | |
*/ | ||
@get:StorageMediaType | ||
const val STORAGE_EXTERNAL_STORAGE = "STORAGE_EXTERNAL_STORAGE" | ||
|
||
/** | ||
* TODO 可拔插的 SD 卡 | ||
*/ | ||
@get:StorageMediaType | ||
const val STORAGE_UUID_SD_CARD = "STORAGE_UUID_SD_CARD" | ||
|
||
/** | ||
* TODO 可拔插 U 盘 | ||
*/ | ||
@get:StorageMediaType | ||
const val STORAGE_UUID_USB_DRIVE = "STORAGE_UUID_USB_DRIVE" | ||
|
||
/** | ||
* 自定义路径 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Wed Nov 27 14:17:28 CST 2019 | ||
#Wed Sep 16 10:42:32 CST 2020 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.