2025-06-30 13:49:41 +08:00
|
|
|
|
package com.tfq.library.base;
|
|
|
|
|
|
|
2025-07-09 16:02:54 +08:00
|
|
|
|
import android.animation.ObjectAnimator;
|
2025-06-30 13:49:41 +08:00
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
|
import android.view.View;
|
2025-07-09 16:02:54 +08:00
|
|
|
|
import android.view.ViewAnimationUtils;
|
2025-06-30 13:49:41 +08:00
|
|
|
|
import android.view.ViewGroup;
|
2025-07-09 16:02:54 +08:00
|
|
|
|
import android.view.animation.AnimationUtils;
|
2025-06-30 13:49:41 +08:00
|
|
|
|
|
|
|
|
|
|
import com.hjq.permissions.OnPermissionCallback;
|
|
|
|
|
|
import com.hjq.permissions.XXPermissions;
|
2025-07-09 16:02:54 +08:00
|
|
|
|
import com.tfq.library.R;
|
|
|
|
|
|
import com.tfq.library.app.BaseConstants;
|
|
|
|
|
|
import com.tfq.library.app.LibraryApp;
|
|
|
|
|
|
import com.tfq.library.view.Animation;
|
|
|
|
|
|
import com.tfq.library.view.AuthDialog;
|
2025-06-30 13:49:41 +08:00
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.LayoutRes;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
|
|
2025-07-09 16:02:54 +08:00
|
|
|
|
import static com.tfq.library.app.BaseConstants.REQUEST_PER;
|
|
|
|
|
|
|
2025-06-30 13:49:41 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Created by JiangKe on 2025/02/20.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class BaseFragment extends Fragment {
|
|
|
|
|
|
|
|
|
|
|
|
private View root = null;
|
|
|
|
|
|
private String content = "当前操作需要您授权相应权限,否则可能无法正常使用此功能";
|
|
|
|
|
|
|
|
|
|
|
|
@LayoutRes
|
|
|
|
|
|
protected abstract int getLayoutId();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 初始化零件
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected abstract void initView();
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract void initData(Bundle savedInstanceState);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 初始化点击事件
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected void initClick() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 逻辑使用区
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected void processLogic() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-09 16:02:54 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 进入动画区
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected void animationStart() {
|
|
|
|
|
|
Animation.startAnimation(requireActivity());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-30 13:49:41 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 权限请求
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected void requestPermission(String[] per, Listener listener) {
|
|
|
|
|
|
requestPermission(per, content, listener);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void requestPermission(String[] per, String content, Listener listener) {
|
|
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
|
|
|
|
|
this.content = content;
|
|
|
|
|
|
}
|
|
|
|
|
|
requestPermission(per, content, true, false, listener);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void requestPermission(String[] per, String content, boolean show_doNotAskAgain, Listener listener) {
|
|
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
|
|
|
|
|
this.content = content;
|
|
|
|
|
|
}
|
|
|
|
|
|
requestPermission(per, content, true, show_doNotAskAgain, listener);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void requestPermission(String[] per, String content, boolean req_permission, boolean show_doNotAskAgain, Listener listener) {
|
|
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
|
|
|
|
|
this.content = content;
|
|
|
|
|
|
}
|
|
|
|
|
|
requestPermission(per, req_permission, show_doNotAskAgain, listener);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 申请权限
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param permission 权限集合
|
|
|
|
|
|
* @param req_permission 申请权限之前是否提示,默认false,不提示
|
|
|
|
|
|
* @param show_doNotAskAgain 权限申请失败是否调整到设置页,默认false,不关闭
|
|
|
|
|
|
* @param listener 监听
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected void requestPermission(String[] permission, boolean req_permission, boolean show_doNotAskAgain, Listener listener) {
|
|
|
|
|
|
if (!req_permission) {//不弹窗直接申请权限
|
|
|
|
|
|
requestPermission(permission, show_doNotAskAgain, listener);
|
|
|
|
|
|
} else {//先弹窗,再去申请
|
2025-07-09 16:02:54 +08:00
|
|
|
|
new AuthDialog(getActivity(), REQUEST_PER, new AuthDialog.Listener() {
|
2025-06-30 13:49:41 +08:00
|
|
|
|
@Override
|
2025-07-09 16:02:54 +08:00
|
|
|
|
public void callBack() {
|
|
|
|
|
|
//同意申请权限,去申请
|
|
|
|
|
|
requestPermission(permission, show_doNotAskAgain, listener);
|
2025-06-30 13:49:41 +08:00
|
|
|
|
}
|
2025-07-09 16:02:54 +08:00
|
|
|
|
}).show();
|
2025-06-30 13:49:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void requestPermission(String[] permission, boolean show_doNotAskAgain, Listener listener) {
|
|
|
|
|
|
XXPermissions.with(getActivity())
|
|
|
|
|
|
.permission(permission)
|
|
|
|
|
|
.request(new OnPermissionCallback() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onGranted(@NonNull List<String> permissions, boolean allGranted) {
|
|
|
|
|
|
if (!allGranted) {
|
|
|
|
|
|
//获取部分权限成功,但部分权限未正常授予
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
listener.success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
|
|
|
|
|
|
if (show_doNotAskAgain) {
|
|
|
|
|
|
if (doNotAskAgain) {
|
|
|
|
|
|
//如果是被永久拒绝就跳转到应用权限系统设置页面
|
|
|
|
|
|
XXPermissions.startPermissionActivity(getActivity(), permissions);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//获取权限失败
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************lifecycle area*****************************************/
|
|
|
|
|
|
@Nullable
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
|
int resId = getLayoutId();
|
|
|
|
|
|
root = inflater.inflate(resId, container, false);
|
|
|
|
|
|
return root;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
|
|
initView();
|
|
|
|
|
|
initData(savedInstanceState);
|
|
|
|
|
|
initClick();
|
|
|
|
|
|
processLogic();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onDetach() {
|
|
|
|
|
|
super.onDetach();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************公共类*******************************************/
|
|
|
|
|
|
public String getName() {
|
|
|
|
|
|
return getClass().getName();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected <VT> VT findViewBy_Id(int id) {
|
|
|
|
|
|
if (root == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
return (VT) root.findViewById(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface Listener {
|
|
|
|
|
|
void success();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|