From 260f234d617d55d8ad21a6a2458a72dc7c03f47a Mon Sep 17 00:00:00 2001 From: Bruno Bierbaumer Date: Mon, 21 Dec 2015 20:57:19 +0100 Subject: [PATCH] refactor out some hardcoded string (more to follow), increment version --- app/build.gradle | 4 +-- .../otp_authenticator/MainActivity.java | 26 +++++++++---------- app/src/main/res/values/strings.xml | 10 +++++++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f20fa65d..ef2f4829 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "net.bierbaumer.otp_authenticator" minSdkVersion 15 targetSdkVersion 23 - versionCode 2 - versionName "0.1.1" + versionCode 3 + versionName "0.1.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java b/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java index 5185dcdb..fb86b8cb 100644 --- a/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java +++ b/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java @@ -11,7 +11,6 @@ import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.view.ActionMode; import android.view.LayoutInflater; import android.view.Menu; @@ -32,7 +31,6 @@ import com.google.zxing.integration.android.IntentIntegrator; import java.util.ArrayList; public class MainActivity extends AppCompatActivity implements ActionMode.Callback { - private ArrayList entries; private EntriesAdapter adapter; private FloatingActionButton fab; @@ -43,7 +41,7 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb private Entry nextSelection = null; private void showNoAccount(){ Snackbar noAccountSnackbar = Snackbar.make(fab, R.string.no_accounts, Snackbar.LENGTH_INDEFINITE) - .setAction("Add", new View.OnClickListener() { + .setAction(R.string.button_add, new View.OnClickListener() { @Override public void onClick(View view) { scanQRCode(); @@ -113,7 +111,7 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb animation.setInterpolator(new LinearInterpolator()); animation.start(); - for(int i =0;i< adapter.getCount();i++){ + for(int i =0;i < adapter.getCount(); i++){ adapter.getItem(i).setCurrentOTP(TOTPHelper.generate(adapter.getItem(i).getSecret())); } adapter.notifyDataSetChanged(); @@ -150,9 +148,9 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb adapter.notifyDataSetChanged(); - Snackbar.make(fab, "Account added", Snackbar.LENGTH_LONG).show(); + Snackbar.make(fab, R.string.msg_account_added, Snackbar.LENGTH_LONG).show(); } catch (Exception e) { - Snackbar.make(fab, "Invalid QR Code", Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() { + Snackbar.make(fab, R.string.msg_invalid_qr_code, Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event) { super.onDismissed(snackbar, event); @@ -216,14 +214,14 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb if (id == R.id.action_delete) { AlertDialog.Builder alert = new AlertDialog.Builder(this); - alert.setTitle("Remove " + adapter.getCurrentSelection().getLabel() + "?"); - alert.setMessage("Are you sure you want do remove this account?"); + alert.setTitle(getString(R.string.alert_remove) + adapter.getCurrentSelection().getLabel() + "?"); + alert.setMessage(R.string.msg_confirm_delete); - alert.setPositiveButton("Remove", new DialogInterface.OnClickListener() { + alert.setPositiveButton(R.string.button_remove, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { entries.remove(adapter.getCurrentSelection()); - Snackbar.make(fab, "Account removed", Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() { + Snackbar.make(fab, R.string.msg_account_removed, Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event) { super.onDismissed(snackbar, event); @@ -238,7 +236,7 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb } }); - alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + alert.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); actionMode.finish(); @@ -251,20 +249,20 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb } else if (id == R.id.action_edit) { AlertDialog.Builder alert = new AlertDialog.Builder(this); - alert.setTitle("Rename"); + alert.setTitle(R.string.alert_rename); final EditText input = new EditText(this); input.setText(adapter.getCurrentSelection().getLabel()); alert.setView(input); - alert.setPositiveButton("Save", new DialogInterface.OnClickListener() { + alert.setPositiveButton(R.string.button_save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { adapter.getCurrentSelection().setLabel(input.getEditableText().toString()); actionMode.finish(); } }); - alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + alert.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); actionMode.finish(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac09b61e..f5c38b7e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,4 +6,14 @@ Edit Scan QR Code About + Invalid QR Code + Account added + Cancel + Save + Are you sure you want do remove this account? + Account removed + Add + Remove + Rename + "Remove "