From 02dcf7f0ec4ac1bd1fa0d307a7708d2ff7b997b0 Mon Sep 17 00:00:00 2001 From: Erik Eelde Date: Wed, 22 Nov 2017 10:07:33 +0100 Subject: [PATCH 1/3] Make sure we only have one GranterFragment --- granter/src/main/java/se/eelde/granter/Granter.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/granter/src/main/java/se/eelde/granter/Granter.java b/granter/src/main/java/se/eelde/granter/Granter.java index c1f8ef9..0b8b338 100644 --- a/granter/src/main/java/se/eelde/granter/Granter.java +++ b/granter/src/main/java/se/eelde/granter/Granter.java @@ -1,9 +1,11 @@ package se.eelde.granter; import android.content.res.Resources; +import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import java.util.ArrayList; @@ -27,7 +29,16 @@ private Granter(FragmentManager fragmentManager, ArrayList permissions, } public void show() { - fragmentManager.beginTransaction().add(GranterFragment.newInstance(permissions, requestCode, rationale, systemSettingRationale), PERMISSIONS_FRAGMENT_TAG).commit(); + @Nullable + Fragment oldGranterFragment = fragmentManager.findFragmentByTag(PERMISSIONS_FRAGMENT_TAG); + + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); + if (oldGranterFragment != null) { + fragmentTransaction.remove(oldGranterFragment); + } + + fragmentTransaction.add(GranterFragment.newInstance(permissions, requestCode, rationale, systemSettingRationale), PERMISSIONS_FRAGMENT_TAG) + .commit(); } @SuppressWarnings("unused") From 97e538ab45b95e601b3e14e0b2225d8e239230e4 Mon Sep 17 00:00:00 2001 From: Erik Eelde Date: Wed, 22 Nov 2017 10:08:47 +0100 Subject: [PATCH 2/3] Make sure we always have a saved state --- .../main/java/se/eelde/granter/GranterFragment.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/granter/src/main/java/se/eelde/granter/GranterFragment.java b/granter/src/main/java/se/eelde/granter/GranterFragment.java index e466edc..bb691c0 100644 --- a/granter/src/main/java/se/eelde/granter/GranterFragment.java +++ b/granter/src/main/java/se/eelde/granter/GranterFragment.java @@ -71,6 +71,15 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + + // with no ui show we would get a null savedInstanceState in onCreate and + // would not be able to distinguish between new creates and recreates of the fragment. + outState.putBoolean("recreated", true); + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); @@ -122,6 +131,7 @@ public void run() { @Override public void onPermissionsDenied(int internalRequestCode, final List perms) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { + // fix to be able to do fragment transactions in the permission callbacks new Handler(Looper.getMainLooper()) .post(new Runnable() { @Override From 60a82b525a749ba5e2ed1207ba03fcb347a73dda Mon Sep 17 00:00:00 2001 From: Erik Eelde Date: Wed, 22 Nov 2017 10:09:00 +0100 Subject: [PATCH 3/3] Bump build tools --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 020eae2..e6b32bc 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong