mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Reorganize the auth/intro activity logic a bit
This commit is contained in:
parent
75a91ce191
commit
152cc8b562
6 changed files with 75 additions and 83 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -24,7 +24,7 @@
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -14,7 +14,6 @@ import me.impy.aegis.db.DatabaseManager;
|
||||||
import me.impy.aegis.ui.MainActivity;
|
import me.impy.aegis.ui.MainActivity;
|
||||||
|
|
||||||
public class AegisApplication extends Application {
|
public class AegisApplication extends Application {
|
||||||
private boolean _running = false;
|
|
||||||
private DatabaseManager _manager;
|
private DatabaseManager _manager;
|
||||||
private Preferences _prefs;
|
private Preferences _prefs;
|
||||||
|
|
||||||
|
@ -37,15 +36,6 @@ public class AegisApplication extends Application {
|
||||||
return _prefs;
|
return _prefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunning() {
|
|
||||||
// return false the first time this is called
|
|
||||||
if (!_running) {
|
|
||||||
_running = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
||||||
private void initAppShortcuts() {
|
private void initAppShortcuts() {
|
||||||
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
private Spinner _spinnerType;
|
private Spinner _spinnerType;
|
||||||
private Spinner _spinnerAlgo;
|
private Spinner _spinnerAlgo;
|
||||||
private Spinner _spinnerDigits;
|
private Spinner _spinnerDigits;
|
||||||
private SpinnerItemSelectedListener _selectedListener = new SpinnerItemSelectedListener();
|
private SpinnerItemSelectedListener _selectedListener;
|
||||||
|
|
||||||
private KropView _kropView;
|
private KropView _kropView;
|
||||||
|
|
||||||
|
@ -110,6 +110,8 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
SpinnerHelper.fillSpinner(this, _spinnerAlgo, R.array.otp_algo_array);
|
SpinnerHelper.fillSpinner(this, _spinnerAlgo, R.array.otp_algo_array);
|
||||||
_spinnerDigits = findViewById(R.id.spinner_digits);
|
_spinnerDigits = findViewById(R.id.spinner_digits);
|
||||||
SpinnerHelper.fillSpinner(this, _spinnerDigits, R.array.otp_digits_array);
|
SpinnerHelper.fillSpinner(this, _spinnerDigits, R.array.otp_digits_array);
|
||||||
|
_selectedListener = new SpinnerItemSelectedListener();
|
||||||
|
|
||||||
_advancedSettingsHeader = findViewById(R.id.accordian_header);
|
_advancedSettingsHeader = findViewById(R.id.accordian_header);
|
||||||
_advancedSettings = findViewById(R.id.expandableLayout);
|
_advancedSettings = findViewById(R.id.expandableLayout);
|
||||||
|
|
||||||
|
|
|
@ -43,16 +43,18 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
|
|
||||||
private AegisApplication _app;
|
private AegisApplication _app;
|
||||||
private DatabaseManager _db;
|
private DatabaseManager _db;
|
||||||
private EntryListView _entryListView;
|
private boolean _loaded;
|
||||||
|
|
||||||
private Menu _menu;
|
private Menu _menu;
|
||||||
private FloatingActionsMenu _fabMenu;
|
private FloatingActionsMenu _fabMenu;
|
||||||
|
private EntryListView _entryListView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
_app = (AegisApplication) getApplication();
|
_app = (AegisApplication) getApplication();
|
||||||
_db = _app.getDatabaseManager();
|
_db = _app.getDatabaseManager();
|
||||||
|
_loaded = false;
|
||||||
|
|
||||||
// set up the main view
|
// set up the main view
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
@ -66,44 +68,12 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
_fabMenu = findViewById(R.id.fab);
|
_fabMenu = findViewById(R.id.fab);
|
||||||
findViewById(R.id.fab_enter).setOnClickListener(view -> {
|
findViewById(R.id.fab_enter).setOnClickListener(view -> {
|
||||||
_fabMenu.collapse();
|
_fabMenu.collapse();
|
||||||
onEnterEntry();
|
startEditProfileActivity(CODE_ENTER_ENTRY, null, true);
|
||||||
});
|
});
|
||||||
findViewById(R.id.fab_scan).setOnClickListener(view -> {
|
findViewById(R.id.fab_scan).setOnClickListener(view -> {
|
||||||
_fabMenu.collapse();
|
_fabMenu.collapse();
|
||||||
onScan();
|
startScanActivity();
|
||||||
});
|
});
|
||||||
|
|
||||||
// skip this part if this is the not initial startup and the database has been unlocked
|
|
||||||
if (!_app.isRunning() && _db.isLocked()) {
|
|
||||||
if (!_db.fileExists()) {
|
|
||||||
// the db doesn't exist, start the intro
|
|
||||||
if (getPreferences().isIntroDone()) {
|
|
||||||
Toast.makeText(this, "Database file not found, starting over...", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
Intent intro = new Intent(this, IntroActivity.class);
|
|
||||||
startActivityForResult(intro, CODE_DO_INTRO);
|
|
||||||
} else {
|
|
||||||
// the db exists, load the database
|
|
||||||
// if the database is still encrypted, start the auth activity
|
|
||||||
try {
|
|
||||||
if (!_db.isLoaded()) {
|
|
||||||
_db.load();
|
|
||||||
}
|
|
||||||
if (_db.isLocked()) {
|
|
||||||
startAuthActivity();
|
|
||||||
}
|
|
||||||
} catch (DatabaseManagerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Toast.makeText(this, "An error occurred while trying to deserialize the database", Toast.LENGTH_LONG).show();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the database has been decrypted at this point, we can load the entries
|
|
||||||
if (!_db.isLocked()) {
|
|
||||||
loadEntries();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -248,33 +218,13 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
}
|
}
|
||||||
|
|
||||||
MasterKey key = (MasterKey) data.getSerializableExtra("key");
|
MasterKey key = (MasterKey) data.getSerializableExtra("key");
|
||||||
try {
|
unlockDatabase(key);
|
||||||
_db.load();
|
|
||||||
if (_db.isLocked()) {
|
|
||||||
_db.unlock(key);
|
|
||||||
}
|
|
||||||
} catch (DatabaseManagerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Toast.makeText(this, "An error occurred while trying to load/decrypt the database", Toast.LENGTH_LONG).show();
|
|
||||||
startAuthActivity();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadEntries();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDecryptResult(int resultCode, Intent intent) {
|
private void onDecryptResult(int resultCode, Intent intent) {
|
||||||
MasterKey key = (MasterKey) intent.getSerializableExtra("key");
|
MasterKey key = (MasterKey) intent.getSerializableExtra("key");
|
||||||
try {
|
unlockDatabase(key);
|
||||||
_db.unlock(key);
|
|
||||||
} catch (DatabaseManagerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Toast.makeText(this, "An error occurred while trying to decrypt the database", Toast.LENGTH_LONG).show();
|
|
||||||
startAuthActivity();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadEntries();
|
|
||||||
doShortcutActions();
|
doShortcutActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,10 +266,28 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
updateLockIcon();
|
|
||||||
|
|
||||||
|
if (_db.isLocked()) {
|
||||||
|
// start the intro if the database file doesn't exist
|
||||||
|
if (!_db.isLoaded() && !_db.fileExists()) {
|
||||||
|
// the db doesn't exist, start the intro
|
||||||
|
if (getPreferences().isIntroDone()) {
|
||||||
|
Toast.makeText(this, "Database file not found, starting intro...", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
Intent intro = new Intent(this, IntroActivity.class);
|
||||||
|
startActivityForResult(intro, CODE_DO_INTRO);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
unlockDatabase(null);
|
||||||
|
}
|
||||||
|
} else if (_loaded) {
|
||||||
// refresh all codes to prevent showing old ones
|
// refresh all codes to prevent showing old ones
|
||||||
_entryListView.refresh(true);
|
_entryListView.refresh(true);
|
||||||
|
} else {
|
||||||
|
loadEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLockIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BottomSheetDialog createBottomSheet(final DatabaseEntry entry) {
|
private BottomSheetDialog createBottomSheet(final DatabaseEntry entry) {
|
||||||
|
@ -376,15 +344,51 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
startActivityForResult(intent, CODE_PREFERENCES);
|
startActivityForResult(intent, CODE_PREFERENCES);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_lock:
|
case R.id.action_lock:
|
||||||
_entryListView.clearEntries();
|
lockDatabase();
|
||||||
_db.lock();
|
|
||||||
startAuthActivity();
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void lockDatabase() {
|
||||||
|
if (_loaded) {
|
||||||
|
_entryListView.clearEntries();
|
||||||
|
_db.lock();
|
||||||
|
_loaded = false;
|
||||||
|
startAuthActivity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unlockDatabase(MasterKey key) {
|
||||||
|
try {
|
||||||
|
if (!_db.isLoaded()) {
|
||||||
|
_db.load();
|
||||||
|
}
|
||||||
|
if (_db.isLocked()) {
|
||||||
|
if (key == null) {
|
||||||
|
startAuthActivity();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
_db.unlock(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DatabaseManagerException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Toast.makeText(this, "An error occurred while trying to load/decrypt the database", Toast.LENGTH_LONG).show();
|
||||||
|
startAuthActivity();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadEntries() {
|
||||||
|
// load all entries
|
||||||
|
_entryListView.addEntries(_db.getEntries());
|
||||||
|
_loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void startAuthActivity() {
|
private void startAuthActivity() {
|
||||||
Intent intent = new Intent(this, AuthActivity.class);
|
Intent intent = new Intent(this, AuthActivity.class);
|
||||||
intent.putExtra("slots", _db.getFile().getSlots());
|
intent.putExtra("slots", _db.getFile().getSlots());
|
||||||
|
@ -400,12 +404,6 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadEntries() {
|
|
||||||
updateLockIcon();
|
|
||||||
|
|
||||||
_entryListView.addEntries(_db.getEntries());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateLockIcon() {
|
private void updateLockIcon() {
|
||||||
// hide the lock icon if the database is not unlocked
|
// hide the lock icon if the database is not unlocked
|
||||||
if (_menu != null && !_db.isLocked()) {
|
if (_menu != null && !_db.isLocked()) {
|
||||||
|
|
|
@ -34,12 +34,13 @@ public class SlotManagerActivity extends AegisActivity implements SlotAdapter.Li
|
||||||
private SlotList _slots;
|
private SlotList _slots;
|
||||||
private SlotAdapter _adapter;
|
private SlotAdapter _adapter;
|
||||||
|
|
||||||
private boolean _edited = false;
|
private boolean _edited;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_slots);
|
setContentView(R.layout.activity_slots);
|
||||||
|
_edited = false;
|
||||||
|
|
||||||
ActionBar bar = getSupportActionBar();
|
ActionBar bar = getSupportActionBar();
|
||||||
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
private Listener _listener;
|
private Listener _listener;
|
||||||
|
|
||||||
private PeriodProgressBar _progressBar;
|
private PeriodProgressBar _progressBar;
|
||||||
private boolean _showProgress = false;
|
private boolean _showProgress;
|
||||||
|
|
||||||
private UiRefresher _refresher;
|
private UiRefresher _refresher;
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
_adapter = new EntryAdapter(this);
|
_adapter = new EntryAdapter(this);
|
||||||
|
_showProgress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue