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.
This commit is contained in:
Peter Serwylo 2014-08-12 07:24:13 +09:30
parent 6d006e70b3
commit bcb47c9490
2 changed files with 17 additions and 6 deletions

View File

@ -192,6 +192,7 @@
<string name="same_wifi_instructions">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:</string>
<string name="qr_code">QR Code</string>
<string name="next">Next</string>
<string name="skip">Skip</string>
<string name="qr_content_description">QR Code of repo URL</string>
<string name="qr_wizard_wifi_network_instructions">Scan this QR Code to connect to the same WiFi network as this device.</string>
<string name="qr_wizard_download_instructions">Scan this QR Code to connect to the website for getting started.</string>

View File

@ -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() {