Initial field-list editing

This commit is contained in:
ligi 2016-04-04 23:40:56 +02:00
parent 7db0de06c6
commit 94ac5499c6
8 changed files with 205 additions and 11 deletions

View file

@ -17,11 +17,15 @@ public class PassEditSteps {
}
public static void goToColor() {
public static void goToFields() {
goToImages();
onView(withId(R.id.passEditPager)).perform(swipeLeft());
}
public static void goToColor() {
goToFields();
onView(withId(R.id.passEditPager)).perform(swipeLeft());
}
public static void goToBarCode() {
goToColor();

View file

@ -22,7 +22,10 @@ object ApplePassbookQuirkCorrector {
}
fun getPassFieldThatMatchesLabel(pass: PassImpl, matcher: String): PassField? {
return pass.fields.firstOrNull() { it.label != null && it.label.matches(matcher.toRegex()) }
return pass.fields.firstOrNull() {
val label = it.label
label != null && label.matches(matcher.toRegex())
}
}
private fun careForRenfe(pass: PassImpl) {
@ -133,9 +136,12 @@ object ApplePassbookQuirkCorrector {
var description = "WESTbahn"
if (originField != null && originField.value != null) {
App.component().tracker().trackEvent("quirk_fix", "description_replace", "westbahn", 1L)
description = originField.value
if (originField != null ) {
val value = originField.value
if (value != null) {
App.component().tracker().trackEvent("quirk_fix", "description_replace", "westbahn", 1L)
description = value
}
}
if (destinationField != null) {

View file

@ -1,6 +1,6 @@
package org.ligi.passandroid.model
class PassField(val key: String?, val label: String?, val value: String?,val hide:Boolean) {
class PassField(var key: String?, var label: String?, var value: String?,var hide:Boolean) {
fun toHtmlSnippet(): String {
val result=StringBuilder()

View file

@ -25,6 +25,7 @@ import org.ligi.passandroid.model.Settings;
import org.ligi.passandroid.ui.edit_fragments.BarcodeEditFragment;
import org.ligi.passandroid.ui.edit_fragments.CategoryPickFragment;
import org.ligi.passandroid.ui.edit_fragments.ColorPickFragment;
import org.ligi.passandroid.ui.edit_fragments.FieldsEditFragment;
import org.ligi.passandroid.ui.edit_fragments.ImageEditFragment;
import org.ligi.passandroid.ui.edit_fragments.MetaDataFragment;
import org.ligi.passandroid.ui.pass_view_holder.CondensedPassViewHolder;
@ -93,9 +94,11 @@ public class PassEditActivity extends AppCompatActivity {
case 2:
return "Images";
case 3:
return "Fields";
case 4:
return "Color";
case 4:
case 5:
default:
return "BarCode";
}
@ -111,9 +114,11 @@ public class PassEditActivity extends AppCompatActivity {
case 2:
return new ImageEditFragment();
case 3:
return new FieldsEditFragment();
case 4:
return new ColorPickFragment();
case 4:
case 5:
default:
return new BarcodeEditFragment();
}
@ -121,7 +126,7 @@ public class PassEditActivity extends AppCompatActivity {
@Override
public int getCount() {
return 5;
return 6;
}
}

View file

@ -267,8 +267,7 @@ public class PassListActivity extends PassAndroidActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_emptytrash).setVisible(adapter.getPageTitle(viewPager.getCurrentItem()).equals(getString(R.string.topic_trash)));
menu.findItem(R.id.menu_emptytrash).setVisible((adapter.getCount()>0) && adapter.getPageTitle(viewPager.getCurrentItem()).equals(getString(R.string.topic_trash)));
return true;
}

View file

@ -0,0 +1,107 @@
package org.ligi.passandroid.ui.edit_fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.v7.widget.SwitchCompat;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import java.util.List;
import org.ligi.axt.simplifications.SimpleTextWatcher;
import org.ligi.passandroid.R;
import org.ligi.passandroid.model.PassField;
public class FieldsEditFragment extends PassandroidFragment {
@Bind(R.id.fields_container)
ViewGroup viewGroup;
@OnClick(R.id.add_field)
void onAddField() {
final PassField passField = new PassField(null, null, null, false);
addField(passField);
getPass().getFields().add(passField);
}
private LayoutInflater inflater;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
this.inflater=inflater;
final View inflate = inflater.inflate(R.layout.edit_fields, container, false);
ButterKnife.bind(this, inflate);
for (final PassField passField : getPass().getFields()) {
addField(passField);
}
return inflate;
}
public void addField(final PassField passField) {
final ViewGroup child = (ViewGroup) inflater.inflate(R.layout.edit_field, viewGroup, false);
new FieldView(child).apply(passField, getPass().getFields());
viewGroup.addView(child);
}
class FieldView {
@Bind(R.id.label_field_edit)
TextInputEditText labelEdit;
@Bind(R.id.value_field_edit)
TextInputEditText valueEdit;
@Bind(R.id.delete_button)
ImageButton deleteButton;
@Bind(R.id.hide_switch)
SwitchCompat hideSwitch;
FieldView(final ViewGroup container) {
ButterKnife.bind(this,container);
}
public void apply(final PassField passField, final List<PassField> fields) {
labelEdit.setText(passField.getLabel());
valueEdit.setText(passField.getValue());
hideSwitch.setChecked(passField.getHide());
hideSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
passField.setHide(isChecked);
}
});
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
((View)(v.getParent())).setVisibility(View.GONE);
fields.remove(passField);
}
});
valueEdit.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(final Editable s) {
passField.setValue(s.toString());
}
});
labelEdit.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(final Editable s) {
passField.setLabel(s.toString());
}
});
}
}
}

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fields_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/delete_button"
android:src="@drawable/ic_action_delete"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/hide_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hide"
android:layout_gravity="center_vertical"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content" android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/label_field_edit"
android:minWidth="64dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:hint="label"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content" android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/value_field_edit"
android:minWidth="64dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:hint="value"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/fields_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<Button
android:id="@+id/add_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="add Field"/>
</LinearLayout>
</ScrollView>