Skip to content

Commit

Permalink
---Fix null pointer problem
Browse files Browse the repository at this point in the history
  • Loading branch information
molihuan committed Jan 4, 2023
1 parent 41d1233 commit b0fbd8c
Show file tree
Hide file tree
Showing 54 changed files with 167 additions and 112 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {

// implementation fileTree(dir: "../pathselector/build/outputs/aar/", includes: ["*-release.aar", "*.jar"])
// implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.11'
// implementation 'com.github.getActivity:XXPermissions:16.2'
implementation 'com.github.getActivity:XXPermissions:16.5'

//调试用

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 @@ -87,7 +87,6 @@ private void setListeners() {

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

super.onActivityResult(requestCode, resultCode, data);
}

Expand All @@ -114,6 +113,7 @@ public void onClick(View v) {
new CustomTitlebarFragment(),
"55"
);

break;
case R.id.btn_custom_filebean_img_selector:
customFilebeanImgSelectShow();
Expand All @@ -128,6 +128,7 @@ public void onClick(View v) {
private void dialogSelectShow() {
//获取PathSelectFragment实例onBackPressed中处理返回按钮点击事件
selector = PathSelector.build(MainActivity.this, MConstants.BUILD_DIALOG)
.setRootPath("/storage/emulated/0/bilibili视频合并/")
.setMorePopupItemListeners(
new CommonItemListener("SelectAll") {
@Override
Expand Down Expand Up @@ -378,7 +379,7 @@ public int getFileBeanImageResource(boolean isDir, String extension, FileBean fi
break;
case "mp4":
//也可以使用默认的图片资源id
resourceId = com.molihuan.pathselector.R.mipmap.movie;
resourceId = com.molihuan.pathselector.R.mipmap.movie_mlh;
break;
default:
if (isDir) {
Expand Down
5 changes: 3 additions & 2 deletions pathselector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ android {
dependencies {
//TODO 精简工具包,去除不需要的工具类
//精简https://github.com/Blankj/AndroidUtilCode工具

//For offline integration, please change the next line to implementation project(path: ':AndroidUtilCode') and copy the AndroidUtilCode folder to your project, because it depends on the AndroidUtilCode tool.
embed project(path: ':AndroidUtilCode', configuration: 'default')

//embed(name: 'XXPermissions-16.2', ext: 'aar')

//权限申请框架
implementation 'com.github.getActivity:XXPermissions:16.5'
implementation 'com.github.getActivity:XXPermissions:16.6'
//万能适配器
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.11'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,59 @@ public int getFileBeanImageResource(boolean isDir, String extension, FileBean fi
int resourceId;
switch (extension) {
case "apk":
resourceId = R.mipmap.apk;
resourceId = R.mipmap.apk_mlh;
break;
case "avi":
resourceId = R.mipmap.avi;
resourceId = R.mipmap.avi_mlh;
break;
case "doc":
case "docx":
resourceId = R.mipmap.doc;
resourceId = R.mipmap.doc_mlh;
break;
case "exe":
resourceId = R.mipmap.exe;
resourceId = R.mipmap.exe_mlh;
break;
case "flv":
resourceId = R.mipmap.flv;
resourceId = R.mipmap.flv_mlh;
break;
case "gif":
resourceId = R.mipmap.gif;
resourceId = R.mipmap.gif_mlh;
break;
case "jpg":
case "jpeg":
case "png":
resourceId = R.mipmap.png;
resourceId = R.mipmap.png_mlh;
break;
case "mp3":
resourceId = R.mipmap.mp3;
resourceId = R.mipmap.mp3_mlh;
break;
case "mp4":
case "f4v":
resourceId = R.mipmap.movie;
resourceId = R.mipmap.movie_mlh;
break;
case "pdf":
resourceId = R.mipmap.pdf;
resourceId = R.mipmap.pdf_mlh;
break;
case "ppt":
case "pptx":
resourceId = R.mipmap.ppt;
resourceId = R.mipmap.ppt_mlh;
break;
case "wav":
resourceId = R.mipmap.wav;
resourceId = R.mipmap.wav_mlh;
break;
case "xls":
case "xlsx":
resourceId = R.mipmap.xls;
resourceId = R.mipmap.xls_mlh;
break;
case "zip":
resourceId = R.mipmap.zip;
resourceId = R.mipmap.zip_mlh;
break;
case "ext":
default:
if (isDir) {
resourceId = R.mipmap.folder;
resourceId = R.mipmap.folder_mlh;
} else {
resourceId = R.mipmap.documents;
resourceId = R.mipmap.documents_mlh;
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.os.Bundle;
import android.view.View;

import androidx.annotation.CallSuper;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -65,7 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {

public abstract void getComponents();

@CallSuper

public void initData() {
psf = (BasePathSelectFragment) mConfigData.fragmentManager.findFragmentByTag(MConstants.TAG_ACTIVITY_FRAGMENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void getComponents() {

@Override
public void initData() {
super.initData();


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.molihuan.pathselector.service.impl.PathFileManager;
import com.molihuan.pathselector.utils.CommonTools;
import com.molihuan.pathselector.utils.FileTools;
import com.molihuan.pathselector.utils.MConstants;
import com.molihuan.pathselector.utils.Mtools;
import com.xuexiang.xtask.XTask;
import com.xuexiang.xtask.core.ITaskChainEngine;
Expand Down Expand Up @@ -249,7 +250,7 @@ public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View v
selectedNumber++;
} else {
//超过选择的最大数量
Mtools.toast(getString(R.string.tip_filebeanitem_select_limit_exceeded));
Mtools.toast(getString(R.string.tip_filebeanitem_select_limit_exceeded_mlh));

}

Expand All @@ -265,9 +266,16 @@ public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View v

//如果是返回FileBean
if (position == 0) {
updateFileList(item.getPath());//更新当前路径
String path = item.getPath();
//如果当前路径比"/storage/emulated/0"还短则设置currentPath为"/storage/emulated/0"
if (path.length() <= MConstants.DEFAULT_ROOTPATH.length() && (!MConstants.DEFAULT_ROOTPATH.equals(path))) {
Mtools.toast(String.format(getString(R.string.tips_path_jump_error_exceeds_default_path_mlh), path, MConstants.DEFAULT_ROOTPATH));
path = MConstants.DEFAULT_ROOTPATH;
}

updateFileList(path);//更新当前路径
//刷新面包屑
psf.updateTabbarList();
psf.updateTabbarList(path);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public int setFragmentViewId() {
public void getComponents(View view) {

}

@Override
public void initData() {

Expand All @@ -83,6 +83,7 @@ public void initData() {

}


@Override
public void initView() {
showAllFragment();
Expand Down Expand Up @@ -187,61 +188,100 @@ public boolean isMultipleSelectionMode() {

@Override
public TabbarListAdapter getTabbarListAdapter() {
if (tabbarFragment == null) {
return null;
}
return tabbarFragment.getTabbarListAdapter();
}

@Override
public List<TabbarFileBean> getTabbarList() {
if (tabbarFragment == null) {
return null;
}
return tabbarFragment.getTabbarList();
}

@Override
public List<TabbarFileBean> updateTabbarList() {
//设置了不显示TabbarFragment则返回null
if (mConfigData.showTabbarFragment) {
if (mConfigData.showTabbarFragment && tabbarFragment != null) {
return tabbarFragment.updateTabbarList();
} else {
return null;
}
}

@Override
public List<TabbarFileBean> updateTabbarList(String path) {
if (mConfigData.showTabbarFragment && tabbarFragment != null) {
return tabbarFragment.updateTabbarList(path);
} else {
return null;
}
}

@Override
public void refreshTabbarList() {
if (tabbarFragment == null) {
return;
}
tabbarFragment.refreshTabbarList();
}

@Override
public List<CommonItemListener> getHandleItemListeners() {
if (handleFragment == null) {
return null;
}
return handleFragment.getHandleItemListeners();
}

@Override
public HandleListAdapter getHandleListAdapter() {
if (handleFragment == null) {
return null;
}
return handleFragment.getHandleListAdapter();
}

@Override
public void refreshHandleList() {
if (handleFragment == null) {
return;
}
handleFragment.refreshHandleList();
}

@Override
public MorePopupAdapter getMorePopupAdapter() {
if (titlebarFragment == null) {
return null;
}
return titlebarFragment.getMorePopupAdapter();
}

@Override
public List<CommonItemListener> getMorePopupItemListeners() {
if (titlebarFragment == null) {
return null;
}
return titlebarFragment.getMorePopupItemListeners();
}

@Override
public void refreshMorePopup() {
if (titlebarFragment == null) {
return;
}
titlebarFragment.refreshMorePopup();
}

@Override
public TextView getOnlyOneMorePopupTextView() {
if (titlebarFragment == null) {
return null;
}
return titlebarFragment.getOnlyOneMorePopupTextView();
}

Expand All @@ -267,15 +307,17 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
//保存这个uri目录的访问权限
if (VersionTool.isAndroid11()) {
if (requestCode == PermissionsTools.PERMISSION_REQUEST_CODE) {
Uri uri;
if ((uri = data.getData()) != null) {
mActivity.getContentResolver()
.takePersistableUriPermission(uri,
data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
);
if (data != null) {
Uri uri;
if ((uri = data.getData()) != null) {
mActivity.getContentResolver()
.takePersistableUriPermission(uri,
data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
);
}
//更新列表数据
fileShowFragment.updateFileList();
}
//更新列表数据
fileShowFragment.updateFileList();
}
}
super.onActivityResult(requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.molihuan.pathselector.fragment.AbstractTabbarFragment;
import com.molihuan.pathselector.service.IFileDataManager;
import com.molihuan.pathselector.service.impl.PathFileManager;
import com.molihuan.pathselector.utils.MConstants;
import com.molihuan.pathselector.utils.Mtools;
import com.xuexiang.xtask.XTask;
import com.xuexiang.xtask.core.ITaskChainEngine;
import com.xuexiang.xtask.core.param.ITaskResult;
Expand Down Expand Up @@ -121,14 +123,18 @@ private List<TabbarFileBean> initTabbarList() {

@Override
public List<TabbarFileBean> updateTabbarList() {
return updateTabbarList(psf.getCurrentPath());
}

@Override
public List<TabbarFileBean> updateTabbarList(String path) {
//开始异步获取数据
XTask.getTaskChain()
.addTask(XTask.getTask(new TaskCommand() {
@Override
public void run() throws Exception {
//TODO 开始异步处理数据
tabbarList = pathFileManager.updateTabbarList(initPath, psf.getCurrentPath(), tabbarList, tabbarListAdapter);
tabbarList = pathFileManager.updateTabbarList(initPath, path, tabbarList, tabbarListAdapter);

}
}))
Expand Down Expand Up @@ -156,8 +162,16 @@ public void refreshTabbarList() {
public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View v, int position) {
if (adapter instanceof TabbarListAdapter) {
TabbarFileBean item = tabbarList.get(position);
psf.updateFileList(item.getPath());
updateTabbarList();
String path = item.getPath();

//如果当前路径比"/storage/emulated/0"还短则设置currentPath为"/storage/emulated/0"
if (path.length() <= MConstants.DEFAULT_ROOTPATH.length() && (!MConstants.DEFAULT_ROOTPATH.equals(path))) {
Mtools.toast(String.format(getString(R.string.tips_path_jump_error_exceeds_default_path_mlh), path, MConstants.DEFAULT_ROOTPATH));
path = MConstants.DEFAULT_ROOTPATH;
}

psf.updateFileList(path);
updateTabbarList(path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface ITabbarFragment {

List<TabbarFileBean> updateTabbarList();

List<TabbarFileBean> updateTabbarList(String path);

/**
* 刷新 TabbarList ui
*
Expand Down
Loading

0 comments on commit b0fbd8c

Please sign in to comment.