Skip to content

Commit

Permalink
Merge pull request #2 from erikeelde/feature/rotation2
Browse files Browse the repository at this point in the history
Feature/rotation2
  • Loading branch information
staffanjonsson authored Nov 22, 2017
2 parents 50a8de0 + 60a82b5 commit eee70d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion granter/src/main/java/se/eelde/granter/Granter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,7 +29,16 @@ private Granter(FragmentManager fragmentManager, ArrayList<String> 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")
Expand Down
10 changes: 10 additions & 0 deletions granter/src/main/java/se/eelde/granter/GranterFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -122,6 +131,7 @@ public void run() {
@Override
public void onPermissionsDenied(int internalRequestCode, final List<String> 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
Expand Down

0 comments on commit eee70d9

Please sign in to comment.