diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index 025567323..8ddbaaf49 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -755,9 +755,10 @@ public class BoardDelegate extends DelegateBase // straight to asking for the permission. private void callInviteChoices( final SentInvitesInfo info ) { - Perms23.tryGetPerms( this, Perm.READ_PHONE_STATE, - R.string.phone_state_rationale, - Action.ASKED_PHONE_STATE, info ); + Perms23.tryGetPermsNA( this, Perm.READ_PHONE_STATE, + R.string.phone_state_rationale, + R.string.key_na_perms_phonestate, + Action.ASKED_PHONE_STATE, info ); } private void showInviteChoicesThen( Object[] params ) @@ -1260,7 +1261,8 @@ public class BoardDelegate extends DelegateBase break; default: - handled = false; + handled = super.onDismissed( action, params ); + break; } return handled; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java index b739af7ca..093a5f296 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java @@ -792,9 +792,20 @@ public class DelegateBase implements DlgClickNotify, public boolean onDismissed( Action action, Object[] params ) { - Log.d( TAG, "%s.dlgDismissed(%s)", getClass().getSimpleName(), + boolean handled = false; + Log.d( TAG, "%s.onDismissed(%s)", getClass().getSimpleName(), action.toString() ); - return false; + + switch( action ) { + case PERMS_QUERY: + handled = true; + Perms23.onGotPermsAction( this, false, params ); + break; + default: + Log.e( TAG, "onDismissed(): not handling action %s", action ); + } + + return handled; } public void inviteChoiceMade( Action action, DlgClickNotify.InviteMeans means, Object... params ) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java index 33be78a13..dd545ec7b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java @@ -783,9 +783,10 @@ public class GameConfigDelegate extends DelegateBase private void showConnAfterCheck() { if ( null == SMSPhoneInfo.get( m_activity ) ) { - Perms23.tryGetPerms( this, Perms23.Perm.READ_PHONE_STATE, - R.string.phone_state_rationale, - Action.ASKED_PHONE_STATE ); + Perms23.tryGetPermsNA( this, Perms23.Perm.READ_PHONE_STATE, + R.string.phone_state_rationale, + R.string.key_na_perms_phonestate, + Action.ASKED_PHONE_STATE ); } else { showDialogFragment( DlgID.CHANGE_CONN, m_conTypes ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java index f8efdf580..ebc106c6b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java @@ -203,23 +203,26 @@ public class Perms23 { private static class QueryInfo { private Action m_action; private Perm[] m_perms; + private int mNAKey; private DelegateBase m_delegate; private String m_rationaleMsg; private Object[] m_params; private QueryInfo( DelegateBase delegate, Action action, - Perm[] perms, String msg, Object[] params ) { + Perm[] perms, String msg, int naKey, + Object[] params ) { m_delegate = delegate; m_action = action; m_perms = perms; m_rationaleMsg = msg; + mNAKey = naKey; m_params = params; } private QueryInfo( DelegateBase delegate, Object[] params ) { this( delegate, (Action)params[0], (Perm[])params[1], (String)params[2], - (Object[])params[3] ); + 0, (Object[])params[3] ); } private Object[] getParams() @@ -260,6 +263,7 @@ public class Perms23 { .setPosButton( R.string.button_ask_again ) .setNegButton( R.string.button_skip ) .setParams( QueryInfo.this.getParams() ) + .setNAKey( mNAKey ) .show(); } } ); @@ -319,30 +323,36 @@ public class Perms23 { * Request permissions, giving rationale once, then call with action and * either positive or negative, the former if permission granted. */ + private static void tryGetPermsImpl( DelegateBase delegate, Perm[] perms, + String rationaleMsg, int naKey, + final Action action, Object... params ) + { + // Log.d( TAG, "tryGetPerms(%s)", perm.toString() ); + new QueryInfo( delegate, action, perms, rationaleMsg, naKey, params ) + .doIt( true ); + } + public static void tryGetPerms( DelegateBase delegate, Perm[] perms, int rationaleId, final Action action, Object... params ) { // Log.d( TAG, "tryGetPerms(%s)", perm.toString() ); - Context context = XWApp.getContext(); - String msg = rationaleId == 0 - ? null : LocUtils.getString( context, rationaleId ); - tryGetPerms( delegate, perms, msg, action, params ); + String msg = LocUtils.getStringOrNull( rationaleId ); + tryGetPermsImpl( delegate, perms, msg, 0, action, params ); } public static void tryGetPerms( DelegateBase delegate, Perm[] perms, String rationaleMsg, final Action action, Object... params ) { - // Log.d( TAG, "tryGetPerms(%s)", perm.toString() ); - new QueryInfo( delegate, action, perms, rationaleMsg, params ) - .doIt( true ); + tryGetPermsImpl( delegate, perms, rationaleMsg, 0, action, params ); } public static void tryGetPerms( DelegateBase delegate, Perm perm, String rationaleMsg, final Action action, Object... params ) { - tryGetPerms( delegate, new Perm[]{ perm }, rationaleMsg, action, params ); + tryGetPermsImpl( delegate, new Perm[]{ perm }, rationaleMsg, 0, + action, params ); } public static void tryGetPerms( DelegateBase delegate, Perm perm, int rationaleId, @@ -351,6 +361,15 @@ public class Perms23 { tryGetPerms( delegate, new Perm[]{perm}, rationaleId, action, params ); } + public static void tryGetPermsNA( DelegateBase delegate, Perm perm, + int rationaleId, int naKey, + Action action, Object... params ) + { + tryGetPermsImpl( delegate, new Perm[] {perm}, + LocUtils.getStringOrNull( rationaleId ), naKey, + action, params ); + } + public static void onGotPermsAction( DelegateBase delegate, boolean positive, Object[] params ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java index 3e65f491c..a2e74fcee 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java @@ -265,6 +265,16 @@ public class LocUtils { return getString( context, true, id ); } + public static String getStringOrNull( int id ) + { + String result = null; + if ( 0 != id ) { + Context context = XWApp.getContext(); + result = getString( context, true, id ); + } + return result; + } + public static String getString( Context context, boolean canUseDB, int id ) { String result = null; diff --git a/xwords4/android/app/src/main/res/values/common_rsrc.xml b/xwords4/android/app/src/main/res/values/common_rsrc.xml index 56e50c8bc..f213c014e 100644 --- a/xwords4/android/app/src/main/res/values/common_rsrc.xml +++ b/xwords4/android/app/src/main/res/values/common_rsrc.xml @@ -145,6 +145,7 @@ key_na_bt_badproto key_na_sms_banned key_na_longtap_lookup + key_na_perms_phonestate xwords@eehouse.org