Skip to content

Commit

Permalink
修复加载数据过慢,增加Rxjava,修复非Android 11访问data目录bug
Browse files Browse the repository at this point in the history
  • Loading branch information
molihuan committed Jul 4, 2022
1 parent 10ebbc9 commit d28b9b5
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//implementation project(path: ':fileselectorlib')//参考库
implementation project(path: ':fileselectorlib')//参考库

testImplementation 'junit:junit:4.12'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.molihuan.pathselector.fragments.PathSelectFragment;
import com.molihuan.pathselector.utils.Constants;
import com.molihuan.pathselector.utils.Mtools;
import com.zlylib.mlhfileselectorlib.FileSelector;

import java.util.List;

Expand Down Expand Up @@ -97,11 +98,18 @@ public void onClick(View v) {
activitySelectShow();
break;
case R.id.btn_custom_toolbar_selector :
customToolbarSelectShow();
//customToolbarSelectShow();
otherOpen();
break;
}
}

private void otherOpen() {
FileSelector.from(this)
.start();
}


public void cs(){

// List list = UriTools.data2UriMimeTypeData(Arrays.asList(new String[]{"txt"}));
Expand Down Expand Up @@ -203,7 +211,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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.Log;

import com.zlylib.mlhfileselectorlib.utils.FileUtils;
import com.zlylib.mlhfileselectorlib.utils.MimeType;
Expand Down Expand Up @@ -54,6 +55,7 @@ protected FileBean(Parcel in) {
uri = in.readParcelable(Uri.class.getClassLoader());
itemType = in.readInt();
isVisible = in.readByte() != 0;

}

public static final Creator<FileBean> CREATOR = new Creator<FileBean>() {
Expand Down Expand Up @@ -104,6 +106,7 @@ public FileBean(File file) {
isFile = file.isFile();
}
mimeType = FileUtils.getMimeType(file.getAbsolutePath());
Log.e("","开始");
}

public FileBean(long id, String mimeType) {
Expand Down
4 changes: 2 additions & 2 deletions pathselector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ dependencies {
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.6'

//Rxjava框架
// implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
// implementation 'io.reactivex.rxjava3:rxjava:3.1.5'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'io.reactivex.rxjava3:rxjava:3.1.5'

//基础控件
implementation 'androidx.recyclerview:recyclerview:1.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public FileListAdapter(List<FileBean> data) {

@Override
protected void convert(BaseViewHolder helper, FileBean fileBean) {

ImageView imgvFiletype = helper.getView(R.id.iv_file_type_fileitem);//文件类型图片
ImageView imgvEnter = helper.getView(R.id.iv_file_enter_fileitem);//右边进入图片
TextView tvFileName = helper.getView(R.id.tv_file_name_fileitem);//文件名称
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.molihuan.pathselector.R;
import com.molihuan.pathselector.utils.Commons;
import com.molihuan.pathselector.utils.FileTools;
import com.molihuan.pathselector.utils.PermissionsTools;
import com.molihuan.pathselector.utils.UriTools;

import java.io.File;
Expand All @@ -18,30 +19,30 @@

public class FileBean {
private String filePath;//文件路径(必须)
private Boolean dir;//是否是文件夹
private Boolean file;//是否文件
private boolean dir;//是否是文件夹
private boolean file;//是否文件
private String fileName;//名称
private String fileNameNoExtension;//名称(无后缀)
private String fileExtension;//后缀
private Integer fileImgType;//文件图片类型
private int fileImgType;//文件图片类型
private String parentPath;//上一级目录/父目录
private String parentName;//上一级文件夹名称
private Integer childrenFileNumber;//子文件数量
private Integer childrenDirNumber;//子文件夹数量
private int childrenFileNumber;//子文件数量
private int childrenDirNumber;//子文件夹数量
private String size;//占空间大小
private Boolean visible;//checkbox是否显示
private Boolean checked;//checkbox是否选择
private boolean visible;//checkbox是否显示
private boolean checked;//checkbox是否选择

private Boolean useUri;//是否使用uri地址
private boolean useUri;//是否使用uri地址
/**
* 通过DocumentFile可以对Android/data目录进行操作
* 具体怎么操作可以百度
*
*/
private DocumentFile documentFile;//documentFile

private Long modifyTime;//文件修改时间
private Long simpleSize;//简单文件大小
private long modifyTime;//文件修改时间
private long simpleSize;//简单文件大小



Expand All @@ -54,7 +55,13 @@ public FileBean(String filePath, Boolean useUri) {

public FileBean(String filePath, Boolean useUri,DocumentFile documentFile) {
this.filePath = filePath;
this.useUri = useUri;

if (PermissionsTools.isAndroid11()){
this.useUri = useUri;
}else {
this.useUri = false;
}


if (this.useUri){//使用Uri
this.documentFile=documentFile;
Expand All @@ -76,11 +83,13 @@ public FileBean(String filePath, Boolean useUri,DocumentFile documentFile) {
parentName=FileTools.getDirName(uriFile);
childrenFileNumber=0;
childrenDirNumber=0;
size=FileTools.getSize(uriFile);
//size=FileTools.getSize(uriFile);
visible=false;
checked=false;
modifyTime=documentFile.lastModified();
simpleSize =FileTools.getSimpleSize(uriFile);
//modifyTime=documentFile.lastModified();
if (file){
//simpleSize =FileTools.getSimpleSize(uriFile);
}

}else {//直接使用路径

Expand All @@ -99,12 +108,14 @@ public FileBean(String filePath, Boolean useUri,DocumentFile documentFile) {
parentName=FileTools.getDirName(filePath);
childrenFileNumber=FileTools.getChildrenNumber(filePath)[0];
childrenDirNumber=FileTools.getChildrenNumber(filePath)[1];
size=FileTools.getSize(filePath);
// size=FileTools.getSize(filePath);
visible=false;
checked=false;
// modifyTime=FileTools.getFileLastModified(filePath);
if (file){
//simpleSize =FileTools.getSimpleSize(filePath);
}

modifyTime=FileTools.getFileLastModified(filePath);
simpleSize =FileTools.getSimpleSize(filePath);
}


Expand All @@ -120,7 +131,7 @@ public FileBean(String filePath, Boolean useUri,DocumentFile documentFile) {
* @return
*/

public Integer setImageResourceByExtension(String extension) {
public int setImageResourceByExtension(String extension) {
int resourceId;
switch (extension){
case "apk":
Expand Down Expand Up @@ -187,15 +198,15 @@ public void setFilePath(String filePath) {
this.filePath = filePath;
}

public void setVisible(Boolean visible) {
public void setVisible(boolean visible) {
this.visible = visible;
}

public void setChecked(Boolean checked) {
public void setChecked(boolean checked) {
this.checked = checked;
}

public void setUseUri(Boolean useUri) {
public void setUseUri(boolean useUri) {
this.useUri = useUri;
}

Expand All @@ -207,11 +218,11 @@ public String getFilePath() {
return filePath;
}

public Boolean isDir() {
public boolean isDir() {
return dir;
}

public Boolean isFile() {
public boolean isFile() {
return file;
}

Expand All @@ -227,7 +238,7 @@ public String getFileExtension() {
return fileExtension;
}

public Integer getFileImgType() {
public int getFileImgType() {
return fileImgType;
}

Expand All @@ -239,39 +250,39 @@ public String getParentName() {
return parentName;
}

public Integer getChildrenFileNumber() {
public int getChildrenFileNumber() {
return childrenFileNumber;
}

public Integer getChildrenDirNumber() {
public int getChildrenDirNumber() {
return childrenDirNumber;
}

public String getSize() {
return size;
}

public Boolean isVisible() {
public boolean isVisible() {
return visible;
}

public Boolean isChecked() {
public boolean isChecked() {
return checked;
}

public Boolean isUseUri() {
public boolean isUseUri() {
return useUri;
}

public DocumentFile getDocumentFile() {
return documentFile;
}

public Long getModifyTime() {
public long getModifyTime() {
return modifyTime;
}

public Long getSimpleSize() {
public long getSimpleSize() {
return simpleSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.molihuan.pathselector.utils.Commons;
import com.molihuan.pathselector.utils.FileTools;
import com.molihuan.pathselector.utils.PermissionsTools;
import com.molihuan.pathselector.utils.UriTools;

import java.io.File;
Expand Down Expand Up @@ -41,6 +42,12 @@ public TabbarFileBean(String filePath, Boolean useUri,DocumentFile documentFile)
this.filePath = filePath;
this.useUri = useUri;

if (PermissionsTools.isAndroid11()){
this.useUri = useUri;
}else {
this.useUri = false;
}

if (this.useUri){
this.documentFile=documentFile;
File uriFile = UriTools.uri2File(documentFile.getUri(), Commons.getApplicationByReflect().getBaseContext(), Commons.getApplicationByReflect());
Expand Down
Loading

0 comments on commit d28b9b5

Please sign in to comment.