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.
|
permanently deny permission.
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="phone_lookup_rationale">To rematch a game using SMS
|
<string name="phone_lookup_rationale">
|
||||||
Crosswords needs permission to access your phone number.</string>
|
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 -->
|
<!-- Case where SMS is the only way the game can communicate -->
|
||||||
<string name="phone_lookup_rationale_drop">Rematching this SMS-only
|
<string name="phone_lookup_rationale_drop">Rematching this SMS-only
|
||||||
game is not possible without this permission.</string>
|
game is not possible without this permission.</string>
|
||||||
<!-- Case where SMS is NOT the only way the game can communicate -->
|
<!-- Case where SMS is NOT the only way the game can communicate -->
|
||||||
<string name="phone_lookup_rationale_others">Without this permission
|
<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
|
<string name="contacts_rationale">
|
||||||
contacts in order to put a name to phone numbers that send you
|
Crosswords want access to your contacts in order to put a name to
|
||||||
invitations via SMS. You\'ll still be able to receive invitations if
|
phone numbers that send you invitations via SMS. You\'ll still be
|
||||||
you don\'t grant this permission, but only the phone number of the
|
able to receive invitations if you don\'t grant this permission,
|
||||||
sender will be displayed.</string>
|
but only the phone number of the sender will be displayed.
|
||||||
|
</string>
|
||||||
|
|
||||||
<string name="move_dict_rationale">Storing a wordlist in the
|
<string name="move_dict_rationale">Storing a wordlist in the
|
||||||
Downloads area requires permission.</string>
|
Downloads area requires permission.</string>
|
||||||
|
|
|
@ -2347,19 +2347,22 @@
|
||||||
SMS e(.g. esuaceb uoy yap rof hcae ,)egassem ti\'s efas ot
|
SMS e(.g. esuaceb uoy yap rof hcae ,)egassem ti\'s efas ot
|
||||||
yltnenamrep yned noissimrep.
|
yltnenamrep yned noissimrep.
|
||||||
</string>
|
</string>
|
||||||
<string name="phone_lookup_rationale">Ot hctamer a emag gnisu SMS
|
<string name="phone_lookup_rationale">
|
||||||
Sdrowssorc sdeen noissimrep ot ssecca ruoy enohp rebmun.</string>
|
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 -->
|
<!-- Case where SMS is the only way the game can communicate -->
|
||||||
<string name="phone_lookup_rationale_drop">Gnihctamer siht YLNo-sms
|
<string name="phone_lookup_rationale_drop">Gnihctamer siht YLNo-sms
|
||||||
emag si ton elbissop tuohtiw siht noissimrep.</string>
|
emag si ton elbissop tuohtiw siht noissimrep.</string>
|
||||||
<!-- Case where SMS is NOT the only way the game can communicate -->
|
<!-- Case where SMS is NOT the only way the game can communicate -->
|
||||||
<string name="phone_lookup_rationale_others">Tuohtiw siht noissimrep
|
<string name="phone_lookup_rationale_others">Tuohtiw siht noissimrep
|
||||||
gnihctamer lliw etaerc a emag taht tonnac ton yalp aiv SMS.</string>
|
gnihctamer lliw etaerc a emag taht tonnac ton yalp aiv SMS.</string>
|
||||||
<string name="contacts_rationale">Sdrowssorc tnaw ssecca ot ruoy
|
<string name="contacts_rationale">
|
||||||
stcatnoc ni redro ot tup a eman ot enohp srebmun taht dnes uoy
|
Sdrowssorc tnaw ssecca ot ruoy stcatnoc ni redro ot tup a eman ot
|
||||||
snoitativni aiv SMS. Uoy\'ll llits eb elba ot eviecer snoitativni fi
|
enohp srebmun taht dnes uoy snoitativni aiv SMS. Uoy\'ll llits eb
|
||||||
uoy nod\'t tnarg siht ,noissimrep tub ylno eht enohp rebmun fo eht
|
elba ot eviecer snoitativni fi uoy nod\'t tnarg siht ,noissimrep
|
||||||
rednes lliw eb deyalpsid.</string>
|
tub ylno eht enohp rebmun fo eht rednes lliw eb deyalpsid.
|
||||||
|
</string>
|
||||||
<string name="move_dict_rationale">Gnirots a tsildrow ni eht
|
<string name="move_dict_rationale">Gnirots a tsildrow ni eht
|
||||||
Sdaolnwod aera seriuqer noissimrep.</string>
|
Sdaolnwod aera seriuqer noissimrep.</string>
|
||||||
<string name="remove_sms">Evomer SMS</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
|
SMS (E.G. BECAUSE YOU PAY FOR EACH MESSAGE), IT\'S SAFE TO
|
||||||
PERMANENTLY DENY PERMISSION.
|
PERMANENTLY DENY PERMISSION.
|
||||||
</string>
|
</string>
|
||||||
<string name="phone_lookup_rationale">TO REMATCH A GAME USING SMS
|
<string name="phone_lookup_rationale">
|
||||||
CROSSWORDS NEEDS PERMISSION TO ACCESS YOUR PHONE NUMBER.</string>
|
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 -->
|
<!-- Case where SMS is the only way the game can communicate -->
|
||||||
<string name="phone_lookup_rationale_drop">REMATCHING THIS SMS-ONLY
|
<string name="phone_lookup_rationale_drop">REMATCHING THIS SMS-ONLY
|
||||||
GAME IS NOT POSSIBLE WITHOUT THIS PERMISSION.</string>
|
GAME IS NOT POSSIBLE WITHOUT THIS PERMISSION.</string>
|
||||||
<!-- Case where SMS is NOT the only way the game can communicate -->
|
<!-- Case where SMS is NOT the only way the game can communicate -->
|
||||||
<string name="phone_lookup_rationale_others">WITHOUT THIS PERMISSION
|
<string name="phone_lookup_rationale_others">WITHOUT THIS PERMISSION
|
||||||
REMATCHING WILL CREATE A GAME THAT CANNOT NOT PLAY VIA SMS.</string>
|
REMATCHING WILL CREATE A GAME THAT CANNOT NOT PLAY VIA SMS.</string>
|
||||||
<string name="contacts_rationale">CROSSWORDS WANT ACCESS TO YOUR
|
<string name="contacts_rationale">
|
||||||
CONTACTS IN ORDER TO PUT A NAME TO PHONE NUMBERS THAT SEND YOU
|
CROSSWORDS WANT ACCESS TO YOUR CONTACTS IN ORDER TO PUT A NAME TO
|
||||||
INVITATIONS VIA SMS. YOU\'LL STILL BE ABLE TO RECEIVE INVITATIONS IF
|
PHONE NUMBERS THAT SEND YOU INVITATIONS VIA SMS. YOU\'LL STILL BE
|
||||||
YOU DON\'T GRANT THIS PERMISSION, BUT ONLY THE PHONE NUMBER OF THE
|
ABLE TO RECEIVE INVITATIONS IF YOU DON\'T GRANT THIS PERMISSION,
|
||||||
SENDER WILL BE DISPLAYED.</string>
|
BUT ONLY THE PHONE NUMBER OF THE SENDER WILL BE DISPLAYED.
|
||||||
|
</string>
|
||||||
<string name="move_dict_rationale">STORING A WORDLIST IN THE
|
<string name="move_dict_rationale">STORING A WORDLIST IN THE
|
||||||
DOWNLOADS AREA REQUIRES PERMISSION.</string>
|
DOWNLOADS AREA REQUIRES PERMISSION.</string>
|
||||||
<string name="remove_sms">REMOVE SMS</string>
|
<string name="remove_sms">REMOVE SMS</string>
|
||||||
|
|
|
@ -71,7 +71,6 @@ public class DlgDelegate {
|
||||||
NEW_GAME_DFLT_NAME,
|
NEW_GAME_DFLT_NAME,
|
||||||
ENABLE_DUALPANE,
|
ENABLE_DUALPANE,
|
||||||
ENABLE_DUALPANE_EXIT,
|
ENABLE_DUALPANE_EXIT,
|
||||||
RETRY_REMATCH,
|
|
||||||
|
|
||||||
// BoardDelegate
|
// BoardDelegate
|
||||||
UNDO_LAST_ACTION,
|
UNDO_LAST_ACTION,
|
||||||
|
|
|
@ -1326,21 +1326,30 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
askDefaultName();
|
askDefaultName();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RETRY_REMATCH:
|
case ASKED_PHONE_STATE:
|
||||||
startRematchWithName( (String)params[0], false );
|
rematchWithNameAndPerm( true, params );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Assert.fail();
|
super.onPosButton( action, params );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNegButton( Action action, Object[] params )
|
public void onNegButton( Action action, Object[] params )
|
||||||
{
|
{
|
||||||
if ( Action.NEW_GAME_DFLT_NAME == action ) {
|
switch ( action ) {
|
||||||
|
case NEW_GAME_DFLT_NAME:
|
||||||
m_newGameParams = params;
|
m_newGameParams = params;
|
||||||
makeThenLaunchOrConfigure();
|
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 ) ) {
|
if ( !hasSMS || null != SMSService.getPhoneInfo( m_activity ) ) {
|
||||||
rematchWithNameAndPerm( gameName, addrs );
|
rematchWithNameAndPerm( gameName, addrs );
|
||||||
} else {
|
} else {
|
||||||
Perms23.Builder builder =
|
int id = (1 == addrs.size())
|
||||||
new Perms23.Builder( Perm.READ_PHONE_STATE );
|
? R.string.phone_lookup_rationale_drop
|
||||||
if ( showRationale ) {
|
: R.string.phone_lookup_rationale_others;
|
||||||
builder.setOnShowRationale( new Perms23.OnShowRationale() {
|
String msg = getString( R.string.phone_lookup_rationale )
|
||||||
public void onShouldShowRationale( Set<Perm> perms )
|
+ "\n\n" + getString( id );
|
||||||
{
|
Perms23.tryGetPerms( this, Perm.READ_PHONE_STATE, msg,
|
||||||
int id = (1 == addrs.size())
|
Action.ASKED_PHONE_STATE, this,
|
||||||
? R.string.phone_lookup_rationale_drop
|
gameName, addrs );
|
||||||
: 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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 )
|
private void rematchWithNameAndPerm( String gameName, CommsConnTypeSet addrs )
|
||||||
{
|
{
|
||||||
if ( null != gameName && 0 < gameName.length() ) {
|
if ( null != gameName && 0 < gameName.length() ) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eehouse.android.xw4;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
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.Action;
|
||||||
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify;
|
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify;
|
||||||
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
@ -148,16 +150,16 @@ public class Perms23 {
|
||||||
private Perm m_perm;
|
private Perm m_perm;
|
||||||
private DelegateBase m_delegate;
|
private DelegateBase m_delegate;
|
||||||
private DlgClickNotify m_cbck;
|
private DlgClickNotify m_cbck;
|
||||||
private int m_rationaleId;
|
private String m_rationaleMsg;
|
||||||
private Object[] m_params;
|
private Object[] m_params;
|
||||||
|
|
||||||
public QueryInfo( DelegateBase delegate, Action action,
|
public QueryInfo( DelegateBase delegate, Action action,
|
||||||
Perm perm, int rationaleId,
|
Perm perm, String msg,
|
||||||
DlgClickNotify cbck, Object[] params ) {
|
DlgClickNotify cbck, Object[] params ) {
|
||||||
m_delegate = delegate;
|
m_delegate = delegate;
|
||||||
m_action = action;
|
m_action = action;
|
||||||
m_perm = perm;
|
m_perm = perm;
|
||||||
m_rationaleId = rationaleId;
|
m_rationaleMsg = msg;
|
||||||
m_cbck = cbck;
|
m_cbck = cbck;
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
@ -165,10 +167,10 @@ public class Perms23 {
|
||||||
private void doIt( boolean showRationale )
|
private void doIt( boolean showRationale )
|
||||||
{
|
{
|
||||||
Builder builder = new Builder( m_perm );
|
Builder builder = new Builder( m_perm );
|
||||||
if ( showRationale && 0 != m_rationaleId ) {
|
if ( showRationale && null != m_rationaleMsg ) {
|
||||||
builder.setOnShowRationale( new OnShowRationale() {
|
builder.setOnShowRationale( new OnShowRationale() {
|
||||||
public void onShouldShowRationale( Set<Perm> perms ) {
|
public void onShouldShowRationale( Set<Perm> perms ) {
|
||||||
m_delegate.makeConfirmThenBuilder( m_rationaleId,
|
m_delegate.makeConfirmThenBuilder( m_rationaleMsg,
|
||||||
Action.PERMS_QUERY )
|
Action.PERMS_QUERY )
|
||||||
.setTitle( R.string.perms_rationale_title )
|
.setTitle( R.string.perms_rationale_title )
|
||||||
.setPosButton( R.string.button_ask_again )
|
.setPosButton( R.string.button_ask_again )
|
||||||
|
@ -216,7 +218,17 @@ public class Perms23 {
|
||||||
Object... params )
|
Object... params )
|
||||||
{
|
{
|
||||||
// DbgUtils.logd( TAG, "tryGetPerms(%s)", perm.toString() );
|
// 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 );
|
.doIt( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue