mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-06 00:32:32 -08:00
Solve timeout bug and remove compat class for invalidateOptionMenu
This commit is contained in:
1 parent
9ef34599ce
commit
9fc47fdf05
5 files changed
+31
-63
No files matched your search
@@ -36,7 +36,6 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.compat.ActivityCompat;
|
||||
import com.keepassdroid.database.Database;
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwEntry;
|
||||
@@ -115,7 +114,7 @@ public class EntryActivity extends LockingHideActivity {
|
||||
}
|
||||
|
||||
// Refresh Menu contents in case onCreateMenuOptions was called before mEntry was set
|
||||
ActivityCompat.invalidateOptionsMenu(this);
|
||||
invalidateOptionsMenu();
|
||||
|
||||
// Update last access time.
|
||||
mEntry.touch(false, false);
|
||||
|
||||
@@ -66,6 +66,8 @@ import com.kunzisoft.keepass.R;
|
||||
public class GroupActivity extends ListNodesActivity
|
||||
implements GroupEditDialogFragment.EditGroupListener, IconPickerDialogFragment.IconPickerListener {
|
||||
|
||||
private static final String GROUP_ID_KEY = "GROUP_ID_KEY";
|
||||
|
||||
private AddNodeButtonView addNodeButtonView;
|
||||
|
||||
protected boolean addGroupEnabled = false;
|
||||
@@ -83,20 +85,29 @@ public class GroupActivity extends ListNodesActivity
|
||||
private static final String TAG = "Group Activity:";
|
||||
|
||||
public static void launch(Activity act) {
|
||||
launch(act, (PwGroup) null);
|
||||
Intent intent = new Intent(act, GroupActivity.class);
|
||||
intent.putExtra(FIRST_LOCKING_ACTIVITY_KEY, true);
|
||||
act.startActivityForResult(intent, 0);
|
||||
}
|
||||
|
||||
public static void launch(Activity act, PwGroup group) {
|
||||
Intent intent = new Intent(act, GroupActivity.class);
|
||||
if ( group != null ) {
|
||||
intent.putExtra(KEY_ENTRY, group.getId());
|
||||
intent.putExtra(GROUP_ID_KEY, group.getId());
|
||||
}
|
||||
act.startActivityForResult(intent, 0);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public static void launch(Activity act, AssistStructure assistStructure) {
|
||||
launch(act, null, assistStructure);
|
||||
if ( assistStructure != null ) {
|
||||
Intent intent = new Intent(act, GroupActivity.class);
|
||||
intent.putExtra(FIRST_LOCKING_ACTIVITY_KEY, true);
|
||||
AutofillHelper.addAssistStructureExtraInIntent(intent, assistStructure);
|
||||
act.startActivityForResult(intent, AutofillHelper.AUTOFILL_RESPONSE_REQUEST_CODE);
|
||||
} else {
|
||||
launch(act);
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@@ -104,7 +115,7 @@ public class GroupActivity extends ListNodesActivity
|
||||
if ( assistStructure != null ) {
|
||||
Intent intent = new Intent(act, GroupActivity.class);
|
||||
if ( group != null ) {
|
||||
intent.putExtra(KEY_ENTRY, group.getId());
|
||||
intent.putExtra(GROUP_ID_KEY, group.getId());
|
||||
}
|
||||
AutofillHelper.addAssistStructureExtraInIntent(intent, assistStructure);
|
||||
act.startActivityForResult(intent, AutofillHelper.AUTOFILL_RESPONSE_REQUEST_CODE);
|
||||
@@ -171,7 +182,7 @@ public class GroupActivity extends ListNodesActivity
|
||||
PwGroup root = db.pm.rootGroup;
|
||||
|
||||
Log.w(TAG, "Creating tree view");
|
||||
PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(KEY_ENTRY);
|
||||
PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY);
|
||||
if ( pwGroupId == null ) {
|
||||
currentGroup = root;
|
||||
} else {
|
||||
|
||||
@@ -38,7 +38,6 @@ import android.widget.TextView;
|
||||
|
||||
import com.keepassdroid.adapters.NodeAdapter;
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.compat.ActivityCompat;
|
||||
import com.keepassdroid.compat.EditorCompat;
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwEntry;
|
||||
@@ -60,8 +59,6 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
NodeAdapter.OnNodeClickCallback,
|
||||
SortDialogFragment.SortSelectionListener {
|
||||
|
||||
public static final String KEY_ENTRY = "entry";
|
||||
|
||||
protected PwGroup mCurrentGroup;
|
||||
protected NodeAdapter mAdapter;
|
||||
|
||||
@@ -83,8 +80,9 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
ActivityCompat.invalidateOptionsMenu(this);
|
||||
invalidateOptionsMenu();
|
||||
|
||||
// TODO Move in search
|
||||
setContentView(R.layout.list_nodes);
|
||||
|
||||
mCurrentGroup = initCurrentGroup();
|
||||
@@ -262,6 +260,7 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
// TODO BUG HERE
|
||||
super.startActivityForResult(intent, requestCode, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.keepassdroid.timeout.TimeoutHelper;
|
||||
|
||||
public abstract class LockingActivity extends StylishActivity {
|
||||
|
||||
protected static final String FIRST_LOCKING_ACTIVITY_KEY = "FIRST_LOCKING_ACTIVITY_KEY";
|
||||
private static final String AT_LEAST_SECOND_SHOWN_KEY = "AT_LEAST_SECOND_SHOWN_KEY";
|
||||
|
||||
private ScreenReceiver screenReceiver;
|
||||
@@ -41,21 +42,25 @@ public abstract class LockingActivity extends StylishActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (PreferencesUtil.isLockDatabaseWhenScreenShutOffEnable(this)) {
|
||||
screenReceiver = new ScreenReceiver();
|
||||
registerReceiver(screenReceiver, new IntentFilter((Intent.ACTION_SCREEN_OFF)));
|
||||
} else
|
||||
screenReceiver = null;
|
||||
|
||||
// If it's the first shown, record the time
|
||||
// WARNING TODO recordTime is not called after a back if was in backstack
|
||||
timeAlreadyRecord = false;
|
||||
// In case of orientation changing
|
||||
if (! (savedInstanceState != null
|
||||
&& savedInstanceState.containsKey(AT_LEAST_SECOND_SHOWN_KEY)
|
||||
&& savedInstanceState.getBoolean(AT_LEAST_SECOND_SHOWN_KEY)) ) {
|
||||
TimeoutHelper.recordTime(this);
|
||||
timeAlreadyRecord = true;
|
||||
} else {
|
||||
timeAlreadyRecord = false;
|
||||
// If it's the first locking activity, record the time
|
||||
if (getIntent() != null
|
||||
&& getIntent().getBooleanExtra(FIRST_LOCKING_ACTIVITY_KEY, false)) {
|
||||
TimeoutHelper.recordTime(this);
|
||||
timeAlreadyRecord = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +70,7 @@ public abstract class LockingActivity extends StylishActivity {
|
||||
// After the first creation
|
||||
// or If simply swipe with another application
|
||||
// If the time is out -> close the Activity
|
||||
// TODO Solve flickering
|
||||
TimeoutHelper.checkTime(this);
|
||||
// If onCreate already record time
|
||||
if (!timeAlreadyRecord)
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.keepassdroid.compat;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
public class ActivityCompat {
|
||||
private static Method invalidateOptMenu;
|
||||
|
||||
static {
|
||||
try {
|
||||
invalidateOptMenu = Activity.class.getMethod("invalidateOptionsMenu", (Class<Activity>[]) null);
|
||||
} catch (Exception e) {
|
||||
// Do nothing if method dosen't exist
|
||||
}
|
||||
}
|
||||
|
||||
public static void invalidateOptionsMenu(Activity act) {
|
||||
if (invalidateOptMenu != null) {
|
||||
try {
|
||||
invalidateOptMenu.invoke(act, (Object[]) null);
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user