Skip to content

Commit

Permalink
adds preference to return to first trait
Browse files Browse the repository at this point in the history
  • Loading branch information
bellerbrock committed Sep 6, 2023
1 parent bc888da commit 77abd20
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,10 @@ public boolean isCyclingTraitsAdvances() {
return ep.getBoolean(GeneralKeys.CYCLING_TRAITS_ADVANCES, false);
}

public boolean isReturnFirstTrait() {
return ep.getBoolean(GeneralKeys.RETURN_FIRST_TRAIT, false);
}

/**
* Inserts a user observation whenever a label is printed.
* See ResultReceiver onReceiveResult in LabelPrintLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface CollectRangeController: CollectController {
fun cancelAndFinish()
fun callFinish()
fun refreshMain()
fun isReturnFirstTrait(): Boolean
fun getNonExistingTraits(plotIndex: Int): List<Int>
fun existsAllTraits(traitIndex: Int, plotIndex: Int): Int
fun existsTrait(plotIndex: Int): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class GeneralKeys {
public static final String RETURN_CHARACTER = "RETURN_CHARACTER";
public static final String VOLUME_NAVIGATION = "VOLUME_NAVIGATION";
public static final String CYCLING_TRAITS_ADVANCES = "CycleTraits";
public static final String RETURN_FIRST_TRAIT = "ReturnFirst";
public static final String DISABLE_ENTRY_ARROW_NO_DATA = "DISABLE_ENTRY_ARROW_NO_DATA";

// General
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ class RangeBoxView : ConstraintLayout {
}

fun moveEntryRight() {
val traitBox = controller.getTraitBox()
if (!controller.validateData()) {
return
}
Expand All @@ -561,11 +562,14 @@ class RangeBoxView : ConstraintLayout {
}
val entryArrow =
controller.getPreferences().getString(GeneralKeys.DISABLE_ENTRY_ARROW_NO_DATA, "0")
if ((entryArrow == "2" || entryArrow == "3") && !controller.getTraitBox().existsTrait()) {
if ((entryArrow == "2" || entryArrow == "3") && !traitBox.existsTrait()) {
controller.getSoundHelper().playError()
} else {
if (rangeID.isNotEmpty()) {
//index.setEnabled(true);
if (controller.isReturnFirstTrait()) {
traitBox.returnFirst()
}
paging = incrementPaging(paging)
controller.refreshMain()
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/fieldbook/tracker/views/TraitBoxView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ class TraitBoxView : ConstraintLayout {
controller.getCollectInputView().resetInitialIndex()
}

fun returnFirst() {
if (!controller.validateData()) {
return
}
if (controller.getPreferences().getBoolean(GeneralKeys.CYCLE_TRAITS_SOUND, false)) {
controller.getSoundHelper().playCycle()
}
traitType.setSelection(0)
controller.refreshLock()
controller.getCollectInputView().resetInitialIndex()
}

fun update(parent: String?, value: String) {
if (newTraits.containsKey(parent!!)) {
newTraits.remove(parent)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/drawable/ic_adv_return_first_trait.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/ray_start_arrow.xml --><vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"><path android:fillColor="#000000" android:pathData="M23,12L19,16V13H6.83C6.42,14.17 5.31,15 4,15A3,3 0 0,1 1,12A3,3 0 0,1 4,9C5.31,9 6.42,9.83 6.83,11H19V8L23,12Z" /></vector>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@
<string name="preferences_behavior_cycle_traits">Cycling traits advances entry</string>
<string name="preferences_behavior_cycle_traits_description">After going through all traits, Field Book goes to the next entry</string>

<string name="preferences_behavior_return_to_first_trait">Advancing entry returns to first trait</string>
<string name="preferences_behavior_return_to_first_trait_description">When moving to the next entry, Field Book also returns to the first trait</string>

<string name="preferences_behavior_volume_buttons_navigate">Map volume keys to entry navigation</string>
<string name="preferences_behavior_volume_buttons_navigate_description">Volume keys go to next or previous entry</string>

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences_behavior.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
android:summary="@string/preferences_behavior_cycle_traits_description"
android:title="@string/preferences_behavior_cycle_traits" />

<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_adv_return_first_trait"
android:key="ReturnFirst"
android:summary="@string/preferences_behavior_return_to_first_trait_description"
android:title="@string/preferences_behavior_return_to_first_trait" />

<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_remap_volume_buttons"
Expand Down

0 comments on commit 77abd20

Please sign in to comment.