From 608b4010a08eb657b5f142db0eaac4f7a32d2b28 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 16 Sep 2020 22:41:53 -0700 Subject: [PATCH] move user-vis strings (resIDs) into enum --- .../org/eehouse/android/xw4/DlgDelegate.java | 18 ++++++-- .../android/xw4/InviteChoicesAlert.java | 44 ++++++++----------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java index 294b77649..ecad78260 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java @@ -330,11 +330,21 @@ public class DlgDelegate { // These are stored in the INVITES table. Don't change order // gratuitously public static enum InviteMeans { - SMS_DATA, // classic NBS-based data sms - EMAIL, NFC, BLUETOOTH, CLIPBOARD, RELAY, WIFIDIRECT, - SMS_USER, // just launch the SMS app, as with email - MQTT, + SMS_DATA(R.string.invite_choice_data_sms), // classic NBS-based data sms + EMAIL(R.string.invite_choice_email), + NFC(R.string.invite_choice_nfc), + BLUETOOTH(R.string.invite_choice_bt), + CLIPBOARD(R.string.slmenu_copy_sel), + RELAY(R.string.invite_choice_relay), + WIFIDIRECT(R.string.invite_choice_p2p), + SMS_USER(R.string.invite_choice_user_sms), // just launch the SMS app, as with email + MQTT(R.string.invite_choice_mqtt); + + private InviteMeans( int resid) { mResID = resid; } + private int mResID; + public int getUserDescID() { return mResID; } }; + boolean onPosButton( Action action, Object... params ); boolean onNegButton( Action action, Object... params ); boolean onDismissed( Action action, Object... params ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java index 1e03d986c..0a27e78aa 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java @@ -1,6 +1,7 @@ /* -*- compile-command: "find-and-gradle.sh inXw4dDebug"; -*- */ /* - * Copyright 2017 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 2017 - 2020 by Eric House (xwords@eehouse.org). All rights + * reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -49,7 +50,6 @@ public class InviteChoicesAlert extends DlgDelegateAlert { AlertDialog.Builder builder ) { final ArrayList means = new ArrayList<>(); - ArrayList items = new ArrayList<>(); InviteMeans lastMeans = null; Object[] params = state.getParams(); if ( null != params @@ -57,36 +57,36 @@ public class InviteChoicesAlert extends DlgDelegateAlert { lastMeans = ((SentInvitesInfo)params[0]).getLastMeans(); } - add( items, means, R.string.invite_choice_email, InviteMeans.EMAIL ); - add( items, means, R.string.invite_choice_user_sms, InviteMeans.SMS_USER ); + means.add( InviteMeans.EMAIL ); + means.add( InviteMeans.SMS_USER ); if ( BTService.BTAvailable() ) { - add( items, means, R.string.invite_choice_bt, InviteMeans.BLUETOOTH ); + means.add( InviteMeans.BLUETOOTH ); } if ( Utils.deviceSupportsNBS(context) ) { - add( items, means, R.string.invite_choice_data_sms, InviteMeans.SMS_DATA ); + means.add( InviteMeans.SMS_DATA ); } if ( BuildConfig.NON_RELEASE ) { - add( items, means, R.string.invite_choice_relay, InviteMeans.RELAY ); + means.add( InviteMeans.RELAY ); } if ( BuildConfig.NON_RELEASE && BuildConfig.OFFER_MQTT ) { - add( items, means, R.string.invite_choice_mqtt, InviteMeans.MQTT ); + means.add( InviteMeans.MQTT ); } if ( WiDirWrapper.enabled() ) { - add( items, means, R.string.invite_choice_p2p, InviteMeans.WIFIDIRECT ); + means.add( InviteMeans.WIFIDIRECT ); } if ( NFCUtils.nfcAvail( context )[0] ) { - add( items, means, R.string.invite_choice_nfc, InviteMeans.NFC ); + means.add( InviteMeans.NFC ); } - add( items, means, R.string.slmenu_copy_sel, InviteMeans.CLIPBOARD ); + means.add( InviteMeans.CLIPBOARD ); + String[] items = new String[means.size()]; final int[] sel = { -1 }; - if ( null != lastMeans ) { - for ( int ii = 0; ii < means.size(); ++ii ) { - if ( lastMeans == means.get(ii) ) { - sel[0] = ii; - break; - } + for ( int ii = 0; ii < items.length; ++ii ) { + InviteMeans oneMeans = means.get(ii); + items[ii] = getString( oneMeans.getUserDescID() ); + if ( lastMeans == oneMeans ) { + sel[0] = ii; } } @@ -149,8 +149,7 @@ public class InviteChoicesAlert extends DlgDelegateAlert { }; builder.setTitle( R.string.invite_choice_title ) - .setSingleChoiceItems( items.toArray( new String[items.size()] ), - sel[0], selChanged ) + .setSingleChoiceItems( items, sel[0], selChanged ) .setPositiveButton( android.R.string.ok, okClicked ) .setNegativeButton( android.R.string.cancel, null ); if ( BuildConfig.DEBUG ) { @@ -168,11 +167,4 @@ public class InviteChoicesAlert extends DlgDelegateAlert { builder.setNeutralButton( R.string.ok_with_robots, ocl ); } } - - private void add( List items, List means, - int resID, InviteMeans oneMeans ) - { - items.add( getString( resID ) ); - means.add( oneMeans ); - } }