mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Refactor search and hide add button during search
This commit is contained in:
@@ -97,7 +97,8 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="com.keepassdroid.activities.GroupActivity"
|
android:name="com.keepassdroid.activities.GroupActivity"
|
||||||
android:configChanges="orientation|keyboardHidden">
|
android:configChanges="orientation|keyboardHidden"
|
||||||
|
android:windowSoftInputMode="adjustPan">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.app.default_searchable"
|
android:name="android.app.default_searchable"
|
||||||
android:value="com.keepassdroid.search.SearchResults"
|
android:value="com.keepassdroid.search.SearchResults"
|
||||||
|
|||||||
@@ -21,13 +21,20 @@ package com.keepassdroid.activities;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.app.SearchManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -43,8 +50,10 @@ import com.keepassdroid.database.edit.AddGroup;
|
|||||||
import com.keepassdroid.database.edit.DeleteEntry;
|
import com.keepassdroid.database.edit.DeleteEntry;
|
||||||
import com.keepassdroid.database.edit.DeleteGroup;
|
import com.keepassdroid.database.edit.DeleteGroup;
|
||||||
import com.keepassdroid.dialog.ReadOnlyDialog;
|
import com.keepassdroid.dialog.ReadOnlyDialog;
|
||||||
|
import com.keepassdroid.fragments.AssignMasterKeyDialogFragment;
|
||||||
import com.keepassdroid.fragments.GroupEditDialogFragment;
|
import com.keepassdroid.fragments.GroupEditDialogFragment;
|
||||||
import com.keepassdroid.fragments.IconPickerDialogFragment;
|
import com.keepassdroid.fragments.IconPickerDialogFragment;
|
||||||
|
import com.keepassdroid.search.SearchResultsActivity;
|
||||||
import com.keepassdroid.tasks.ProgressTask;
|
import com.keepassdroid.tasks.ProgressTask;
|
||||||
import com.keepassdroid.view.ListNodesWithAddButtonView;
|
import com.keepassdroid.view.ListNodesWithAddButtonView;
|
||||||
import com.kunzisoft.keepass.KeePass;
|
import com.kunzisoft.keepass.KeePass;
|
||||||
@@ -58,6 +67,7 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
protected boolean isRoot = false;
|
protected boolean isRoot = false;
|
||||||
protected boolean readOnly = false;
|
protected boolean readOnly = false;
|
||||||
protected EditGroupDialogAction editGroupDialogAction = EditGroupDialogAction.NONE;
|
protected EditGroupDialogAction editGroupDialogAction = EditGroupDialogAction.NONE;
|
||||||
|
private ListNodesWithAddButtonView rootView;
|
||||||
|
|
||||||
private enum EditGroupDialogAction {
|
private enum EditGroupDialogAction {
|
||||||
CREATION, UPDATE, NONE
|
CREATION, UPDATE, NONE
|
||||||
@@ -113,7 +123,7 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
addEntryEnabled = !isRoot && addEntryEnabled;
|
addEntryEnabled = !isRoot && addEntryEnabled;
|
||||||
|
|
||||||
// Construct main view
|
// Construct main view
|
||||||
ListNodesWithAddButtonView rootView = new ListNodesWithAddButtonView(this);
|
rootView = new ListNodesWithAddButtonView(this);
|
||||||
rootView.enableAddGroup(addGroupEnabled);
|
rootView.enableAddGroup(addGroupEnabled);
|
||||||
rootView.enableAddEntry(addEntryEnabled);
|
rootView.enableAddEntry(addEntryEnabled);
|
||||||
setContentView(rootView);
|
setContentView(rootView);
|
||||||
@@ -233,16 +243,61 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
pt.run();
|
pt.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.search, menu);
|
||||||
|
inflater.inflate(R.menu.database, menu);
|
||||||
|
|
||||||
|
// Get the SearchView and set the searchable configuration
|
||||||
|
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||||
|
assert searchManager != null;
|
||||||
|
|
||||||
|
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
||||||
|
SearchView searchView = null;
|
||||||
|
if (searchItem != null) {
|
||||||
|
searchView = (SearchView) searchItem.getActionView();
|
||||||
|
}
|
||||||
|
if (searchView != null) {
|
||||||
|
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchResultsActivity.class)));
|
||||||
|
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_search:
|
||||||
|
onSearchRequested();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_lock:
|
||||||
|
App.setShutdown();
|
||||||
|
setResult(KeePass.EXIT_LOCK);
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_change_master_key:
|
||||||
|
setPassword();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setPassword() {
|
||||||
|
AssignMasterKeyDialogFragment dialog = new AssignMasterKeyDialogFragment();
|
||||||
|
dialog.show(getSupportFragmentManager(), "passwordDialog");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void approveEditGroup(Bundle bundle) {
|
public void approveEditGroup(Bundle bundle) {
|
||||||
String GroupName = bundle.getString(GroupEditDialogFragment.KEY_NAME);
|
String GroupName = bundle.getString(GroupEditDialogFragment.KEY_NAME);
|
||||||
|
|||||||
@@ -19,9 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.keepassdroid.activities;
|
package com.keepassdroid.activities;
|
||||||
|
|
||||||
import android.app.SearchManager;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
@@ -32,7 +29,6 @@ import android.os.Handler;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.SearchView;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -50,7 +46,6 @@ import com.keepassdroid.database.PwNode;
|
|||||||
import com.keepassdroid.database.edit.AfterAddNodeOnFinish;
|
import com.keepassdroid.database.edit.AfterAddNodeOnFinish;
|
||||||
import com.keepassdroid.database.edit.OnFinish;
|
import com.keepassdroid.database.edit.OnFinish;
|
||||||
import com.keepassdroid.fragments.AssignMasterKeyDialogFragment;
|
import com.keepassdroid.fragments.AssignMasterKeyDialogFragment;
|
||||||
import com.keepassdroid.search.SearchResultsActivity;
|
|
||||||
import com.keepassdroid.tasks.UIToastTask;
|
import com.keepassdroid.tasks.UIToastTask;
|
||||||
import com.keepassdroid.utils.MenuUtil;
|
import com.keepassdroid.utils.MenuUtil;
|
||||||
import com.keepassdroid.view.AssignPasswordHelper;
|
import com.keepassdroid.view.AssignPasswordHelper;
|
||||||
@@ -140,26 +135,10 @@ public abstract class ListNodesActivity extends LockCloseListActivity
|
|||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.search, menu);
|
|
||||||
MenuUtil.donationMenuInflater(inflater, menu);
|
MenuUtil.donationMenuInflater(inflater, menu);
|
||||||
inflater.inflate(R.menu.tree, menu);
|
inflater.inflate(R.menu.tree, menu);
|
||||||
inflater.inflate(R.menu.database, menu);
|
|
||||||
inflater.inflate(R.menu.default_menu, menu);
|
inflater.inflate(R.menu.default_menu, menu);
|
||||||
|
|
||||||
// Get the SearchView and set the searchable configuration
|
|
||||||
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
|
||||||
assert searchManager != null;
|
|
||||||
|
|
||||||
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
|
||||||
SearchView searchView = null;
|
|
||||||
if (searchItem != null) {
|
|
||||||
searchView = (SearchView) searchItem.getActionView();
|
|
||||||
}
|
|
||||||
if (searchView != null) {
|
|
||||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchResultsActivity.class)));
|
|
||||||
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,24 +173,10 @@ public abstract class ListNodesActivity extends LockCloseListActivity
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch ( item.getItemId() ) {
|
switch ( item.getItemId() ) {
|
||||||
|
|
||||||
case R.id.menu_search:
|
|
||||||
onSearchRequested();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.menu_sort:
|
case R.id.menu_sort:
|
||||||
toggleSort();
|
toggleSort();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_lock:
|
|
||||||
App.setShutdown();
|
|
||||||
setResult(KeePass.EXIT_LOCK);
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.menu_change_master_key:
|
|
||||||
setPassword();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
MenuUtil.onDefaultMenuOptionsItemSelected(this, item);
|
MenuUtil.onDefaultMenuOptionsItemSelected(this, item);
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@@ -252,11 +217,6 @@ public abstract class ListNodesActivity extends LockCloseListActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPassword() {
|
|
||||||
AssignMasterKeyDialogFragment dialog = new AssignMasterKeyDialogFragment();
|
|
||||||
dialog.show(getSupportFragmentManager(), "passwordDialog");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|||||||
@@ -110,20 +110,29 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Hide when scroll
|
||||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.nodes_list);
|
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.nodes_list);
|
||||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||||
super.onScrolled(recyclerView, dx, dy);
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
if (dy > 0 && addButton.getVisibility() == View.VISIBLE) {
|
if (dy > 0 && addButton.getVisibility() == View.VISIBLE) {
|
||||||
addButton.hide(onAddButtonVisibilityChangedListener);
|
hideButton();
|
||||||
} else if (dy < 0 && addButton.getVisibility() != View.VISIBLE) {
|
} else if (dy < 0 && addButton.getVisibility() != View.VISIBLE) {
|
||||||
addButton.show(onAddButtonVisibilityChangedListener);
|
showButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showButton() {
|
||||||
|
addButton.show(onAddButtonVisibilityChangedListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideButton() {
|
||||||
|
addButton.hide(onAddButtonVisibilityChangedListener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||||
Rect viewRectG = new Rect();
|
Rect viewRectG = new Rect();
|
||||||
|
|||||||
Reference in New Issue
Block a user