Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
molihuan committed Jul 3, 2022
1 parent 6773d39 commit 10ebbc9
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 31 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

提供文件或路径选择,自动申请存储权限,支持安卓4.4 ~ 12,支持Android/data目录访问,支持自定义UI,支持SD卡。(Provide file or path selection, automatically apply for storage permission, support Android 4.4 to 12, support Android/data directory access, support custom UI,Support SD card.The Keyword:file selector operator android/data android 11)

## 语言(Language)

### **[中文](./README.md)** | [English](./README_EN.md)

## 前言

#### 在开始之前可以给我一个小星星吗?
Expand All @@ -16,10 +20,6 @@
#### [Github地址](https://github.com/molihuan/mlhfileselectorlib)
#### [Gitee地址](https://gitee.com/molihuan/mlhfileselectorlib)

## 语言(Language)

### **[中文](./README.md)** | [English](./README_EN.md)

## 一、如何使用

#### 第1步:添加仓库:
Expand Down Expand Up @@ -298,7 +298,9 @@ mPathSelectFragment = PathSelector.build(MainActivity.this, Constants.BUILD_ACTI

请在你的项目中的`AndroidManifest.xml`设置一致

#### 代码混淆

- 一般来说无需配置,会自动导入混淆规则

# 非常感谢

Expand Down
10 changes: 6 additions & 4 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Provide file or path selection, automatically apply for storage permission, support Android 4.4 to 12, support Android/data directory access, support custom UI,Support SD card.The Keyword:file selector operator android/data android 11

## Language(语言)

### [Chinese](./README.md) | **[English](./README_EN.md)**

## Preface

#### may I have a little star before we begin?
Expand All @@ -18,10 +22,6 @@ Provide file or path selection, automatically apply for storage permission, supp

#### [Gitee](https://gitee.com/molihuan/mlhfileselectorlib)

## 语言(Language)

### [Chinese](./README.md) | **[English](./README_EN.md)**

## 一、how to use

#### Step 1: Add repository:
Expand Down Expand Up @@ -302,7 +302,9 @@ mPathSelectFragment = PathSelector.build(MainActivity.this, Constants.BUILD_ACTI

Please be consistent in setting 'androidmanifest.xml' in your project

#### code confusion

- Generally, obfuscation rules are automatically imported without configuration

# Thank

Expand Down
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled true // 开启代码混淆
zipAlignEnabled false // 开启Zip压缩优化
shrinkResources false // 移除未被使用的资源
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void activitySelectShow(){
//Constants.BUILD_ACTIVITY为ACTIVITY模式
PathSelector.build(MainActivity.this, Constants.BUILD_ACTIVITY)
.requestCode(10011)//请求码
.setRootPath("/storage/emulated/0")//设置根目录(注意最后没有/)
.setRootPath("/storage/emulated/0/")//设置根目录(注意最后没有/)
.setMaxCount(3)//设置最大选择数量,默认是-1不限制
//.setToolbarFragment(new TestFragment())//加载自定义ToolbarFragment
//.setMoreChooseFragment(new TestFragment())//加载自定义MoreChooseFragment
Expand Down
6 changes: 4 additions & 2 deletions pathselector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0.6"
versionName "1.0.9"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -23,7 +23,9 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled false // 开启代码混淆
zipAlignEnabled false // 开启Zip压缩优化
shrinkResources false // 移除未被使用的资源
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand Down
21 changes: 20 additions & 1 deletion pathselector/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,23 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

# 指定代码的压缩级别,值在0-7之间。一般设置5足矣
-optimizationpasses 5

# 打印混淆信息
-verbose

# 代码优化选项,不加该行会将没有用到的类删除,发布的是代码库这个选项需要
# 在做混淆之前最开始会默认对代码进行压缩,为了增加反编译的难度可以选择不压缩
-dontshrink

# 过滤泛型,出现类型转换错误时再启用这个。目前的项目暂时无泛型类型,我先注释了
-keepattributes Signature

#抛出异常时保留代码行数
-keepattributes SourceFile,LineNumberTable
# 不混淆指定类
-keep public class com.molihuan.pathselector.utils.Commons { *; }
-keep public class com.molihuan.pathselector.utils.FileTools { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ private void moreChooseCheckBox(int position){
break;
default:
FileBean fileBean = mFileList.get(position);
fileBean.setChecked(true);
if (!fileBean.isChecked()&&fileBean.isVisible()){
fileBean.setChecked(true);
}
mFileListAdapter.notifyDataSetChanged();
//choosedFileItemNumber++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public SelectManager requestCode(int code){
* @return
*/
public SelectManager setRootPath(String path){
mSelectOptions.rootPath = path;
if (path.endsWith("/")){//判断是否是以/结束的
mSelectOptions.rootPath = path.substring(0,path.length()-1);//去除最后的/
}else {
mSelectOptions.rootPath = path;
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static void getTabbarFileBeanList(List<TabbarFileBean> tabbarList,String
}

/**
* 更新tabbarFileBeanList数据
* 通过uri更新tabbarFileBeanList数据
* @param tabbarList
* @param tabbarAdapter
* @param path
Expand Down Expand Up @@ -197,25 +197,18 @@ public static List<FileBean> upDataFileBeanListByUri(Context context, Uri uri, L
if (context == null || uri == null) return null;//判空
//通过URI创建DocumentFile对象
DocumentFile rootDocumentFile = DocumentFile.fromSingleUri(context, uri);
Mtools.log("fromSingleUri完毕");
//Mtools.log("fromSingleUri完毕");
if (rootDocumentFile == null) return null;//判空
Mtools.log("rootDocumentFile有值");
//Mtools.log("rootDocumentFile有值");



//创建一个 DocumentFile表示以给定的 Uri根的文档树。其实就是获取子目录的权限
DocumentFile pickedDir = rootDocumentFile.fromTreeUri(context, uri);
Mtools.log("fromTreeUri完毕");
//Mtools.log("fromTreeUri完毕");
if (pickedDir==null) return null;//判空
Mtools.log("pickedDir有值");
//Mtools.log("pickedDir有值");
for (DocumentFile i : pickedDir.listFiles()) {//遍历
if (i.isDirectory()) {//如果是一个目录
Mtools.log("文件:"+i.getName());
Mtools.log("类型:"+i.getType());
} else {//如果是一个文件
Mtools.log("文件:"+i.getName());
Mtools.log("类型:"+i.getType());
}

fileBean=new FileBean(UriTools.uri2File(i.getUri()),true,i);
//只添加文件后缀符合要求的、文件夹添加、没有要求就都添加
Expand Down Expand Up @@ -255,14 +248,14 @@ public static void handleDirSubfileByUri(ContentResolver contentResolver, Contex
if (context == null || uri == null) return;//判空
//通过URI创建DocumentFile对象
DocumentFile rootDocumentFile = DocumentFile.fromSingleUri(context, uri);
Mtools.log("fromSingleUri完毕");
//Mtools.log("fromSingleUri完毕");
if (rootDocumentFile == null) return;
Mtools.log("rootDocumentFile有值");
//Mtools.log("rootDocumentFile有值");
//创建一个 DocumentFile表示以给定的 Uri根的文档树。其实就是获取子目录的权限
DocumentFile pickedDir = rootDocumentFile.fromTreeUri(context, uri);
Mtools.log("fromTreeUri完毕");
//Mtools.log("fromTreeUri完毕");
if (pickedDir==null) return;
Mtools.log("pickedDir有值");
//Mtools.log("pickedDir有值");
for (DocumentFile i : pickedDir.listFiles()) {//遍历
if (i.isDirectory()) {//如果是一个目录
handleDirSubfileByUri(contentResolver,context, i.getUri(), handleType,filerType);//递归
Expand Down

0 comments on commit 10ebbc9

Please sign in to comment.