Skip to content

Commit

Permalink
🔥Fix fragment mode shows replacement bugs and optimization details
Browse files Browse the repository at this point in the history
  • Loading branch information
molihuan committed Dec 27, 2022
1 parent cd0b9e6 commit 55812e1
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 55 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

## 特性

- [x] 自动申请存储权限
- [x] 自动申请存储权限(可以控制)
- [x] 安卓 4.4 ~ 13
- [x] Android/data和Android/obb目录访问和操作
- [x] SD卡
Expand All @@ -39,6 +39,8 @@

#### 在开始之前可以给项目一个Star吗?非常感谢,你的支持是我唯一的动力。欢迎Star和Issues!

#### 欢迎Pr,请Pr提交到dev分支

#### 项目地址:
##### [Github地址](https://github.com/molihuan/mlhfileselectorlib)
##### [Gitee地址](https://gitee.com/molihuan/mlhfileselectorlib)
Expand Down Expand Up @@ -88,7 +90,7 @@ dependencyResolutionManagement {
```java
dependencies {
...
// 请将"版本"替换成具体的版本号,如 1.1.3
// 请将"版本"替换成具体的版本号,如 1.1.7
implementation 'io.github.molihuan:pathselector:版本'
}
```
Expand Down
8 changes: 6 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(语言)

Expand All @@ -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)
Expand Down Expand Up @@ -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'
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -73,6 +77,7 @@ private void setListeners() {
btnFragmentSelector.setOnClickListener(this);
btnDialogSelector.setOnClickListener(this);
btnCustomSelector.setOnClickListener(this);
btnTest.setOnClickListener(this);
}

@Override
Expand All @@ -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;
}
}
Expand All @@ -117,7 +129,7 @@ public boolean onClick(View v, List<FileBean> selectedFiles, String currentPath,
* pathSelectFragment.getSelectConfigData().buildController.getDialogFragment().dismiss();
*/

pathSelectFragment.selectAllFile(true);
//pathSelectFragment.selectAllFile(true);
return false;
}
},
Expand Down Expand Up @@ -346,6 +358,12 @@ public void onBackPressed() {
return;
}

if (System.currentTimeMillis() - firstBackTime > 2000) {
Mtools.toast("再按一次返回键退出程序");
firstBackTime = System.currentTimeMillis();
return;
}

super.onBackPressed();
}

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -33,6 +40,7 @@
android:layout_height="wrap_content"
android:text="自定义toolbar选择器" />


<FrameLayout
android:id="@+id/fragment_select_show_area"
android:layout_width="wrap_content"
Expand Down
4 changes: 2 additions & 2 deletions pathselector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ dependencies {
//embed(name: 'XXPermissions-16.2', ext: 'aar')

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

//异步库
implementation 'com.github.xuexiangjys.XTask:xtask-core:1.0.2'

//使用这个包遍历Android/data目录
implementation 'androidx.documentfile:documentfile:1.0.1'
//基础控件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
//TODO 先要解决:关于这个库的升级提示问题:开启调试模式的时候会向服务器获取库的版本信息并判断本地库的版本是不是小于服务器的版本,如果是则向开发者的控制台打印该库可以升级,如果需要请获取新的版本
public class PathSelectorConfig {

//是否需要自动获取权限
public static boolean AUTO_GET_PERMISSION = true;

/**
* 是否开启debug模式
* 默认开启debug模式,开发时可以开启,生产模式请务必关闭
Expand All @@ -24,4 +27,7 @@ public static void setDebug(boolean var) {
XTask.debug(var);
}

public static void setAutoGetPermission(boolean need) {
AUTO_GET_PERMISSION = need;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,24 @@ public PathSelectFragment show() {
} else {
if (context instanceof FragmentActivity) {
FragmentActivity activity = (FragmentActivity) context;
//去除ActionBar不应该影响用户的UI
// if (activity instanceof AppCompatActivity) {
// ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
// if (supportActionBar != null) {
// supportActionBar.hide();
// }
// } else {
// android.app.ActionBar actionBar = activity.getActionBar();
// if (actionBar != null) {
// actionBar.hide();
// }
// }
fragmentManager = activity.getSupportFragmentManager();
} else {
throw new ClassCastException("context必须为FragmentActivity类型以及其子类(如 AppCompatActivity)或PathSelector.fragment不为空");
}
}
mConfigData.fragmentManager = fragmentManager;
Mtools.log("PathSelectFragment new start");
if (pathSelectFragment == null) {
pathSelectFragment = new PathSelectFragment();
}
// if (pathSelectFragment == null) {
pathSelectFragment = new PathSelectFragment();
// }
Mtools.log("PathSelectFragment new end");

Mtools.log("PathSelectFragment show start");
FragmentTools.fragmentShowHide(
FragmentTools.fragmentReplace(
fragmentManager,
frameLayoutId,
pathSelectFragment,
MConstants.TAG_ACTIVITY_FRAGMENT,
true
MConstants.TAG_ACTIVITY_FRAGMENT
);
Mtools.log("PathSelectFragment show end");

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

import androidx.fragment.app.FragmentManager;

import com.blankj.molihuan.utilcode.util.LogUtils;
import com.blankj.molihuan.utilcode.util.ScreenUtils;
import com.molihuan.pathselector.controller.AbstractBuildController;
import com.molihuan.pathselector.entity.FontBean;
Expand Down Expand Up @@ -151,7 +150,7 @@ public void initAllFragment() throws IllegalAccessException, InstantiationExcept

//使用自定义视图 或者 不需要显示则不创建
if (showTitlebarFragment) {
LogUtils.e("titlebarFragment");

if (titlebarFragment == null || titlebarFragment.getClass().isAssignableFrom(TitlebarFragment.class)) {
titlebarFragment = new TitlebarFragment();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import android.net.Uri;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;

import com.hjq.permissions.OnPermissionCallback;
import com.molihuan.pathselector.R;
import com.molihuan.pathselector.adapter.FileListAdapter;
import com.molihuan.pathselector.adapter.TabbarListAdapter;
import com.molihuan.pathselector.configs.PathSelectorConfig;
import com.molihuan.pathselector.dao.SelectConfigData;
import com.molihuan.pathselector.entity.FileBean;
import com.molihuan.pathselector.entity.TabbarFileBean;
Expand Down Expand Up @@ -61,8 +64,25 @@ public void getComponents(View view) {

@Override
public void initData() {
//存储权限的申请
PermissionsTools.getStoragePermissions(mActivity);

if (PathSelectorConfig.AUTO_GET_PERMISSION) {
//存储权限的申请
PermissionsTools.getStoragePermissions(
mActivity,
new OnPermissionCallback() {
@Override
public void onGranted(@NonNull List<String> permissions, boolean all) {

}
},
new OnPermissionCallback() {
@Override
public void onGranted(@NonNull List<String> permissions, boolean all) {

}
}
);
}

//获取Fragment
titlebarFragment = mConfigData.titlebarFragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 55812e1

Please sign in to comment.