Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some issues. Feel free to pull partially or fully #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<meta-data android:name="android.app.default_searchable"
android:value="com.keepassdroid.search.SearchResults" />
</activity>
<activity android:name="com.keepassdroid.EntryActivity"
<activity android:name="com.keepassdroid.EntryActivity" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar"></activity>
<activity android:name="com.keepassdroid.EntryActivityV4"
<activity android:name="com.keepassdroid.EntryActivityV4" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar"></activity>
<activity android:name="com.keepassdroid.LockingActivity"
android:theme="@android:style/Theme.NoTitleBar"></activity>
Expand Down
Binary file added res/drawable/notify_profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions src/com/keepassdroid/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
import com.keepassdroid.database.load.ImporterFactory;
import com.keepassdroid.database.save.PwDbOutput;
import com.keepassdroid.icons.DrawableFactory;
import com.keepassdroid.search.SearchDbHelper;
import com.keepassdroid.search.InMemorySearchHelper;
import com.keepassdroid.search.SearchHelper;

/**
* @author bpellin
Expand All @@ -59,7 +60,7 @@ public class Database {
public PwGroup root;
public PwDatabase pm;
public String mFilename;
public SearchDbHelper searchHelper;
private SearchHelper searchHelper;
public boolean indexBuilt = false;

public DrawableFactory drawFactory = new DrawableFactory();
Expand Down Expand Up @@ -129,7 +130,8 @@ public void LoadData(Context ctx, InputStream is, String password, String keyfil
*/
public void buildSearchIndex(Context ctx) {

searchHelper = new SearchDbHelper(ctx);
searchHelper = new InMemorySearchHelper();
// searchHelper = new SearchDbHelper(ctx);

initSearch();

Expand Down Expand Up @@ -235,5 +237,12 @@ public void markAllGroupsAsDirty() {
}
}

public SearchHelper getSearchHelper() {
if( searchHelper == null ) {
searchHelper = new InMemorySearchHelper();
}
return searchHelper;
}


}
44 changes: 32 additions & 12 deletions src/com/keepassdroid/EntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,19 @@ protected void onCreate(Bundle savedInstanceState) {
// Notification Manager
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

String title = mEntry.getTitle();
if( title == null ) {
title = "";
}
if ( mEntry.getPassword().length() > 0 ) {
// only show notification if password is available
Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password);
// only show notification if password is available
Notification password = getNotification(Intents.COPY_PASSWORD, String.format( "%s [%s]", getString(R.string.copy_password), title ), R.drawable.notify);
mNM.notify(NOTIFY_PASSWORD, password);
}

if ( mEntry.getUsername().length() > 0 ) {
// only show notification if username is available
Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username);
Notification username = getNotification(Intents.COPY_USERNAME, String.format( "%s [%s]", getString(R.string.copy_username), title ), R.drawable.notify_profile);
mNM.notify(NOTIFY_USERNAME, username);
}

Expand Down Expand Up @@ -200,16 +204,32 @@ protected void onDestroy() {
super.onDestroy();
}

/**
* Get {@link Notification} using custom icon resource
* @param intentText
* @param desc
* @param icon
* @return
*/
private Notification getNotification(String intentText, String desc, int icon) {
Notification notify = new Notification(icon, desc, System.currentTimeMillis());

Intent intent = new Intent(intentText);
PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending);

return notify;
}

/**
* Get {@link Notification} using default icon (R.drawable.notify)
* @param intentText
* @param descResId
* @return
*/
private Notification getNotification(String intentText, int descResId) {
String desc = getString(descResId);
Notification notify = new Notification(R.drawable.notify, desc, System.currentTimeMillis());

Intent intent = new Intent(intentText);
PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending);

return notify;
return getNotification(intentText, getString(descResId), R.drawable.notify);
}

private String getDateTime(Date dt) {
Expand Down
5 changes: 2 additions & 3 deletions src/com/keepassdroid/compat/BackupManagerCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
import android.content.Context;


@SuppressWarnings("unchecked")
public class BackupManagerCompat {
private static Class classBackupManager;
private static Constructor constructorBackupManager;
private static Class<?> classBackupManager;
private static Constructor<?> constructorBackupManager;
private static Method dataChanged;

private Object backupManager;
Expand Down
4 changes: 2 additions & 2 deletions src/com/keepassdroid/database/edit/AddEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.keepassdroid.Database;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.search.SearchDbHelper;
import com.keepassdroid.search.SearchHelper;

public class AddEntry extends RunnableOnFinish {
protected Database mDb;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void run() {

if ( mDb.indexBuilt ) {
// Add entry to search index
SearchDbHelper helper = mDb.searchHelper;
SearchHelper helper = mDb.getSearchHelper();
helper.open();
helper.insertEntry(mDb.pm, mEntry);
helper.close();
Expand Down
4 changes: 2 additions & 2 deletions src/com/keepassdroid/database/edit/DeleteEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.keepassdroid.Database;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.search.SearchDbHelper;
import com.keepassdroid.search.SearchHelper;

/** Task to delete entries
* @author bpellin
Expand Down Expand Up @@ -88,7 +88,7 @@ public AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry) {
public void run() {
if ( mSuccess ) {
if ( mDb.indexBuilt ) {
SearchDbHelper dbHelper = mDb.searchHelper;
SearchHelper dbHelper = mDb.getSearchHelper();
dbHelper.open();

// Remove from entry global
Expand Down
4 changes: 2 additions & 2 deletions src/com/keepassdroid/database/edit/UpdateEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.keepassdroid.Database;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.search.SearchDbHelper;
import com.keepassdroid.search.SearchHelper;

public class UpdateEntry extends RunnableOnFinish {
private Database mDb;
Expand Down Expand Up @@ -79,7 +79,7 @@ public void run() {

if ( mDb.indexBuilt ) {
// Update search index
SearchDbHelper helper = mDb.searchHelper;
SearchHelper helper = mDb.getSearchHelper();
helper.open();
helper.updateEntry(mDb.pm, mOldE);
helper.close();
Expand Down
134 changes: 134 additions & 0 deletions src/com/keepassdroid/search/InMemorySearchHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright 2009-2011 Brian Pellin.
* Copyright 2011 riku salkia
*
* This file is part of KeePassDroid.
*
* KeePassDroid 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.
*
* KeePassDroid 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 KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid.search;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import android.util.Log;

import com.keepassdroid.Database;
import com.keepassdroid.database.PwDatabase;
import com.keepassdroid.database.PwDatabaseV3;
import com.keepassdroid.database.PwDatabaseV4;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwEntryV4;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.PwGroupV3;
import com.keepassdroid.database.PwGroupV4;

public class InMemorySearchHelper implements SearchHelper {
private static final String TAG = InMemorySearchHelper.class.getSimpleName();
private Map<UUID, Collection<String>> stringMap = new HashMap<UUID, Collection<String>>();

@Override
public SearchHelper open(){
return this;
}

@Override
public void close() {
}

@Override
public void clear() {
}

@Override
public void insertEntry(PwDatabase db, PwEntry entry) {
UUID uuid = entry.getUUID();
Collection<String> strings = new ArrayList<String>();
strings.add( entry.getTitle().toLowerCase() );
strings.add( entry.getUrl().toLowerCase() );
strings.add( entry.getUsername().toLowerCase() );
strings.add( entry.getNotes().toLowerCase() );

if( entry instanceof PwEntryV4 ) {
// Add Advanced keys&values https://code.google.com/p/keepassdroid/issues/detail?id=162
PwEntryV4 v4 = (PwEntryV4) entry;
for( String key : v4.strings.keySet() ) {
strings.add(key.toLowerCase());
strings.add(v4.strings.get(key).toLowerCase());
}
}

stringMap.put(uuid, strings);
}

@Override
public void insertEntry(PwDatabase db, List<? extends PwEntry> entries) {
for( PwEntry entry : entries ) {
insertEntry( db, entry );
}
}

@Override
public void updateEntry(PwDatabase db, PwEntry entry) {
insertEntry(db, entry);
}

@Override
public void deleteEntry(PwEntry entry) {
stringMap.remove( entry.getUUID() );
}

@Override
public PwGroup search(Database db, String qStr) {
long start = System.currentTimeMillis();

final String searchStr = qStr.toLowerCase();

PwGroup group;
if ( db.pm instanceof PwDatabaseV3 ) {
group = new PwGroupV3();
} else if ( db.pm instanceof PwDatabaseV4 ) {
group = new PwGroupV4();
} else {
Log.d(TAG, "Tried to search with unknown db");
return null;
}
group.name = "Search results";
group.childEntries = new ArrayList<PwEntry>();

int entries = 0;
int total = 0;

for( UUID uuid : stringMap.keySet() ) {
for( String str : stringMap.get(uuid) ) {
if( str.contains( searchStr ) ) {
PwEntry entry = (PwEntry) db.entries.get(uuid);
group.childEntries.add(entry);
}

total++;
}
entries++;
}
Log.d(TAG, String.format("Searched %d entries, %d strings. Search took %dms to complete", entries, total, System.currentTimeMillis()-start) );

return group;
}

}
Loading