From 83340567b29d5e0cc98ed5d686c327249e7e6fda Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 6 Jan 2019 15:20:36 -0800 Subject: [PATCH] add and implement remove button for btinvite dialog --- .../eehouse/android/xw4/BTInviteDelegate.java | 18 +++++++++++++++ .../eehouse/android/xw4/InviteDelegate.java | 22 +++++++++++++++++++ .../app/src/main/res/layout/bt_buttons.xml | 5 +++++ .../app/src/main/res/values/strings.xml | 11 ++++++---- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java index 6538ec013..f735cfe0d 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java @@ -45,6 +45,7 @@ public class BTInviteDelegate extends InviteDelegate { private static final String KEY_PERSIST = TAG + "_persist"; private static final int[] BUTTONIDS = { R.id.button_scan, R.id.button_settings, + R.id.button_clear, }; private Activity m_activity; private ProgressDialog m_progress; @@ -74,6 +75,15 @@ public class BTInviteDelegate extends InviteDelegate { sort(); } + void remove(final Set checked) + { + for ( InviterItem item : checked ) { + TwoStringPair pair = (TwoStringPair)item; + stamps.remove( pair.str2 ); + pairs = TwoStringPair.remove( pairs, pair ); + } + } + boolean empty() { return pairs == null || pairs.length == 0; } private void sort() @@ -149,6 +159,14 @@ public class BTInviteDelegate extends InviteDelegate { case R.id.button_settings: BTService.openBTSettings( m_activity ); break; + case R.id.button_clear: + mPersisted.remove( getChecked() ); + store(); + + clearChecked(); + updateListAdapter( mPersisted.pairs ); + tryEnable(); + break; } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java index d5c9f5249..9e8de5b80 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java @@ -85,6 +85,26 @@ abstract class InviteDelegate extends ListDelegateBase return pairs; } + public static TwoStringPair[] remove( TwoStringPair[] pairs, InviterItem dead ) + { + int pos = -1; + for ( int ii = 0; ii < pairs.length; ++ii ) { + TwoStringPair pair = pairs[ii]; + if ( pair.equals(dead) ) { + pos = ii; + break; + } + } + + TwoStringPair[] newPairs = new TwoStringPair[pairs.length - 1]; + // lower range + System.arraycopy(pairs, 0, newPairs, 0, pos ); + // upper range + System.arraycopy(pairs, pos + 1, newPairs, pos, newPairs.length - pos ); + + return newPairs; + } + public String getDev() { return str1; } public boolean equals( InviterItem item ) @@ -167,6 +187,8 @@ abstract class InviteDelegate extends ListDelegateBase for ( int id : buttonBarItemIds ) { bar.findViewById( id ).setOnClickListener( listener ); } + + tryEnable(); } protected void updateListAdapter( InviterItem[] items ) diff --git a/xwords4/android/app/src/main/res/layout/bt_buttons.xml b/xwords4/android/app/src/main/res/layout/bt_buttons.xml index df6e78e69..30a230022 100644 --- a/xwords4/android/app/src/main/res/layout/bt_buttons.xml +++ b/xwords4/android/app/src/main/res/layout/bt_buttons.xml @@ -14,4 +14,9 @@ android:text="@string/bt_pair_settings" style="@style/evenly_spaced_horizontal" /> + +