Skip to content

Commit

Permalink
fix: update events for changing state of automatic update switch
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Jun 24, 2024
1 parent a195966 commit a47efc0
Showing 1 changed file with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

binding.customUrl.setVisibility(descriptor.getName().equals(OONITests.WEBSITES.getLabel()) ? View.VISIBLE : View.GONE);

viewModel.getSelectedAllBtnStatus().observe(this, this::selectAllBtnStatusObserver);
binding.expandableListView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (binding.expandableListView.getChildCount() > 0) {
if (adapter.isSelectedAllItems()) {
binding.switchTests.setCheckedState(MaterialCheckBox.STATE_CHECKED);
} else if (adapter.isNotSelectedAnyGroupItem()) {
binding.switchTests.setCheckedState(MaterialCheckBox.STATE_UNCHECKED);
} else {
binding.switchTests.setCheckedState(MaterialCheckBox.STATE_INDETERMINATE);
}
}
});

binding.switchTests.addOnCheckedStateChangedListener((checkBox, state) -> {
switch (state) {
case MaterialCheckBox.STATE_CHECKED -> {
Expand Down Expand Up @@ -209,23 +220,6 @@ private void onDescriptorLoaded(AbstractDescriptor<BaseNettest> descriptor) {

}

private void selectAllBtnStatusObserver(String selectAllBtnStatus) {
if (!TextUtils.isEmpty(selectAllBtnStatus)) {
switch (selectAllBtnStatus) {
case SELECT_ALL -> {
binding.switchTests.setCheckedState(MaterialCheckBox.STATE_CHECKED);
}
case SELECT_NONE -> {
binding.switchTests.setCheckedState(MaterialCheckBox.STATE_UNCHECKED);
}
case SELECT_SOME -> {
binding.switchTests.setCheckedState(MaterialCheckBox.STATE_INDETERMINATE);
}
}
adapter.notifyDataSetChanged();
}
}

public void setThemeColor(int color) {
Window window = getWindow();
window.setStatusBarColor(color);
Expand Down

0 comments on commit a47efc0

Please sign in to comment.