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 <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" 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> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>

View file

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