Toggle bookmark icon in BottomSheetAdapter instead of finding the location each time in the bookmark

* Update bookmark button image in `BottomSheetAdapter`
* Add new toggle function to `BottomSheetAdapter`
* Call the toggle function in `NearbyParentFragment`
This commit is contained in:
Saifuddin 2025-01-17 18:26:42 +05:30
parent 8295edeb0a
commit 97037858a3
2 changed files with 21 additions and 3 deletions

View file

@ -68,7 +68,21 @@ class BottomSheetAdapter(
item.imageResourceId == R.drawable.ic_round_star_border_24px
) {
item.imageResourceId = icon
this.notifyItemChanged(index)
notifyItemChanged(index)
return
}
}
}
fun toggleBookmarkIcon() {
itemList.forEachIndexed { index, item ->
if(item.imageResourceId == R.drawable.ic_round_star_filled_24px) {
item.imageResourceId = R.drawable.ic_round_star_border_24px
notifyItemChanged(index)
return
} else if(item.imageResourceId == R.drawable.ic_round_star_border_24px){
item.imageResourceId = R.drawable.ic_round_star_filled_24px
notifyItemChanged(index)
return
}
}

View file

@ -2145,6 +2145,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
);
}
private void toggleBookmarkButtonImage() {
bottomSheetAdapter.toggleBookmarkIcon();
}
@Override
public void onAttach(final Context context) {
super.onAttach(context);
@ -2304,11 +2308,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
switch (item.getImageResourceId()) {
case R.drawable.ic_round_star_border_24px:
presenter.toggleBookmarkedStatus(selectedPlace, scope);
updateBookmarkButtonImage(selectedPlace);
toggleBookmarkButtonImage();
break;
case R.drawable.ic_round_star_filled_24px:
presenter.toggleBookmarkedStatus(selectedPlace, scope);
updateBookmarkButtonImage(selectedPlace);
toggleBookmarkButtonImage();
break;
case R.drawable.ic_directions_black_24dp:
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());