From 55812e1794d43575f9d5b588f527418049a8f474 Mon Sep 17 00:00:00 2001
From: molihuan <1492906929@qq.com>
Date: Tue, 27 Dec 2022 16:57:15 +0800
Subject: [PATCH] :fire:Fix fragment mode shows replacement bugs and
optimization details
---
.idea/deploymentTargetDropDown.xml | 17 ------------
README.md | 6 +++--
README_EN.md | 8 ++++--
.../pathselectdemo/activity/MainActivity.java | 22 +++++++++++++--
app/src/main/res/layout/activity_main.xml | 8 ++++++
pathselector/build.gradle | 4 +--
.../configs/PathSelectorConfig.java | 6 +++++
.../controller/impl/FragmentController.java | 23 ++++------------
.../pathselector/dao/SelectConfigData.java | 3 +--
.../fragment/impl/PathSelectFragment.java | 24 +++++++++++++++--
.../pathselector/utils/FragmentTools.java | 22 +++++++++++++++
.../molihuan/pathselector/utils/Mtools.java | 6 ++++-
.../pathselector/utils/PermissionsTools.java | 27 ++++++++++++++-----
13 files changed, 121 insertions(+), 55 deletions(-)
delete mode 100644 .idea/deploymentTargetDropDown.xml
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
deleted file mode 100644
index ac6bf40..0000000
--- a/.idea/deploymentTargetDropDown.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 9a3b257..7268dc3 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
## 特性
-- [x] 自动申请存储权限
+- [x] 自动申请存储权限(可以控制)
- [x] 安卓 4.4 ~ 13
- [x] Android/data和Android/obb目录访问和操作
- [x] SD卡
@@ -39,6 +39,8 @@
#### 在开始之前可以给项目一个Star吗?非常感谢,你的支持是我唯一的动力。欢迎Star和Issues!
+#### 欢迎Pr,请Pr提交到dev分支
+
#### 项目地址:
##### [Github地址](https://github.com/molihuan/mlhfileselectorlib)
##### [Gitee地址](https://gitee.com/molihuan/mlhfileselectorlib)
@@ -88,7 +90,7 @@ dependencyResolutionManagement {
```java
dependencies {
...
- // 请将"版本"替换成具体的版本号,如 1.1.3
+ // 请将"版本"替换成具体的版本号,如 1.1.7
implementation 'io.github.molihuan:pathselector:版本'
}
```
diff --git a/README_EN.md b/README_EN.md
index e18a2a9..2307755 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -21,13 +21,15 @@ Automatically apply storage permission, support Android4.4 ~ 13, no longer need
## Characteristics
-- [x] Automatically request storage permissions
+- [x] Automatically request storage permissions(Can control)
- [x] Android 4.4 ~ 13
- [x] Android/data and Android/obb directory access and manipulation
- [x] SD Card
- [x] Highly customizable UI
- [x] Internationalization
- [ ] Search function
+- [ ] Custom icon
+- [ ] Show hidden files
## Language(语言)
@@ -37,6 +39,8 @@ Automatically apply storage permission, support Android4.4 ~ 13, no longer need
#### Can you give the project a Star before starting? Thank you very much, your support is the only thing that keeps me going. Welcome Star and Issues!
+#### Welcome to Pr, please submit to the dev branch
+
#### Project Address:
##### [Github](https://github.com/molihuan/mlhfileselectorlib)
##### [Gitee](https://gitee.com/molihuan/mlhfileselectorlib)
@@ -86,7 +90,7 @@ dependencyResolutionManagement {
```java
dependencies {
...
- // Please replace "version" with a specific version number, e.g. 1.1.2
+ // Please replace "version" with a specific version number, e.g. 1.1.7
implementation 'io.github.molihuan:pathselector:version'
}
```
diff --git a/app/src/main/java/com/molihuan/pathselectdemo/activity/MainActivity.java b/app/src/main/java/com/molihuan/pathselectdemo/activity/MainActivity.java
index 200e98d..25e59d3 100644
--- a/app/src/main/java/com/molihuan/pathselectdemo/activity/MainActivity.java
+++ b/app/src/main/java/com/molihuan/pathselectdemo/activity/MainActivity.java
@@ -19,6 +19,7 @@
import com.molihuan.pathselector.fragment.impl.PathSelectFragment;
import com.molihuan.pathselector.listener.CommonItemListener;
import com.molihuan.pathselector.listener.FileItemListener;
+import com.molihuan.pathselector.utils.FragmentTools;
import com.molihuan.pathselector.utils.MConstants;
import com.molihuan.pathselector.utils.Mtools;
@@ -37,8 +38,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private Button btnFragmentSelector;
private Button btnDialogSelector;
private Button btnCustomSelector;
+ private Button btnTest;
private PathSelectFragment selector;
+ private long firstBackTime;
@Override
@@ -57,6 +60,7 @@ private void getComponents() {
btnFragmentSelector = findViewById(R.id.btn_fragment_selector);
btnDialogSelector = findViewById(R.id.btn_dialog_selector);
btnCustomSelector = findViewById(R.id.btn_custom_toolbar_selector);
+ btnTest = findViewById(R.id.btn_test);
}
private void initData() {
@@ -73,6 +77,7 @@ private void setListeners() {
btnFragmentSelector.setOnClickListener(this);
btnDialogSelector.setOnClickListener(this);
btnCustomSelector.setOnClickListener(this);
+ btnTest.setOnClickListener(this);
}
@Override
@@ -97,7 +102,14 @@ public void onClick(View v) {
case R.id.btn_custom_toolbar_selector:
customTitlebarSelectShow();
// t1();
-
+ break;
+ case R.id.btn_test:
+ FragmentTools.fragmentReplace(
+ getSupportFragmentManager(),
+ R.id.fragment_select_show_area,
+ new CustomTitlebarFragment(),
+ "55"
+ );
break;
}
}
@@ -117,7 +129,7 @@ public boolean onClick(View v, List selectedFiles, String currentPath,
* pathSelectFragment.getSelectConfigData().buildController.getDialogFragment().dismiss();
*/
- pathSelectFragment.selectAllFile(true);
+ //pathSelectFragment.selectAllFile(true);
return false;
}
},
@@ -346,6 +358,12 @@ public void onBackPressed() {
return;
}
+ if (System.currentTimeMillis() - firstBackTime > 2000) {
+ Mtools.toast("再按一次返回键退出程序");
+ firstBackTime = System.currentTimeMillis();
+ return;
+ }
+
super.onBackPressed();
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 3b8bacc..9531c9a 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -3,6 +3,13 @@
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
+
+
+
+
permissions, boolean all) {
+
+ }
+ },
+ new OnPermissionCallback() {
+ @Override
+ public void onGranted(@NonNull List permissions, boolean all) {
+
+ }
+ }
+ );
+ }
//获取Fragment
titlebarFragment = mConfigData.titlebarFragment;
diff --git a/pathselector/src/main/java/com/molihuan/pathselector/utils/FragmentTools.java b/pathselector/src/main/java/com/molihuan/pathselector/utils/FragmentTools.java
index 13aae6d..5f39862 100644
--- a/pathselector/src/main/java/com/molihuan/pathselector/utils/FragmentTools.java
+++ b/pathselector/src/main/java/com/molihuan/pathselector/utils/FragmentTools.java
@@ -53,4 +53,26 @@ public static Fragment fragmentShowHide(FragmentManager fragmentManager, int fra
return fragment;
}
+ public static Fragment fragmentReplace(FragmentManager fragmentManager, int frameLayoutID, Fragment fragment, String tag) {
+ // Fragment获取事务
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+
+ if (fragment == null) {
+ Mtools.log("fragment is null and Unable to replace");
+ return fragment;
+ }
+
+ try {
+ fragmentTransaction = fragmentTransaction.replace(frameLayoutID, fragment, tag);
+ } catch (Exception e) {
+ Mtools.log("frameLayoutID may not exist and cannot be replace");
+ e.printStackTrace();
+ }
+
+
+ //提交事务
+ fragmentTransaction.commitAllowingStateLoss();
+ return fragment;
+ }
+
}
diff --git a/pathselector/src/main/java/com/molihuan/pathselector/utils/Mtools.java b/pathselector/src/main/java/com/molihuan/pathselector/utils/Mtools.java
index 00f91e6..ad335e7 100644
--- a/pathselector/src/main/java/com/molihuan/pathselector/utils/Mtools.java
+++ b/pathselector/src/main/java/com/molihuan/pathselector/utils/Mtools.java
@@ -33,7 +33,11 @@ public static void toast(Context context, String text) {
}
public static void toast(String text) {
- toast(ReflectTools.getApplicationByReflect(), text, Toast.LENGTH_SHORT);
+ toast(text, Toast.LENGTH_SHORT);
+ }
+
+ public static void toast(String text, int time) {
+ toast(ReflectTools.getApplicationByReflect(), text, time);
}
public static void toast(Context context, String text, int time) {
diff --git a/pathselector/src/main/java/com/molihuan/pathselector/utils/PermissionsTools.java b/pathselector/src/main/java/com/molihuan/pathselector/utils/PermissionsTools.java
index 3a81936..b4b3215 100644
--- a/pathselector/src/main/java/com/molihuan/pathselector/utils/PermissionsTools.java
+++ b/pathselector/src/main/java/com/molihuan/pathselector/utils/PermissionsTools.java
@@ -36,12 +36,18 @@ public class PermissionsTools {
public static final int DEFAULT_URI_BUILD_SUFFIX_ANDROID_DATA = 156;
public static final int DEFAULT_URI_BUILD_SUFFIX_ANDROID_OBB = 157;
+ public OnPermissionCallback specialPermissionCallback;
+ public OnPermissionCallback generalPermissionCallback;
+
+
+ public static void getStoragePermissions(Context context, OnPermissionCallback specialPermissionCallback, OnPermissionCallback generalPermissionCallback) {
- public static void getStoragePermissions(Context context) {
- //普通存储访问权限Android 11 -
- generalPermissionsOfStorage(context);
//所有文件访问权限Android 11 +
- specialPermissionsOfStorage(context);
+ specialPermissionsOfStorage(context, specialPermissionCallback);
+
+ //普通存储访问权限Android 11 -
+ generalPermissionsOfStorage(context, generalPermissionCallback);
+
}
@@ -49,7 +55,7 @@ public static void getStoragePermissions(Context context) {
* 获取一般读写权限
* Android 11 -
*/
- public static void generalPermissionsOfStorage(Context context) {
+ public static void generalPermissionsOfStorage(Context context, OnPermissionCallback generalPermissionCallback) {
boolean isGet = XXPermissions.isGranted(context, Permission.Group.STORAGE);
//已有权限则返回
@@ -66,6 +72,7 @@ public static void generalPermissionsOfStorage(Context context) {
@Override
public void onGranted(List permissions, boolean all) {
Mtools.log("一般存储权限------获取成功");
+ generalPermissionCallback.onGranted(permissions, all);
}
@Override
@@ -73,10 +80,13 @@ public void onDenied(List permissions, boolean never) {
if (never) {
ToastUtils.make().show(R.string.tip_denial_authorization);
//如果是被永久拒绝就跳转到应用权限系统设置页面
- XXPermissions.startPermissionActivity(context, permissions);
+ //XXPermissions.startPermissionActivity(context, permissions);
} else {
ToastUtils.make().show(R.string.tip_permission_failed);
}
+
+ generalPermissionCallback.onDenied(permissions, never);
+
}
});
}
@@ -87,7 +97,7 @@ public void onDenied(List permissions, boolean never) {
*
* @param context
*/
- public static void specialPermissionsOfStorage(Context context) {
+ public static void specialPermissionsOfStorage(Context context, OnPermissionCallback specialPermissionCallback) {
if (!VersionTool.isAndroid11()) {
return;
}
@@ -108,6 +118,7 @@ public static void specialPermissionsOfStorage(Context context) {
@Override
public void onGranted(List permissions, boolean all) {
Mtools.log("全文件读取权限------获取成功");
+ specialPermissionCallback.onGranted(permissions, all);
}
@Override
@@ -119,6 +130,8 @@ public void onDenied(List permissions, boolean never) {
} else {
ToastUtils.make().show(R.string.tip_permission_failed);
}
+
+ specialPermissionCallback.onDenied(permissions, never);
}
});