d
This commit is contained in:
251
app/src/main/java/com/fenghoo/seven/base/BaseActivity.java
Normal file
251
app/src/main/java/com/fenghoo/seven/base/BaseActivity.java
Normal file
@@ -0,0 +1,251 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextPaint;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.dialog.LoadingDialog;
|
||||
import com.fenghoo.seven.dialog.PersonnelDialogHelptwo;
|
||||
import com.fenghoo.seven.utils.NetUtils;
|
||||
import com.fenghoo.seven.utils.StatusBarUtil;
|
||||
import com.fenghoo.seven.utils.ToastUtils;
|
||||
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
|
||||
/**
|
||||
* @author: qndroid
|
||||
* @function: 所有Activity的基类,用来处理一些公共事件,如:数据统计
|
||||
* @date: 16/3/10
|
||||
*/
|
||||
public abstract class BaseActivity extends FragmentActivity {
|
||||
|
||||
private LoadingDialog mProgressDialog;
|
||||
public static final int REQUEST_CALL_PERMISSION = 10111; //拨号请求码
|
||||
protected final String TAG = this.getClass().getSimpleName();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
reverseStatusColor();
|
||||
StatusBarUtil.transparencyBar(this); //设置状态栏全透明
|
||||
StatusBarUtil.StatusBarLightMode(this); //设置白底黑字
|
||||
initFontScale();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 拨打电话(直接拨打)
|
||||
*
|
||||
* @param telPhone 电话
|
||||
*/
|
||||
public void call(String telPhone) {
|
||||
if (checkReadPermission(Manifest.permission.CALL_PHONE, REQUEST_CALL_PERMISSION)) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_CALL);
|
||||
Uri phoneNum = Uri.parse("tel:" + telPhone);
|
||||
intent.setData(phoneNum);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有某项权限
|
||||
*
|
||||
* @param string_permission 权限
|
||||
* @param request_code 请求码
|
||||
* @return
|
||||
*/
|
||||
public boolean checkReadPermission(String string_permission, int request_code) {
|
||||
boolean flag = false;
|
||||
if (ContextCompat.checkSelfPermission(this, string_permission) == PackageManager.PERMISSION_GRANTED) {//已有权限
|
||||
flag = true;
|
||||
} else {//申请权限
|
||||
ActivityCompat.requestPermissions(this, new String[]{string_permission}, request_code);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private void initFontScale() {
|
||||
Configuration configuration = getResources().getConfiguration();
|
||||
configuration.fontScale = (float) 1;
|
||||
//0.85 小, 1 标准大小, 1.15 大,1.3 超大 ,1.45 特大
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
metrics.scaledDensity = configuration.fontScale * metrics.density;
|
||||
getBaseContext().getResources().updateConfiguration(configuration, metrics);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请指定的权限.
|
||||
*/
|
||||
public void requestPermission(int code, String... permissions) {
|
||||
|
||||
ActivityCompat.requestPermissions(this, permissions, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化进度对话框
|
||||
*/
|
||||
|
||||
public void showProgressDialog(String dialogMessage,Context mContext) {
|
||||
mProgressDialog = new LoadingDialog(mContext);
|
||||
mProgressDialog.setCanceledOnTouchOutside(false);
|
||||
// mProgressDialog.setMessage(dialogMessage);
|
||||
mProgressDialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭进度对话框
|
||||
*/
|
||||
|
||||
public void dismissProgressDialog() {
|
||||
if (null != mProgressDialog && mProgressDialog.isShowing()) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有指定的权限
|
||||
*/
|
||||
public boolean hasPermission(String... permissions) {
|
||||
|
||||
for (String permisson : permissions) {
|
||||
if (ContextCompat.checkSelfPermission(this, permisson)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理整个应用用中的SDCard业务
|
||||
*/
|
||||
public void doSDCardPermission() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏状态栏
|
||||
*/
|
||||
public void hiddenStatusBar() {
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
/**
|
||||
* 开启一个Activity
|
||||
*
|
||||
* @param clz
|
||||
*/
|
||||
public void startActivity(Class<? extends Activity> clz) {
|
||||
startActivity(new Intent(this, clz));
|
||||
}
|
||||
/**
|
||||
* 改变状态栏颜色
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void changeStatusBarColor(@ColorRes int color) {
|
||||
// StatusBarUtil.setStatusBarColor(this, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整状态栏为亮模式,这样状态栏的文字颜色就为深模式了。
|
||||
*/
|
||||
private void reverseStatusColor() {
|
||||
// StatusBarUtil.statusBarLightMode(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 弹出提示对话框
|
||||
*/
|
||||
|
||||
public void alertmessage(Context context,String msg) {
|
||||
|
||||
new PersonnelDialogHelptwo().showDownloadDialog(BaseActivity.this, msg,"确定", new PersonnelDialogHelptwo.ClickListener() {
|
||||
@Override
|
||||
public void confirm() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
public void messageDialog(String str) {
|
||||
new PersonnelDialogHelptwo().showDownloadDialog(BaseActivity.this, str,"确定", new PersonnelDialogHelptwo.ClickListener() {
|
||||
@Override
|
||||
public void confirm() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
/**
|
||||
* 字体加粗
|
||||
*/
|
||||
protected void Thickening(TextView mLayTopTitle) {
|
||||
TextPaint tp = mLayTopTitle.getPaint();
|
||||
tp.setFakeBoldText(true);
|
||||
}
|
||||
protected void Thickeningtwo(TextView mLayTopTitle) {
|
||||
TextPaint tp = mLayTopTitle.getPaint();
|
||||
tp.setFakeBoldText(false);
|
||||
}
|
||||
|
||||
|
||||
public boolean ConnectNetwork(Context context,String str) {
|
||||
if (!NetUtils.isConnected(context)) {
|
||||
ToastUtils.showToast(context, str);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 初始化一般返回按钮事件
|
||||
*/
|
||||
public void initNormalBack() {
|
||||
|
||||
ImageView iv_back = (ImageView) findViewById(R.id.iv_left_btn);
|
||||
|
||||
if (iv_back != null) {
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
15
app/src/main/java/com/fenghoo/seven/base/BaseBean.java
Normal file
15
app/src/main/java/com/fenghoo/seven/base/BaseBean.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description 实体基类
|
||||
* @author fangyan
|
||||
* @date 2015年8月1日
|
||||
*/
|
||||
public class BaseBean implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
}
|
||||
114
app/src/main/java/com/fenghoo/seven/base/BaseFragment.java
Normal file
114
app/src/main/java/com/fenghoo/seven/base/BaseFragment.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextPaint;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
/**
|
||||
* 项目名:erp
|
||||
* 包名:com.realize.erp.view.fragment
|
||||
* 文件名:BaseFragment
|
||||
* 创建者:任剑波
|
||||
* 创建时间:2017/9/29 17:42
|
||||
* 描述:TODO
|
||||
*/
|
||||
public class BaseFragment extends Fragment {
|
||||
|
||||
protected Activity mContext;
|
||||
|
||||
public static final int REQUEST_CALL_PERMISSION = 10111; //拨号请求码
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 申请指定的权限.
|
||||
*/
|
||||
public void requestPermission(int code, String... permissions) {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
requestPermissions(permissions, code);
|
||||
}
|
||||
}
|
||||
|
||||
/**s
|
||||
* 判断是否有指定的权限
|
||||
*/
|
||||
public boolean hasPermission(String... permissions) {
|
||||
|
||||
for (String permisson : permissions) {
|
||||
if (ContextCompat.checkSelfPermission(getActivity(), permisson)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void doOpenCamera() {
|
||||
|
||||
}
|
||||
|
||||
public void doWriteSDCard() {
|
||||
|
||||
}
|
||||
/**
|
||||
* 字体加粗
|
||||
*/
|
||||
protected void Thickening(TextView mLayTopTitle) {
|
||||
TextPaint tp = mLayTopTitle.getPaint();
|
||||
tp.setFakeBoldText(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启一个Activity
|
||||
*
|
||||
* @param clz 需要开启的Activity
|
||||
*/
|
||||
public void startActivity(Context mContext,Class<? extends Activity> clz) {
|
||||
startActivity(new Intent(mContext, clz));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 拨打电话(直接拨打)
|
||||
*
|
||||
* @param telPhone 电话
|
||||
*/
|
||||
public void call(String telPhone) {
|
||||
if (checkReadPermission(Manifest.permission.CALL_PHONE, REQUEST_CALL_PERMISSION)) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_CALL);
|
||||
Uri phoneNum = Uri.parse("tel:" + telPhone);
|
||||
intent.setData(phoneNum);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 判断是否有某项权限
|
||||
*
|
||||
* @param string_permission 权限
|
||||
* @param request_code 请求码
|
||||
* @return
|
||||
*/
|
||||
public boolean checkReadPermission(String string_permission, int request_code) {
|
||||
boolean flag = false;
|
||||
if (ContextCompat.checkSelfPermission(getActivity(), string_permission) == PackageManager.PERMISSION_GRANTED) {//已有权限
|
||||
flag = true;
|
||||
} else {//申请权限
|
||||
ActivityCompat.requestPermissions(getActivity(), new String[]{string_permission}, request_code);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
257
app/src/main/java/com/fenghoo/seven/base/BaseRecycleAdapter.java
Normal file
257
app/src/main/java/com/fenghoo/seven/base/BaseRecycleAdapter.java
Normal file
@@ -0,0 +1,257 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import static com.fenghoo.seven.common.Constants.LIMIT;
|
||||
|
||||
|
||||
/**
|
||||
* BaseRecycleAdapter
|
||||
* (๑• . •๑)
|
||||
* 类描述:普通RecycleView的普通BaseAdapter
|
||||
* 支持多类型item,支持加载更多,通过{{@link #canLoadMore}开启}
|
||||
* 支持Empty布局
|
||||
* simple{@link ProjectAdapter}
|
||||
* Created by LeiXiaoXing on 2017/3/17 14:26
|
||||
*/
|
||||
|
||||
public abstract class BaseRecycleAdapter<E, VH extends BaseViewHolder<E>> extends RecyclerView.Adapter<BaseViewHolder<E>> {
|
||||
|
||||
/**
|
||||
* Item类型: 加载更多
|
||||
*/
|
||||
private static final int ITEM_TYPE_LOAD_MORE = -1;
|
||||
/**
|
||||
* Item类型: Empty
|
||||
*/
|
||||
private static final int ITEM_TYPE_EMPTY = -2;
|
||||
public List<E> mEList;
|
||||
protected Context mContext;
|
||||
private OnItemClickListener<E> mListener;
|
||||
/**
|
||||
* 是否支付加载更多,默认不开启
|
||||
*/
|
||||
private boolean canLoadMore;
|
||||
/**
|
||||
* 是否加载完全部,默认可以加载更多
|
||||
*/
|
||||
private boolean isLoadAll;
|
||||
|
||||
/**
|
||||
* 构造Adapter
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param eList 数据集合
|
||||
* @param canLoadMore 是否支持加载更多
|
||||
*/
|
||||
protected BaseRecycleAdapter(Context context, List<E> eList, boolean canLoadMore) {
|
||||
mEList = eList;
|
||||
mContext = context;
|
||||
this.canLoadMore = canLoadMore;
|
||||
}
|
||||
|
||||
public List<E> getEList() {
|
||||
return mEList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseViewHolder<E> onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_TYPE_LOAD_MORE) {
|
||||
//返回加载更多类型 ViewHolder
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_rcv_load_and_all, parent, false);
|
||||
return new LoadMoreViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE_EMPTY) {
|
||||
//返回空布局类型 ViewHolder
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_rcv_empty, parent, false);
|
||||
return new EmptyViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(mContext).inflate(getItemLayout(viewType), parent, false);
|
||||
return createViewHolder(view, viewType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final BaseViewHolder<E> holder, final int position) {
|
||||
holder.bindView(mEList.get(position), position);
|
||||
if (!canLoadMore || position <= LIMIT
|
||||
|| position != mEList.size() - 1
|
||||
&& mEList.get(0) != null) {
|
||||
//在没有开启加载更多时,开启加更多但未满一页数据时,大于一页数据但不是加载更多的item时,并且为空内容时
|
||||
//点击事件生效
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mListener != null) {
|
||||
if (mEList.get(position) == null) {
|
||||
return;
|
||||
}
|
||||
mListener.onItemClick(mEList.get(position),position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (canLoadMore && position > LIMIT - 1 && position == mEList.size() - 1) {
|
||||
//如果开启加载更多,显示加载中
|
||||
return ITEM_TYPE_LOAD_MORE;
|
||||
} else if (mEList.get(0) == null) {
|
||||
//如果无内容,显示空布局
|
||||
return ITEM_TYPE_EMPTY;
|
||||
}
|
||||
return getCustomItemViewType(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建自定义的item Type
|
||||
*
|
||||
* @param position item下标
|
||||
* @return 自定义item Type
|
||||
*/
|
||||
protected int getCustomItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建ViewHolder
|
||||
*
|
||||
* @param view item
|
||||
* @param viewType item视图类型
|
||||
* @return ViewHolder
|
||||
*/
|
||||
protected abstract VH createViewHolder(View view, int viewType);
|
||||
|
||||
/**
|
||||
* 获取子项布局文件id
|
||||
*
|
||||
* @return 子项布局文件id
|
||||
*/
|
||||
protected abstract int getItemLayout(int viewType);
|
||||
|
||||
/**
|
||||
* 刷新列表数据
|
||||
*
|
||||
* @param entitys 新的数据集合
|
||||
*/
|
||||
public void upDate(List<E> entitys) {
|
||||
this.mEList = entitys;
|
||||
isLoadAll = false;//刷新列表,取消已加载完全部状态
|
||||
if (entitys != null && entitys.size() != 0) {
|
||||
//有内容,移除EmptyView
|
||||
mEList.remove(null);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加数据并更新
|
||||
*
|
||||
* @param entitys 新的数据集合
|
||||
*/
|
||||
public void upDateAdd(List<E> entitys) {
|
||||
|
||||
if (this.mEList == null) {
|
||||
mEList = entitys;
|
||||
} else if (entitys != null) {
|
||||
if (canLoadMore) {
|
||||
//k
|
||||
isLoadAll = entitys.size() == 0;
|
||||
if (entitys.size() != 0) {
|
||||
//移除加载更多
|
||||
isLoadAll = false;
|
||||
mEList.remove(null);
|
||||
}
|
||||
|
||||
}
|
||||
mEList.addAll(entitys);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (canLoadMore && mEList != null && mEList.size() >= LIMIT) {
|
||||
//数据条数大于每页条数时显示加载更多
|
||||
//添加加载更多到尾部
|
||||
if (!mEList.contains(null)) {
|
||||
mEList.add(null);
|
||||
}
|
||||
} else if (mEList == null || mEList.size() == 0) {
|
||||
//无内容,添加EmptyView
|
||||
mEList = new ArrayList<>();
|
||||
mEList.add(null);
|
||||
}
|
||||
return mEList.size();
|
||||
}
|
||||
|
||||
public boolean isLoadAll() {
|
||||
return isLoadAll;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener<E> listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
|
||||
public interface OnItemClickListener<E> {
|
||||
void onItemClick(E entity, int position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多item以及加载完全部 ViewHolder
|
||||
*/
|
||||
private class LoadMoreViewHolder extends BaseViewHolder<E> {
|
||||
|
||||
private View viewLoadAll;
|
||||
private View viewLoading;
|
||||
|
||||
LoadMoreViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView(View itemView) {
|
||||
viewLoadAll = itemView.findViewById(R.id.view_load_all);
|
||||
viewLoading = itemView.findViewById(R.id.view_loading);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindView(E entity, int position) {
|
||||
viewLoadAll.setVisibility(isLoadAll ? View.VISIBLE : View.GONE);
|
||||
viewLoading.setVisibility(isLoadAll ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 空布局ViewHolder
|
||||
*/
|
||||
private class EmptyViewHolder extends BaseViewHolder<E> {
|
||||
|
||||
EmptyViewHolder(View view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView(View itemView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindView(E entity, int position) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
233
app/src/main/java/com/fenghoo/seven/base/BaseTreeActivity.java
Normal file
233
app/src/main/java/com/fenghoo/seven/base/BaseTreeActivity.java
Normal file
@@ -0,0 +1,233 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.dialog.LoadingDialogy;
|
||||
import com.fenghoo.seven.utils.StatusBarUtil;
|
||||
import com.fenghoo.seven.widget.TitleBar;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpActivity;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpPresenter;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpView;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
/**
|
||||
* BaseTreeActivity
|
||||
* (๑• . •๑)
|
||||
* 类描述: 使用第三方MVP库的BaseActivity
|
||||
* Created by LeiXiaoXing on 2017/3/14 09:54
|
||||
*/
|
||||
|
||||
public abstract class BaseTreeActivity<V extends MvpView, P extends MvpPresenter<V>> extends MvpActivity<V, P> implements BaseTreeView {
|
||||
private final String TAG = getClass().getSimpleName();
|
||||
protected Context mContext;
|
||||
private LoadingDialogy mProgressDialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutId());
|
||||
mContext = this;
|
||||
StatusBarUtil.transparencyBar(this); //设置状态栏全透明
|
||||
StatusBarUtil.StatusBarLightMode(this); //设置白底黑字
|
||||
initView();
|
||||
initData();
|
||||
initEvent();
|
||||
initNormalBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取布局文件ID
|
||||
*
|
||||
* @return 布局文件ID
|
||||
*/
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图状态
|
||||
*/
|
||||
protected abstract void initView();
|
||||
|
||||
/**
|
||||
* 初始化数据参数
|
||||
*/
|
||||
protected abstract void initData();
|
||||
|
||||
/**
|
||||
* 初始化操作事件
|
||||
*/
|
||||
protected abstract void initEvent();
|
||||
|
||||
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void toast(@StringRes int ids) {
|
||||
this.toast(getString(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 线程安全的toast
|
||||
*
|
||||
* @param ids toast内容
|
||||
*/
|
||||
public void toastThreadSafe(@StringRes final int ids) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toast(ids);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开启一个Activity
|
||||
*
|
||||
* @param clz 需要开启的Activity
|
||||
*/
|
||||
public void startActivity(Class<? extends Activity> clz) {
|
||||
startActivity(new Intent(this, clz));
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启一个Activity并关闭当前Activity
|
||||
*
|
||||
* @param clz 需要开启的Activity
|
||||
*/
|
||||
public void startActivityAndFinishSelf(Class<? extends Activity> clz) {
|
||||
startActivity(clz);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题栏参数
|
||||
*
|
||||
* @param titleIds 标题栏的id
|
||||
* @param title 标题
|
||||
* @param goneLeftBtn 左边按钮是否显示
|
||||
* @param goneRightBtn 右边按钮是否显示
|
||||
* @param titleBarClickListener 左右边的按钮点击事件回调接口
|
||||
* @return 返回设置好的titlebar
|
||||
*/
|
||||
public TitleBar setTitleBar(@IdRes int titleIds, String title
|
||||
, boolean goneLeftBtn, boolean goneRightBtn, TitleBar.OnTitleBarClickListener titleBarClickListener) {
|
||||
TitleBar titleBar = (TitleBar) findViewById(titleIds);
|
||||
titleBar.setTitle(title);
|
||||
titleBar.visibleIvLeftBtn(goneLeftBtn);
|
||||
titleBar.visibleIvRightBtn(goneRightBtn);
|
||||
titleBar.setOnTitleBarClickListener(titleBarClickListener);
|
||||
return titleBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化进度对话框
|
||||
*/
|
||||
@Override
|
||||
public void showProgressDialog(String dialogMessage) {
|
||||
mProgressDialog = LoadingDialogy.showDialog(mContext, dialogMessage);
|
||||
mProgressDialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭进度对话框
|
||||
*/
|
||||
@Override
|
||||
public void dismissProgressDialog() {
|
||||
if (null != mProgressDialog && mProgressDialog.isShowing()) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化刷新控件的参数
|
||||
*
|
||||
* @param ids 刷新控件的id
|
||||
*/
|
||||
protected SwipeRefreshLayout setSwipeRefreshLayout(@IdRes int ids) {
|
||||
SwipeRefreshLayout mRefreshLayout = (SwipeRefreshLayout) findViewById(ids);
|
||||
mRefreshLayout.setProgressViewOffset(false, 0,
|
||||
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));
|
||||
mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
|
||||
return mRefreshLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示或隐藏软键盘,如果当时是显示则隐藏,如果当前是隐藏则显示
|
||||
*/
|
||||
public void showOrHide() {
|
||||
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
// 得到InputMethodManager的实例
|
||||
if (imm.isActive()) {
|
||||
// 如果开启
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
|
||||
InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 隐藏软键盘
|
||||
*/
|
||||
public void hintKb() {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
/**点击空白处隐藏键盘*/
|
||||
if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {
|
||||
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示软键盘
|
||||
*
|
||||
* @param view
|
||||
*/
|
||||
public void showKb(View view) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(view, InputMethodManager.RESULT_SHOWN);
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化一般返回按钮事件
|
||||
*/
|
||||
private void initNormalBack() {
|
||||
ImageButton ib_back = (ImageButton) findViewById(R.id.ib_back);
|
||||
ImageView iv_back = (ImageView) findViewById(R.id.iv_left_btn);
|
||||
if (ib_back != null) {
|
||||
ib_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
if (iv_back != null) {
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
306
app/src/main/java/com/fenghoo/seven/base/BaseTreeFragment.java
Normal file
306
app/src/main/java/com/fenghoo/seven/base/BaseTreeFragment.java
Normal file
@@ -0,0 +1,306 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.dialog.LoadingDialog;
|
||||
import com.fenghoo.seven.widget.TitleBar;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpFragment;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpPresenter;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpView;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
/**
|
||||
* BaseTreeFragment
|
||||
* (๑• . •๑)
|
||||
* 类描述: Fragment基类,使用第三方MVP
|
||||
* Created by LeiXiaoXing on 2017/3/14 09:57
|
||||
*/
|
||||
|
||||
public abstract class BaseTreeFragment<V extends MvpView, P extends MvpPresenter<V>> extends MvpFragment<V, P> implements View.OnClickListener{
|
||||
|
||||
protected final String TAG = getClass().getSimpleName();
|
||||
protected Context mContext;
|
||||
protected Activity mActivity;
|
||||
private LoadingDialog mProgressDialog;
|
||||
/**
|
||||
* 视图是否已经初初始化
|
||||
*/
|
||||
protected boolean isInit = false;
|
||||
protected boolean isLoad = false;
|
||||
// 两次点击按钮之间的点击间隔不能少于1000毫秒
|
||||
private static final int MIN_CLICK_DELAY_TIME = 1000;
|
||||
private static long lastClickTime;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
return inflater.inflate(getFragmentLayoutId(), container, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
initView(view);
|
||||
initData();
|
||||
initEvent(view);
|
||||
isInit = true;
|
||||
isCanLoadData();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isFastClick())
|
||||
widgetClick(v);
|
||||
}
|
||||
/** View点击 **/
|
||||
public abstract void widgetClick(View v);
|
||||
/**
|
||||
* [防止快速点击]
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFastClick() {
|
||||
boolean flag = false;
|
||||
long curClickTime = System.currentTimeMillis();
|
||||
if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
|
||||
flag = true;
|
||||
}
|
||||
lastClickTime = curClickTime;
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Fragment布局文件id
|
||||
*
|
||||
* @return Fragment布局文件id
|
||||
*/
|
||||
protected abstract int getFragmentLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图状态
|
||||
*/
|
||||
protected abstract void initView(View view);
|
||||
|
||||
/**
|
||||
* 初始化数据参数
|
||||
*/
|
||||
protected abstract void initData();
|
||||
|
||||
/**
|
||||
* 初始化操作事件
|
||||
*/
|
||||
protected abstract void initEvent(View view);
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mContext = context;
|
||||
mActivity = getActivity();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 视图是否已经对用户可见,系统的方法,setUserVisibleHint在onCreate之前调用
|
||||
* 1.第一次创建Fragment时,加载数据会报空指针异常,所以要加个判断是否已经初始化
|
||||
* 2.当Fragment已经初始化,再次可见时会直接调用此方法,此时可以直接加载数据
|
||||
* 所以要在两个地方调用加载数据
|
||||
*/
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
isCanLoadData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以加载数据
|
||||
* 可以加载数据的条件:
|
||||
* 1.视图已经初始化
|
||||
* 2.视图对用户可见
|
||||
*/
|
||||
private void isCanLoadData() {
|
||||
if (!isInit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getUserVisibleHint()) {
|
||||
setUpView();
|
||||
isLoad = true;
|
||||
} else {
|
||||
if (isLoad) {
|
||||
stopLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当视图初始化并且对用户可见的时候去真正的加载数据
|
||||
*/
|
||||
protected void setUpView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 当视图已经对用户不可见并且加载过数据,如果需要在切换到其他页面时停止加载数据,可以调用此方法
|
||||
*/
|
||||
protected void stopLoad() {
|
||||
}
|
||||
|
||||
/**
|
||||
* toast
|
||||
*
|
||||
* @param msg 吐丝的内容
|
||||
*/
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* toast
|
||||
*
|
||||
* @param ids 吐丝的内容的字符串ids
|
||||
*/
|
||||
public void toast(@StringRes int ids) {
|
||||
toast(getString(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 线程安全的toast
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void toastThreadSafe(final String msg) {
|
||||
if (null != mActivity) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toast(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 线程安全的toast
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
public void toastThreadSafe(@StringRes final int ids) {
|
||||
if (null != mActivity) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toast(ids);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启一个Activity
|
||||
*
|
||||
* @param clz 需要开启的Activity
|
||||
*/
|
||||
public void startActivity(Class<? extends Activity> clz) {
|
||||
if (null != mContext) {
|
||||
startActivity(new Intent(mContext, clz));
|
||||
// getActivity().overridePendingTransition(R.anim.trans_next_in,R.anim.trans_next_out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启一个Activity,并finish掉当前的Activity
|
||||
*
|
||||
* @param clz
|
||||
*/
|
||||
public void startActivityAndFinishSelf(Class<? extends Activity> clz) {
|
||||
if (null != mActivity) {
|
||||
startActivity(clz);
|
||||
mActivity.finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化进度对话框
|
||||
*/
|
||||
|
||||
public void showProgressDialog(String dialogMessage) {
|
||||
mProgressDialog = new LoadingDialog(mContext);
|
||||
mProgressDialog.setCanceledOnTouchOutside(false);
|
||||
// mProgressDialog.setMessage(dialogMessage);
|
||||
mProgressDialog.show();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
Log.d(TAG, "onHiddenChanged");
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭进度对话框
|
||||
*/
|
||||
|
||||
public void dismissProgressDialog() {
|
||||
if (null != mProgressDialog && mProgressDialog.isShowing()) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化刷新控件的参数
|
||||
*
|
||||
* @param ids 刷新控件的id
|
||||
*/
|
||||
protected SwipeRefreshLayout setSwipeRefreshLayout(@IdRes int ids) {
|
||||
SwipeRefreshLayout mRefreshLayout = (SwipeRefreshLayout) getView().findViewById(ids);
|
||||
mRefreshLayout.setProgressViewOffset(false, 0,
|
||||
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));
|
||||
mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
|
||||
return mRefreshLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题栏参数
|
||||
*
|
||||
* @param titleIds 标题栏的id
|
||||
* @param title 标题
|
||||
* @param goneLeftBtn 左边按钮是否显示
|
||||
* @param goneRightBtn 右边按钮是否显示
|
||||
* @param titleBarClickListener 左右边的按钮点击事件回调接口
|
||||
* @return 返回设置好的titlebar
|
||||
*/
|
||||
public TitleBar setTitleBar(@IdRes int titleIds, String title
|
||||
, boolean goneLeftBtn, boolean goneRightBtn, TitleBar.OnTitleBarClickListener titleBarClickListener) {
|
||||
TitleBar titleBar = (TitleBar) getView().findViewById(titleIds);
|
||||
titleBar.setTitle(title);
|
||||
titleBar.visibleIvLeftBtn(goneLeftBtn);
|
||||
titleBar.visibleIvRightBtn(goneRightBtn);
|
||||
titleBar.setOnTitleBarClickListener(titleBarClickListener);
|
||||
return titleBar;
|
||||
}
|
||||
}
|
||||
63
app/src/main/java/com/fenghoo/seven/base/BaseTreeView.java
Normal file
63
app/src/main/java/com/fenghoo/seven/base/BaseTreeView.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpView;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
/**
|
||||
* BaseTreeView
|
||||
* (๑• . •๑)
|
||||
* 类描述:基础View接口
|
||||
* Created by LeiXiaoXing on 2017/3/13 18:20
|
||||
*/
|
||||
|
||||
public interface BaseTreeView extends MvpView {
|
||||
|
||||
/**
|
||||
* 显示加载中对话框
|
||||
*/
|
||||
@UiThread
|
||||
|
||||
void showProgressDialog(String dialogMessage);
|
||||
|
||||
/**
|
||||
* 隐藏加载中对话框
|
||||
*/
|
||||
@UiThread
|
||||
|
||||
void dismissProgressDialog();
|
||||
|
||||
|
||||
/**
|
||||
* toast
|
||||
*
|
||||
* @param msg 吐丝的内容
|
||||
*/
|
||||
void toast(String msg);
|
||||
|
||||
/**
|
||||
* toast
|
||||
*
|
||||
* @param ids 吐丝的内容的字符串ids
|
||||
*/
|
||||
void toast(@StringRes int ids);
|
||||
|
||||
|
||||
/**
|
||||
* 开启一个Activity
|
||||
*
|
||||
* @param clz 需要开启的Activity
|
||||
*/
|
||||
void startActivity(Class<? extends Activity> clz);
|
||||
|
||||
/**
|
||||
* 开启一个Activity,并finish掉当前的Activity
|
||||
*
|
||||
* @param clz 消息内容
|
||||
*/
|
||||
void startActivityAndFinishSelf(Class<? extends Activity> clz);
|
||||
|
||||
}
|
||||
34
app/src/main/java/com/fenghoo/seven/base/BaseViewHolder.java
Normal file
34
app/src/main/java/com/fenghoo/seven/base/BaseViewHolder.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* BaseViewHolder
|
||||
* (๑• . •๑)
|
||||
* 类描述:普通的BaseViewHolder
|
||||
* Created by LeiXiaoXing on 2017/3/17 14:12
|
||||
*/
|
||||
|
||||
public abstract class BaseViewHolder<E> extends RecyclerView.ViewHolder {
|
||||
|
||||
protected BaseViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
initView(itemView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*
|
||||
* @param itemView 子视图
|
||||
*/
|
||||
protected abstract void initView(View itemView);
|
||||
|
||||
/**
|
||||
* 绑定数据
|
||||
*
|
||||
* @param entity 实体对象
|
||||
*/
|
||||
protected abstract void bindView(E entity,int position);
|
||||
}
|
||||
280
app/src/main/java/com/fenghoo/seven/base/BasetwoFragment.java
Normal file
280
app/src/main/java/com/fenghoo/seven/base/BasetwoFragment.java
Normal file
@@ -0,0 +1,280 @@
|
||||
package com.fenghoo.seven.base;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.dialog.LoadingDialog;
|
||||
import com.fenghoo.seven.widget.TitleBar;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpFragment;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpPresenter;
|
||||
import com.hannesdorfmann.mosby3.mvp.MvpView;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
/**
|
||||
* BaseTreeFragment
|
||||
* (๑• . •๑)
|
||||
* 类描述: Fragment基类,使用第三方MVP
|
||||
* Created by LeiXiaoXing on 2017/3/14 09:57
|
||||
*/
|
||||
|
||||
public abstract class BasetwoFragment<V extends MvpView, P extends MvpPresenter<V>> extends MvpFragment<V, P> {
|
||||
|
||||
protected final String TAG = getClass().getSimpleName();
|
||||
protected Context mContext;
|
||||
protected Activity mActivity;
|
||||
private LoadingDialog mProgressDialog;
|
||||
/**
|
||||
* 视图是否已经初初始化
|
||||
*/
|
||||
protected boolean isInit = false;
|
||||
protected boolean isLoad = false;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
return inflater.inflate(getFragmentLayoutId(), container, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
initView(view);
|
||||
initData();
|
||||
initEvent(view);
|
||||
isInit = true;
|
||||
isCanLoadData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Fragment布局文件id
|
||||
*
|
||||
* @return Fragment布局文件id
|
||||
*/
|
||||
protected abstract int getFragmentLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图状态
|
||||
*/
|
||||
protected abstract void initView(View view);
|
||||
|
||||
/**
|
||||
* 初始化数据参数
|
||||
*/
|
||||
protected abstract void initData();
|
||||
|
||||
/**
|
||||
* 初始化操作事件
|
||||
*/
|
||||
protected abstract void initEvent(View view);
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mContext = context;
|
||||
mActivity = getActivity();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 视图是否已经对用户可见,系统的方法,setUserVisibleHint在onCreate之前调用
|
||||
* 1.第一次创建Fragment时,加载数据会报空指针异常,所以要加个判断是否已经初始化
|
||||
* 2.当Fragment已经初始化,再次可见时会直接调用此方法,此时可以直接加载数据
|
||||
* 所以要在两个地方调用加载数据
|
||||
*/
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
isCanLoadData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以加载数据
|
||||
* 可以加载数据的条件:
|
||||
* 1.视图已经初始化
|
||||
* 2.视图对用户可见
|
||||
*/
|
||||
private void isCanLoadData() {
|
||||
if (!isInit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getUserVisibleHint()) {
|
||||
setUpView();
|
||||
isLoad = true;
|
||||
} else {
|
||||
if (isLoad) {
|
||||
stopLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当视图初始化并且对用户可见的时候去真正的加载数据
|
||||
*/
|
||||
protected void setUpView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 当视图已经对用户不可见并且加载过数据,如果需要在切换到其他页面时停止加载数据,可以调用此方法
|
||||
*/
|
||||
protected void stopLoad() {
|
||||
}
|
||||
|
||||
/**
|
||||
* toast
|
||||
*
|
||||
* @param msg 吐丝的内容
|
||||
*/
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* toast
|
||||
*
|
||||
* @param ids 吐丝的内容的字符串ids
|
||||
*/
|
||||
public void toast(@StringRes int ids) {
|
||||
toast(getString(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 线程安全的toast
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void toastThreadSafe(final String msg) {
|
||||
if (null != mActivity) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toast(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 线程安全的toast
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
public void toastThreadSafe(@StringRes final int ids) {
|
||||
if (null != mActivity) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toast(ids);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启一个Activity
|
||||
*
|
||||
* @param clz 需要开启的Activity
|
||||
*/
|
||||
public void startActivity(Class<? extends Activity> clz) {
|
||||
if (null != mContext) {
|
||||
startActivity(new Intent(mContext, clz));
|
||||
// getActivity().overridePendingTransition(R.anim.trans_next_in,R.anim.trans_next_out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启一个Activity,并finish掉当前的Activity
|
||||
*
|
||||
* @param clz
|
||||
*/
|
||||
public void startActivityAndFinishSelf(Class<? extends Activity> clz) {
|
||||
if (null != mActivity) {
|
||||
startActivity(clz);
|
||||
mActivity.finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化进度对话框
|
||||
*/
|
||||
|
||||
public void showProgressDialog(String dialogMessage) {
|
||||
mProgressDialog = new LoadingDialog(mContext);
|
||||
mProgressDialog.setCanceledOnTouchOutside(false);
|
||||
// mProgressDialog.setMessage(dialogMessage);
|
||||
mProgressDialog.show();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
Log.d(TAG, "onHiddenChanged");
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭进度对话框
|
||||
*/
|
||||
|
||||
public void dismissProgressDialog() {
|
||||
if (null != mProgressDialog && mProgressDialog.isShowing()) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化刷新控件的参数
|
||||
*
|
||||
* @param ids 刷新控件的id
|
||||
*/
|
||||
protected SwipeRefreshLayout setSwipeRefreshLayout(@IdRes int ids) {
|
||||
SwipeRefreshLayout mRefreshLayout = (SwipeRefreshLayout) getView().findViewById(ids);
|
||||
mRefreshLayout.setProgressViewOffset(false, 0,
|
||||
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));
|
||||
mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
|
||||
return mRefreshLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题栏参数
|
||||
*
|
||||
* @param titleIds 标题栏的id
|
||||
* @param title 标题
|
||||
* @param goneLeftBtn 左边按钮是否显示
|
||||
* @param goneRightBtn 右边按钮是否显示
|
||||
* @param titleBarClickListener 左右边的按钮点击事件回调接口
|
||||
* @return 返回设置好的titlebar
|
||||
*/
|
||||
public TitleBar setTitleBar(@IdRes int titleIds, String title
|
||||
, boolean goneLeftBtn, boolean goneRightBtn, TitleBar.OnTitleBarClickListener titleBarClickListener) {
|
||||
TitleBar titleBar = (TitleBar) getView().findViewById(titleIds);
|
||||
titleBar.setTitle(title);
|
||||
titleBar.visibleIvLeftBtn(goneLeftBtn);
|
||||
titleBar.visibleIvRightBtn(goneRightBtn);
|
||||
titleBar.setOnTitleBarClickListener(titleBarClickListener);
|
||||
return titleBar;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user