diff --git a/app/build.gradle b/app/build.gradle index 63bbc54..93ab61e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,6 +41,8 @@ android { signingConfig signingConfigs.sdwfqinSigning } debug { + minifyEnabled false + shrinkResources false signingConfig signingConfigs.sdwfqinSigning } } diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 1ba68c7..e03bb17 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/src/main/java/com/sdwfqin/quickseed/ui/main/MainActivity.java b/app/src/main/java/com/sdwfqin/quickseed/ui/main/MainActivity.java index 6f30fb2..455cb7e 100644 --- a/app/src/main/java/com/sdwfqin/quickseed/ui/main/MainActivity.java +++ b/app/src/main/java/com/sdwfqin/quickseed/ui/main/MainActivity.java @@ -100,7 +100,7 @@ private void initTabs() { private void getPermissions() { String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA}; - initCheckPermissions(perms, true, false, new OnPermissionCallback() { + initCheckPermissions(perms, new OnPermissionCallback() { @Override public void onSuccess() { Toast.makeText(mContext, "取得权限", Toast.LENGTH_SHORT).show(); diff --git a/config.gradle b/config.gradle index b57e7cc..4e41a20 100644 --- a/config.gradle +++ b/config.gradle @@ -1,7 +1,7 @@ ext { - versionCode = 202007201 - versionName = "4.2.0" + versionCode = 202007231 + versionName = "4.3.0" qmui = "2.0.0-alpha10" okhttp = "4.7.2" @@ -72,8 +72,7 @@ ext { ] utilsDependencies = [ - // easypermissions - "easypermissions": "pub.devrel:easypermissions:3.0.0", + "permissionx": "com.permissionx.guolindev:permissionx:1.3.0", // utils "utilcodex" : "com.blankj:utilcodex:1.29.0", // agentweb diff --git a/quicklib/build.gradle b/quicklib/build.gradle index e4cbfb6..bf8355d 100644 --- a/quicklib/build.gradle +++ b/quicklib/build.gradle @@ -59,7 +59,7 @@ dependencies { api utilsDependencies["utilcodex"] api utilsDependencies["agentweb"] - api utilsDependencies["easypermissions"] + api utilsDependencies["permissionx"] api utilsDependencies["arouter"] api utilsDependencies["gson"] diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java b/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java index 44dedc4..313ccd9 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/base/BaseActivity.java @@ -3,7 +3,6 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.os.Handler; import android.view.View; import android.view.ViewGroup; @@ -12,10 +11,12 @@ import androidx.viewbinding.ViewBinding; import com.blankj.utilcode.util.ToastUtils; +import com.permissionx.guolindev.PermissionX; import com.qmuiteam.qmui.arch.QMUIActivity; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; import com.sdwfqin.quicklib.R; +import com.sdwfqin.quicklib.dialog.PermissionCustomDialog; import com.sdwfqin.quicklib.mvp.BaseView; import com.sdwfqin.quicklib.utils.AppManager; import com.sdwfqin.quicklib.utils.eventbus.Event; @@ -24,21 +25,15 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import java.util.List; - import io.reactivex.rxjava3.disposables.CompositeDisposable; import io.reactivex.rxjava3.disposables.Disposable; -import pub.devrel.easypermissions.AppSettingsDialog; -import pub.devrel.easypermissions.EasyPermissions; /** * 描述:Activity基类 * * @author 张钦 */ -public abstract class BaseActivity extends QMUIActivity implements BaseView, EasyPermissions.PermissionCallbacks { - - private static final int PERMS_REQUEST_CODE = 1122; +public abstract class BaseActivity extends QMUIActivity implements BaseView { protected Activity mContext; protected V mBinding; @@ -55,17 +50,6 @@ public abstract class BaseActivity extends QMUIActivity i * TipDialog */ protected QMUITipDialog mQmuiTipDialog; - /** - * 权限相关 - */ - private String[] mPerms; - private OnPermissionCallback mOnPermissionCallback; - private boolean mShowPermissionsDialog; - private boolean mLoopPermissionsDialog; - /** - * 权限请求次数 - */ - private int mPermissionsRequestNum = 0; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -254,101 +238,31 @@ public interface OnPermissionCallback { void onError(); } - /** - * 检查权限是否全部获取 - * - * @param perms - * @param onPermissionCallback - */ - public void initCheckPermissions(String[] perms, OnPermissionCallback onPermissionCallback) { - initCheckPermissions(perms, false, false, onPermissionCallback); - } - /** * 初始化权限检查 * - * @param perms 权限列表 - * @param showPermissionsDialog true:拒绝显示弹窗 - * @param loopPermissionsDialog true:弹窗关闭继续弹出弹窗 - * @param onPermissionCallback 权限回掉接口 + * @param perms 权限列表 + * @param onPermissionCallback 权限回掉接口 */ - public void initCheckPermissions(String[] perms, boolean showPermissionsDialog, boolean loopPermissionsDialog, - OnPermissionCallback onPermissionCallback) { - mPerms = perms; - mShowPermissionsDialog = showPermissionsDialog; - mLoopPermissionsDialog = loopPermissionsDialog; - mOnPermissionCallback = onPermissionCallback; - - checkPermissions(); - } - - /** - * 检查权限是否全部获取 - */ - public void checkPermissions() { - - if (EasyPermissions.hasPermissions(this, mPerms)) { - // Already have permission, do the thing - mOnPermissionCallback.onSuccess(); - } else { - // Do not have permissions, request them now - if (mShowPermissionsDialog) { - mPermissionsRequestNum++; - new Handler().postDelayed(() -> { - EasyPermissions.requestPermissions(this, getString(R.string.quick_permissions_check_error), - PERMS_REQUEST_CODE, mPerms); - }, 100); - } else { - mOnPermissionCallback.onError(); - } - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - // Forward results to EasyPermissions - EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); - } - - @Override - public void onPermissionsGranted(int requestCode, List perms) { - // Some permissions have been granted - if (perms.size() >= mPerms.length) { - mOnPermissionCallback.onSuccess(); - } - } - - @Override - public void onPermissionsDenied(int requestCode, List perms) { - // Some permissions have been denied - if (mLoopPermissionsDialog || (mPermissionsRequestNum == 1 && EasyPermissions.somePermissionPermanentlyDenied(this, perms))) { - if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { - AppSettingsDialog.Builder builder = new AppSettingsDialog.Builder(this); - AppSettingsDialog appSettingsDialog = builder.setTitle(R.string.quick_permissions_dialog_title_settings) - .setRationale(R.string.quick_permissions_dialog_rationale_ask_again) - .setNegativeButton(R.string.quick_permissions_dialog_cancel) - .setPositiveButton(R.string.quick_permissions_dialog_to_setting) - .build(); - appSettingsDialog.show(); - } else { - checkPermissions(); - } - } else { - mOnPermissionCallback.onError(); - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) { - // Do something after user returned from app settings screen, like showing a Toast. - checkPermissions(); - } + public void initCheckPermissions(String[] perms, OnPermissionCallback onPermissionCallback) { + PermissionX.init(this) + .permissions(perms) + .onExplainRequestReason((scope, deniedList, beforeRequest) -> { + PermissionCustomDialog dialog = new PermissionCustomDialog(mContext, getString(R.string.quick_permissions_title, getString(R.string.app_name)), deniedList); + scope.showRequestReasonDialog(dialog); + }) + .onForwardToSettings((scope, deniedList) -> { + PermissionCustomDialog dialog = new PermissionCustomDialog(mContext, getString(R.string.quick_permissions_forward), deniedList); + scope.showForwardToSettingsDialog(dialog); + }) + .request((allGranted, grantedList, deniedList) -> { + if (allGranted) { + onPermissionCallback.onSuccess(); + } else { + onPermissionCallback.onError(); + } + }); } - // ==================== 提供的接口 ==================== protected void initViewModel() { diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/dialog/PermissionCustomDialog.java b/quicklib/src/main/java/com/sdwfqin/quicklib/dialog/PermissionCustomDialog.java new file mode 100644 index 0000000..05e692c --- /dev/null +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/dialog/PermissionCustomDialog.java @@ -0,0 +1,136 @@ +package com.sdwfqin.quicklib.dialog; + +import android.Manifest; +import android.content.Context; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.view.Gravity; +import android.view.View; +import android.view.WindowManager; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.blankj.utilcode.util.ScreenUtils; +import com.permissionx.guolindev.request.RationaleDialog; +import com.qmuiteam.qmui.skin.QMUISkinManager; +import com.sdwfqin.quicklib.R; +import com.sdwfqin.quicklib.databinding.QuickDialogPermissionBinding; +import com.sdwfqin.quicklib.databinding.QuickItemPermissionsBinding; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * 自定义权限弹窗 + *

+ * + * @author 张钦 + * @date 2020/7/23 + */ +public class PermissionCustomDialog extends RationaleDialog { + + private Map permissionMap = new HashMap<>(); + private Set groupSet = new HashSet<>(); + private String message; + private List permissions; + private QuickDialogPermissionBinding mBinding; + + { + permissionMap.put(Manifest.permission.READ_CALENDAR, Manifest.permission_group.CALENDAR); + permissionMap.put(Manifest.permission.WRITE_CALENDAR, Manifest.permission_group.CALENDAR); + permissionMap.put(Manifest.permission.READ_CALL_LOG, Manifest.permission_group.CALL_LOG); + permissionMap.put(Manifest.permission.WRITE_CALL_LOG, Manifest.permission_group.CALL_LOG); + permissionMap.put(Manifest.permission.PROCESS_OUTGOING_CALLS, Manifest.permission_group.CALL_LOG); + permissionMap.put(Manifest.permission.CAMERA, Manifest.permission_group.CAMERA); + permissionMap.put(Manifest.permission.READ_CONTACTS, Manifest.permission_group.CONTACTS); + permissionMap.put(Manifest.permission.WRITE_CONTACTS, Manifest.permission_group.CONTACTS); + permissionMap.put(Manifest.permission.GET_ACCOUNTS, Manifest.permission_group.CONTACTS); + permissionMap.put(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission_group.LOCATION); + permissionMap.put(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission_group.LOCATION); + permissionMap.put(Manifest.permission.ACCESS_BACKGROUND_LOCATION, Manifest.permission_group.LOCATION); + permissionMap.put(Manifest.permission.RECORD_AUDIO, Manifest.permission_group.MICROPHONE); + permissionMap.put(Manifest.permission.READ_PHONE_STATE, Manifest.permission_group.PHONE); + permissionMap.put(Manifest.permission.READ_PHONE_NUMBERS, Manifest.permission_group.PHONE); + permissionMap.put(Manifest.permission.CALL_PHONE, Manifest.permission_group.PHONE); + permissionMap.put(Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission_group.PHONE); + permissionMap.put(Manifest.permission.ADD_VOICEMAIL, Manifest.permission_group.PHONE); + permissionMap.put(Manifest.permission.USE_SIP, Manifest.permission_group.PHONE); + permissionMap.put(Manifest.permission.ACCEPT_HANDOVER, Manifest.permission_group.PHONE); + permissionMap.put(Manifest.permission.BODY_SENSORS, Manifest.permission_group.SENSORS); + permissionMap.put(Manifest.permission.ACTIVITY_RECOGNITION, Manifest.permission_group.ACTIVITY_RECOGNITION); + permissionMap.put(Manifest.permission.SEND_SMS, Manifest.permission_group.SMS); + permissionMap.put(Manifest.permission.RECEIVE_SMS, Manifest.permission_group.SMS); + permissionMap.put(Manifest.permission.READ_SMS, Manifest.permission_group.SMS); + permissionMap.put(Manifest.permission.RECEIVE_WAP_PUSH, Manifest.permission_group.SMS); + permissionMap.put(Manifest.permission.RECEIVE_MMS, Manifest.permission_group.SMS); + permissionMap.put(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission_group.STORAGE); + permissionMap.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission_group.STORAGE); + permissionMap.put(Manifest.permission.ACCESS_MEDIA_LOCATION, Manifest.permission_group.STORAGE); + } + + public PermissionCustomDialog(@NonNull Context context, String message, List permissions) { + super(context, R.style.transactionDialog); + this.message = message; + this.permissions = permissions; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mBinding = QuickDialogPermissionBinding.inflate(getLayoutInflater()); + setContentView(mBinding.getRoot()); + + mBinding.messageText.setText(message); + buildPermissionsLayout(); + if (getWindow() != null) { + int width = (int) (ScreenUtils.getScreenWidth() * 0.8); + getWindow() + .setLayout(width, WindowManager.LayoutParams.WRAP_CONTENT); + getWindow().setGravity(Gravity.CENTER); + } + } + + @Override + public void onStart() { + super.onStart(); + QMUISkinManager.defaultInstance(getContext()).register(this); + } + + private void buildPermissionsLayout() { + for (String permission : permissions) { + String permissionGroup = permissionMap.get(permission); + if (permissionGroup != null && !groupSet.contains(permissionGroup)) { + QuickItemPermissionsBinding permissionsItemBinding = QuickItemPermissionsBinding.inflate(getLayoutInflater()); + try { + permissionsItemBinding.bodyItem.setText(getContext().getPackageManager().getPermissionGroupInfo(permissionGroup, 0).loadLabel(getContext().getPackageManager())); + mBinding.permissionsLayout.addView(permissionsItemBinding.getRoot()); + groupSet.add(permissionGroup); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + } + } + } + + @NonNull + @Override + public View getPositiveButton() { + return mBinding.positiveBtn; + } + + @Nullable + @Override + public View getNegativeButton() { + return mBinding.negativeBtn; + } + + @NonNull + @Override + public List getPermissionsToRequest() { + return permissions; + } +} diff --git a/quicklib/src/main/res/drawable/quick_permission_dialog_bg.xml b/quicklib/src/main/res/drawable/quick_permission_dialog_bg.xml new file mode 100644 index 0000000..a818750 --- /dev/null +++ b/quicklib/src/main/res/drawable/quick_permission_dialog_bg.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/quicklib/src/main/res/layout/quick_dialog_permission.xml b/quicklib/src/main/res/layout/quick_dialog_permission.xml new file mode 100644 index 0000000..d7f66a1 --- /dev/null +++ b/quicklib/src/main/res/layout/quick_dialog_permission.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + +