Skip to content

Commit

Permalink
Merge pull request #1123 from PhenoApps/flip_flop_ui_arrows
Browse files Browse the repository at this point in the history
flip_flop_ui_arrows
  • Loading branch information
trife authored Jan 3, 2025
2 parents 5183bce + a53019e commit 6c77ca7
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.documentfile.provider.DocumentFile;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
Expand Down Expand Up @@ -553,6 +554,44 @@ private void loadScreen() {
refreshInfoBarAdapter();

uvcView = findViewById(R.id.collect_activity_uvc_tv);

handleFlipFlopPreferences();
}

/**
* Handles the flip flop preferences for the collect activity.
* Change from issue #934:
* Originally, the arrow functionalities were switched depending on this preference,
* now the whole UI is swapped.
*/
private void handleFlipFlopPreferences() {

ConstraintLayout layout = findViewById(R.id.layout_main);

ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(layout);

if (preferences.getBoolean(GeneralKeys.FLIP_FLOP_ARROWS, false)) {
constraintSet.connect(R.id.act_collect_range_box, ConstraintSet.TOP,
R.id.act_collect_infobar_rv, ConstraintSet.BOTTOM, 0);
constraintSet.connect(R.id.act_collect_range_box, ConstraintSet.BOTTOM,
R.id.act_collect_trait_box, ConstraintSet.TOP, 0);
constraintSet.connect(R.id.act_collect_trait_box, ConstraintSet.TOP,
R.id.act_collect_range_box, ConstraintSet.BOTTOM, 0);
constraintSet.connect(R.id.act_collect_input_view, ConstraintSet.TOP,
R.id.act_collect_trait_box, ConstraintSet.BOTTOM, 0);
} else {
constraintSet.connect(R.id.act_collect_trait_box, ConstraintSet.TOP,
R.id.act_collect_infobar_rv, ConstraintSet.BOTTOM, 0);
constraintSet.connect(R.id.act_collect_trait_box, ConstraintSet.BOTTOM,
R.id.act_collect_range_box, ConstraintSet.TOP, 0);
constraintSet.connect(R.id.act_collect_range_box, ConstraintSet.TOP,
R.id.act_collect_trait_box, ConstraintSet.BOTTOM, 0);
constraintSet.connect(R.id.act_collect_input_view, ConstraintSet.TOP,
R.id.act_collect_range_box, ConstraintSet.BOTTOM, 0);
}

constraintSet.applyTo(layout);
}

//when softkeyboard is displayed, reset the snackbar to redisplay with a calculated bottom margin
Expand Down
55 changes: 12 additions & 43 deletions app/src/main/java/com/fieldbook/tracker/views/RangeBoxView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,8 @@ class RangeBoxView : ConstraintLayout {

fun connectTraitBox(traitBoxView: TraitBoxView) {

//determine range button function based on user-preferences
//issues217 introduces the ability to swap trait and plot arrows
val flipFlopArrows =
controller.getPreferences().getBoolean(GeneralKeys.FLIP_FLOP_ARROWS, false)
if (flipFlopArrows) {
rangeLeft = traitBoxView.getTraitLeft()
rangeRight = traitBoxView.getTraitRight()
} else {
rangeLeft = findViewById(R.id.rangeLeft)
rangeRight = findViewById(R.id.rangeRight)
}
rangeLeft = findViewById(R.id.rangeLeft)
rangeRight = findViewById(R.id.rangeRight)

rangeLeft.setOnTouchListener(createOnLeftTouchListener())
rangeRight.setOnTouchListener(createOnRightTouchListener())
Expand Down Expand Up @@ -298,43 +289,21 @@ class RangeBoxView : ConstraintLayout {
private fun createOnLeftTouchListener(): OnTouchListener {
val actionLeft = createRunnable("left")

//change click-arrow based on preferences
val flipFlopArrows =
controller.getPreferences().getBoolean(GeneralKeys.FLIP_FLOP_ARROWS, false)
return if (flipFlopArrows) {
createOnTouchListener(
rangeLeft, actionLeft,
R.drawable.trait_chevron_left_pressed,
R.drawable.trait_chevron_left
)
} else {
createOnTouchListener(
rangeLeft, actionLeft,
R.drawable.chevron_left_pressed,
R.drawable.chevron_left
)
}
return createOnTouchListener(
rangeLeft, actionLeft,
R.drawable.chevron_left_pressed,
R.drawable.chevron_left
)
}

private fun createOnRightTouchListener(): OnTouchListener {
val actionRight = createRunnable("right")

//change click-arrow based on preferences
val flipFlopArrows =
controller.getPreferences().getBoolean(GeneralKeys.FLIP_FLOP_ARROWS, false)
return if (flipFlopArrows) {
createOnTouchListener(
rangeRight, actionRight,
R.drawable.trait_chevron_right_pressed,
R.drawable.trait_chevron_right
)
} else {
createOnTouchListener(
rangeRight, actionRight,
R.drawable.chevron_right_pressed,
R.drawable.chevron_right
)
}
return createOnTouchListener(
rangeRight, actionRight,
R.drawable.chevron_right_pressed,
R.drawable.chevron_right
)
}

private fun createOnTouchListener(
Expand Down
68 changes: 20 additions & 48 deletions app/src/main/java/com/fieldbook/tracker/views/TraitBoxView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,71 +87,41 @@ class TraitBoxView : ConstraintLayout {

fun connectRangeBox(rangeBoxView: RangeBoxView) {

//determine trait button function based on user-preferences
//issues217 introduces the ability to swap trait and plot arrows
val flipFlopArrows: Boolean =
controller.getPreferences().getBoolean(GeneralKeys.FLIP_FLOP_ARROWS, false)
if (flipFlopArrows) {
traitLeft = rangeBoxView.getRangeLeft()
traitRight = rangeBoxView.getRangeRight()
} else {
traitLeft = findViewById(R.id.traitLeft)
traitRight = findViewById(R.id.traitRight)
}
traitLeft = findViewById(R.id.traitLeft)
traitRight = findViewById(R.id.traitRight)
traitDetails = findViewById(R.id.traitDetails)

//change click-arrow based on preferences
if (flipFlopArrows) {
traitLeft.setImageResource(R.drawable.chevron_left)
traitLeft.setOnTouchListener(
createTraitOnTouchListener(
traitLeft, R.drawable.chevron_left,
R.drawable.chevron_left_pressed
)
)
} else {
traitLeft.setImageResource(R.drawable.trait_chevron_left)
traitLeft.setOnTouchListener(
createTraitOnTouchListener(
traitLeft, R.drawable.trait_chevron_left,
R.drawable.trait_chevron_left_pressed
)
traitLeft.setImageResource(R.drawable.trait_chevron_left)
traitLeft.setOnTouchListener(
createTraitOnTouchListener(
traitLeft, R.drawable.trait_chevron_left,
R.drawable.trait_chevron_left_pressed
)
}
)

// Go to previous trait
traitLeft.setOnClickListener { moveTrait("left") }

//change click-arrow based on preferences
if (flipFlopArrows) {
traitRight.setImageResource(R.drawable.chevron_right)
traitRight.setOnTouchListener(
createTraitOnTouchListener(
traitRight, R.drawable.chevron_right,
R.drawable.chevron_right_pressed
)
traitRight.setImageResource(R.drawable.trait_chevron_right)
traitRight.setOnTouchListener(
createTraitOnTouchListener(
traitRight, R.drawable.trait_chevron_right,
R.drawable.trait_chevron_right_pressed
)
} else {
traitRight.setImageResource(R.drawable.trait_chevron_right)
traitRight.setOnTouchListener(
createTraitOnTouchListener(
traitRight, R.drawable.trait_chevron_right,
R.drawable.trait_chevron_right_pressed
)
)
}
)

// Go to next trait
traitRight.setOnClickListener { moveTrait("right") }
}

fun initTraitDetails() {
val traitDetails: TextView = findViewById(R.id.traitDetails)
traitDetails.setOnTouchListener { _, event ->
traitDetails.setOnTouchListener { view, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> traitDetails.maxLines = 10
MotionEvent.ACTION_UP -> traitDetails.maxLines = 1
}
view?.performClick()
true
}
}
Expand Down Expand Up @@ -416,9 +386,11 @@ class TraitBoxView : ConstraintLayout {
arrow: ImageView,
imageIdUp: Int, imageIdDown: Int
): OnTouchListener {
return OnTouchListener { _, event ->
return OnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> arrow.setImageResource(imageIdDown)
MotionEvent.ACTION_DOWN -> {
arrow.setImageResource(imageIdDown)
}
MotionEvent.ACTION_MOVE -> {}
MotionEvent.ACTION_UP -> arrow.setImageResource(imageIdUp)
MotionEvent.ACTION_CANCEL -> {}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@
<string name="preferences_behavior_skip_entries_across_all_traits">Arrows skip entries that already have values for all traits</string>

<string name="preferences_general_swap_navigation">Swap Navigation</string>
<string name="preferences_general_swap_navigation_description">Swap the behavior of the entry and trait arrows</string>
<string name="preferences_general_swap_navigation_description">Swap the location of the entry and trait arrows</string>

<string name="preferences_behavior_volume_buttons_navigate">Navigate With Volume Keys</string>
<string name="preferences_behavior_volume_buttons_navigate_disabled">Disabled</string>
Expand Down

0 comments on commit 6c77ca7

Please sign in to comment.