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"); keyStore.deleteEntry("settings");
} }
new File(context.getFilesDir() + "/" + SettingsHelper.SETTINGS_FILE).delete(); new File(context.getFilesDir() + "/" + DatabaseHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + SettingsHelper.KEY_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()); assertEquals(0, b.size());
@ -146,13 +146,13 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
e.setSecret("secret2".getBytes()); e.setSecret("secret2".getBytes());
a.add(e); a.add(e);
SettingsHelper.store(context, a); DatabaseHelper.store(context, a);
b = SettingsHelper.load(context); b = DatabaseHelper.load(context);
assertEquals(a, b); assertEquals(a, b);
new File(context.getFilesDir() + "/" + SettingsHelper.SETTINGS_FILE).delete(); new File(context.getFilesDir() + "/" + DatabaseHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + SettingsHelper.KEY_FILE).delete(); new File(context.getFilesDir() + "/" + DatabaseHelper.KEY_FILE).delete();
} }
public void testEncryptionHelper() throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, InvalidAlgorithmParameterException, DecoderException { 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.readFully;
import static org.shadowice.flocke.andotp.Utils.writeFully; 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 KEY_FILE = "otp.key";
public static final String SETTINGS_FILE = "secrets.dat"; 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)); entries.remove(removeIndex(position));
notifyItemRemoved(position); notifyItemRemoved(position);
SettingsHelper.store(context, entries); DatabaseHelper.store(context, entries);
} }
}) })
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@ -175,7 +175,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
Collections.swap(entries, fromPosition, toPosition); Collections.swap(entries, fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition); notifyItemMoved(fromPosition, toPosition);
SettingsHelper.store(context, entries); DatabaseHelper.store(context, entries);
return true; return true;
} }
@ -202,7 +202,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
entries.get(displayedEntries.get(pos)).setLabel(input.getEditableText().toString()); entries.get(displayedEntries.get(pos)).setLabel(input.getEditableText().toString());
notifyItemChanged(pos); notifyItemChanged(pos);
SettingsHelper.store(context, entries); DatabaseHelper.store(context, entries);
} }
}) })
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

View file

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