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

Move entry to different group and share DB #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions res/layout/entry_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,25 @@
android:layout_above="@id/entry_divider">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Parent -->
<TextView android:id="@+id/entry_parent_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/entry_parent" />

<Spinner
android:id="@+id/entry_parent_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/entry_parent_label" />

<!-- Title -->
<TextView android:id="@+id/entry_title_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/entry_parent_spinner"
android:text="@string/entry_title" />
<ImageButton android:id="@+id/icon_button"
android:layout_width="wrap_content"
Expand Down
5 changes: 5 additions & 0 deletions res/menu-v11/password.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
android:title="@string/menu_app_settings"
android:showAsAction="ifRoom"
/>
<item android:id="@+id/menu_share"
android:title="@string/menu_share"
android:icon="@android:drawable/ic_menu_share"
android:showAsAction="ifRoom"
/>
</menu>
4 changes: 4 additions & 0 deletions res/menu/password.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
android:icon="@android:drawable/ic_menu_help"
android:title="@string/menu_about"
/>
<item android:id="@+id/menu_share"
android:icon="@android:drawable/ic_menu_share"
android:title="@string/menu_share"
/>
</menu>
3 changes: 3 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@
<item>Medium</item>
<item>Large</item>
</string-array>
<string name="entry_parent">Group:</string>
<string name="menu_share">Share</string>
<string name="send_to">Send to</string>
</resources>
46 changes: 44 additions & 2 deletions src/com/keepassdroid/EntryEditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.UUID;

Expand All @@ -37,9 +38,11 @@
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -51,6 +54,7 @@
import com.keepassdroid.database.PwEntryV3;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.PwGroupV3;
import com.keepassdroid.database.PwGroupIdV3;
import com.keepassdroid.database.edit.AddEntry;
import com.keepassdroid.database.edit.OnFinish;
import com.keepassdroid.database.edit.RunnableOnFinish;
Expand All @@ -70,6 +74,7 @@ public class EntryEditActivity extends LockCloseActivity {
private boolean mShowPassword = false;
private boolean mIsNew;
private int mSelectedIconID = -1;
private ArrayAdapter<PwGroup> mGroupsAdapter;

public static void Launch(Activity act, PwEntry pw) {
if ( !(pw instanceof PwEntryV3) ) {
Expand Down Expand Up @@ -118,6 +123,7 @@ protected void onCreate(Bundle savedInstanceState) {

mEntry = new PwEntryV3(db, groupId);
mIsNew = true;
fillGroupsAndSelect(groupId);

} else {
UUID uuid = Types.bytestoUUID(uuidBytes);
Expand Down Expand Up @@ -176,7 +182,9 @@ public void onClick(View v) {
PwEntryV3 newEntry = new PwEntryV3();

newEntry.binaryDesc = mEntry.binaryDesc;
newEntry.groupId = mEntry.groupId;
//newEntry.groupId = mEntry.groupId;
newEntry.groupId = getSelectedGroupId();
newEntry.parent = (PwGroupV3)App.getDB().groups.get(new PwGroupIdV3(newEntry.groupId));

if (mSelectedIconID == -1) {
if (mIsNew) {
Expand All @@ -190,7 +198,7 @@ public void onClick(View v) {
newEntry.icon = App.getDB().pm.iconFactory.getIcon(mSelectedIconID);
}

newEntry.parent = mEntry.parent;
//newEntry.parent = mEntry.parent;
newEntry.tCreation = mEntry.tCreation;
newEntry.tExpire = mEntry.tExpire;
newEntry.setUUID(mEntry.getUUID());
Expand Down Expand Up @@ -257,7 +265,40 @@ public void onClick(View v) {
pass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
conf.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
}
}

private void fillGroupsAndSelect(int groupId) {
mGroupsAdapter = new ArrayAdapter<PwGroup>(this, android.R.layout.simple_spinner_item);
mGroupsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner spinner = (Spinner) findViewById(R.id.entry_parent_spinner);
spinner.setAdapter(mGroupsAdapter);
addGroups(App.getDB().groups.values());
for(int i = 0; i < mGroupsAdapter.getCount(); ++i) {
PwGroup item = mGroupsAdapter.getItem(i);
if (item instanceof PwGroupV3 && ((PwGroupV3)item).groupId == groupId) {
spinner.setSelection(i, false);
return;
}
}
}

private void addGroups(Collection<PwGroup> groups) {
if (groups.isEmpty()) {
return;
}
for (PwGroup group : groups) {
mGroupsAdapter.add(group);
// addGroups(group.childGroups);
}
}

protected int getSelectedGroupId() {
Spinner spinner = (Spinner) findViewById(R.id.entry_parent_spinner);
Object obj = spinner.getSelectedItem();
if (obj instanceof PwGroupV3) {
return ((PwGroupV3)obj).groupId;
}
return 0;
}

@Override
Expand Down Expand Up @@ -337,6 +378,7 @@ private void setPasswordStyle() {
}

private void fillData() {
fillGroupsAndSelect(mEntry.groupId);
ImageButton currIconButton = (ImageButton) findViewById(R.id.icon_button);
App.getDB().drawFactory.assignDrawableTo(currIconButton, getResources(), mEntry.getIcon());

Expand Down
13 changes: 13 additions & 0 deletions src/com/keepassdroid/PasswordActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
Expand Down Expand Up @@ -72,6 +73,7 @@ public class PasswordActivity extends LockingActivity {
private String mKeyFile;
private boolean mRememberKeyfile;
SharedPreferences prefs;
BroadcastReceiver mIntentReceiver;

public static void Launch(Activity act, String fileName) throws FileNotFoundException {
Launch(act,fileName,"");
Expand Down Expand Up @@ -370,11 +372,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.menu_app_settings:
AppSettingsActivity.Launch(this);
return true;
case R.id.menu_share:
shareFile();
return true;
}

return super.onOptionsItemSelected(item);
}

private void shareFile() {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(mFileName)));
shareIntent.setType("application/octet-stream");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
}

private final class AfterLoad extends OnFinish {

public AfterLoad(Handler handler) {
Expand Down
1 change: 1 addition & 0 deletions src/com/keepassdroid/database/PwEntryV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public Object clone() {

newEntry.parent = parent;

newEntry.groupId = groupId;

return newEntry;
}
Expand Down
17 changes: 17 additions & 0 deletions src/com/keepassdroid/database/edit/UpdateEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public UpdateEntry(Database db, PwEntry oldE, PwEntry newE, OnFinish finish) {

@Override
public void run() {
//move to the new group
if (!mOldE.getParent().equals(mNewE.getParent())) {
mOldE.getParent().childEntries.remove(mOldE);
mNewE.getParent().childEntries.add(mOldE);
}

// Update entry with new values
mOldE.assign(mNewE);

Expand Down Expand Up @@ -76,8 +82,19 @@ public void run() {

}
}
// if group changed, sort new group and mark both groups as dirty
if (!mBackup.getParent().equals(mNewE.getParent())) {
mNewE.getParent().sortEntriesByName();
mDb.dirty.add(mNewE.getParent());
mDb.dirty.add(mBackup.getParent());
}
} else {
// If we fail to save, back out changes to global structure
// move back to original group if they changed
if (!mBackup.getParent().equals(mNewE.getParent())) {
mBackup.getParent().childEntries.add(mOldE);
mNewE.getParent().childEntries.remove(mOldE);
}
mOldE.assign(mBackup);
}

Expand Down