From a4536764560985b17004ad366e1110f725495ec0 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 7 Jan 2017 12:16:59 -0800 Subject: [PATCH] use tryGetPerms to replace a bunch of Perms23 crud This one required allowing passing in a string rather than a res id. --- .../android/XWords4/res/values/strings.xml | 20 +++--- .../XWords4/res_src/values-ba_CK/strings.xml | 17 +++-- .../XWords4/res_src/values-ca_PS/strings.xml | 17 +++-- .../org/eehouse/android/xw4/DlgDelegate.java | 1 - .../android/xw4/GamesListDelegate.java | 70 +++++++++---------- .../src/org/eehouse/android/xw4/Perms23.java | 24 +++++-- 6 files changed, 83 insertions(+), 66 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 6bbe15fa1..d8d4e3f48 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2750,21 +2750,25 @@ permanently deny permission. - To rematch a game using SMS - Crosswords needs permission to access your phone number. + + To rematch a game that uses SMS Crosswords needs permission to + access your phone number. + Rematching this SMS-only game is not possible without this permission. Without this permission - rematching will create a game that cannot not play via SMS. + rematching will continue but will create a game that cannot not play + via SMS. - Crosswords want access to your - contacts in order to put a name to phone numbers that send you - invitations via SMS. You\'ll still be able to receive invitations if - you don\'t grant this permission, but only the phone number of the - sender will be displayed. + + Crosswords want access to your contacts in order to put a name to + phone numbers that send you invitations via SMS. You\'ll still be + able to receive invitations if you don\'t grant this permission, + but only the phone number of the sender will be displayed. + Storing a wordlist in the Downloads area requires permission. diff --git a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml index ecf7a84b5..e31ac38e0 100644 --- a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml @@ -2347,19 +2347,22 @@ SMS e(.g. esuaceb uoy yap rof hcae ,)egassem ti\'s efas ot yltnenamrep yned noissimrep. - Ot hctamer a emag gnisu SMS - Sdrowssorc sdeen noissimrep ot ssecca ruoy enohp rebmun. + + Ot hctamer a emag taht sesu SMS Sdrowssorc sdeen noissimrep ot + ssecca ruoy enohp rebmun. + Gnihctamer siht YLNo-sms emag si ton elbissop tuohtiw siht noissimrep. Tuohtiw siht noissimrep gnihctamer lliw etaerc a emag taht tonnac ton yalp aiv SMS. - Sdrowssorc tnaw ssecca ot ruoy - stcatnoc ni redro ot tup a eman ot enohp srebmun taht dnes uoy - snoitativni aiv SMS. Uoy\'ll llits eb elba ot eviecer snoitativni fi - uoy nod\'t tnarg siht ,noissimrep tub ylno eht enohp rebmun fo eht - rednes lliw eb deyalpsid. + + Sdrowssorc tnaw ssecca ot ruoy stcatnoc ni redro ot tup a eman ot + enohp srebmun taht dnes uoy snoitativni aiv SMS. Uoy\'ll llits eb + elba ot eviecer snoitativni fi uoy nod\'t tnarg siht ,noissimrep + tub ylno eht enohp rebmun fo eht rednes lliw eb deyalpsid. + Gnirots a tsildrow ni eht Sdaolnwod aera seriuqer noissimrep. Evomer SMS diff --git a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml index f541b1616..bedcf455b 100644 --- a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml @@ -2347,19 +2347,22 @@ SMS (E.G. BECAUSE YOU PAY FOR EACH MESSAGE), IT\'S SAFE TO PERMANENTLY DENY PERMISSION. - TO REMATCH A GAME USING SMS - CROSSWORDS NEEDS PERMISSION TO ACCESS YOUR PHONE NUMBER. + + TO REMATCH A GAME THAT USES SMS CROSSWORDS NEEDS PERMISSION TO + ACCESS YOUR PHONE NUMBER. + REMATCHING THIS SMS-ONLY GAME IS NOT POSSIBLE WITHOUT THIS PERMISSION. WITHOUT THIS PERMISSION REMATCHING WILL CREATE A GAME THAT CANNOT NOT PLAY VIA SMS. - CROSSWORDS WANT ACCESS TO YOUR - CONTACTS IN ORDER TO PUT A NAME TO PHONE NUMBERS THAT SEND YOU - INVITATIONS VIA SMS. YOU\'LL STILL BE ABLE TO RECEIVE INVITATIONS IF - YOU DON\'T GRANT THIS PERMISSION, BUT ONLY THE PHONE NUMBER OF THE - SENDER WILL BE DISPLAYED. + + CROSSWORDS WANT ACCESS TO YOUR CONTACTS IN ORDER TO PUT A NAME TO + PHONE NUMBERS THAT SEND YOU INVITATIONS VIA SMS. YOU\'LL STILL BE + ABLE TO RECEIVE INVITATIONS IF YOU DON\'T GRANT THIS PERMISSION, + BUT ONLY THE PHONE NUMBER OF THE SENDER WILL BE DISPLAYED. + STORING A WORDLIST IN THE DOWNLOADS AREA REQUIRES PERMISSION. REMOVE SMS diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 2e382b471..75c5fd3a7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -71,7 +71,6 @@ public class DlgDelegate { NEW_GAME_DFLT_NAME, ENABLE_DUALPANE, ENABLE_DUALPANE_EXIT, - RETRY_REMATCH, // BoardDelegate UNDO_LAST_ACTION, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 84b8969d6..1bff61964 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -1326,21 +1326,30 @@ public class GamesListDelegate extends ListDelegateBase askDefaultName(); break; - case RETRY_REMATCH: - startRematchWithName( (String)params[0], false ); + case ASKED_PHONE_STATE: + rematchWithNameAndPerm( true, params ); break; default: - Assert.fail(); + super.onPosButton( action, params ); } } @Override public void onNegButton( Action action, Object[] params ) { - if ( Action.NEW_GAME_DFLT_NAME == action ) { + switch ( action ) { + case NEW_GAME_DFLT_NAME: m_newGameParams = params; makeThenLaunchOrConfigure(); + break; + + case ASKED_PHONE_STATE: + rematchWithNameAndPerm( false, params ); + break; + + default: + super.onNegButton( action, params ); } } @@ -2186,43 +2195,30 @@ public class GamesListDelegate extends ListDelegateBase if ( !hasSMS || null != SMSService.getPhoneInfo( m_activity ) ) { rematchWithNameAndPerm( gameName, addrs ); } else { - Perms23.Builder builder = - new Perms23.Builder( Perm.READ_PHONE_STATE ); - if ( showRationale ) { - builder.setOnShowRationale( new Perms23.OnShowRationale() { - public void onShouldShowRationale( Set perms ) - { - int id = (1 == addrs.size()) - ? R.string.phone_lookup_rationale_drop - : R.string.phone_lookup_rationale_others; - String msg = getString( R.string.phone_lookup_rationale ) - + "\n\n" + getString( id ); - makeConfirmThenBuilder( msg, Action.RETRY_REMATCH ) - .setTitle( R.string.perms_rationale_title ) - .setParams( gameName ) - .show(); - } - }); - } - builder.asyncQuery( m_activity, new Perms23.PermCbck() { - @Override - public void onPermissionResult( Map granted ) - { - if ( !granted.get( Perm.READ_PHONE_STATE ) ) { - addrs.remove( CommsConnType.COMMS_CONN_SMS ); - } - if ( 0 == addrs.size() ) { - DbgUtils.showf( m_activity, R.string.toast_no_permission ); - } else { - rematchWithNameAndPerm( gameName, addrs ); - } - } - } ); + int id = (1 == addrs.size()) + ? R.string.phone_lookup_rationale_drop + : R.string.phone_lookup_rationale_others; + String msg = getString( R.string.phone_lookup_rationale ) + + "\n\n" + getString( id ); + Perms23.tryGetPerms( this, Perm.READ_PHONE_STATE, msg, + Action.ASKED_PHONE_STATE, this, + gameName, addrs ); } } } + private void rematchWithNameAndPerm( boolean granted, Object[] params ) + { + CommsConnTypeSet addrs = (CommsConnTypeSet)params[1]; + if ( !granted ) { + addrs.remove( CommsConnType.COMMS_CONN_SMS ); + m_rematchExtras.remove( REMATCH_PHONE_EXTRA ); + } + if ( 0 < addrs.size() ) { + rematchWithNameAndPerm( (String)params[0], addrs ); + } + } + private void rematchWithNameAndPerm( String gameName, CommsConnTypeSet addrs ) { if ( null != gameName && 0 < gameName.length() ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Perms23.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Perms23.java index aa092a05f..41fbd375f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Perms23.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Perms23.java @@ -21,6 +21,7 @@ package org.eehouse.android.xw4; import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.content.pm.PackageManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; @@ -33,6 +34,7 @@ import java.util.Set; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify; +import org.eehouse.android.xw4.loc.LocUtils; import junit.framework.Assert; @@ -148,16 +150,16 @@ public class Perms23 { private Perm m_perm; private DelegateBase m_delegate; private DlgClickNotify m_cbck; - private int m_rationaleId; + private String m_rationaleMsg; private Object[] m_params; public QueryInfo( DelegateBase delegate, Action action, - Perm perm, int rationaleId, + Perm perm, String msg, DlgClickNotify cbck, Object[] params ) { m_delegate = delegate; m_action = action; m_perm = perm; - m_rationaleId = rationaleId; + m_rationaleMsg = msg; m_cbck = cbck; m_params = params; } @@ -165,10 +167,10 @@ public class Perms23 { private void doIt( boolean showRationale ) { Builder builder = new Builder( m_perm ); - if ( showRationale && 0 != m_rationaleId ) { + if ( showRationale && null != m_rationaleMsg ) { builder.setOnShowRationale( new OnShowRationale() { public void onShouldShowRationale( Set perms ) { - m_delegate.makeConfirmThenBuilder( m_rationaleId, + m_delegate.makeConfirmThenBuilder( m_rationaleMsg, Action.PERMS_QUERY ) .setTitle( R.string.perms_rationale_title ) .setPosButton( R.string.button_ask_again ) @@ -216,7 +218,17 @@ public class Perms23 { Object... params ) { // DbgUtils.logd( TAG, "tryGetPerms(%s)", perm.toString() ); - new QueryInfo( delegate, action, perm, rationaleId, cbck, params ) + Context context = XWApp.getContext(); + String msg = LocUtils.getString( context, rationaleId ); + tryGetPerms( delegate, perm, msg, action, cbck, params ); + } + + public static void tryGetPerms( DelegateBase delegate, Perm perm, + String rationaleMsg, final Action action, + final DlgClickNotify cbck, Object... params ) + { + // DbgUtils.logd( TAG, "tryGetPerms(%s)", perm.toString() ); + new QueryInfo( delegate, action, perm, rationaleMsg, cbck, params ) .doIt( true ); }