Skip to content

Commit

Permalink
fix:#19 fix:#20
Browse files Browse the repository at this point in the history
  • Loading branch information
molihuan committed Sep 18, 2023
1 parent 0f5fe50 commit 484482e
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 57 deletions.
1 change: 0 additions & 1 deletion .idea/saveactions_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ dependencyResolutionManagement {
dependencies {
...
// 建议使用最新发布版,最新发布版请看上面
// 请将"版本"替换成具体的版本号,如 1.1.15
// 请将"版本"替换成具体的版本号,如 1.1.16
implementation 'io.github.molihuan:pathselector:版本'
}
```
Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ dependencyResolutionManagement {
dependencies {
...
// We recommend using the latest release version, please see above for the latest release version
// Please replace "version" with a specific version number, e.g. 1.1.15
// Please replace "version" with a specific version number, e.g. 1.1.16
implementation 'io.github.molihuan:pathselector:version'
}
```
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 @@ -135,7 +135,7 @@ private void dialogSelectShow() {
@Override
public boolean onClick(View v, TextView tv, List<FileBean> selectedFiles, String currentPath, BasePathSelectFragment pathSelectFragment) {
/**取消dialog弹窗
* pathSelectFragment.dismiss();
* pathSelectFragment.close();
*/
return false;
}
Expand Down Expand Up @@ -189,9 +189,7 @@ private void fragmentSelectShow() {
new CommonItemListener("SelectAll") {
@Override
public boolean onClick(View v, TextView tv, List<FileBean> selectedFiles, String currentPath, BasePathSelectFragment pathSelectFragment) {

pathSelectFragment.selectAllFile(true);

return false;
}
},
Expand Down Expand Up @@ -236,12 +234,14 @@ private void activitySelectShow() {
//Constants.BUILD_ACTIVITY为ACTIVITY模式
selector = PathSelector.build(this, MConstants.BUILD_ACTIVITY)
.setRequestCode(635)
.setStatusBarColor("#000000")
.setMorePopupItemListeners(
new CommonItemListener("SelectAll") {
@Override
public boolean onClick(View v, TextView tv, List<FileBean> selectedFiles, String currentPath, BasePathSelectFragment pathSelectFragment) {

pathSelectFragment.selectAllFile(true);
pathSelectFragment.setSortType(MConstants.SortRules.SORT_TIME_ASC);

return false;
}
Expand Down Expand Up @@ -305,7 +305,7 @@ private void CompleteConfiguration() {
.setSelectFileTypes("", "mp3")//只能选择(没有后缀)或(后缀为mp3)的文件
.setMaxCount(3)//最多可以选择3个文件,默认是-1不限制
.setRadio()//单选,默认多选
.setSortType(MConstants.SORT_NAME_ASC)//按名称排序
.setSortType(MConstants.SortRules.SORT_NAME_ASC)//按名称排序
.setTitlebarMainTitle(new FontBean("My Selector"))//设置标题栏主标题,还可以设置字体大小,颜色等
.setTitlebarBG(Color.GREEN)//设置标题栏背景颜色
.setFileItemListener(//设置文件item点击回调(点击是文件才会回调,如果点击是文件夹则不会)
Expand Down
2 changes: 1 addition & 1 deletion pathselector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {
implementation 'androidx.documentfile:documentfile:1.0.1'
//基础控件
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.0'

}
//Please remove the next line when integrating offline(离线集成时请移除下一行)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import androidx.appcompat.app.AppCompatActivity;

import com.molihuan.pathselector.dao.SelectConfigData;
import com.molihuan.pathselector.fragment.impl.PathSelectFragment;
import com.molihuan.pathselector.interfaces.IActivityAndFragment;
import com.molihuan.pathselector.service.impl.ConfigDataBuilderImpl;

Expand All @@ -25,6 +26,8 @@ public abstract class AbstractActivity extends AppCompatActivity implements IAct

protected SelectConfigData mConfigData = ConfigDataBuilderImpl.getInstance().getSelectConfigData();

protected PathSelectFragment pathSelectFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -33,9 +36,9 @@ protected void onCreate(Bundle savedInstanceState) {
//获取组件
getComponents();
//初始化数据
initData();
initData(savedInstanceState);
//初始化视图
initView();
initView(savedInstanceState);
//设置监听
setListeners();
}
Expand All @@ -46,16 +49,19 @@ protected void onCreate(Bundle savedInstanceState) {
public void getComponents() {
}

public void initData() {
public void initData(Bundle savedInstanceState) {

}

public void initView() {

public void initView(Bundle savedInstanceState) {
hideActionBar();
}

public void setListeners() {
}


protected void hideActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.molihuan.pathselector.activity.impl;


import android.os.Bundle;

import com.molihuan.pathselector.R;
import com.molihuan.pathselector.activity.AbstractActivity;
import com.molihuan.pathselector.fragment.impl.PathSelectFragment;
Expand All @@ -15,28 +17,30 @@
*/
public class PathSelectActivity extends AbstractActivity {

private PathSelectFragment pathSelectFragment;

@Override
public int setContentViewID() {
return R.layout.activity_path_select_mlh;
}


@Override
public void getComponents() {

}

@Override
public void initData() {
public void initData(Bundle savedInstanceState) {

}

@Override
public void initView() {
super.initView();
pathSelectFragment = new PathSelectFragment();
public void initView(Bundle savedInstanceState) {
super.initView(savedInstanceState);

mConfigData.fragmentManager = getSupportFragmentManager();

pathSelectFragment = new PathSelectFragment();
////加载 PathSelectFragment
FragmentTools.fragmentShowHide(
mConfigData.fragmentManager,
Expand All @@ -45,6 +49,8 @@ public void initView() {
MConstants.TAG_ACTIVITY_FRAGMENT,
true
);


}

@Override
Expand All @@ -56,8 +62,4 @@ public void onBackPressed() {
super.onBackPressed();
}

@Override
public void setListeners() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SelectConfigData {
public AbstractBuildController buildController;//构建控制
public Integer requestCode;//请求码
public Integer frameLayoutId;//添加fragment地方
public Integer sortType;//排序类型
public MConstants.SortRules sortType;//排序类型
public Boolean radio;//是否是单选非单选则是多选,多选必须设为false
public Integer maxCount;//多选的个数
public String rootPath;//默认目录
Expand Down Expand Up @@ -83,6 +83,8 @@ public class SelectConfigData {

//生命周期钩子
public AbstractLifeCycle lifeCycle;
//状态栏16进制颜色
public String statusBarHexColor;

//TODO 构建顺序 需要优化,减少不必要类的创建和一些赋值操作,减少开销

Expand All @@ -98,7 +100,7 @@ public void initDefaultConfig(Context context) {
requestCode = null;//非必须(activity模式必须)
frameLayoutId = null;//非必须(fragment模式必须)

sortType = MConstants.SORT_NAME_ASC;
sortType = MConstants.SortRules.SORT_NAME_ASC;
radio = false;//默认多选
maxCount = -1;//不限制
rootPath = MConstants.DEFAULT_ROOTPATH;
Expand Down Expand Up @@ -126,6 +128,11 @@ public void initDefaultConfig(Context context) {

lifeCycle = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int colorInt = context.getColor(R.color.orange_mlh);
statusBarHexColor = String.format("#%06X", (0xFFFFFF & colorInt));
}

titlebarFragment = null;
tabbarFragment = null;
handleFragment = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ public abstract class AbstractFragment extends DialogFragment {

protected SelectConfigData mConfigData = ConfigDataBuilderImpl.getInstance().getSelectConfigData();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (mFragmentView == null) {
Expand Down Expand Up @@ -109,6 +104,8 @@ public void onAttach(@NonNull Context context) {
if (mActivity == null) {
mActivity = getActivity();
}


//获取与Activity通讯实例
// try {
// if (context instanceof IActivityAndFragment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.molihuan.pathselector.fragment;

import android.graphics.Color;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.CallSuper;

import com.molihuan.pathselector.activity.AbstractActivity;
import com.molihuan.pathselector.adapter.MorePopupAdapter;
import com.molihuan.pathselector.interfaces.ITitlebarFragment;
import com.molihuan.pathselector.listener.CommonItemListener;
Expand All @@ -25,6 +30,7 @@ public abstract class AbstractTitlebarFragment extends AbstractFragment implemen
@Override
public void initData() {
psf = (BasePathSelectFragment) mConfigData.fragmentManager.findFragmentByTag(MConstants.TAG_ACTIVITY_FRAGMENT);

}

@Override
Expand All @@ -46,4 +52,37 @@ public void refreshMorePopup() {
public TextView getOnlyOneMorePopupTextView() {
return null;
}


@Override
@CallSuper
public void initView() {
super.initView();
setStatusBarColor(mConfigData.statusBarHexColor);
}

/**
* 设置状态栏颜色
*
* @param hexColor:16进制颜色
*/
public void setStatusBarColor(String hexColor) {

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return;
}

if (!(mActivity instanceof AbstractActivity)) {
return;
}

Window window = mActivity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 将十六进制颜色值转换为对应的整数值
int color = Color.parseColor(hexColor);
// 将整数颜色值设置为状态栏颜色
window.setStatusBarColor(color);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import android.app.Dialog;

import com.molihuan.pathselector.controller.impl.ActivityController;
import com.molihuan.pathselector.controller.impl.DialogController;
import com.molihuan.pathselector.controller.impl.FragmentController;
import com.molihuan.pathselector.dao.SelectConfigData;
import com.molihuan.pathselector.interfaces.IFileShowFragment;
import com.molihuan.pathselector.interfaces.IHandleFragment;
import com.molihuan.pathselector.interfaces.ITabbarFragment;
import com.molihuan.pathselector.interfaces.ITitlebarFragment;
import com.molihuan.pathselector.service.IFileDataManager;
import com.molihuan.pathselector.service.impl.ConfigDataBuilderImpl;
import com.molihuan.pathselector.utils.MConstants;

/**
* @ClassName: BasePathSelectFragment
Expand All @@ -17,9 +21,16 @@
* @Description: 拥有了她就拥有了它就拥有了全世界(具体方法可以看她的实现类或者她的接口)
*/
public abstract class BasePathSelectFragment extends AbstractFragment implements IFileShowFragment, IHandleFragment, ITabbarFragment, ITitlebarFragment {


public ConfigDataBuilderImpl mConfigDataBuilder = ConfigDataBuilderImpl.getInstance();

public abstract void returnDataToActivityResult();

/**
* 获取配置数据
*
* @return
*/
public abstract SelectConfigData getSelectConfigData();

public abstract AbstractTitlebarFragment getTitlebarFragment();
Expand All @@ -34,6 +45,36 @@ public abstract class BasePathSelectFragment extends AbstractFragment implements

public abstract IFileDataManager getUriFileManager();

/**
* 关闭选择器
*/
public void close() {
if (mConfigData.buildController instanceof DialogController) {
mConfigData.buildController.getDialogFragment().dismiss();
} else if (mConfigData.buildController instanceof ActivityController) {
mActivity.finish();
} else if (mConfigData.buildController instanceof FragmentController) {
super.dismiss();
}
}

/**
* 更新UI
*/
public void updateUI() {
updateFileList();
}

public void setSortType(MConstants.SortRules sortType) {
mConfigDataBuilder.setSortType(sortType);
updateFileList();
}


/**
* 请使用close()
*/
@Deprecated
@Override
public void dismiss() {
if (mConfigData.buildController instanceof DialogController) {
Expand Down
Loading

0 comments on commit 484482e

Please sign in to comment.