Skip to content

Commit

Permalink
Refactor storage permission checking method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Sep 8, 2023
1 parent 60c878a commit 7c277a2
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.view.OnApplyWindowInsetsListener;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;

import com.drdisagree.iconify.R;
import com.drdisagree.iconify.ui.utils.ThemeHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -95,8 +94,8 @@ private void addItem(ArrayList<Object[]> pack) {

refreshBackground();
} else {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
// Show loading dialog
loadingDialog.show(getResources().getString(R.string.loading_dialog_wait));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -381,8 +380,8 @@ public void onStopTrackingTouch(@NonNull Slider slider) {
binding.floatingActionMenu.hide();
showApplyButton = false;
binding.enableCustomMonet.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else if (Objects.equals(selectedStyle, STR_NULL)) {
Toast.makeText(MonetEngine.this, getResources().getString(R.string.toast_select_style), Toast.LENGTH_SHORT).show();
} else {
Expand Down Expand Up @@ -660,8 +659,8 @@ private List<List<Object>> cloneList(final List<List<Object>> src) {
}

private void importExportSettings(boolean export) {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(MonetEngine.this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(MonetEngine.this);
} else {
Intent fileIntent = new Intent();
fileIntent.setAction(export ? Intent.ACTION_CREATE_DOCUMENT : Intent.ACTION_GET_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.PersistableBundle;
Expand Down Expand Up @@ -165,13 +164,13 @@ public void onPageSelected(int position) {

if (RootUtil.isDeviceRooted()) {
if (RootUtil.isMagiskInstalled() || RootUtil.isKSUInstalled()) {
if (!Environment.isExternalStorageManager()) {
if (!SystemUtil.hasStoragePermission()) {
showInfo(R.string.need_storage_perm_title, R.string.need_storage_perm_desc);
Toast.makeText(Onboarding.this, R.string.toast_storage_access, Toast.LENGTH_SHORT).show();

new Handler(Looper.getMainLooper()).postDelayed(() -> {
clickedContinue.set(true);
SystemUtil.getStoragePermission(Onboarding.this);
SystemUtil.requestStoragePermission(Onboarding.this);
}, clickedContinue.get() ? 10 : 2000);
} else {
if (!ModuleUtil.moduleExists()) {
Expand Down Expand Up @@ -213,13 +212,13 @@ public void onPageSelected(int position) {

if (RootUtil.isDeviceRooted()) {
if (RootUtil.isMagiskInstalled() || RootUtil.isKSUInstalled()) {
if (!Environment.isExternalStorageManager()) {
if (!SystemUtil.hasStoragePermission()) {
showInfo(R.string.need_storage_perm_title, R.string.need_storage_perm_desc);
Toast.makeText(Onboarding.this, R.string.toast_storage_access, Toast.LENGTH_SHORT).show();

new Handler(Looper.getMainLooper()).postDelayed(() -> {
clickedContinue.set(true);
SystemUtil.getStoragePermission(this);
SystemUtil.requestStoragePermission(this);
}, clickedContinue.get() ? 10 : 2000);
} else {
boolean moduleExists = ModuleUtil.moduleExists();
Expand Down Expand Up @@ -353,6 +352,12 @@ protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
selectedItemPosition = savedInstanceState.getInt(mData);
}

@Override
protected void onResume() {
super.onResume();
binding.btnNextStep.requestLayout();
}

@SuppressLint("StaticFieldLeak")
private class StartInstallationProcess extends TaskExecutor<Void, Integer, Integer> {
@SuppressLint("SetTextI18n")
Expand Down Expand Up @@ -637,10 +642,4 @@ protected void onCancelled() {
Shell.cmd("rm -rf " + Resources.MODULE_DIR).exec();
}
}

@Override
protected void onResume() {
super.onResume();
binding.btnNextStep.requestLayout();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
Expand Down Expand Up @@ -121,8 +120,8 @@ public void onStopTrackingTouch(@NonNull Slider slider) {
binding.qsMarginReset.setVisibility(View.VISIBLE);

binding.qsMarginApply.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
// Show loading dialog
loadingDialog.show(getResources().getString(R.string.loading_dialog_wait));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
Expand Down Expand Up @@ -172,8 +171,8 @@ public void onStopTrackingTouch(@NonNull Slider slider) {
binding.qsTileHeightReset.setVisibility(View.VISIBLE);

binding.qsTileHeightApply.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
// Show loading dialog
loadingDialog.show(getResources().getString(R.string.loading_dialog_wait));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -122,8 +121,8 @@ protected void onCreate(Bundle savedInstanceState) {
binding.disableSettingsIcons.setVisibility(View.VISIBLE);

binding.enableSettingsIcons.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
// Show loading dialog
loadingDialog.show(getResources().getString(R.string.loading_dialog_wait));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -80,8 +79,8 @@ private void addItem(ArrayList<Object[]> pack) {

int finalI = i;
list.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
// Show loading dialog
loadingDialog.show(getResources().getString(R.string.loading_dialog_wait));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.content.res.Configuration;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -91,8 +90,8 @@ public void onStopTrackingTouch(@NonNull Slider slider) {
});

binding.applyRadius.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
// Show loading dialog
loadingDialog.show(getResources().getString(R.string.loading_dialog_wait));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -119,8 +118,8 @@ protected void onCreate(Bundle savedInstanceState) {
realCheckedId = checkedId1 == -1 ? checkedId2 : checkedId1;

binding.volumeStyle.volumeStyleCreateModule.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
if (realCheckedId == -1) {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_select_style), Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
Expand Down Expand Up @@ -99,8 +98,8 @@ protected void onCreate(Bundle savedInstanceState) {

// Lockscreen clock font picker
binding.pickHeaderClockFont.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
browseHeaderClockFont();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Toast;

Expand Down Expand Up @@ -58,8 +57,8 @@ protected void onCreate(Bundle savedInstanceState) {

// Header image picker
binding.pickHeaderImage.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
browseHeaderImage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
Expand Down Expand Up @@ -107,8 +106,8 @@ protected void onCreate(Bundle savedInstanceState) {

// Lockscreen clock font picker
binding.pickLsclockFont.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(this);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
browseLSClockFont();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -115,8 +114,8 @@ private void enableOnClickListener(ViewHolder holder) {

// Set onClick operation for Enable button
holder.btn_enable.setOnClickListener(v -> {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(context);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(context);
} else {
// Show loading dialog
loadingDialog.show(context.getResources().getString(R.string.loading_dialog_wait));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -120,8 +119,8 @@ private void enableOnCheckedChangeListener(ViewHolder holder) {
private void switchAction(ViewHolder holder, boolean checked) {
new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (checked) {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(context);
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(context);
holder.aSwitch.setChecked(false);
} else {
// Show loading dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -334,8 +333,8 @@ public void onItemSelected(int dialogId, int selectedIndex) {
}

private void importExportSettings(boolean export) {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(requireContext());
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(requireContext());
} else {
Intent fileIntent = new Intent();
fileIntent.setAction(export ? Intent.ACTION_CREATE_DOCUMENT : Intent.ACTION_GET_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -282,8 +281,8 @@ private void addItem(ArrayList<Object[]> pack) {
}

private void importExportSettings(boolean export) {
if (!Environment.isExternalStorageManager()) {
SystemUtil.getStoragePermission(requireContext());
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(requireContext());
} else {
Intent fileIntent = new Intent();
fileIntent.setAction(export ? Intent.ACTION_CREATE_DOCUMENT : Intent.ACTION_GET_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.drdisagree.iconify.ui.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.TypedValue;

import androidx.annotation.AttrRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;
Expand Down
Loading

0 comments on commit 7c277a2

Please sign in to comment.