From 2649cacdfdac50970fb637cbce50ff8c952e9606 Mon Sep 17 00:00:00 2001 From: Nikita Korovkin Date: Wed, 31 Oct 2018 18:13:44 +0300 Subject: [PATCH] java.lang.SecurityException --- .../droid/playlist/TaskGetPlaylist.java | 46 +++++++++++++------ freemp.iml | 2 +- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/freemp/droid/playlist/TaskGetPlaylist.java b/app/src/main/java/org/freemp/droid/playlist/TaskGetPlaylist.java index 27ae6dc..cbdb21d 100644 --- a/app/src/main/java/org/freemp/droid/playlist/TaskGetPlaylist.java +++ b/app/src/main/java/org/freemp/droid/playlist/TaskGetPlaylist.java @@ -2,7 +2,10 @@ import android.Manifest; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.AsyncTask; +import android.os.Build; import android.os.Environment; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; @@ -15,6 +18,7 @@ import com.karumi.dexter.listener.multi.MultiplePermissionsListener; import org.freemp.droid.Constants; +import org.freemp.droid.player.ActPlayer; import org.freemp.droid.playlist.albums.FragmentAlbums; import org.freemp.droid.playlist.artists.FragmentArtists; import org.freemp.droid.playlist.folders.FragmentFolders; @@ -56,20 +60,26 @@ public TaskGetPlaylist(Activity activity, int type, boolean refresh, OnTaskGetPl .withListener(new MultiplePermissionsListener() { @Override public void onPermissionsChecked(MultiplePermissionsReport report) { - getPlayList(activity, finalType, refresh, onTaskGetPlaylist) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(object -> { - OnTaskGetPlaylist onTaskGetPlaylist1 = mOnTaskGetPlaylist.get(); - Activity activityResult = mActivity.get(); - if (null != onTaskGetPlaylist1) { - onTaskGetPlaylist1.OnTaskResult(object); - } - if (null != activityResult) { - ((ActPlaylist) activityResult).setRefreshing(false); - ((ActPlaylist) activityResult).setRefreshActionButtonState(); - } - }); + if (!report.isAnyPermissionPermanentlyDenied()) { + getPlayList(activity, finalType, refresh, onTaskGetPlaylist) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object -> { + OnTaskGetPlaylist onTaskGetPlaylist1 = mOnTaskGetPlaylist.get(); + Activity activityResult = mActivity.get(); + if (null != onTaskGetPlaylist1) { + onTaskGetPlaylist1.OnTaskResult(object); + } + if (null != activityResult) { + ((ActPlaylist) activityResult).setRefreshing(false); + ((ActPlaylist) activityResult).setRefreshActionButtonState(); + } + }); + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + showMessageOKCancel("You need to allow access to both the permissions"); + } + } } @Override @@ -81,6 +91,14 @@ public void onPermissionRationaleShouldBeShown(List permissio } + private void showMessageOKCancel(String message) { + new AlertDialog.Builder(mActivity.get()) + .setMessage(message) + .setNegativeButton("Cancel", null) + .create() + .show(); + } + private Single getPlayList(Activity activity, final int type, final boolean refresh, OnTaskGetPlaylist onTaskGetPlaylist){ return new Single() { @Override diff --git a/freemp.iml b/freemp.iml index 5f3d22a..9e960c4 100644 --- a/freemp.iml +++ b/freemp.iml @@ -13,7 +13,7 @@ - + \ No newline at end of file