From 6094027ee096cce78dbd89ea8151f1ca6bd5c6f6 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Tue, 3 May 2016 23:31:07 +0200 Subject: [PATCH] refactored max/min repetitions to receiver constant fixed incorrectly initialized repetition buttons when editing receiver --- .../ConfigureReceiverDialogPage4GatewayFragment.java | 11 +++++++++-- .../java/eu/power_switch/obj/receiver/Receiver.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Smartphone/src/main/java/eu/power_switch/gui/fragment/configure_receiver/ConfigureReceiverDialogPage4GatewayFragment.java b/Smartphone/src/main/java/eu/power_switch/gui/fragment/configure_receiver/ConfigureReceiverDialogPage4GatewayFragment.java index d576dab0..c492551c 100644 --- a/Smartphone/src/main/java/eu/power_switch/gui/fragment/configure_receiver/ConfigureReceiverDialogPage4GatewayFragment.java +++ b/Smartphone/src/main/java/eu/power_switch/gui/fragment/configure_receiver/ConfigureReceiverDialogPage4GatewayFragment.java @@ -134,7 +134,7 @@ public void onClick(View v) { buttonMinus.setEnabled(true); - if (repetitionAmount >= 3) { + if (repetitionAmount >= Receiver.MAX_REPETITIONS) { buttonPlus.setEnabled(false); } @@ -151,7 +151,7 @@ public void onClick(View v) { buttonPlus.setEnabled(true); - if (repetitionAmount <= 1) { + if (repetitionAmount <= Receiver.MIN_REPETITIONS) { buttonMinus.setEnabled(false); } @@ -206,6 +206,13 @@ private void initializeReceiverData(long receiverId) { Receiver receiver = DatabaseHandler.getReceiver(receiverId); repetitionAmount = receiver.getRepetitionAmount(); textView_repetitionAmount.setText(String.valueOf(repetitionAmount)); + if (repetitionAmount >= Receiver.MAX_REPETITIONS) { + buttonPlus.setEnabled(false); + } + if (repetitionAmount <= Receiver.MIN_REPETITIONS) { + buttonMinus.setEnabled(false); + } + room = DatabaseHandler.getRoom(receiver.getRoomId()); diff --git a/Smartphone/src/main/java/eu/power_switch/obj/receiver/Receiver.java b/Smartphone/src/main/java/eu/power_switch/obj/receiver/Receiver.java index 7ccef019..907df289 100644 --- a/Smartphone/src/main/java/eu/power_switch/obj/receiver/Receiver.java +++ b/Smartphone/src/main/java/eu/power_switch/obj/receiver/Receiver.java @@ -122,6 +122,16 @@ public abstract class Receiver { } }; + /** + * Maximum value for network signal repetitions + */ + public static final int MAX_REPETITIONS = 3; + + /** + * Minimum value for network signal repetitions + */ + public static final int MIN_REPETITIONS = 1; + protected Context context; /** * ID of this Receiver