diff --git a/app/src/main/java/com/keepassdroid/activities/EntryEditActivityV4.java b/app/src/main/java/com/keepassdroid/activities/EntryEditActivityV4.java
index 497b724cc..d7411bf53 100644
--- a/app/src/main/java/com/keepassdroid/activities/EntryEditActivityV4.java
+++ b/app/src/main/java/com/keepassdroid/activities/EntryEditActivityV4.java
@@ -19,10 +19,8 @@
*/
package com.keepassdroid.activities;
-import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
-import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
@@ -31,7 +29,6 @@ import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
-import com.kunzisoft.keepass.R;
import com.keepassdroid.app.App;
import com.keepassdroid.database.PwDatabaseV4;
import com.keepassdroid.database.PwEntry;
@@ -41,7 +38,8 @@ import com.keepassdroid.database.PwGroupIdV4;
import com.keepassdroid.database.PwGroupV4;
import com.keepassdroid.database.security.ProtectedString;
import com.keepassdroid.utils.Types;
-import com.keepassdroid.view.EntryEditSection;
+import com.keepassdroid.view.EntryEditNewField;
+import com.kunzisoft.keepass.R;
import java.util.ArrayList;
import java.util.Iterator;
@@ -52,7 +50,6 @@ import java.util.UUID;
public class EntryEditActivityV4 extends EntryEditActivity {
private ScrollView scroll;
- private LayoutInflater inflater;
protected static void putParentId(Intent i, String parentKey, PwGroupV4 parent) {
PwGroupId id = parent.getId();
@@ -72,13 +69,11 @@ public class EntryEditActivityV4 extends EntryEditActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
- inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
super.onCreate(savedInstanceState);
scroll = (ScrollView) findViewById(R.id.entry_scroll);
- View add = findViewById(R.id.add_advanced);
+ View add = findViewById(R.id.add_new_field);
add.setVisibility(View.VISIBLE);
add.setOnClickListener(new View.OnClickListener() {
@@ -86,7 +81,7 @@ public class EntryEditActivityV4 extends EntryEditActivity {
public void onClick(View v) {
LinearLayout container = (LinearLayout) findViewById(R.id.advanced_container);
- EntryEditSection ees = (EntryEditSection) inflater.inflate(R.layout.entry_edit_section, container, false);
+ EntryEditNewField ees = new EntryEditNewField(EntryEditActivityV4.this);
ees.setData("", new ProtectedString(false, ""));
container.addView(ees);
@@ -97,10 +92,8 @@ public class EntryEditActivityV4 extends EntryEditActivity {
scroll.fullScroll(ScrollView.FOCUS_DOWN);
}
});
-
}
});
-
}
@Override
@@ -116,12 +109,11 @@ public class EntryEditActivityV4 extends EntryEditActivity {
String key = pair.getKey();
if (!PwEntryV4.IsStandardString(key)) {
- EntryEditSection ees = (EntryEditSection) inflater.inflate(R.layout.entry_edit_section, container, false);
+ EntryEditNewField ees = new EntryEditNewField(EntryEditActivityV4.this);
ees.setData(key, pair.getValue());
container.addView(ees);
}
}
-
}
}
@@ -148,55 +140,30 @@ public class EntryEditActivityV4 extends EntryEditActivity {
LinearLayout container = (LinearLayout) findViewById(R.id.advanced_container);
for (int i = 0; i < container.getChildCount(); i++) {
- View view = container.getChildAt(i);
-
- TextView keyView = (TextView)view.findViewById(R.id.title);
- String key = keyView.getText().toString();
-
- TextView valueView = (TextView)view.findViewById(R.id.value);
- String value = valueView.getText().toString();
-
- CheckBox cb = (CheckBox)view.findViewById(R.id.protection);
- boolean protect = cb.isChecked();
-
+ EntryEditNewField view = (EntryEditNewField) container.getChildAt(i);
+ String key = view.getLabel();
+ String value = view.getValue();
+ boolean protect = view.isProtected();
strings.put(key, new ProtectedString(protect, value));
}
return newEntry;
}
-
- public void deleteAdvancedString(View view) {
- ViewGroup section = (ViewGroup) view.getParent();
- LinearLayout container = (LinearLayout) findViewById(R.id.advanced_container);
-
- for (int i = 0; i < container.getChildCount(); i++) {
- ViewGroup ees = (ViewGroup) container.getChildAt(i);
- if (ees == section) {
- container.removeViewAt(i);
- container.invalidate();
- break;
- }
- }
- }
@Override
protected boolean validateBeforeSaving() {
if(!super.validateBeforeSaving()) {
return false;
}
-
- LinearLayout container = (LinearLayout) findViewById(R.id.advanced_container);
+
+ ViewGroup container = (ViewGroup) findViewById(R.id.advanced_container);
for (int i = 0; i < container.getChildCount(); i++) {
- EntryEditSection ees = (EntryEditSection) container.getChildAt(i);
-
- TextView keyView = (TextView) ees.findViewById(R.id.title);
- CharSequence key = keyView.getText();
-
+ EntryEditNewField ees = (EntryEditNewField) container.getChildAt(i);
+ String key = ees.getLabel();
if (key == null || key.length() == 0) {
Toast.makeText(this, R.string.error_string_key, Toast.LENGTH_LONG).show();
return false;
}
-
}
return true;
diff --git a/app/src/main/java/com/keepassdroid/view/EntryEditNewField.java b/app/src/main/java/com/keepassdroid/view/EntryEditNewField.java
new file mode 100644
index 000000000..064c874a3
--- /dev/null
+++ b/app/src/main/java/com/keepassdroid/view/EntryEditNewField.java
@@ -0,0 +1,99 @@
+/*
+ * 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 .
+ *
+ */
+package com.keepassdroid.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.CompoundButton;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.keepassdroid.database.security.ProtectedString;
+import com.kunzisoft.keepass.R;
+
+public class EntryEditNewField extends RelativeLayout {
+
+ private TextView labelView;
+ private TextView valueView;
+ private CompoundButton protectionCheckView;
+
+ public EntryEditNewField(Context context) {
+ this(context, null);
+ }
+
+ public EntryEditNewField(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public EntryEditNewField(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ assert inflater != null;
+ inflater.inflate(R.layout.entry_edit_new_field, this);
+
+ View deleteView = findViewById(R.id.entry_edit_new_field_delete);
+ deleteView.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ deleteViewFromParent();
+ }
+ });
+
+ labelView = (TextView) findViewById(R.id.entry_edit_new_field_label);
+ valueView = (TextView) findViewById(R.id.entry_edit_new_field_value);
+ protectionCheckView = (CompoundButton) findViewById(R.id.protection);
+ }
+
+ public void setData(String label, ProtectedString value) {
+ if (label != null)
+ labelView.setText(label);
+ if (value != null) {
+ valueView.setText(value.toString());
+ protectionCheckView.setChecked(value.isProtected());
+ }
+ }
+
+ public String getLabel() {
+ return labelView.getText().toString();
+ }
+
+ public String getValue() {
+ return valueView.getText().toString();
+ }
+
+ public boolean isProtected() {
+ return protectionCheckView.isChecked();
+ }
+
+ public void deleteViewFromParent() {
+ try {
+ ViewGroup parent = (ViewGroup) getParent();
+ parent.removeView(this);
+ parent.invalidate();
+ } catch (ClassCastException e) {
+ Log.e(getClass().getName(), e.getMessage());
+ }
+ }
+}
diff --git a/app/src/main/java/com/keepassdroid/view/EntryEditSection.java b/app/src/main/java/com/keepassdroid/view/EntryEditSection.java
deleted file mode 100644
index e458bc23b..000000000
--- a/app/src/main/java/com/keepassdroid/view/EntryEditSection.java
+++ /dev/null
@@ -1,60 +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 .
- *
- */
-package com.keepassdroid.view;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.widget.CheckBox;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-
-import com.kunzisoft.keepass.R;
-import com.keepassdroid.database.security.ProtectedString;
-
-public class EntryEditSection extends RelativeLayout {
-
- public EntryEditSection(Context context) {
- super(context);
- }
-
- public EntryEditSection(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public EntryEditSection(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- public void setData(String title, ProtectedString value) {
- setText(R.id.title, title);
- setText(R.id.value, value.toString());
-
- CheckBox cb = (CheckBox) findViewById(R.id.protection);
- cb.setChecked(value.isProtected());
- }
-
- private void setText(int resId, String str) {
- if (str != null) {
- TextView tvTitle = (TextView) findViewById(resId);
- tvTitle.setText(str);
- }
-
- }
-}
diff --git a/app/src/main/res/layout/entry_edit.xml b/app/src/main/res/layout/entry_edit.xml
index 3bb2bb956..2bf1d2363 100644
--- a/app/src/main/res/layout/entry_edit.xml
+++ b/app/src/main/res/layout/entry_edit.xml
@@ -177,7 +177,7 @@
android:orientation="vertical">
- .
-->
-
-
-
-
-
+ android:layout_height="match_parent"
+ android:paddingTop="12dp"
+ android:paddingBottom="12dp">
+ android:layout_toLeftOf="@+id/entry_edit_new_field_delete"
+ android:layout_toStartOf="@+id/entry_edit_new_field_delete">
-
+ android:maxLines="1" />
+
+
+
+
-
-
\ No newline at end of file
+