Skip to content

Commit a75d606

Browse files
authored
Disable entering 0 in count fields (#476)
1 parent 1653eec commit a75d606

16 files changed

+76
-25
lines changed

app/src/main/java/org/bspb/smartbirds/pro/ui/fragment/NewBirdsEntryRequiredFormFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.bspb.smartbirds.pro.prefs.BirdPrefs;
2222
import org.bspb.smartbirds.pro.prefs.CommonPrefs;
2323
import org.bspb.smartbirds.pro.ui.views.DecimalNumberFormInput;
24+
import org.bspb.smartbirds.pro.ui.views.PositiveDecimalNumberFormInput;
2425
import org.bspb.smartbirds.pro.ui.views.SingleChoiceFormInput;
2526
import org.bspb.smartbirds.pro.ui.views.SwitchFormInput;
2627

@@ -41,7 +42,7 @@ public class NewBirdsEntryRequiredFormFragment extends BaseFormFragment {
4142

4243
SingleChoiceFormInput countUnits;
4344
SingleChoiceFormInput countType;
44-
DecimalNumberFormInput count;
45+
PositiveDecimalNumberFormInput count;
4546
DecimalNumberFormInput countMin;
4647
DecimalNumberFormInput countMax;
4748
SwitchFormInput confidential;

app/src/main/java/org/bspb/smartbirds/pro/ui/fragment/NewHerptileEntryRequiredFormFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.bspb.smartbirds.pro.R;
1212
import org.bspb.smartbirds.pro.prefs.CommonPrefs;
1313
import org.bspb.smartbirds.pro.prefs.HerptilePrefs;
14-
import org.bspb.smartbirds.pro.ui.views.DecimalNumberFormInput;
14+
import org.bspb.smartbirds.pro.ui.views.PositiveDecimalNumberFormInput;
1515
import org.bspb.smartbirds.pro.ui.views.SingleChoiceFormInput;
1616
import org.bspb.smartbirds.pro.ui.views.SwitchFormInput;
1717

@@ -24,7 +24,7 @@
2424
public class NewHerptileEntryRequiredFormFragment extends BaseFormFragment {
2525

2626
SingleChoiceFormInput habitat;
27-
DecimalNumberFormInput count;
27+
PositiveDecimalNumberFormInput count;
2828
SwitchFormInput confidential;
2929

3030
HerptilePrefs prefs;

app/src/main/java/org/bspb/smartbirds/pro/ui/fragment/NewMammalEntryRequiredFormFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.bspb.smartbirds.pro.R;
1212
import org.bspb.smartbirds.pro.prefs.CommonPrefs;
1313
import org.bspb.smartbirds.pro.prefs.MammalPrefs;
14-
import org.bspb.smartbirds.pro.ui.views.DecimalNumberFormInput;
14+
import org.bspb.smartbirds.pro.ui.views.PositiveDecimalNumberFormInput;
1515
import org.bspb.smartbirds.pro.ui.views.SingleChoiceFormInput;
1616
import org.bspb.smartbirds.pro.ui.views.SwitchFormInput;
1717

@@ -24,7 +24,7 @@
2424
public class NewMammalEntryRequiredFormFragment extends BaseFormFragment {
2525

2626
SingleChoiceFormInput habitat;
27-
DecimalNumberFormInput count;
27+
PositiveDecimalNumberFormInput count;
2828
SwitchFormInput confidential;
2929

3030
MammalPrefs prefs;
@@ -97,7 +97,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
9797
@Override
9898
protected void initViews() {
9999
super.initViews();
100-
100+
101101
habitat = requireView().findViewById(R.id.form_herp_habitat);
102102
count = requireView().findViewById(R.id.form_herp_count);
103103
confidential = requireView().findViewById(R.id.form_mammals_confidential);

app/src/main/java/org/bspb/smartbirds/pro/ui/fragment/NewThreatsEntryRequiredFormFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.bspb.smartbirds.pro.R;
1515
import org.bspb.smartbirds.pro.prefs.CommonPrefs;
1616
import org.bspb.smartbirds.pro.ui.utils.FormsConfig;
17-
import org.bspb.smartbirds.pro.ui.views.DecimalNumberFormInput;
17+
import org.bspb.smartbirds.pro.ui.views.PositiveDecimalNumberFormInput;
1818
import org.bspb.smartbirds.pro.ui.views.SingleChoiceConfigFormInput;
1919
import org.bspb.smartbirds.pro.ui.views.SingleChoiceConfigRadioFormInput;
2020
import org.bspb.smartbirds.pro.ui.views.SingleChoiceFormInput;
@@ -42,7 +42,7 @@ public static NewThreatsEntryRequiredFormFragment newInstance(boolean isNewEntry
4242
SingleChoiceFormInput category;
4343
SingleChoiceConfigFormInput classInput;
4444
SingleChoiceFormInput species;
45-
DecimalNumberFormInput count;
45+
PositiveDecimalNumberFormInput count;
4646
SingleChoiceFormInput estimate;
4747
SingleChoiceConfigRadioFormInput poisonedType;
4848
SingleChoiceFormInput stateCarcass;

app/src/main/java/org/bspb/smartbirds/pro/ui/views/FormBirdsRow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class FormBirdsRow extends LinearLayout implements SingleChoiceFormInput.
2626
protected SingleChoiceFormInput species;
2727
protected SingleChoiceFormInput countUnits;
2828
protected SingleChoiceFormInput countType;
29-
protected DecimalNumberFormInput count;
29+
protected PositiveDecimalNumberFormInput count;
3030
protected DecimalNumberFormInput countMin;
3131
protected DecimalNumberFormInput countMax;
3232

app/src/main/java/org/bspb/smartbirds/pro/ui/views/SumDecimalNumberFormInput.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.bspb.smartbirds.pro.ui.views;
22

3+
import static android.text.TextUtils.isEmpty;
4+
35
import android.content.Context;
46
import android.text.Editable;
57
import android.text.method.DigitsKeyListener;
@@ -10,8 +12,6 @@
1012

1113
import java.util.regex.Pattern;
1214

13-
import static android.text.TextUtils.isEmpty;
14-
1515
/**
1616
* Input field for numbers that will be summed together.
1717
* Ime actions Go / Next are replaced with + sign. When a number is chosen then pressing the
@@ -21,7 +21,7 @@
2121
* <p>
2222
* Created by Ilian Georgiev.
2323
*/
24-
public class SumDecimalNumberFormInput extends DecimalNumberFormInput {
24+
public class SumDecimalNumberFormInput extends PositiveDecimalNumberFormInput {
2525

2626
private static final String PLUS = "+";
2727
private static final String PLUS_PATTERN = Pattern.quote(PLUS);
@@ -47,6 +47,8 @@ public SumDecimalNumberFormInput(Context context, AttributeSet attrs, int defSty
4747
setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NAVIGATE_NEXT);
4848
setImeActionLabel(context.getText(R.string.sum_decimal_number_form_input_plus), EditorInfo.IME_ACTION_NEXT);
4949
setKeyListener(DigitsKeyListener.getInstance("0123456789+"));
50+
51+
setIncludeZero(false);
5052
}
5153

5254
@Override

app/src/main/kotlin/org/bspb/smartbirds/pro/ui/views/PositiveDecimalNumberFormInput.kt

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,48 @@ package org.bspb.smartbirds.pro.ui.views
22

33
import android.content.Context
44
import android.util.AttributeSet
5+
import androidx.core.content.withStyledAttributes
56
import org.bspb.smartbirds.pro.R
67

7-
class PositiveDecimalNumberFormInput : TextFormInput {
8+
open class PositiveDecimalNumberFormInput : TextFormInput {
9+
10+
var includeZero = true
811

912
constructor(context: Context) : this(context, null)
1013

11-
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, R.attr.positiveDecimalNumberFormInputStyle)
1214

13-
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
15+
constructor(context: Context, attrs: AttributeSet?) : this(
16+
context,
17+
attrs,
18+
R.attr.positiveDecimalNumberFormInputStyle
19+
)
20+
21+
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
22+
context,
23+
attrs,
24+
defStyleAttr
25+
) {
26+
context.withStyledAttributes(
27+
attrs,
28+
R.styleable.PositiveDecimalNumberFormInput,
29+
defStyleAttr,
30+
0
31+
) {
32+
includeZero = getBoolean(R.styleable.PositiveDecimalNumberFormInput_includeZero, true)
33+
}
34+
}
35+
36+
override fun onTextChanged(
37+
text: CharSequence?,
38+
start: Int,
39+
lengthBefore: Int,
40+
lengthAfter: Int,
41+
) {
42+
super.onTextChanged(text, start, lengthBefore, lengthAfter)
43+
text?.let {
44+
if (it.contentEquals("0") && !includeZero) {
45+
setText("")
46+
}
47+
}
48+
}
1449
}

app/src/main/res/layout-land/fragment_monitoring_form_new_herptile_required_entry.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@
9292
android:layout_height="wrap_content"
9393
android:layout_span="2">
9494

95-
<org.bspb.smartbirds.pro.ui.views.DecimalNumberFormInput
95+
<org.bspb.smartbirds.pro.ui.views.PositiveDecimalNumberFormInput
9696
android:id="@+id/form_herp_count"
9797
android:layout_width="match_parent"
9898
android:layout_height="wrap_content"
9999
android:hint="@string/monitoring_herp_count"
100100
android:tag="@string/tag_count"
101101
android:text="1"
102102
app:required="true"
103+
app:includeZero="false"
103104
tools:ignore="HardcodedText" />
104105
</com.google.android.material.textfield.TextInputLayout>
105106
</TableRow>

app/src/main/res/layout-land/fragment_monitoring_form_new_invertebrates_entry.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@
9292
android:layout_height="wrap_content"
9393
android:layout_span="2">
9494

95-
<org.bspb.smartbirds.pro.ui.views.DecimalNumberFormInput
95+
<org.bspb.smartbirds.pro.ui.views.PositiveDecimalNumberFormInput
9696
android:id="@+id/form_invertebrates_count"
9797
android:layout_width="match_parent"
9898
android:layout_height="wrap_content"
9999
android:hint="@string/monitoring_herp_count"
100100
android:tag="@string/tag_count"
101101
android:text="1"
102102
app:required="true"
103+
app:includeZero="false"
103104
tools:ignore="HardcodedText" />
104105
</com.google.android.material.textfield.TextInputLayout>
105106
</TableRow>

app/src/main/res/layout-land/fragment_monitoring_form_new_mammal_required_entry.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@
9292
android:layout_height="wrap_content"
9393
android:layout_span="2">
9494

95-
<org.bspb.smartbirds.pro.ui.views.DecimalNumberFormInput
95+
<org.bspb.smartbirds.pro.ui.views.PositiveDecimalNumberFormInput
9696
android:id="@+id/form_herp_count"
9797
android:layout_width="match_parent"
9898
android:layout_height="wrap_content"
9999
android:hint="@string/monitoring_herp_count"
100100
android:tag="@string/tag_count"
101101
android:text="1"
102102
app:required="true"
103+
app:includeZero="false"
103104
tools:ignore="HardcodedText" />
104105
</com.google.android.material.textfield.TextInputLayout>
105106
</TableRow>

0 commit comments

Comments
 (0)