From a8872df5ed4fe3181cf1f6d7d238c8587370ddc5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 16 Jan 2019 20:32:44 -0800 Subject: [PATCH] cleanup: I like the call-chain style better these days --- .../eehouse/android/xw4/BoardDelegate.java | 86 ++++++++++--------- .../java/org/eehouse/android/xw4/Toolbar.java | 21 ++--- 2 files changed, 53 insertions(+), 54 deletions(-) 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 8d0b26788..ae4dc6135 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 @@ -2276,39 +2276,41 @@ public class BoardDelegate extends DelegateBase m_toolbar.setListener( Buttons.BUTTON_BROWSE_DICT, R.string.not_again_browseall, R.string.key_na_browseall, - Action.BUTTON_BROWSEALL_ACTION ); - m_toolbar.setLongClickListener( Buttons.BUTTON_BROWSE_DICT, - R.string.not_again_browse, - R.string.key_na_browse, - Action.BUTTON_BROWSE_ACTION ); - m_toolbar.setListener( Buttons.BUTTON_HINT_PREV, - R.string.not_again_hintprev, - R.string.key_notagain_hintprev, - Action.PREV_HINT_ACTION ); - m_toolbar.setListener( Buttons.BUTTON_HINT_NEXT, - R.string.not_again_hintnext, - R.string.key_notagain_hintnext, - Action.NEXT_HINT_ACTION ); - m_toolbar.setListener( Buttons.BUTTON_JUGGLE, - R.string.not_again_juggle, - R.string.key_notagain_juggle, - Action.JUGGLE_ACTION ); - m_toolbar.setListener( Buttons.BUTTON_FLIP, - R.string.not_again_flip, - R.string.key_notagain_flip, - Action.FLIP_ACTION ); - m_toolbar.setListener( Buttons.BUTTON_VALUES, - R.string.not_again_values, - R.string.key_na_values, - Action.VALUES_ACTION ); - m_toolbar.setListener( Buttons.BUTTON_UNDO, - R.string.not_again_undo, - R.string.key_notagain_undo, - Action.UNDO_ACTION ); - m_toolbar.setListener( Buttons.BUTTON_CHAT, - R.string.not_again_chat, - R.string.key_notagain_chat, - Action.CHAT_ACTION ); + Action.BUTTON_BROWSEALL_ACTION ) + .setLongClickListener( Buttons.BUTTON_BROWSE_DICT, + R.string.not_again_browse, + R.string.key_na_browse, + Action.BUTTON_BROWSE_ACTION ) + .setListener( Buttons.BUTTON_HINT_PREV, + R.string.not_again_hintprev, + R.string.key_notagain_hintprev, + Action.PREV_HINT_ACTION ) + .setListener( Buttons.BUTTON_HINT_NEXT, + R.string.not_again_hintnext, + R.string.key_notagain_hintnext, + Action.NEXT_HINT_ACTION ) + .setListener( Buttons.BUTTON_JUGGLE, + R.string.not_again_juggle, + R.string.key_notagain_juggle, + Action.JUGGLE_ACTION ) + .setListener( Buttons.BUTTON_FLIP, + R.string.not_again_flip, + R.string.key_notagain_flip, + Action.FLIP_ACTION ) + .setListener( Buttons.BUTTON_VALUES, + R.string.not_again_values, + R.string.key_na_values, + Action.VALUES_ACTION ) + .setListener( Buttons.BUTTON_UNDO, + R.string.not_again_undo, + R.string.key_notagain_undo, + Action.UNDO_ACTION ) + .setListener( Buttons.BUTTON_CHAT, + R.string.not_again_chat, + R.string.key_notagain_chat, + Action.CHAT_ACTION ); + } else { + Log.e( TAG, "not initing toolbar; still null" ); } } // populateToolbar @@ -2499,15 +2501,15 @@ public class BoardDelegate extends DelegateBase private void updateToolbar() { if ( null != m_toolbar ) { - m_toolbar.update( Buttons.BUTTON_FLIP, m_gsi.visTileCount >= 1 ); - m_toolbar.update( Buttons.BUTTON_VALUES, m_gsi.visTileCount >= 1 ); - m_toolbar.update( Buttons.BUTTON_JUGGLE, m_gsi.canShuffle ); - m_toolbar.update( Buttons.BUTTON_UNDO, m_gsi.canRedo ); - m_toolbar.update( Buttons.BUTTON_HINT_PREV, m_gsi.canHint ); - m_toolbar.update( Buttons.BUTTON_HINT_NEXT, m_gsi.canHint ); - m_toolbar.update( Buttons.BUTTON_CHAT, m_gsi.canChat ); - m_toolbar.update( Buttons.BUTTON_BROWSE_DICT, - null != m_gi.dictName( m_view.getCurPlayer() ) ); + m_toolbar.update( Buttons.BUTTON_FLIP, m_gsi.visTileCount >= 1 ) + .update( Buttons.BUTTON_VALUES, m_gsi.visTileCount >= 1 ) + .update( Buttons.BUTTON_JUGGLE, m_gsi.canShuffle ) + .update( Buttons.BUTTON_UNDO, m_gsi.canRedo ) + .update( Buttons.BUTTON_HINT_PREV, m_gsi.canHint ) + .update( Buttons.BUTTON_HINT_NEXT, m_gsi.canHint ) + .update( Buttons.BUTTON_CHAT, m_gsi.canChat ) + .update( Buttons.BUTTON_BROWSE_DICT, + null != m_gi.dictName( m_view.getCurPlayer() ) ); int count = m_toolbar.enabledCount(); if ( 0 == count ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java index 0ecefa929..dc86f8aa8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java @@ -62,8 +62,8 @@ public class Toolbar implements BoardContainer.SizeChangeListener { private DlgDelegate.HasDlgDelegate m_dlgDlgt; private LinearLayout m_layout; private boolean m_visible; - private Map m_onClickListeners; - private Map m_onLongClickListeners; + private Map m_onClickListeners = new HashMap<>(); + private Map m_onLongClickListeners = new HashMap<>(); private Set m_enabled = new HashSet(); public Toolbar( Activity activity, HasDlgDelegate dlgDlgt ) @@ -87,12 +87,9 @@ public class Toolbar implements BoardContainer.SizeChangeListener { return (ImageButton)m_activity.findViewById( index.getResId() ); } - public void setListener( Buttons index, final int msgID, - final int prefsKey, final Action action ) + public Toolbar setListener( Buttons index, final int msgID, + final int prefsKey, final Action action ) { - if ( null == m_onClickListeners ) { - m_onClickListeners = new HashMap(); - } m_onClickListeners.put( index, new View.OnClickListener() { @Override public void onClick( View view ) { @@ -102,14 +99,12 @@ public class Toolbar implements BoardContainer.SizeChangeListener { .show(); } } ); + return this; } - public void setLongClickListener( Buttons index, final int msgID, + public Toolbar setLongClickListener( Buttons index, final int msgID, final int prefsKey, final Action action ) { - if ( null == m_onLongClickListeners ) { - m_onLongClickListeners = new HashMap(); - } m_onLongClickListeners.put( index, new View.OnLongClickListener() { public boolean onLongClick( View view ) { m_dlgDlgt.makeNotAgainBuilder( msgID, prefsKey, action ) @@ -117,9 +112,10 @@ public class Toolbar implements BoardContainer.SizeChangeListener { return true; } } ); + return this; } - public void update( Buttons index, boolean enable ) + public Toolbar update( Buttons index, boolean enable ) { int id = index.getResId(); ImageButton button = (ImageButton)m_activity.findViewById( id ); @@ -132,6 +128,7 @@ public class Toolbar implements BoardContainer.SizeChangeListener { } else { m_enabled.remove( index ); } + return this; } protected int enabledCount() { return m_enabled.size(); }