mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
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:
parent
8295edeb0a
commit
97037858a3
2 changed files with 21 additions and 3 deletions
|
|
@ -68,7 +68,21 @@ class BottomSheetAdapter(
|
||||||
item.imageResourceId == R.drawable.ic_round_star_border_24px
|
item.imageResourceId == R.drawable.ic_round_star_border_24px
|
||||||
) {
|
) {
|
||||||
item.imageResourceId = icon
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2145,6 +2145,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toggleBookmarkButtonImage() {
|
||||||
|
bottomSheetAdapter.toggleBookmarkIcon();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(final Context context) {
|
public void onAttach(final Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
@ -2304,11 +2308,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
switch (item.getImageResourceId()) {
|
switch (item.getImageResourceId()) {
|
||||||
case R.drawable.ic_round_star_border_24px:
|
case R.drawable.ic_round_star_border_24px:
|
||||||
presenter.toggleBookmarkedStatus(selectedPlace, scope);
|
presenter.toggleBookmarkedStatus(selectedPlace, scope);
|
||||||
updateBookmarkButtonImage(selectedPlace);
|
toggleBookmarkButtonImage();
|
||||||
break;
|
break;
|
||||||
case R.drawable.ic_round_star_filled_24px:
|
case R.drawable.ic_round_star_filled_24px:
|
||||||
presenter.toggleBookmarkedStatus(selectedPlace, scope);
|
presenter.toggleBookmarkedStatus(selectedPlace, scope);
|
||||||
updateBookmarkButtonImage(selectedPlace);
|
toggleBookmarkButtonImage();
|
||||||
break;
|
break;
|
||||||
case R.drawable.ic_directions_black_24dp:
|
case R.drawable.ic_directions_black_24dp:
|
||||||
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());
|
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue