1、依赖导入和源码查看
网址:https://github.com/LuckSiege/PictureSelector/tree/version_component
使用PictureSelector
2、自定义路径的实现:
使用方法:setLoaderFactoryEngine进行设置
见[read.md]
(https://github.com/LuckSiege/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E5%8A%A0%E8%BD%BD%E8%87%AA%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E6%BA%90%EF%BC%9F)解析
代码实现:
PictureSelector.create(getContext()).setExtendLoaderEngine(getExtendLoaderEngine())
需要注意的是,但设置自定义的路径后,默认的文件路径不会再进行加载了
自定义数据加载器的设置
/**
* 自定义数据加载器
*/
private class MeExtendLoaderEngine implements ExtendLoaderEngine {
@Override
public void loadAllAlbumData(Context context,
OnQueryAllAlbumListener<LocalMediaFolder> query) {
LocalMediaFolder folder = SandboxFileLoader
.loadInAppSandboxFolderFile(context, getSandboxPath());
List<LocalMediaFolder> folders = new ArrayList<>();
folders.add(folder);
query.onComplete(folders);
}
@Override
public void loadOnlyInAppDirAllMediaData(Context context,
OnQueryAlbumListener<LocalMediaFolder> query) {
LocalMediaFolder folder = SandboxFileLoader
.loadInAppSandboxFolderFile(context, getSandboxPath());
query.onComplete(folder);
}
@Override
public void loadFirstPageMediaData(Context context, long bucketId, int page, int pageSize, OnQueryDataResultListener<LocalMedia> query) {
LocalMediaFolder folder = SandboxFileLoader
.loadInAppSandboxFolderFile(context, getSandboxPath());
query.onComplete(folder.getData(), false);
}
@Override
public void loadMoreMediaData(Context context, long bucketId, int page, int limit, int pageSize, OnQueryDataResultListener<LocalMedia> query) {
}
}
/**
* 创建自定义输出目录
*
* @return
*/
private String getSandboxPath() {
File externalFilesDir = getContext().getExternalFilesDir("");
File customFile = new File(externalFilesDir.getAbsolutePath(), "Sandbox");
if (!customFile.exists()) {
customFile.mkdirs();
}
return customFile.getAbsolutePath() + File.separator;
}
3、问题出现
但是使用自定义路径的实现,数据加载的首页没有数据查看,切换之后就可以查看数据
4、问题解决
修改源码:
源码路径:
selector的模块中,
[本地路径]\PictureSelector\selector\src\main\java\com\luck\picture\lib,文件为PictureSelectorFragment.java