Solve bug for new field

This commit is contained in:
J-Jamet committed 2018-02-19 21:21:23 +01:00
1 parent 0a386c3985
commit 87c9aeeb12
5 files changed
+146 -138

No files matched your search

@@ -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;
@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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());
}
}
}
@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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);
}
}
}