Hopefully maybe partially fix app shortcuts

This commit is contained in:
Alexander Bakker 2017-12-25 19:02:46 +01:00
parent 950c6d0cf3
commit 456069fbc7
2 changed files with 34 additions and 20 deletions

View file

@ -17,10 +17,11 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.Default.NoActionBar">
android:theme="@style/AppTheme.Default.NoActionBar"
android:alwaysRetainTaskState="true"
android:relinquishTaskIdentity="false">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

View file

@ -53,6 +53,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
private DatabaseManager _db;
private KeyProfileView _keyProfileView;
private String _pendingAction = null;
private boolean _nightMode = false;
private Menu _menu;
@ -67,15 +68,15 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// init the app shortcuts and execute any pending actions
initializeAppShortcuts();
doShortcutActions();
// set up the key profile view
_keyProfileView = (KeyProfileView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
_keyProfileView.setListener(this);
_keyProfileView.setShowIssuer(_app.getPreferences().getBoolean("pref_issuer", false));
// init the app shortcuts and execute any pending actions
initializeAppShortcuts();
doShortcutActions();
// set up the floating action button
FloatingActionButton fab = findViewById(R.id.fab);
fab.setEnabled(true);
@ -94,7 +95,9 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
// the db exists, load the database
// if the database is still encrypted, start the auth activity
try {
_db.load();
if (!_db.isLoaded()) {
_db.load();
}
if (_db.isLocked()) {
startAuthActivity();
}
@ -291,8 +294,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
return;
}
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
startActivityForResult(scannerActivity, CODE_GET_KEYINFO);
startScanActivity();
}
private void onGetKeyInfoResult(int resultCode, Intent data) {
@ -351,8 +353,8 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
loadKeyProfiles();
}
private void onDecryptResult(int resultCode, Intent data) {
MasterKey key = (MasterKey) data.getSerializableExtra("key");
private void onDecryptResult(int resultCode, Intent intent) {
MasterKey key = (MasterKey) intent.getSerializableExtra("key");
try {
_db.unlock(key);
} catch (Exception e) {
@ -366,21 +368,32 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
doShortcutActions();
}
private void startScanActivity() {
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
startActivityForResult(scannerActivity, CODE_GET_KEYINFO);
}
private void doShortcutActions() {
Intent intent = getIntent();
String mode = intent.getStringExtra("Action");
if (mode == null || _db.isLocked()) {
String action = intent.getStringExtra("action");
intent.removeExtra("action");
if (action == null) {
if (_pendingAction == null) {
return;
} else {
action = _pendingAction;
}
}
if (_db.isLocked()) {
_pendingAction = action;
return;
}
switch (mode) {
case "Scan":
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
startActivityForResult(scannerActivity, CODE_GET_KEYINFO);
switch (action) {
case "scan":
startScanActivity();
break;
}
intent.removeExtra("Action");
}
public void startActivityForResult(Intent intent, int requestCode) {
@ -509,7 +522,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
if (shortcutManager.getDynamicShortcuts().size() == 0) {
// Application restored. Need to re-publish dynamic shortcuts.
Intent intent = new Intent(this.getBaseContext(), MainActivity.class);
intent.putExtra("Action", "Scan");
intent.putExtra("action", "scan");
intent.setAction(Intent.ACTION_MAIN);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")