From bcb47c949008c7c4a900c332fa05073d05b68e46 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Tue, 12 Aug 2014 07:24:13 +0930 Subject: [PATCH] Update the "next" button label correctly during swap workflow. Instead of always showing "swap", sometimes it shouldn't be shown at all (i.e. on the first and last screen) and on the NFC screen, it says "skip". There is a translated string called "skip_button_label" available in the AndroidPreferenceFragment library, but I don't want to rely on that. Prefer to have our awesome translators be in charge of that label. --- res/values/strings.xml | 1 + .../fdroid/views/swap/SwapActivity.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c36a16739..1cb4e6e47 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -192,6 +192,7 @@ To connect to other people\'s devices, make sure both devices are on the same WiFi network. Then either type the URL above into F-Droid, or scan this QR Code: QR Code Next + Skip QR Code of repo URL Scan this QR Code to connect to the same WiFi network as this device. Scan this QR Code to connect to the website for getting started. diff --git a/src/org/fdroid/fdroid/views/swap/SwapActivity.java b/src/org/fdroid/fdroid/views/swap/SwapActivity.java index dfff84fdd..430e9e84e 100644 --- a/src/org/fdroid/fdroid/views/swap/SwapActivity.java +++ b/src/org/fdroid/fdroid/views/swap/SwapActivity.java @@ -30,7 +30,7 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage private static final String STATE_NFC = "nfc"; private static final String STATE_WIFI_QR = "wifiQr"; - private MenuItem nextMenuItem; + private Menu menu; private String nextMenuItemLabel; private Timer shutdownLocalRepoTimer; private UpdateAsyncTask updateSwappableAppsTask = null; @@ -69,8 +69,9 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); + this.menu = menu; getMenuInflater().inflate(R.menu.swap_next, menu); - nextMenuItem = menu.getItem(0); + MenuItem nextMenuItem = menu.findItem(R.id.action_next); nextMenuItem.setVisible(false); MenuItemCompat.setShowAsAction(nextMenuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); return true; @@ -86,21 +87,30 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage supportInvalidateOptionsMenu(); } + private void showSkipButton() { + nextMenuItemLabel = getString(R.string.skip); + supportInvalidateOptionsMenu(); + } + @Override public boolean onPrepareOptionsMenu(Menu menu) { + MenuItem nextMenuItem = menu.findItem(R.id.action_next); if (nextMenuItemLabel == null) { + nextMenuItem.setTitle(""); + nextMenuItem.setTitleCondensed(""); nextMenuItem.setVisible(false); - return false; + return true; } else { nextMenuItem.setVisible(true); nextMenuItem.setTitle(nextMenuItemLabel); + nextMenuItem.setTitleCondensed(nextMenuItemLabel); return true; } } @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == nextMenuItem.getItemId()) { + if (item.getItemId() == R.id.action_next) { nextStep(); } return super.onOptionsItemSelected(item); @@ -161,7 +171,7 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage .replace(android.R.id.content, new NfcSwapFragment(), STATE_NFC) .addToBackStack(STATE_NFC) .commit(); - showNextButton(); + showSkipButton(); } else { onWifiQr(); } @@ -177,7 +187,7 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage .replace(android.R.id.content, new WifiQrFragment(), STATE_WIFI_QR) .addToBackStack(STATE_WIFI_QR) .commit(); - showNextButton(); + hideNextButton(); } private void prepareLocalRepo() {