change DlgClickNotify methods to return boolean

So dispatching over possible targets can stop when one has handled it.
This commit is contained in:
Eric House 2017-02-09 06:23:41 -08:00
parent 796192380f
commit 939688e3cd
16 changed files with 122 additions and 51 deletions

View file

@ -168,14 +168,16 @@ public class BTInviteDelegate extends InviteDelegate {
// DlgDelegate.DlgClickNotify interface
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch( action ) {
case OPEN_BT_PREFS_ACTION:
BTService.openBTSettings( m_activity );
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
}

View file

@ -1007,8 +1007,9 @@ public class BoardDelegate extends DelegateBase
//////////////////////////////////////////////////
@Override
public void onPosButton( Action action, final Object[] params )
public boolean onPosButton( Action action, final Object[] params )
{
boolean handled = true;
JNICmd cmd = JNICmd.CMD_NONE;
switch ( action ) {
case ENABLE_RELAY_DO_OR:
@ -1100,17 +1101,20 @@ public class BoardDelegate extends DelegateBase
} );
// FALLTHRU: so super gets called, before
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
if ( JNICmd.CMD_NONE != cmd ) {
handleViaThread( cmd );
}
return handled;
}
@Override
public void onNegButton( Action action, Object[] params )
public boolean onNegButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case ENABLE_RELAY_DO_OR:
m_dropOnDismiss = true;
@ -1125,13 +1129,15 @@ public class BoardDelegate extends DelegateBase
showInviteChoicesThen( params );
break;
default:
super.onNegButton( action, params );
handled = super.onNegButton( action, params );
}
return handled;
}
@Override
public void onDismissed( Action action, Object[] params )
public boolean onDismissed( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case ENABLE_RELAY_DO_OR:
if ( m_dropOnDismiss ) {
@ -1145,7 +1151,10 @@ public class BoardDelegate extends DelegateBase
case DELETE_AND_EXIT:
finish();
break;
default:
handled = false;
}
return handled;
}
public void inviteChoiceMade( Action action, InviteMeans means,

View file

@ -226,8 +226,9 @@ public class ChatDelegate extends DelegateBase {
}
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case CLEAR_ACTION:
DBUtils.clearChatHistory( m_activity, m_rowid );
@ -236,8 +237,9 @@ public class ChatDelegate extends DelegateBase {
layout.removeAllViews();
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
public static boolean append( long rowid, String msg, int fromIndx )

View file

@ -641,8 +641,9 @@ public class DelegateBase implements DlgClickNotify,
//////////////////////////////////////////////////////////////////////
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////////////////////////
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
DbgUtils.logd( TAG, "%s.posButtonClicked(%s)", getClass().getSimpleName(),
action.toString() );
switch( action ) {
@ -664,12 +665,15 @@ public class DelegateBase implements DlgClickNotify,
default:
DbgUtils.logd( TAG, "unhandled action %s", action.toString() );
// Assert.assertTrue( !BuildConfig.DEBUG );
handled = false;
break;
}
return handled;
}
public void onNegButton( Action action, Object[] params )
public boolean onNegButton( Action action, Object[] params )
{
boolean handled = true;
// DbgUtils.logd( TAG, "%s.negButtonClicked(%s)", getClass().getSimpleName(),
// action.toString() );
switch ( action ) {
@ -678,14 +682,17 @@ public class DelegateBase implements DlgClickNotify,
break;
default:
DbgUtils.logd( TAG, "onNegButton: unhandled action %s", action.toString() );
handled = false;
break;
}
return handled;
}
public void onDismissed( Action action, Object[] params )
public boolean onDismissed( Action action, Object[] params )
{
DbgUtils.logd( TAG, "%s.dlgDismissed(%s)", getClass().getSimpleName(),
action.toString() );
return false;
}
public void inviteChoiceMade( Action action, DlgClickNotify.InviteMeans means, Object[] params )

View file

@ -300,10 +300,11 @@ public class DictBrowseDelegate extends DelegateBase
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
Assert.assertTrue( !BuildConfig.DEBUG || Action.FINISH_ACTION==action );
finish();
return true;
}
private void findButtonClicked()

View file

@ -923,8 +923,9 @@ public class DictsDelegate extends ListDelegateBase
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////////////////////////
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch( action ) {
case DELETE_DICT_ACTION:
String[] names = (String[])params[0];
@ -956,8 +957,9 @@ public class DictsDelegate extends ListDelegateBase
mkListAdapter();
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
private DictLoc itemToRealLoc( int item )

View file

@ -308,9 +308,9 @@ public class DlgDelegate {
public static enum InviteMeans {
SMS, EMAIL, NFC, BLUETOOTH, CLIPBOARD, RELAY, WIFIDIRECT,
};
void onPosButton( Action action, Object[] params );
void onNegButton( Action action, Object[] params );
void onDismissed( Action action, Object[] params );
boolean onPosButton( Action action, Object[] params );
boolean onNegButton( Action action, Object[] params );
boolean onDismissed( Action action, Object[] params );
void inviteChoiceMade( Action action, InviteMeans means, Object[] params );
}

View file

@ -98,12 +98,32 @@ public class DualpaneDelegate extends DelegateBase {
}
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = false;
MainActivity main = (MainActivity)m_activity;
XWFragment[] frags = main.getVisibleFragments();
for ( XWFragment frag : frags ) {
frag.getDelegate().onPosButton( action, params );
handled = frag.getDelegate().onPosButton( action, params );
if ( handled ) {
break;
}
}
return handled;
}
@Override
public boolean onNegButton( Action action, Object[] params )
{
boolean handled = false;
MainActivity main = (MainActivity)m_activity;
XWFragment[] frags = main.getVisibleFragments();
for ( XWFragment frag : frags ) {
handled = frag.getDelegate().onNegButton( action, params );
if ( handled ) {
break;
}
}
return handled;
}
}

View file

@ -346,27 +346,31 @@ public class DwnldDelegate extends ListDelegateBase {
}
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case STORAGE_CONFIRMED:
doWithPermissions( (Uri[])params[0] );
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
@Override
public void onNegButton( Action action, Object[] params )
public boolean onNegButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case STORAGE_CONFIRMED:
finish();
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
private void mkListAdapter()

View file

@ -680,8 +680,9 @@ public class GameConfigDelegate extends DelegateBase
}
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
Assert.assertTrue( curThis() == this );
switch( action ) {
case LOCKED_CHANGE_ACTION:
@ -707,13 +708,15 @@ public class GameConfigDelegate extends DelegateBase
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
@Override
public void onNegButton( Action action, Object[] params )
public boolean onNegButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case DELETE_AND_EXIT:
showConnAfterCheck();
@ -722,9 +725,10 @@ public class GameConfigDelegate extends DelegateBase
showDialog( DlgID.CHANGE_CONN );
break;
default:
super.onNegButton( action, params );
handled = super.onNegButton( action, params );
break;
}
return handled;
}
public void onClick( View view )

View file

@ -1269,8 +1269,9 @@ public class GamesListDelegate extends ListDelegateBase
// DlgDelegate.DlgClickNotify interface
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch( action ) {
case NEW_NET_GAME:
m_netLaunchInfo = (NetLaunchInfo)params[0];
@ -1377,13 +1378,15 @@ public class GamesListDelegate extends ListDelegateBase
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
@Override
public void onNegButton( Action action, Object[] params )
public boolean onNegButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case NEW_GAME_DFLT_NAME:
m_newGameParams = params;
@ -1395,20 +1398,23 @@ public class GamesListDelegate extends ListDelegateBase
break;
default:
super.onNegButton( action, params );
handled = super.onNegButton( action, params );
}
return handled;
}
@Override
public void onDismissed( Action action, Object[] params )
public boolean onDismissed( Action action, Object[] params )
{
boolean handled = true;
switch( action ) {
case ENABLE_DUALPANE_EXIT:
setDualpaneAndFinish( true );
break;
default:
super.onDismissed( action, params );
handled = super.onDismissed( action, params );
}
return handled;
}
@Override

View file

@ -242,8 +242,9 @@ public class PrefsDelegate extends DelegateBase
}
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case ENABLE_SMS_DO:
XWPrefs.setSMSEnabled( m_activity, true );
@ -254,8 +255,9 @@ public class PrefsDelegate extends DelegateBase
RelayCheckBoxPreference.setChecked();
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
private void relaunch()

View file

@ -278,8 +278,9 @@ public class RelayInviteDelegate extends InviteDelegate {
// DlgDelegate.DlgClickNotify interface
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch( action ) {
case CLEAR_ACTION:
clearSelectedImpl();
@ -288,20 +289,25 @@ public class RelayInviteDelegate extends InviteDelegate {
m_immobileConfirmed = true;
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
break;
}
return handled;
}
@Override
public void onDismissed( Action action, Object[] params )
public boolean onDismissed( Action action, Object[] params )
{
boolean handled = true;
if ( Action.USE_IMMOBILE_ACTION == action && m_immobileConfirmed ) {
makeConfirmThenBuilder( R.string.warn_unlimited,
Action.POST_WARNING_ACTION )
.setPosButton( R.string.button_yes )
.show();
} else {
handled = false;
}
return handled;
}
// private int countChecks()

View file

@ -187,8 +187,9 @@ public class SMSInviteDelegate extends InviteDelegate {
// DlgDelegate.DlgClickNotify interface
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case CLEAR_ACTION:
clearSelectedImpl();
@ -205,13 +206,15 @@ public class SMSInviteDelegate extends InviteDelegate {
saveAndRebuild();
break;
default:
super.onPosButton( action, params );
handled = super.onPosButton( action, params );
}
return handled;
}
@Override
public void onNegButton( Action action, final Object[] params )
public boolean onNegButton( Action action, final Object[] params )
{
boolean handled = true;
switch ( action ) {
case USE_IMMOBILE_ACTION:
if ( m_immobileConfirmed ) {
@ -230,8 +233,9 @@ public class SMSInviteDelegate extends InviteDelegate {
}
break;
default:
super.onNegButton( action, params );
handled = super.onNegButton( action, params );
}
return handled;
}
private void addPhoneNumbers( Intent intent )

View file

@ -196,8 +196,9 @@ public class StudyListDelegate extends ListDelegateBase
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
boolean handled = true;
switch ( action ) {
case SL_CLEAR_ACTION:
String[] selWords = getSelWords();
@ -219,9 +220,10 @@ public class StudyListDelegate extends ListDelegateBase
showToast( msg );
break;
default:
Assert.fail();
Assert.assertFalse( BuildConfig.DEBUG );
break;
}
return handled;
}
//////////////////////////////////////////////////

View file

@ -265,21 +265,21 @@ public class XWActivity extends FragmentActivity
// DlgClickNotify interface
////////////////////////////////////////////////////////////
@Override
public void onPosButton( Action action, Object[] params )
public boolean onPosButton( Action action, Object[] params )
{
m_dlgt.onPosButton( action, params );
return m_dlgt.onPosButton( action, params );
}
@Override
public void onNegButton( Action action, Object[] params )
public boolean onNegButton( Action action, Object[] params )
{
m_dlgt.onNegButton( action, params );
return m_dlgt.onNegButton( action, params );
}
@Override
public void onDismissed( Action action, Object[] params )
public boolean onDismissed( Action action, Object[] params )
{
m_dlgt.onDismissed( action, params );
return m_dlgt.onDismissed( action, params );
}
@Override