From 6e9a0b217d5f711cb1a75a9e9ac3b502d8860206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Thu, 25 Mar 2021 17:57:05 +0100 Subject: [PATCH] [UI] Remove unused permission checking. --- app/src/main/AndroidManifest.xml | 1 - .../pl/szczodrzynski/edziennik/Extensions.kt | 17 ----- .../ui/modules/webpush/QrScannerActivity.java | 75 ------------------- 3 files changed, 93 deletions(-) delete mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/webpush/QrScannerActivity.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 39704c99..15919246 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -143,7 +143,6 @@ - diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index aaf0eec7..c17f4b3a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -1,12 +1,9 @@ package pl.szczodrzynski.edziennik -import android.Manifest -import android.app.Activity import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.content.Intent -import android.content.pm.PackageManager import android.content.res.ColorStateList import android.content.res.Resources import android.database.Cursor @@ -29,7 +26,6 @@ import android.view.View import android.view.WindowManager import android.widget.* import androidx.annotation.* -import androidx.core.app.ActivityCompat import androidx.core.database.getIntOrNull import androidx.core.database.getLongOrNull import androidx.core.database.getStringOrNull @@ -304,19 +300,6 @@ fun colorFromCssName(name: String): Int { fun List.filterOutArchived() = this.filter { !it.archived } -fun Activity.isStoragePermissionGranted(): Boolean { - return if (Build.VERSION.SDK_INT >= 23) { - if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - true - } else { - ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1) - false - } - } else { - true - } -} - fun Response?.getUnixDate(): Long { val rfcDate = this?.headers()?.get("date") ?: return currentTimeUnix() val pattern = "EEE, dd MMM yyyy HH:mm:ss Z" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/webpush/QrScannerActivity.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/webpush/QrScannerActivity.java deleted file mode 100644 index b9028ac5..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/webpush/QrScannerActivity.java +++ /dev/null @@ -1,75 +0,0 @@ -package pl.szczodrzynski.edziennik.ui.modules.webpush; - -import android.Manifest; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; - -import com.google.zxing.Result; - -import me.dm7.barcodescanner.zxing.ZXingScannerView; -import pl.szczodrzynski.edziennik.R; - -public class QrScannerActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler { - private ZXingScannerView mScannerView; - public static ZXingScannerView.ResultHandler resultHandler; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view - setContentView(mScannerView); - int result = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA); - if (result == PackageManager.PERMISSION_GRANTED) { - mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. - mScannerView.startCamera(); // Start camera on resume - } else { - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1); - } - } - - @Override - public void onResume() { - super.onResume(); - mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. - mScannerView.startCamera(); // Start camera on resume - } - - @Override - public void onPause() { - super.onPause(); - mScannerView.stopCamera(); // Stop camera on pause - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - switch (requestCode) { - case 1: { - // If request is cancelled, the result arrays are empty. - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - mScannerView.startCamera(); - } else { - // permission denied, boo! Disable the - // functionality that depends on this permission. - Toast.makeText(this, R.string.no_permissions, Toast.LENGTH_SHORT).show(); - } - } - // other 'case' lines to check for other - // permissions this app might request - } - } - - @Override - public void handleResult(Result rawResult) { - if (resultHandler != null) { - resultHandler.handleResult(rawResult); - } - finish(); - } -}