Skip to content

Commit

Permalink
Use a specific row type instead of TextRow for the value widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Oct 19, 2024
1 parent 1380d1f commit 6a8489d
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,10 @@ void addRow(@Nullable final LinearLayout rowLayout, @NonNull final PresetTagFiel
rowLayout.addView(LongTextDialogRow.getRow(this, inflater, rowLayout, preset, (PresetTextField) field, value, maxStringLength));
return;
}
if ( ValueType.INTEGER == valueType || ValueType.CARDINAL_DIRECTION == valueType) {
rowLayout.addView(ValueWidgetRow.getRow(this, inflater, rowLayout, preset, field, value, values, allTags));
return;
}
rowLayout.addView(TextRow.getRow(this, inflater, rowLayout, preset, field, value, values, allTags));
return;
}
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/de/blau/android/propertyeditor/tagform/TextRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ static TextRow getRow(@NonNull final TagFormFragment caller, @NonNull final Layo
final TextRow row = (TextRow) inflater.inflate(R.layout.tag_form_text_row, rowLayout, false);
final String key = field.getKey();
final String hint = preset != null ? field.getHint() : null;
final String defaultValue = field.getDefaultValue();
row.valueType = preset != null ? preset.getValueType(key) : null;
final boolean isName = Tags.isLikeAName(key);
final Context context = rowLayout.getContext();
Expand Down Expand Up @@ -218,24 +217,6 @@ static TextRow getRow(@NonNull final TagFormFragment caller, @NonNull final Layo
dialog.show();
});
}
if (ValueType.INTEGER == valueType) {
ourValueView.setFocusable(false);
ourValueView.setFocusableInTouchMode(false);
ourValueView.setOnClickListener(v -> {
final View finalView = v;
finalView.setEnabled(false); // debounce
IntegerValueFragment.show(caller, hint != null ? hint : key, key, ((TextView) v).getText().toString(), values, preset, allTags);
});
}
if (ValueType.CARDINAL_DIRECTION == valueType) {
ourValueView.setFocusable(false);
ourValueView.setFocusableInTouchMode(false);
ourValueView.setOnClickListener(v -> {
final View finalView = v;
finalView.setEnabled(false); // debounce
DirectionValueFragment.show(caller, hint != null ? hint : key, key, ((TextView) v).getText().toString(), values, preset, allTags);
});
}
ourValueView.setOnFocusChangeListener((v, hasFocus) -> {
Log.d(DEBUG_TAG, "onFocusChange");
String rowValue = row.getValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package de.blau.android.propertyeditor.tagform;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import de.blau.android.R;
import de.blau.android.presets.PresetComboField;
import de.blau.android.presets.PresetItem;
import de.blau.android.presets.PresetTagField;
import de.blau.android.presets.ValueType;
import de.blau.android.propertyeditor.TagChanged;
import de.blau.android.util.StringWithDescription;
import de.blau.android.util.StringWithDescriptionAndIcon;
import de.blau.android.util.Value;
import de.blau.android.views.CustomAutoCompleteTextView;

public class ValueWidgetRow extends DialogRow implements TagChanged {

private ValueType valueType;
private PresetTagField field;

/**
* Construct a row that will display a Dialog when clicked
*
* @param context Android Context
*/
public ValueWidgetRow(@NonNull Context context) {
super(context);
}

/**
* Construct a row that will display a Dialog when clicked
*
* @param context Android Context
* @param attrs an AttributeSet
*/
public ValueWidgetRow(@NonNull Context context, AttributeSet attrs) {
super(context, attrs);
}

/**
* Add a row that displays a dialog for selecting a single when clicked
*
* @param caller the calling TagFormFragment instance
* @param inflater the inflater to use
* @param rowLayout the Layout holding the roes
* @param preset the relevant PresetItem
* @param field the current PresetTagField
* @param value the current value
* @param values all relevant values (preset MRU etc)
* @param allTags all current tags
* @return
*/
static ValueWidgetRow getRow(@NonNull final TagFormFragment caller, @NonNull final LayoutInflater inflater, @NonNull final LinearLayout rowLayout,
@NonNull final PresetItem preset, @NonNull final PresetTagField field, @NonNull final String value, @Nullable final List<String> values,
final Map<String, String> allTags) {
final ValueWidgetRow row = (ValueWidgetRow) inflater.inflate(R.layout.tag_form_value_widget_row, rowLayout, false);
final String key = field.getKey();
final String hint = preset != null ? field.getHint() : key;
row.keyView.setText(hint);
row.keyView.setTag(key);
row.setPreset(preset);
row.valueType = preset != null ? preset.getValueType(key) : null;
row.field = field;

row.valueView.setHint(R.string.tag_dialog_value_hint);
row.setValue(value == null ? "" : value);

row.valueView.setFocusable(false);
row.valueView.setFocusableInTouchMode(false);
row.setOnClickListener(v -> {
final View finalView = v;
finalView.setEnabled(false); // debounce
if (ValueType.INTEGER == row.valueType) {
IntegerValueFragment.show(caller, hint, key, row.getValue(), values, preset, allTags);
}
if (ValueType.CARDINAL_DIRECTION == row.valueType) {
DirectionValueFragment.show(caller, hint, key, row.getValue(), values, preset, allTags);
}
});
return row;
}

@Override
public void changed(String key, String value) {
if (key.equals(this.getKey())) {
valueView.setEnabled(true);
setValue(value);
}
}

@Override
public void setValue(@NonNull String value) {
// it might be simpler to simply use the normal autocomplete adapter here
if (field instanceof PresetComboField) {
for (StringWithDescription swd : ((PresetComboField) field).getValues()) {
if (value.equals(swd.getValue())) {
setValue(swd);
return;
}
}
}
super.setValue(value);
}
}
57 changes: 57 additions & 0 deletions src/main/res/layout/tag_form_value_widget_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- inner classes must be specified using <view class="classname" /> due to dollar sign -->
<view xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="de.blau.android.propertyeditor.tagform.ValueWidgetRow"
android:orientation="horizontal" >

<LinearLayout
style="?attr/Layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:saveEnabled="false" >

<TextView
android:id="@+id/textKey"
style="?attr/StaticText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="1dp"
android:layout_marginRight="1dp"
android:layout_marginEnd="1dp"
android:layout_weight="3"
android:gravity="center_vertical"
android:maxLines="3"
android:minHeight="34dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:saveEnabled="false" />

<TextView
android:id="@+id/textValue"
style="?attr/StaticText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_weight="2"
android:gravity="center_vertical"
android:drawableEnd="?attr/edit"
android:drawableRight="?attr/edit"
android:focusable="false"
android:focusableInTouchMode="false"
android:minHeight="34dp"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:paddingRight="3dp"
android:paddingEnd="3dp"
android:saveEnabled="false"
android:singleLine="true"
android:ellipsize="none" />
</LinearLayout>

</view>

0 comments on commit 6a8489d

Please sign in to comment.