mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
use tryGetPerms to replace a bunch of Perms23 crud
This one required allowing passing in a string rather than a res id.
This commit is contained in:
parent
6203012db6
commit
a453676456
6 changed files with 83 additions and 66 deletions
|
@ -2750,21 +2750,25 @@
|
|||
permanently deny permission.
|
||||
</string>
|
||||
|
||||
<string name="phone_lookup_rationale">To rematch a game using SMS
|
||||
Crosswords needs permission to access your phone number.</string>
|
||||
<string name="phone_lookup_rationale">
|
||||
To rematch a game that uses SMS Crosswords needs permission to
|
||||
access your phone number.
|
||||
</string>
|
||||
|
||||
<!-- Case where SMS is the only way the game can communicate -->
|
||||
<string name="phone_lookup_rationale_drop">Rematching this SMS-only
|
||||
game is not possible without this permission.</string>
|
||||
<!-- Case where SMS is NOT the only way the game can communicate -->
|
||||
<string name="phone_lookup_rationale_others">Without this permission
|
||||
rematching will create a game that cannot not play via SMS.</string>
|
||||
rematching will continue but will create a game that cannot not play
|
||||
via SMS.</string>
|
||||
|
||||
<string name="contacts_rationale">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.</string>
|
||||
<string name="contacts_rationale">
|
||||
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.
|
||||
</string>
|
||||
|
||||
<string name="move_dict_rationale">Storing a wordlist in the
|
||||
Downloads area requires permission.</string>
|
||||
|
|
|
@ -2347,19 +2347,22 @@
|
|||
SMS e(.g. esuaceb uoy yap rof hcae ,)egassem ti\'s efas ot
|
||||
yltnenamrep yned noissimrep.
|
||||
</string>
|
||||
<string name="phone_lookup_rationale">Ot hctamer a emag gnisu SMS
|
||||
Sdrowssorc sdeen noissimrep ot ssecca ruoy enohp rebmun.</string>
|
||||
<string name="phone_lookup_rationale">
|
||||
Ot hctamer a emag taht sesu SMS Sdrowssorc sdeen noissimrep ot
|
||||
ssecca ruoy enohp rebmun.
|
||||
</string>
|
||||
<!-- Case where SMS is the only way the game can communicate -->
|
||||
<string name="phone_lookup_rationale_drop">Gnihctamer siht YLNo-sms
|
||||
emag si ton elbissop tuohtiw siht noissimrep.</string>
|
||||
<!-- Case where SMS is NOT the only way the game can communicate -->
|
||||
<string name="phone_lookup_rationale_others">Tuohtiw siht noissimrep
|
||||
gnihctamer lliw etaerc a emag taht tonnac ton yalp aiv SMS.</string>
|
||||
<string name="contacts_rationale">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.</string>
|
||||
<string name="contacts_rationale">
|
||||
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.
|
||||
</string>
|
||||
<string name="move_dict_rationale">Gnirots a tsildrow ni eht
|
||||
Sdaolnwod aera seriuqer noissimrep.</string>
|
||||
<string name="remove_sms">Evomer SMS</string>
|
||||
|
|
|
@ -2347,19 +2347,22 @@
|
|||
SMS (E.G. BECAUSE YOU PAY FOR EACH MESSAGE), IT\'S SAFE TO
|
||||
PERMANENTLY DENY PERMISSION.
|
||||
</string>
|
||||
<string name="phone_lookup_rationale">TO REMATCH A GAME USING SMS
|
||||
CROSSWORDS NEEDS PERMISSION TO ACCESS YOUR PHONE NUMBER.</string>
|
||||
<string name="phone_lookup_rationale">
|
||||
TO REMATCH A GAME THAT USES SMS CROSSWORDS NEEDS PERMISSION TO
|
||||
ACCESS YOUR PHONE NUMBER.
|
||||
</string>
|
||||
<!-- Case where SMS is the only way the game can communicate -->
|
||||
<string name="phone_lookup_rationale_drop">REMATCHING THIS SMS-ONLY
|
||||
GAME IS NOT POSSIBLE WITHOUT THIS PERMISSION.</string>
|
||||
<!-- Case where SMS is NOT the only way the game can communicate -->
|
||||
<string name="phone_lookup_rationale_others">WITHOUT THIS PERMISSION
|
||||
REMATCHING WILL CREATE A GAME THAT CANNOT NOT PLAY VIA SMS.</string>
|
||||
<string name="contacts_rationale">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.</string>
|
||||
<string name="contacts_rationale">
|
||||
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.
|
||||
</string>
|
||||
<string name="move_dict_rationale">STORING A WORDLIST IN THE
|
||||
DOWNLOADS AREA REQUIRES PERMISSION.</string>
|
||||
<string name="remove_sms">REMOVE SMS</string>
|
||||
|
|
|
@ -71,7 +71,6 @@ public class DlgDelegate {
|
|||
NEW_GAME_DFLT_NAME,
|
||||
ENABLE_DUALPANE,
|
||||
ENABLE_DUALPANE_EXIT,
|
||||
RETRY_REMATCH,
|
||||
|
||||
// BoardDelegate
|
||||
UNDO_LAST_ACTION,
|
||||
|
|
|
@ -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<Perm> 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<Perm,
|
||||
Boolean> 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() ) {
|
||||
|
|
|
@ -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<Perm> 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 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue