diff --git a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Notifier.java b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Notifier.java index 64f7be1..1f0073f 100644 --- a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Notifier.java +++ b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Notifier.java @@ -51,15 +51,26 @@ void addOnSegmentClickListener(OnSegmentClickListener onSegmentClickListener) onSegmentClickListeners.add(onSegmentClickListener); } + void removeOnSegmentClickListener(OnSegmentClickListener onSegmentClickListener) { + onSegmentClickListeners = lazy(onSegmentClickListeners, new ArrayList>()); + onSegmentClickListeners.remove(onSegmentClickListener); + } + void addOnSegmentSelectListener(OnSegmentSelectedListener onSegmentSelectedListener) { onSegmentSelectedListeners = lazy(onSegmentSelectedListeners, new ArrayList>()); onSegmentSelectedListeners.add(onSegmentSelectedListener); } + void removeOnSegmentSelectListener(OnSegmentSelectedListener onSegmentSelectedListener) { + onSegmentSelectedListeners = lazy(onSegmentSelectedListeners, new ArrayList>()); + onSegmentSelectedListeners.remove(onSegmentSelectedListener); + } + void setOnSegmentSelectRequestListener(OnSegmentSelectRequestListener onSegmentSelectRequestListener) { this.onSegmentSelectRequestListener = onSegmentSelectRequestListener; } + private void onEvent(List eventListeners, Consumer listenerConsumer) { if (eventListeners != null && eventListeners.size() != 0) { for (T t : eventListeners) { diff --git a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControl.java b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControl.java index cf9c51a..4232371 100644 --- a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControl.java +++ b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControl.java @@ -393,6 +393,16 @@ public void addOnSegmentClickListener(OnSegmentClickListener onSegmentClickLi getControllerComponent().addOnSegmentClickListener(onSegmentClickListener); } + /** + * @param onSegmentClickListener, every time click event will be notified, + * even if the segment is already selected + * + * Remove listener + */ + public void removeOnSegmentClickListener(OnSegmentClickListener onSegmentClickListener) { + getControllerComponent().removeOnSegmentClickListener(onSegmentClickListener); + } + /** * @param onSegmentSelectedListener, event will be notified, when segment is selected and unSelected and reselected, * for more info check out {@link OnSegmentSelectedListener} class @@ -401,6 +411,16 @@ public void addOnSegmentSelectListener(OnSegmentSelectedListener onSegmentSel getControllerComponent().addOnSegmentSelectListener(onSegmentSelectedListener); } + /** + * @param onSegmentSelectedListener, event will be notified, when segment is selected and unSelected and reselected, + * for more info check out {@link OnSegmentSelectedListener} class + * + * Remove listener + */ + public void removeOnSegmentSelectListener(OnSegmentSelectedListener onSegmentSelectedListener) { + getControllerComponent().removeOnSegmentSelectListener(onSegmentSelectedListener); + } + /** * @param onSegmentSelectRequestListener, event will be triggered after click event and before selection event * for more info click out {@link OnSegmentSelectRequestListener} class diff --git a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java index adb3348..bbecb2c 100644 --- a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java +++ b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java @@ -289,10 +289,18 @@ void addOnSegmentClickListener(OnSegmentClickListener onSegmentClickListener) notifier.addOnSegmentClickListener(onSegmentClickListener); } + void removeOnSegmentClickListener(OnSegmentClickListener onSegmentClickListener) { + notifier.removeOnSegmentClickListener(onSegmentClickListener); + } + void addOnSegmentSelectListener(OnSegmentSelectedListener onSegmentSelectedListener) { notifier.addOnSegmentSelectListener(onSegmentSelectedListener); } + void removeOnSegmentSelectListener(OnSegmentSelectedListener onSegmentSelectedListener) { + notifier.removeOnSegmentSelectListener(onSegmentSelectedListener); + } + void setOnSegmentSelectRequestListener(OnSegmentSelectRequestListener onSegmentSelectRequestListener) { notifier.setOnSegmentSelectRequestListener(onSegmentSelectRequestListener); }