summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-23 15:42:41 +0100
committercyBerta <cyberta@riseup.net>2021-11-23 15:42:41 +0100
commit638b2c53f00f552693cc8f425eaa862343e6cf20 (patch)
tree2ee410828842a074f76e97976d4fab1d509675de /app/src/main/java
parentf29ee8ac7378408e070be1130c9cadc8e947ddb3 (diff)
add OnCheckedChangedListener in SimpleCheckbox
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java25
1 files changed, 24 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java
index 7cd790db..09a9132e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java
@@ -9,11 +9,19 @@ import android.widget.RelativeLayout;
import androidx.appcompat.widget.AppCompatImageView;
+import java.lang.ref.WeakReference;
+
import se.leap.bitmaskclient.R;
public class SimpleCheckBox extends RelativeLayout {
AppCompatImageView checkView;
+ private WeakReference<OnCheckedChangeListener> checkedChangeListener = new WeakReference<OnCheckedChangeListener>(null);
+ private boolean checked;
+
+ public interface OnCheckedChangeListener {
+ void onCheckedChanged(SimpleCheckBox simpleCheckBox, boolean isChecked);
+ }
public SimpleCheckBox(Context context) {
@@ -45,6 +53,21 @@ public class SimpleCheckBox extends RelativeLayout {
}
public void setChecked(boolean checked) {
- this.checkView.setVisibility(checked ? VISIBLE : INVISIBLE);
+ if (this.checked != checked) {
+ this.checkView.setVisibility(checked ? VISIBLE : INVISIBLE);
+ this.checked = checked;
+ OnCheckedChangeListener listener = checkedChangeListener.get();
+ if (listener != null) {
+ listener.onCheckedChanged(this, this.checked);
+ }
+ }
+ }
+
+ public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
+ checkedChangeListener = new WeakReference<>(listener);
+ }
+
+ public void toggle() {
+ setChecked(!this.checked);
}
}