Rename SettingsHelper to DatabaseHelper

This commit is contained in:
Jakob Nixdorf 2017-07-06 08:54:38 +02:00
parent ae073a7591
commit c31b8e9c86
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
4 changed files with 16 additions and 16 deletions

View file

@ -128,10 +128,10 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
keyStore.deleteEntry("settings");
}
new File(context.getFilesDir() + "/" + SettingsHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + SettingsHelper.KEY_FILE).delete();
new File(context.getFilesDir() + "/" + DatabaseHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + DatabaseHelper.KEY_FILE).delete();
ArrayList<Entry> b = SettingsHelper.load(context);
ArrayList<Entry> b = DatabaseHelper.load(context);
assertEquals(0, b.size());
@ -146,13 +146,13 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
e.setSecret("secret2".getBytes());
a.add(e);
SettingsHelper.store(context, a);
b = SettingsHelper.load(context);
DatabaseHelper.store(context, a);
b = DatabaseHelper.load(context);
assertEquals(a, b);
new File(context.getFilesDir() + "/" + SettingsHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + SettingsHelper.KEY_FILE).delete();
new File(context.getFilesDir() + "/" + DatabaseHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + DatabaseHelper.KEY_FILE).delete();
}
public void testEncryptionHelper() throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, InvalidAlgorithmParameterException, DecoderException {

View file

@ -42,7 +42,7 @@ import javax.crypto.SecretKey;
import static org.shadowice.flocke.andotp.Utils.readFully;
import static org.shadowice.flocke.andotp.Utils.writeFully;
public class SettingsHelper {
public class DatabaseHelper {
public static final String KEY_FILE = "otp.key";
public static final String SETTINGS_FILE = "secrets.dat";

View file

@ -158,7 +158,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
entries.remove(removeIndex(position));
notifyItemRemoved(position);
SettingsHelper.store(context, entries);
DatabaseHelper.store(context, entries);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@ -175,7 +175,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
Collections.swap(entries, fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
SettingsHelper.store(context, entries);
DatabaseHelper.store(context, entries);
return true;
}
@ -202,7 +202,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
entries.get(displayedEntries.get(pos)).setLabel(input.getEditableText().toString());
notifyItemChanged(pos);
SettingsHelper.store(context, entries);
DatabaseHelper.store(context, entries);
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

View file

@ -117,7 +117,7 @@ public class MainActivity extends AppCompatActivity {
// Export to JSON
private void doExportJSON(Uri uri) {
if (StorageHelper.isExternalStorageWritable()) {
boolean success = SettingsHelper.exportAsJSON(this, uri);
boolean success = DatabaseHelper.exportAsJSON(this, uri);
if (success)
Toast.makeText(this, R.string.msg_export_success, Toast.LENGTH_LONG).show();
@ -167,10 +167,10 @@ public class MainActivity extends AppCompatActivity {
// Import from JSON
private void doImportJSON(Uri uri) {
if (StorageHelper.isExternalStorageReadable()) {
boolean success = SettingsHelper.importFromJSON(this, uri);
boolean success = DatabaseHelper.importFromJSON(this, uri);
if (success) {
adapter.setEntries(SettingsHelper.load(this));
adapter.setEntries(DatabaseHelper.load(this));
Toast.makeText(this, R.string.msg_import_success, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, R.string.msg_import_failed, Toast.LENGTH_LONG).show();
@ -245,7 +245,7 @@ public class MainActivity extends AppCompatActivity {
llm.setOrientation(LinearLayoutManager.VERTICAL);
recList.setLayoutManager(llm);
adapter = new EntriesCardAdapter(this, SettingsHelper.load(this));
adapter = new EntriesCardAdapter(this, DatabaseHelper.load(this));
recList.setAdapter(adapter);
touchHelperCallback = new SimpleItemTouchHelperCallback(adapter);
@ -327,7 +327,7 @@ public class MainActivity extends AppCompatActivity {
Entry e = new Entry(result.getContents());
e.setCurrentOTP(TOTPHelper.generate(e.getSecret(), e.getPeriod()));
adapter.addEntry(e);
SettingsHelper.store(this, adapter.getEntries());
DatabaseHelper.store(this, adapter.getEntries());
adapter.notifyDataSetChanged();
} catch (Exception e) {