diff --git a/res/layout/entry_edit.xml b/res/layout/entry_edit.xml index acda809bb..955bd965a 100644 --- a/res/layout/entry_edit.xml +++ b/res/layout/entry_edit.xml @@ -43,10 +43,25 @@ android:layout_above="@id/entry_divider"> + + + + + + diff --git a/res/menu/password.xml b/res/menu/password.xml index e30daea3c..b7f90f64c 100644 --- a/res/menu/password.xml +++ b/res/menu/password.xml @@ -26,4 +26,8 @@ android:icon="@android:drawable/ic_menu_help" android:title="@string/menu_about" /> + diff --git a/res/values/strings.xml b/res/values/strings.xml index 4faf4892c..111936da1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -180,4 +180,7 @@ Medium Large + Group: + Share + Send to diff --git a/src/com/keepassdroid/EntryEditActivity.java b/src/com/keepassdroid/EntryEditActivity.java index e411d8834..f6f7f7684 100644 --- a/src/com/keepassdroid/EntryEditActivity.java +++ b/src/com/keepassdroid/EntryEditActivity.java @@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException; import java.util.Calendar; +import java.util.Collection; import java.util.Date; import java.util.UUID; @@ -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; @@ -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; @@ -70,6 +74,7 @@ public class EntryEditActivity extends LockCloseActivity { private boolean mShowPassword = false; private boolean mIsNew; private int mSelectedIconID = -1; + private ArrayAdapter mGroupsAdapter; public static void Launch(Activity act, PwEntry pw) { if ( !(pw instanceof PwEntryV3) ) { @@ -118,6 +123,7 @@ protected void onCreate(Bundle savedInstanceState) { mEntry = new PwEntryV3(db, groupId); mIsNew = true; + fillGroupsAndSelect(groupId); } else { UUID uuid = Types.bytestoUUID(uuidBytes); @@ -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) { @@ -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()); @@ -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(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 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 @@ -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()); diff --git a/src/com/keepassdroid/PasswordActivity.java b/src/com/keepassdroid/PasswordActivity.java index 11f10bbb5..860dea072 100644 --- a/src/com/keepassdroid/PasswordActivity.java +++ b/src/com/keepassdroid/PasswordActivity.java @@ -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; @@ -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,""); @@ -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) { diff --git a/src/com/keepassdroid/database/PwEntryV3.java b/src/com/keepassdroid/database/PwEntryV3.java index 9a5f0fa3e..f5eef23e8 100644 --- a/src/com/keepassdroid/database/PwEntryV3.java +++ b/src/com/keepassdroid/database/PwEntryV3.java @@ -315,6 +315,7 @@ public Object clone() { newEntry.parent = parent; + newEntry.groupId = groupId; return newEntry; } diff --git a/src/com/keepassdroid/database/edit/UpdateEntry.java b/src/com/keepassdroid/database/edit/UpdateEntry.java index b12ed3404..6e39d397d 100644 --- a/src/com/keepassdroid/database/edit/UpdateEntry.java +++ b/src/com/keepassdroid/database/edit/UpdateEntry.java @@ -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); @@ -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); }