2016-08-15 21:29:41 +02:00
|
|
|
package me.impy.aegis;
|
|
|
|
|
2016-08-21 22:32:07 +02:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2016-08-21 22:24:04 +02:00
|
|
|
import android.content.Context;
|
2016-08-15 22:31:28 +02:00
|
|
|
import android.content.Intent;
|
2016-09-29 12:31:55 +02:00
|
|
|
import android.content.SharedPreferences;
|
2016-11-03 22:03:34 +01:00
|
|
|
import android.content.pm.ShortcutInfo;
|
|
|
|
import android.content.pm.ShortcutManager;
|
|
|
|
import android.graphics.drawable.Icon;
|
|
|
|
import android.os.Build;
|
2016-09-30 01:08:03 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2016-11-01 22:16:54 +01:00
|
|
|
import android.support.design.widget.BottomSheetDialog;
|
2016-08-16 14:14:17 +02:00
|
|
|
import android.support.design.widget.FloatingActionButton;
|
2016-11-01 22:57:21 +01:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2016-08-15 21:29:41 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.os.Bundle;
|
2016-08-16 20:04:38 +02:00
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2016-08-16 14:14:17 +02:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2016-08-21 22:54:27 +02:00
|
|
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
2016-11-13 18:00:13 +01:00
|
|
|
import android.util.Log;
|
2016-08-16 14:14:17 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2016-11-01 22:16:54 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.LinearLayout;
|
2016-08-17 01:14:25 +02:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2017-05-03 21:08:38 +02:00
|
|
|
import java.lang.reflect.UndeclaredThrowableException;
|
2016-08-16 20:04:38 +02:00
|
|
|
import java.util.ArrayList;
|
2016-11-03 22:03:34 +01:00
|
|
|
import java.util.Arrays;
|
2016-10-25 23:53:33 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2016-11-13 18:00:13 +01:00
|
|
|
import java.util.Objects;
|
2016-08-16 20:04:38 +02:00
|
|
|
|
2017-05-03 21:08:38 +02:00
|
|
|
import me.impy.aegis.crypto.MasterKey;
|
2017-05-03 21:18:42 +02:00
|
|
|
import me.impy.aegis.crypto.otp.OTP;
|
2017-08-06 16:03:36 +02:00
|
|
|
import me.impy.aegis.db.DatabaseManager;
|
2016-10-04 22:23:34 +02:00
|
|
|
import me.impy.aegis.helpers.SimpleItemTouchHelperCallback;
|
2016-08-15 21:29:41 +02:00
|
|
|
|
2016-11-13 18:21:00 +01:00
|
|
|
public class MainActivity extends AppCompatActivity {
|
2017-08-06 16:03:36 +02:00
|
|
|
private static final int CODE_GET_KEYINFO = 0;
|
|
|
|
private static final int CODE_ADD_KEYINFO = 1;
|
|
|
|
private static final int CODE_DO_INTRO = 2;
|
2017-08-06 18:15:47 +02:00
|
|
|
private static final int CODE_DECRYPT = 3;
|
2016-08-24 23:48:25 +02:00
|
|
|
|
2016-08-16 20:04:38 +02:00
|
|
|
RecyclerView rvKeyProfiles;
|
|
|
|
KeyProfileAdapter mKeyProfileAdapter;
|
2016-11-13 18:21:00 +01:00
|
|
|
ArrayList<KeyProfile> mKeyProfiles = new ArrayList<>();
|
2017-08-06 16:03:36 +02:00
|
|
|
private DatabaseManager db;
|
2016-09-30 01:08:03 +02:00
|
|
|
|
|
|
|
boolean nightMode = false;
|
2016-11-01 22:16:54 +01:00
|
|
|
int clickedItemPosition = -1;
|
2016-08-16 14:14:17 +02:00
|
|
|
|
2016-08-15 21:29:41 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-08-06 16:03:36 +02:00
|
|
|
db = new DatabaseManager(getApplicationContext());
|
2016-09-29 12:31:55 +02:00
|
|
|
|
|
|
|
SharedPreferences prefs = this.getSharedPreferences("me.impy.aegis", Context.MODE_PRIVATE);
|
2016-11-13 18:21:00 +01:00
|
|
|
if (!prefs.getBoolean("passedIntro", false)) {
|
2016-09-29 12:31:55 +02:00
|
|
|
Intent intro = new Intent(this, IntroActivity.class);
|
2017-08-06 16:03:36 +02:00
|
|
|
startActivityForResult(intro, CODE_DO_INTRO);
|
2017-08-06 18:15:47 +02:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
db.load();
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO: feedback
|
|
|
|
throw new UndeclaredThrowableException(e);
|
|
|
|
}
|
|
|
|
if (!db.isDecrypted()) {
|
|
|
|
Intent intent = new Intent(this, AuthActivity.class);
|
|
|
|
intent.putExtra("slots", db.getFile().getSlots());
|
|
|
|
startActivityForResult(intent, CODE_DECRYPT);
|
2017-08-06 21:45:27 +02:00
|
|
|
} else {
|
|
|
|
loadKeyProfiles();
|
2017-08-06 18:15:47 +02:00
|
|
|
}
|
2016-09-29 12:31:55 +02:00
|
|
|
}
|
|
|
|
|
2016-09-30 01:08:03 +02:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2016-11-13 18:21:00 +01:00
|
|
|
if (sharedPreferences.getBoolean("pref_night_mode", false)) {
|
2016-09-30 01:08:03 +02:00
|
|
|
nightMode = true;
|
|
|
|
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
2016-11-13 18:21:00 +01:00
|
|
|
} else {
|
2016-09-30 01:08:03 +02:00
|
|
|
setPreferredTheme();
|
|
|
|
}
|
|
|
|
|
2016-08-15 21:29:41 +02:00
|
|
|
setContentView(R.layout.activity_main);
|
2016-08-16 14:14:17 +02:00
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2016-11-03 22:03:34 +01:00
|
|
|
initializeAppShortcuts();
|
2016-08-16 14:14:17 +02:00
|
|
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
2017-05-03 21:08:38 +02:00
|
|
|
fab.setEnabled(true);
|
2016-10-26 00:07:39 +02:00
|
|
|
fab.setOnClickListener(view -> {
|
|
|
|
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
|
2017-08-06 16:03:36 +02:00
|
|
|
startActivityForResult(scannerActivity, CODE_GET_KEYINFO);
|
2016-08-15 22:31:28 +02:00
|
|
|
});
|
2016-08-16 14:14:17 +02:00
|
|
|
|
2016-08-16 20:04:38 +02:00
|
|
|
rvKeyProfiles = (RecyclerView) findViewById(R.id.rvKeyProfiles);
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
|
|
|
|
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
|
|
|
|
2016-08-21 23:13:27 +02:00
|
|
|
mKeyProfileAdapter = new KeyProfileAdapter(mKeyProfiles);
|
2016-10-26 00:29:21 +02:00
|
|
|
mKeyProfileAdapter.setOnItemClickListener((position, v) -> {
|
2016-11-01 22:16:54 +01:00
|
|
|
clickedItemPosition = position;
|
|
|
|
InitializeBottomSheet().show();
|
|
|
|
});
|
2016-10-28 13:18:11 +02:00
|
|
|
mKeyProfileAdapter.setOnLongItemClickListener((position, v) -> {
|
2016-11-01 22:16:54 +01:00
|
|
|
|
2016-10-28 13:18:11 +02:00
|
|
|
});
|
|
|
|
|
2016-10-04 22:23:34 +02:00
|
|
|
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mKeyProfileAdapter);
|
|
|
|
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
|
|
|
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
2016-08-21 22:54:27 +02:00
|
|
|
|
2016-08-16 20:04:38 +02:00
|
|
|
rvKeyProfiles.setAdapter(mKeyProfileAdapter);
|
2016-10-25 23:53:33 +02:00
|
|
|
Comparator<KeyProfile> comparator = new Comparator<KeyProfile>() {
|
|
|
|
@Override
|
|
|
|
public int compare(KeyProfile keyProfile, KeyProfile t1) {
|
|
|
|
return keyProfile.Order - t1.Order;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Collections.sort(mKeyProfiles, comparator);
|
2016-08-15 21:29:41 +02:00
|
|
|
}
|
2016-08-16 00:08:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
2017-08-06 16:03:36 +02:00
|
|
|
switch (requestCode) {
|
|
|
|
case CODE_GET_KEYINFO:
|
|
|
|
onGetKeyInfoResult(resultCode, data);
|
|
|
|
break;
|
|
|
|
case CODE_ADD_KEYINFO:
|
|
|
|
onAddKeyInfoResult(resultCode, data);
|
|
|
|
break;
|
|
|
|
case CODE_DO_INTRO:
|
|
|
|
onDoIntroResult(resultCode, data);
|
|
|
|
break;
|
2017-08-06 18:15:47 +02:00
|
|
|
case CODE_DECRYPT:
|
|
|
|
onDecryptResult(resultCode, data);
|
|
|
|
break;
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-16 00:08:01 +02:00
|
|
|
|
2017-08-06 16:03:36 +02:00
|
|
|
private void onGetKeyInfoResult(int resultCode, Intent data) {
|
|
|
|
if (resultCode != RESULT_OK) {
|
|
|
|
return;
|
2016-08-16 00:08:01 +02:00
|
|
|
}
|
2016-08-24 23:48:25 +02:00
|
|
|
|
2017-08-06 16:03:36 +02:00
|
|
|
final KeyProfile keyProfile = (KeyProfile)data.getSerializableExtra("KeyProfile");
|
2016-08-24 23:48:25 +02:00
|
|
|
|
2017-08-06 16:03:36 +02:00
|
|
|
Intent intent = new Intent(this, AddProfileActivity.class);
|
|
|
|
intent.putExtra("KeyProfile", keyProfile);
|
|
|
|
startActivityForResult(intent, CODE_ADD_KEYINFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onAddKeyInfoResult(int resultCode, Intent data) {
|
|
|
|
if (resultCode != RESULT_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final KeyProfile keyProfile = (KeyProfile) data.getSerializableExtra("KeyProfile");
|
|
|
|
|
|
|
|
String otp;
|
|
|
|
try {
|
|
|
|
otp = OTP.generateOTP(keyProfile.Info);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyProfile.Order = mKeyProfiles.size() + 1;
|
|
|
|
keyProfile.Code = otp;
|
|
|
|
try {
|
|
|
|
db.addKey(keyProfile);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// TODO: feedback
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mKeyProfiles.add(keyProfile);
|
|
|
|
mKeyProfileAdapter.notifyDataSetChanged();
|
|
|
|
saveDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onDoIntroResult(int resultCode, Intent data) {
|
|
|
|
if (resultCode == IntroActivity.RESULT_EXCEPTION) {
|
|
|
|
// TODO: user feedback
|
|
|
|
Exception e = (Exception) data.getSerializableExtra("exception");
|
|
|
|
throw new UndeclaredThrowableException(e);
|
|
|
|
}
|
2016-11-13 18:21:00 +01:00
|
|
|
|
2017-08-06 16:03:36 +02:00
|
|
|
MasterKey key = (MasterKey) data.getSerializableExtra("key");
|
|
|
|
try {
|
|
|
|
db.load();
|
|
|
|
if (!db.isDecrypted()) {
|
|
|
|
db.setMasterKey(key);
|
2016-08-24 23:48:25 +02:00
|
|
|
}
|
2017-08-06 16:03:36 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO: feedback
|
|
|
|
throw new UndeclaredThrowableException(e);
|
2016-08-24 23:48:25 +02:00
|
|
|
}
|
2017-08-06 18:15:47 +02:00
|
|
|
|
|
|
|
loadKeyProfiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onDecryptResult(int resultCode, Intent data) {
|
|
|
|
MasterKey key = (MasterKey) data.getSerializableExtra("key");
|
|
|
|
try {
|
|
|
|
db.setMasterKey(key);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO: feedback
|
|
|
|
throw new UndeclaredThrowableException(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
loadKeyProfiles();
|
2016-08-16 00:08:01 +02:00
|
|
|
}
|
2016-08-16 14:14:17 +02:00
|
|
|
|
2016-09-30 01:08:03 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2016-11-01 23:43:46 +01:00
|
|
|
mKeyProfileAdapter.notifyDataSetChanged();
|
2016-09-30 01:08:03 +02:00
|
|
|
setPreferredTheme();
|
|
|
|
}
|
|
|
|
|
2016-10-25 23:53:33 +02:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
2017-05-03 21:08:38 +02:00
|
|
|
// update order of keys
|
|
|
|
for (int i = 0; i < mKeyProfiles.size(); i++) {
|
|
|
|
try {
|
2017-08-06 16:03:36 +02:00
|
|
|
db.updateKey(mKeyProfiles.get(i));
|
2017-05-03 21:08:38 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2016-10-25 23:53:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-03 21:08:38 +02:00
|
|
|
saveDatabase();
|
2016-10-25 23:53:33 +02:00
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
2016-11-01 22:16:54 +01:00
|
|
|
private BottomSheetDialog InitializeBottomSheet()
|
|
|
|
{
|
|
|
|
View bottomSheetView = getLayoutInflater ().inflate (R.layout.bottom_sheet_edit_profile, null);
|
|
|
|
LinearLayout copyLayout = (LinearLayout)bottomSheetView.findViewById(R.id.copy_button);
|
|
|
|
LinearLayout deleteLayout = (LinearLayout)bottomSheetView.findViewById(R.id.delete_button);
|
|
|
|
LinearLayout editLayout = (LinearLayout)bottomSheetView.findViewById(R.id.edit_button);
|
|
|
|
bottomSheetView.findViewById(R.id.edit_button);
|
|
|
|
BottomSheetDialog bottomDialog = new BottomSheetDialog(this);
|
|
|
|
bottomDialog.setContentView(bottomSheetView);
|
|
|
|
bottomDialog.setCancelable (true);
|
|
|
|
bottomDialog.getWindow ().setLayout (LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
bottomDialog.show();
|
|
|
|
|
|
|
|
copyLayout.setOnClickListener(view -> {
|
|
|
|
bottomDialog.dismiss();
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
ClipData clip = ClipData.newPlainText("text/plain", mKeyProfiles.get(clickedItemPosition).Code);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
|
|
|
|
Toast.makeText(this.getApplicationContext(), "Code successfully copied to the clipboard", Toast.LENGTH_SHORT).show();
|
|
|
|
});
|
2016-11-01 22:57:21 +01:00
|
|
|
|
|
|
|
deleteLayout.setOnClickListener(view -> {
|
|
|
|
bottomDialog.dismiss();
|
|
|
|
|
|
|
|
KeyProfile keyProfile = mKeyProfiles.get(clickedItemPosition);
|
|
|
|
deleteProfile(keyProfile);
|
|
|
|
});
|
|
|
|
|
|
|
|
editLayout.setOnClickListener(view -> {
|
|
|
|
bottomDialog.dismiss();
|
|
|
|
Toast.makeText(this.getApplicationContext(), "Coming soon", Toast.LENGTH_SHORT).show();
|
|
|
|
});
|
|
|
|
|
2016-11-01 22:16:54 +01:00
|
|
|
return bottomDialog;
|
2016-11-01 22:57:21 +01:00
|
|
|
}
|
2016-11-01 22:16:54 +01:00
|
|
|
|
2016-11-01 22:57:21 +01:00
|
|
|
private void deleteProfile(KeyProfile profile)
|
|
|
|
{
|
|
|
|
new AlertDialog.Builder(MainActivity.this)
|
2017-05-03 21:08:38 +02:00
|
|
|
.setTitle("Delete entry")
|
|
|
|
.setMessage("Are you sure you want to delete this profile?")
|
|
|
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
|
|
|
try {
|
2017-08-06 16:03:36 +02:00
|
|
|
db.removeKey(profile);
|
2017-05-03 21:08:38 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
//TODO: feedback
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mKeyProfiles.remove(clickedItemPosition);
|
|
|
|
mKeyProfileAdapter.notifyItemRemoved(clickedItemPosition);
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
|
|
|
})
|
|
|
|
.show();
|
2016-11-01 22:16:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-16 14:14:17 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2017-08-14 00:04:06 +02:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_settings:
|
|
|
|
Intent preferencesActivity = new Intent(this, PreferencesActivity.class);
|
|
|
|
startActivity(preferencesActivity);
|
|
|
|
return true;
|
|
|
|
case R.id.action_lock:
|
|
|
|
// TODO: properly close the database
|
|
|
|
recreate();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
2016-08-16 14:14:17 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-30 01:08:03 +02:00
|
|
|
|
2016-11-03 22:03:34 +01:00
|
|
|
private void initializeAppShortcuts()
|
|
|
|
{
|
2016-11-13 18:00:13 +01:00
|
|
|
String mode = getIntent().getStringExtra("Action");
|
|
|
|
if(mode != null)
|
|
|
|
{
|
|
|
|
Log.println(Log.DEBUG, "MODE: ", mode);
|
|
|
|
if(Objects.equals(mode, "Scan"))
|
|
|
|
{
|
|
|
|
Log.println(Log.DEBUG, "OKK ", "OKKK");
|
|
|
|
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
|
2017-08-06 18:15:47 +02:00
|
|
|
startActivityForResult(scannerActivity, CODE_GET_KEYINFO);
|
2016-11-13 18:00:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-03 22:03:34 +01:00
|
|
|
ShortcutManager shortcutManager = null;
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
|
|
|
shortcutManager = getSystemService(ShortcutManager.class);
|
|
|
|
if(shortcutManager != null) {
|
2016-11-13 18:00:13 +01:00
|
|
|
//TODO: Remove this line
|
|
|
|
shortcutManager.removeAllDynamicShortcuts();
|
2016-11-03 22:03:34 +01:00
|
|
|
if (shortcutManager.getDynamicShortcuts().size() == 0) {
|
|
|
|
// Application restored. Need to re-publish dynamic shortcuts.
|
|
|
|
|
2016-11-13 18:00:13 +01:00
|
|
|
Intent intent1 = new Intent(this.getBaseContext(), MainActivity.class);
|
|
|
|
intent1.putExtra("Action", "Scan");
|
|
|
|
intent1.setAction(Intent.ACTION_MAIN);
|
2016-11-03 22:03:34 +01:00
|
|
|
|
|
|
|
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")
|
2016-11-13 18:00:13 +01:00
|
|
|
.setShortLabel("New profile")
|
2016-11-03 22:03:34 +01:00
|
|
|
.setLongLabel("Add new profile")
|
|
|
|
.setIcon(Icon.createWithResource(this.getApplicationContext(), R.drawable.intro_scanner))
|
2016-11-13 18:00:13 +01:00
|
|
|
.setIntent(intent1)
|
2016-11-03 22:03:34 +01:00
|
|
|
.build();
|
|
|
|
|
|
|
|
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 01:08:03 +02:00
|
|
|
private void setPreferredTheme()
|
|
|
|
{
|
2016-10-26 00:07:39 +02:00
|
|
|
boolean restart = false;
|
2016-09-30 01:08:03 +02:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2016-10-26 00:07:39 +02:00
|
|
|
if(sharedPreferences.getBoolean("pref_night_mode", false)) {
|
|
|
|
if(!nightMode) {
|
2016-09-30 01:08:03 +02:00
|
|
|
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
2016-10-26 00:07:39 +02:00
|
|
|
restart = true;
|
2016-09-30 01:08:03 +02:00
|
|
|
}
|
2016-10-26 00:07:39 +02:00
|
|
|
} else {
|
|
|
|
if(nightMode) {
|
2016-09-30 01:08:03 +02:00
|
|
|
setTheme(R.style.AppTheme_Default_NoActionBar);
|
2016-10-26 00:07:39 +02:00
|
|
|
restart = true;
|
2016-09-30 01:08:03 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-26 00:07:39 +02:00
|
|
|
|
|
|
|
if(restart){
|
|
|
|
finish();
|
|
|
|
startActivity(new Intent(this, this.getClass()));
|
|
|
|
}
|
2016-09-30 01:08:03 +02:00
|
|
|
}
|
2016-11-13 18:21:00 +01:00
|
|
|
|
2017-08-06 18:15:47 +02:00
|
|
|
private void saveDatabase() {
|
|
|
|
if (!db.isDecrypted()) {
|
2017-05-03 21:08:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2017-08-06 18:15:47 +02:00
|
|
|
db.save();
|
2017-05-03 21:08:38 +02:00
|
|
|
} catch (Exception e) {
|
2017-08-06 18:15:47 +02:00
|
|
|
//TODO: feedback
|
2017-05-03 21:08:38 +02:00
|
|
|
throw new UndeclaredThrowableException(e);
|
2016-11-13 18:21:00 +01:00
|
|
|
}
|
2017-08-06 18:15:47 +02:00
|
|
|
}
|
2016-11-13 18:21:00 +01:00
|
|
|
|
2017-08-06 18:15:47 +02:00
|
|
|
private void loadKeyProfiles() {
|
2016-11-13 18:21:00 +01:00
|
|
|
try {
|
2017-08-06 18:15:47 +02:00
|
|
|
mKeyProfiles.addAll(db.getKeys());
|
2016-11-13 18:21:00 +01:00
|
|
|
mKeyProfileAdapter.notifyDataSetChanged();
|
|
|
|
} catch (Exception e) {
|
2017-08-06 18:15:47 +02:00
|
|
|
e.printStackTrace();
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|
2016-11-13 18:21:00 +01:00
|
|
|
}
|
2016-08-15 21:29:41 +02:00
|
|
|
}
|