hacky fix to prevent key list from scrolling to top when opening nav drawer

This commit is contained in:
Dominik Schürmann
2014-08-14 18:51:35 +02:00
parent 110f8c4d52
commit 65e76f6e44

View File

@@ -330,12 +330,12 @@ public class KeyListFragment extends LoaderFragment
* Show dialog to delete key * Show dialog to delete key
* *
* @param masterKeyIds * @param masterKeyIds
* @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not
*/ */
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) { public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) {
// Can only work on singular secret keys // Can only work on singular secret keys
if(hasSecret && masterKeyIds.length > 1) { if (hasSecret && masterKeyIds.length > 1) {
Notify.showNotify(getActivity(), R.string.secret_cannot_multiple, Notify.showNotify(getActivity(), R.string.secret_cannot_multiple,
Notify.Style.ERROR); Notify.Style.ERROR);
return; return;
@@ -365,6 +365,7 @@ public class KeyListFragment extends LoaderFragment
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
// Get the searchview // Get the searchview
MenuItem searchItem = menu.findItem(R.id.menu_key_list_search); MenuItem searchItem = menu.findItem(R.id.menu_key_list_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem); mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
// Execute this when searching // Execute this when searching
@@ -383,7 +384,6 @@ public class KeyListFragment extends LoaderFragment
@Override @Override
public boolean onMenuItemActionCollapse(MenuItem item) { public boolean onMenuItemActionCollapse(MenuItem item) {
mQuery = null; mQuery = null;
mSearchView.setQuery("", true);
getLoaderManager().restartLoader(0, null, KeyListFragment.this); getLoaderManager().restartLoader(0, null, KeyListFragment.this);
return true; return true;
} }
@@ -399,11 +399,18 @@ public class KeyListFragment extends LoaderFragment
@Override @Override
public boolean onQueryTextChange(String s) { public boolean onQueryTextChange(String s) {
Log.d(Constants.TAG, "onQueryTextChange s:" + s);
// Called when the action bar search text has changed. Update // Called when the action bar search text has changed. Update
// the search filter, and restart the loader to do a new query // the search filter, and restart the loader to do a new query
// with this filter. // with this filter.
mQuery = !TextUtils.isEmpty(s) ? s : null; // If the nav drawer is opened, onQueryTextChange("") is executed.
getLoaderManager().restartLoader(0, null, this); // This hack prevents restarting the loader.
// TODO: better way to fix this?
String tmp = (mQuery == null) ? "" : mQuery;
if (!s.equals(tmp)) {
mQuery = s;
getLoaderManager().restartLoader(0, null, this);
}
return true; return true;
} }
@@ -479,7 +486,7 @@ public class KeyListFragment extends LoaderFragment
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
boolean isExpired = !cursor.isNull(INDEX_EXPIRY) boolean isExpired = !cursor.isNull(INDEX_EXPIRY)
&& new Date(cursor.getLong(INDEX_EXPIRY)*1000).before(new Date()); && new Date(cursor.getLong(INDEX_EXPIRY) * 1000).before(new Date());
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0; boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
// Note: order is important! // Note: order is important!
@@ -521,6 +528,7 @@ public class KeyListFragment extends LoaderFragment
return mCursor.getInt(INDEX_HAS_ANY_SECRET) != 0; return mCursor.getInt(INDEX_HAS_ANY_SECRET) != 0;
} }
public long getMasterKeyId(int id) { public long getMasterKeyId(int id) {
if (!mCursor.moveToPosition(id)) { if (!mCursor.moveToPosition(id)) {
throw new IllegalStateException("couldn't move cursor to position " + id); throw new IllegalStateException("couldn't move cursor to position " + id);
@@ -625,7 +633,7 @@ public class KeyListFragment extends LoaderFragment
public boolean isAnySecretSelected() { public boolean isAnySecretSelected() {
for (int pos : mSelection.keySet()) { for (int pos : mSelection.keySet()) {
if(mAdapter.isSecretAvailable(pos)) if (mAdapter.isSecretAvailable(pos))
return true; return true;
} }
return false; return false;