mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Change search methods
This commit is contained in:
@@ -41,21 +41,21 @@ public class SearchTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void testSearch() {
|
||||
PwGroup results = mDb.Search("Amazon");
|
||||
PwGroup results = mDb.search("Amazon");
|
||||
assertTrue("Search result not found.", results.numbersOfChildEntries() > 0);
|
||||
|
||||
}
|
||||
|
||||
public void testBackupIncluded() {
|
||||
updateOmitSetting(false);
|
||||
PwGroup results = mDb.Search("BackupOnly");
|
||||
PwGroup results = mDb.search("BackupOnly");
|
||||
|
||||
assertTrue("Search result not found.", results.numbersOfChildEntries() > 0);
|
||||
}
|
||||
|
||||
public void testBackupExcluded() {
|
||||
updateOmitSetting(true);
|
||||
PwGroup results = mDb.Search("BackupOnly");
|
||||
PwGroup results = mDb.search("BackupOnly");
|
||||
|
||||
assertFalse("Search result found, but should not have been.", results.numbersOfChildEntries() > 0);
|
||||
}
|
||||
|
||||
@@ -179,29 +179,42 @@ public class Database {
|
||||
|
||||
pm = imp.openDatabase(bis, password, kfIs, status, roundsFix);
|
||||
if ( pm != null ) {
|
||||
PwGroup root = pm.getRootGroup();
|
||||
pm.populateGlobals(root);
|
||||
loadData(ctx, pm, password);
|
||||
try {
|
||||
switch (pm.getVersion()) {
|
||||
case V3:
|
||||
PwGroupV3 rootV3 = ((PwDatabaseV3) pm).getRootGroup();
|
||||
((PwDatabaseV3) pm).populateGlobals(rootV3);
|
||||
passwordEncodingError = !pm.validatePasswordEncoding(password);
|
||||
searchHelper = new SearchDbHelper.SearchDbHelperV3(ctx);
|
||||
break;
|
||||
case V4:
|
||||
PwGroupV4 rootV4 = ((PwDatabaseV4) pm).getRootGroup();
|
||||
((PwDatabaseV4) pm).populateGlobals(rootV4);
|
||||
passwordEncodingError = !pm.validatePasswordEncoding(password);
|
||||
searchHelper = new SearchDbHelper.SearchDbHelperV4(ctx);
|
||||
break;
|
||||
}
|
||||
loaded = true;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Load can't be performed with this Database version", e);
|
||||
loaded = false;
|
||||
}
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void loadData(Context ctx, PwDatabase pm, String password) {
|
||||
passwordEncodingError = !pm.validatePasswordEncoding(password);
|
||||
switch (pm.getVersion()) {
|
||||
case V3:
|
||||
searchHelper = new SearchDbHelper.SearchDbHelperV3(ctx);
|
||||
break;
|
||||
case V4:
|
||||
searchHelper = new SearchDbHelper.SearchDbHelperV4(ctx);
|
||||
break;
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public PwGroup Search(String str) {
|
||||
public PwGroup search(String str) {
|
||||
if (searchHelper == null) { return null; }
|
||||
return searchHelper.search(this.pm, str);
|
||||
try {
|
||||
switch (pm.getVersion()) {
|
||||
case V3:
|
||||
return ((SearchDbHelper.SearchDbHelperV3) searchHelper).search(((PwDatabaseV3) pm), str);
|
||||
case V4:
|
||||
return ((SearchDbHelper.SearchDbHelperV4) searchHelper).search(((PwDatabaseV4) pm), str);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Search can't be performed with this SearchHelper", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SaveData(Context ctx) throws IOException, PwDbOutputException {
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Queue;
|
||||
|
||||
public class SearchDbHelper<PwDatabaseVersion extends PwDatabase,
|
||||
public class SearchDbHelper<PwDatabaseVersion extends PwDatabase<PwGroupSearch, PwEntrySearch>,
|
||||
PwGroupSearch extends PwGroup<PwGroupSearch, PwGroupSearch, PwEntrySearch>,
|
||||
PwEntrySearch extends PwEntry<PwGroupSearch>> {
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SearchDbHelper<PwDatabaseVersion extends PwDatabase,
|
||||
|
||||
public PwGroupSearch search(PwDatabaseVersion pm, String qStr) {
|
||||
|
||||
PwGroupSearch group = (PwGroupSearch) pm.createGroup();
|
||||
PwGroupSearch group = pm.createGroup();
|
||||
group.setName(mCtx.getString(R.string.search_results));
|
||||
group.setEntries(new ArrayList<>());
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SearchDbHelper<PwDatabaseVersion extends PwDatabase,
|
||||
|
||||
Queue<PwGroupSearch> worklist = new LinkedList<>();
|
||||
if (pm.getRootGroup() != null) {
|
||||
worklist.add((PwGroupSearch) pm.getRootGroup());
|
||||
worklist.add(pm.getRootGroup());
|
||||
}
|
||||
|
||||
while (worklist.size() != 0) {
|
||||
@@ -92,7 +92,7 @@ public class SearchDbHelper<PwDatabaseVersion extends PwDatabase,
|
||||
return group;
|
||||
}
|
||||
|
||||
public void processEntries(PwEntrySearch entry, List<PwEntrySearch> results, String qStr, Locale loc) {
|
||||
private void processEntries(PwEntrySearch entry, List<PwEntrySearch> results, String qStr, Locale loc) {
|
||||
// Search all strings in the entry
|
||||
Iterator<String> iter = entry.stringIterator();
|
||||
while (iter.hasNext()) {
|
||||
|
||||
@@ -46,14 +46,14 @@ public class SearchResultsActivity extends ListNodesActivity {
|
||||
|
||||
setContentView(getLayoutInflater().inflate(R.layout.search_results, null));
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.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 = (RecyclerView) findViewById(R.id.nodes_list);
|
||||
listView = findViewById(R.id.nodes_list);
|
||||
View notFoundView = findViewById(R.id.not_found_container);
|
||||
|
||||
if ( mCurrentGroup == null || mCurrentGroup.numbersOfChildEntries() < 1 ) {
|
||||
@@ -74,7 +74,7 @@ public class SearchResultsActivity extends ListNodesActivity {
|
||||
if ( ! mDb.getLoaded() ) {
|
||||
finish();
|
||||
}
|
||||
return mDb.Search(getSearchStr(getIntent()).trim());
|
||||
return mDb.search(getSearchStr(getIntent()).trim());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user