Change search and menu

This commit is contained in:
J-Jamet committed 2017-11-07 21:45:16 +01:00
1 parent 9710be42a7
commit f21a25ed35
23 files changed
+321 -161

No files matched your search

@@ -211,7 +211,7 @@ public class Database {
}
// TODO: This should probably be abstracted out
// The root group in v3 is not an 'official' group
// The root tree in v3 is not an 'official' tree
if ( pm instanceof PwDatabaseV3 ) {
dirty.add(pm.rootGroup);
}
@@ -70,7 +70,7 @@ public abstract class GroupActivity extends GroupBaseActivity
public static void Launch(Activity act, PwGroup group) {
Intent i;
// Need to use PwDatabase since group may be null
// Need to use PwDatabase since tree may be null
PwDatabase db = App.getDB().pm;
if ( db instanceof PwDatabaseV3 ) {
i = new Intent(act, GroupActivityV3.class);
@@ -111,7 +111,7 @@ public abstract class GroupActivity extends GroupBaseActivity
setResult(KeePass.EXIT_NORMAL);
Log.w(TAG, "Creating group view");
Log.w(TAG, "Creating tree view");
Intent intent = getIntent();
PwGroupId id = retrieveGroupId(intent);
@@ -125,7 +125,7 @@ public abstract class GroupActivity extends GroupBaseActivity
mGroup = db.pm.groups.get(id);
}
Log.w(TAG, "Retrieved group");
Log.w(TAG, "Retrieved tree");
if ( mGroup == null ) {
Log.w(TAG, "Group was null");
return;
@@ -181,7 +181,7 @@ public abstract class GroupActivity extends GroupBaseActivity
setListAdapter(new PwGroupListAdapter(this, mGroup));
registerForContextMenu(getListView());
Log.w(TAG, "Finished creating group");
Log.w(TAG, "Finished creating tree");
if (isRoot) {
showWarnings();
@@ -222,7 +222,7 @@ public abstract class GroupActivity extends GroupBaseActivity
}
@Override
// For icon in create group dialog
// For icon in create tree dialog
public void iconPicked(Bundle bundle) {
GroupEditFragment groupEditFragment = (GroupEditFragment) getSupportFragmentManager().findFragmentByTag(TAG_CREATE_GROUP);
if (groupEditFragment != null) {
@@ -20,12 +20,15 @@
package com.keepassdroid;
import android.content.ActivityNotFoundException;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -36,7 +39,6 @@ import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.keepass.KeePass;
import com.android.keepass.R;
@@ -45,8 +47,8 @@ import com.keepassdroid.compat.ActivityCompat;
import com.keepassdroid.compat.EditorCompat;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.edit.OnFinish;
import com.keepassdroid.settings.SettingsActivity;
import com.keepassdroid.utils.Util;
import com.keepassdroid.search.SearchResultsActivity;
import com.keepassdroid.utils.MenuUtil;
import com.keepassdroid.view.ClickView;
import com.keepassdroid.view.GroupViewOnlyView;
@@ -163,9 +165,26 @@ public abstract class GroupBaseActivity extends LockCloseListActivity {
MenuInflater inflater = getMenuInflater();
// TODO Donation
inflater.inflate(R.menu.search, menu);
inflater.inflate(R.menu.donation, menu);
inflater.inflate(R.menu.group, menu);
inflater.inflate(R.menu.tree, menu);
inflater.inflate(R.menu.database, 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;
}
@@ -201,40 +220,29 @@ public abstract class GroupBaseActivity extends LockCloseListActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
case R.id.menu_donate:
try {
Util.gotoUrl(this, R.string.donate_url);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
return false;
}
return true;
case R.id.menu_lock:
App.setShutdown();
setResult(KeePass.EXIT_LOCK);
finish();
return true;
case R.id.menu_search:
onSearchRequested();
return true;
case R.id.menu_app_settings:
SettingsActivity.Launch(this);
return true;
case R.id.menu_change_master_key:
setPassword();
return true;
case R.id.menu_sort:
toggleSort();
return true;
case R.id.menu_search:
onSearchRequested();
return true;
case R.id.menu_sort:
toggleSort();
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:
MenuUtil.onDefaultMenuOptionsItemSelected(this, item);
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}
private void toggleSort() {
@@ -251,7 +259,7 @@ public abstract class GroupBaseActivity extends LockCloseListActivity {
// Mark all groups as dirty now to refresh them on load
Database db = App.getDB();
db.markAllGroupsAsDirty();
// We'll manually refresh this group so we can remove it
// We'll manually refresh this tree so we can remove it
db.dirty.remove(mGroup);
// Tell the adapter to refresh it's list
@@ -257,7 +257,7 @@ public abstract class PwDatabase {
public abstract PwEncryptionAlgorithm getEncAlgorithm();
public void addGroupTo(PwGroup newGroup, PwGroup parent) {
// Add group to parent group
// Add tree to parent tree
if ( parent == null ) {
parent = rootGroup;
}
@@ -270,7 +270,7 @@ public abstract class PwDatabase {
}
public void removeGroupFrom(PwGroup remove, PwGroup parent) {
// Remove group from parent group
// Remove tree from parent tree
parent.childGroups.remove(remove);
groups.remove(remove.getId());
@@ -194,16 +194,16 @@ public class PwDatabaseV3 extends PwDatabase {
}
/*
public void removeGroup(PwGroupV3 group) {
group.parent.childGroups.remove(group);
groups.remove(group);
public void removeGroup(PwGroupV3 tree) {
tree.parent.childGroups.remove(tree);
groups.remove(tree);
}
*/
/**
* Generates an unused random group id
* Generates an unused random tree id
*
* @return new group id
* @return new tree id
*/
@Override
public PwGroupIdV3 newGroupId() {
@@ -280,7 +280,7 @@ public class PwDatabaseV3 extends PwDatabase {
public void addGroupTo(PwGroup newGroup, PwGroup parent) {
super.addGroupTo(newGroup, parent);
// Add group to root groups
// Add tree to root groups
groups.add(newGroup);
}
@@ -297,7 +297,7 @@ public class PwDatabaseV3 extends PwDatabase {
public void removeGroupFrom(PwGroup remove, PwGroup parent) {
super.removeGroupFrom(remove, parent);
// Remove group from root entry
// Remove tree from root entry
groups.remove(remove);
}
@@ -350,7 +350,7 @@ public class PwDatabaseV3 extends PwDatabase {
algorithm = PwEncryptionAlgorithm.Rjindal;
numKeyEncRounds = DEFAULT_ENCRYPTION_ROUNDS;
name = "KeePass Password Manager";
// Build the root group
// Build the root tree
constructTree(null);
// Add a couple default groups
@@ -336,7 +336,7 @@ public class PwDatabaseV4 extends PwDatabase {
super.populateGlobals(currentGroup);
}
/** Ensure that the recycle bin group exists, if enabled and create it
/** Ensure that the recycle bin tree exists, if enabled and create it
* if it doesn't exist
*
*/
@@ -234,7 +234,7 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
group = group.parent;
}
// If we get to the root group and its null, default to true
// If we get to the root tree and its null, default to true
return true;
}
@@ -67,7 +67,7 @@ public class AddEntry extends RunnableOnFinish {
PwGroup parent = mEntry.getParent();
// Mark parent group dirty
// Mark parent tree dirty
mDb.dirty.add(parent);
} else {
@@ -102,10 +102,10 @@ public class DeleteGroup extends RunnableOnFinish {
public void run() {
if ( mSuccess ) {
// Remove from group global
// Remove from tree global
mDb.pm.groups.remove(mGroup.getId());
// Remove group from the dirty global (if it is present), not a big deal if this fails
// Remove tree from the dirty global (if it is present), not a big deal if this fails
mDb.dirty.remove(mGroup);
// Mark parent dirty
@@ -115,7 +115,7 @@ public class DeleteGroup extends RunnableOnFinish {
}
mDb.dirty.add(mDb.pm.rootGroup);
} else {
// Let's not bother recovering from a failure to save a deleted group. It is too much work.
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
App.setShutdown();
}
@@ -109,7 +109,7 @@ public class PwDbV3Output extends PwDbOutput {
}
private void prepForOutput() {
// Before we output the header, we should sort our list of groups and remove any orphaned nodes that are no longer part of the group hierarchy
// Before we output the header, we should sort our list of groups and remove any orphaned nodes that are no longer part of the tree hierarchy
sortGroupsForOutput();
}
@@ -227,7 +227,7 @@ public class PwDbV3Output extends PwDbOutput {
try {
pgo.output();
} catch (IOException e) {
throw new PwDbOutputException("Failed to output a group: " + e.getMessage());
throw new PwDbOutputException("Failed to output a tree: " + e.getMessage());
}
}
@@ -256,7 +256,7 @@ public class PwDbV3Output extends PwDbOutput {
}
private void sortGroup(PwGroupV3 group, List<PwGroup> groupList) {
// Add current group
// Add current tree
groupList.add(group);
// Recurse over children
@@ -22,20 +22,26 @@ package com.keepassdroid.search;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import com.android.keepass.KeePass;
import com.android.keepass.R;
import com.keepassdroid.Database;
import com.keepassdroid.GroupBaseActivity;
import com.keepassdroid.PwGroupListAdapter;
import com.keepassdroid.app.App;
import com.keepassdroid.view.GroupEmptyView;
import com.keepassdroid.view.GroupViewOnlyView;
public class SearchResults extends GroupBaseActivity {
public class SearchResultsActivity extends GroupBaseActivity {
private Database mDb;
//private String mQuery;
private View listView;
private View imageNotFoundView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -53,39 +59,58 @@ public class SearchResults extends GroupBaseActivity {
finish();
}
setContentView(getLayoutInflater().inflate(R.layout.search_results, null));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.search_label));
setSupportActionBar(toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
listView = findViewById(R.id.group_list);
imageNotFoundView = findViewById(R.id.img_not_found);
performSearch(getSearchStr(getIntent()));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
// TODO Donation
inflater.inflate(R.menu.donation, menu);
inflater.inflate(R.menu.tree, menu);
inflater.inflate(R.menu.default_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
case android.R.id.home:
finish();
}
return super.onOptionsItemSelected(item);
}
private void performSearch(String query) {
query(query.trim());
}
private void query(String query) {
mGroup = mDb.Search(query);
mGroup = mDb.Search(query.trim());
if ( mGroup == null || mGroup.childEntries.size() < 1 ) {
setContentView(new GroupEmptyView(this));
listView.setVisibility(View.GONE);
imageNotFoundView.setVisibility(View.VISIBLE);
} else {
setContentView(new GroupViewOnlyView(this));
}
listView.setVisibility(View.VISIBLE);
imageNotFoundView.setVisibility(View.GONE);
}
setGroupTitle();
setListAdapter(new PwGroupListAdapter(this, mGroup));
}
/*
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
mQuery = getSearchStr(intent);
performSearch();
//mGroup = processSearchIntent(intent);
//assert(mGroup != null);
}
*/
private String getSearchStr(Intent queryIntent) {
// get and process search query here
@@ -93,9 +118,7 @@ public class SearchResults extends GroupBaseActivity {
if ( Intent.ACTION_SEARCH.equals(queryAction) ) {
return queryIntent.getStringExtra(SearchManager.QUERY);
}
return "";
}
}
@@ -1,48 +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.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import com.android.keepass.R;
public class GroupEmptyView extends RelativeLayout {
public GroupEmptyView(Context context) {
this(context, null);
}
public GroupEmptyView(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context);
}
private void inflate(Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.group_empty, this);
}
}