From d408134b7efce0b87dcbf8bbf46e9814dd1908be Mon Sep 17 00:00:00 2001 From: Shashank Kumar <126143257+shashankiitbhu@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:04:52 +0530 Subject: [PATCH] Enhacement - Add Custom Image Selector FAB Option to Nearby (#5655) * Fix * Fix * Migrate NearbyParentFragment to ViewBinding * remove unused Imports * fix crash --- .../fragments/NearbyParentFragment.java | 517 ++++++++---------- .../res/layout/fragment_nearby_parent.xml | 421 +++++++------- 2 files changed, 443 insertions(+), 495 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index 6a16fccf29..6fe0928775 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -36,13 +36,6 @@ import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; -import android.widget.Button; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; -import android.widget.TextView; import android.widget.Toast; import androidx.activity.result.ActivityResultCallback; import androidx.activity.result.ActivityResultLauncher; @@ -51,21 +44,10 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.AppCompatButton; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.AppCompatTextView; -import androidx.appcompat.widget.SearchView; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; import com.google.android.material.bottomsheet.BottomSheetBehavior; -import com.google.android.material.chip.Chip; -import com.google.android.material.chip.ChipGroup; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import com.jakewharton.rxbinding2.view.RxView; import com.jakewharton.rxbinding3.appcompat.RxSearchView; @@ -79,6 +61,7 @@ import fr.free.nrw.commons.contributions.ContributionController; import fr.free.nrw.commons.contributions.MainActivity; import fr.free.nrw.commons.contributions.MainActivity.ActiveFragment; +import fr.free.nrw.commons.databinding.FragmentNearbyParentBinding; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.kvstore.JsonKvStore; import fr.free.nrw.commons.location.LatLng; @@ -146,88 +129,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment implements NearbyParentFragmentContract.View, WikidataEditListener.WikidataP18EditListener, LocationUpdateListener { - @BindView(R.id.bottom_sheet) - RelativeLayout rlBottomSheet; - @BindView(R.id.bottom_sheet_details) - View bottomSheetDetails; - @BindView(R.id.transparentView) - View transparentView; - @BindView(R.id.directionsButtonText) - TextView directionsButtonText; - @BindView(R.id.wikipediaButtonText) - TextView wikipediaButtonText; - @BindView(R.id.wikidataButtonText) - TextView wikidataButtonText; - @BindView(R.id.commonsButtonText) - TextView commonsButtonText; - @BindView(R.id.fab_plus) - FloatingActionButton fabPlus; - @BindView(R.id.fab_camera) - FloatingActionButton fabCamera; - @BindView(R.id.fab_gallery) - FloatingActionButton fabGallery; - @BindView(R.id.fab_recenter) - FloatingActionButton fabRecenter; - @BindView(R.id.bookmarkButtonImage) - ImageView bookmarkButtonImage; - @BindView(R.id.bookmarkButton) - LinearLayout bookmarkButton; - @BindView(R.id.wikipediaButton) - LinearLayout wikipediaButton; - @BindView(R.id.wikidataButton) - LinearLayout wikidataButton; - @BindView(R.id.directionsButton) - LinearLayout directionsButton; - @BindView(R.id.commonsButton) - LinearLayout commonsButton; - @BindView(R.id.description) - TextView description; - @BindView(R.id.title) - TextView title; - @BindView(R.id.category) - TextView distance; - @BindView(R.id.icon) - ImageView icon; - @BindView(R.id.search_this_area_button) - Button searchThisAreaButton; - @BindView(R.id.map_progress_bar) - ProgressBar progressBar; - @BindView(R.id.choice_chip_exists) - Chip chipExists; - @BindView(R.id.choice_chip_wlm) - Chip chipWlm; - @BindView(R.id.choice_chip_needs_photo) - Chip chipNeedsPhoto; - @BindView(R.id.choice_chip_group) - ChipGroup choiceChipGroup; - @BindView(R.id.search_view) - SearchView searchView; - @BindView(R.id.search_list_view) - RecyclerView recyclerView; - @BindView(R.id.nearby_filter_list) - View nearbyFilterList; - @BindView(R.id.checkbox_tri_states) - CheckBoxTriStates checkBoxTriStates; - @BindView(R.id.map) - org.osmdroid.views.MapView mapView; - @BindView(R.id.rv_nearby_list) - RecyclerView rvNearbyList; - @BindView(R.id.no_results_message) - TextView noResultsView; - @BindView(R.id.tv_attribution) - AppCompatTextView tvAttribution; - @BindView(R.id.rl_container_wlm_month_message) - RelativeLayout rlContainerWLMMonthMessage; - @BindView(R.id.tv_learn_more) - AppCompatTextView tvLearnMore; - @BindView(R.id.iv_toggle_chips) - AppCompatImageView ivToggleChips; - @BindView(R.id.chip_view) - View llContainerChips; - @BindView(R.id.btn_advanced_options) - AppCompatButton btnAdvancedOptions; - @BindView(R.id.fl_container_nearby_children) - FrameLayout flConainerNearbyChildren; + + FragmentNearbyParentBinding binding; + @Inject LocationServiceManager locationManager; @Inject @@ -348,8 +252,9 @@ public static NearbyParentFragment newInstance() { @Override public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { - view = inflater.inflate(R.layout.fragment_nearby_parent, container, false); - ButterKnife.bind(this, view); + binding = FragmentNearbyParentBinding.inflate(inflater, container, false); + view = binding.getRoot(); + initNetworkBroadCastReceiver(); presenter = new NearbyParentFragmentPresenter(bookmarkLocationDao); setHasOptionsMenu(true); @@ -377,8 +282,8 @@ public boolean onMenuItemClick(MenuItem item) { @Override public boolean onMenuItemClick(@NonNull MenuItem item) { try { - IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0); - IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight()); + IGeoPoint screenTopRight = binding.map.getProjection().fromPixels(binding.map.getWidth(), 0); + IGeoPoint screenBottomLeft = binding.map.getProjection().fromPixels(0, binding.map.getHeight()); fr.free.nrw.commons.location.LatLng screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng( screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0); fr.free.nrw.commons.location.LatLng screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng( @@ -396,8 +301,8 @@ public boolean onMenuItemClick(@NonNull MenuItem item) { @Override public boolean onMenuItemClick(@NonNull MenuItem item) { try { - IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0); - IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight()); + IGeoPoint screenTopRight = binding.map.getProjection().fromPixels(binding.map.getWidth(), 0); + IGeoPoint screenBottomLeft = binding.map.getProjection().fromPixels(0, binding.map.getHeight()); fr.free.nrw.commons.location.LatLng screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng( screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0); fr.free.nrw.commons.location.LatLng screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng( @@ -417,9 +322,9 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved super.onViewCreated(view, savedInstanceState); isDarkTheme = systemThemeUtils.isDeviceInNightMode(); if (Utils.isMonumentsEnabled(new Date())) { - rlContainerWLMMonthMessage.setVisibility(View.VISIBLE); + binding.rlContainerWlmMonthMessage.setVisibility(View.VISIBLE); } else { - rlContainerWLMMonthMessage.setVisibility(View.GONE); + binding.rlContainerWlmMonthMessage.setVisibility(View.GONE); } presenter.attachView(this); @@ -433,8 +338,8 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved // Use the Wikimedia tile server, rather than OpenStreetMap (Mapnik) which has various // restrictions that we do not satisfy. - mapView.setTileSource(TileSourceFactory.WIKIMEDIA); - mapView.setTilesScaledToDpi(true); + binding.map.setTileSource(TileSourceFactory.WIKIMEDIA); + binding.map.setTilesScaledToDpi(true); // Add referer HTTP header because the Wikimedia tile server requires it. // This was suggested by Dmitry Brant within an email thread between us and WMF. @@ -450,16 +355,16 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved } else { lastMapFocus = new GeoPoint(51.50550, -0.07520); } - ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(mapView); + ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(binding.map); scaleBarOverlay.setScaleBarOffset(15, 25); Paint barPaint = new Paint(); barPaint.setARGB(200, 255, 250, 250); scaleBarOverlay.setBackgroundPaint(barPaint); scaleBarOverlay.enableScaleBar(); - mapView.getOverlays().add(scaleBarOverlay); - mapView.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER); - mapView.getController().setZoom(ZOOM_LEVEL); - mapView.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() { + binding.map.getOverlays().add(scaleBarOverlay); + binding.map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER); + binding.map.getController().setZoom(ZOOM_LEVEL); + binding.map.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() { @Override public boolean singleTapConfirmedHelper(GeoPoint p) { if (clickedMarkerPlace != null){ @@ -483,14 +388,14 @@ public boolean longPressHelper(GeoPoint p) { } })); - mapView.addMapListener(new MapListener() { + binding.map.addMapListener(new MapListener() { @Override public boolean onScroll(ScrollEvent event) { if (lastMapFocus != null) { Location mylocation = new Location(""); Location dest_location = new Location(""); - dest_location.setLatitude(mapView.getMapCenter().getLatitude()); - dest_location.setLongitude(mapView.getMapCenter().getLongitude()); + dest_location.setLatitude(binding.map.getMapCenter().getLatitude()); + dest_location.setLongitude(binding.map.getMapCenter().getLongitude()); mylocation.setLatitude(lastMapFocus.getLatitude()); mylocation.setLongitude(lastMapFocus.getLongitude()); Float distance = mylocation.distanceTo(dest_location);//in meters @@ -518,7 +423,7 @@ public boolean onZoom(ZoomEvent event) { }); - mapView.setMultiTouchControls(true); + binding.map.setMultiTouchControls(true); if (nearbyParentFragmentInstanceReadyCallback != null) { nearbyParentFragmentInstanceReadyCallback.onReady(); } @@ -528,10 +433,10 @@ public boolean onZoom(ZoomEvent event) { moveCameraToPosition(lastMapFocus); initRvNearbyList(); onResume(); - tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution))); - tvAttribution.setMovementMethod(LinkMovementMethod.getInstance()); - btnAdvancedOptions.setOnClickListener(v -> { - searchView.clearFocus(); + binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution))); + binding.tvAttribution.setMovementMethod(LinkMovementMethod.getInstance()); + binding.nearbyFilterList.btnAdvancedOptions.setOnClickListener(v -> { + binding.nearbyFilter.searchViewLayout.searchView.clearFocus(); showHideAdvancedQueryFragment(true); final AdvanceQueryFragment fragment = new AdvanceQueryFragment(); final Bundle bundle = new Bundle(); @@ -565,6 +470,9 @@ public void apply(@NotNull final String query) { .replace(R.id.fl_container_nearby_children, fragment) .commit(); }); + + binding.tvLearnMore.setOnClickListener(v ->onLearnMoreClicked()); + binding.nearbyFilter.ivToggleChips.setOnClickListener(v -> onToggleChipsClicked()); } /** @@ -573,30 +481,30 @@ public void apply(@NotNull final String query) { */ private void initThemePreferences() { if (isDarkTheme) { - rvNearbyList.setBackgroundColor( + binding.bottomSheetNearby.rvNearbyList.setBackgroundColor( getContext().getResources().getColor(R.color.contributionListDarkBackground)); - checkBoxTriStates.setTextColor( + binding.nearbyFilterList.checkboxTriStates.setTextColor( getContext().getResources().getColor(android.R.color.white)); - checkBoxTriStates.setTextColor( + binding.nearbyFilterList.checkboxTriStates.setTextColor( getContext().getResources().getColor(android.R.color.white)); - nearbyFilterList.setBackgroundColor( + binding.nearbyFilterList.getRoot().setBackgroundColor( getContext().getResources().getColor(R.color.contributionListDarkBackground)); - mapView.getOverlayManager().getTilesOverlay() + binding.map.getOverlayManager().getTilesOverlay() .setColorFilter(TilesOverlay.INVERT_COLORS); } else { - rvNearbyList.setBackgroundColor( + binding.bottomSheetNearby.rvNearbyList.setBackgroundColor( getContext().getResources().getColor(android.R.color.white)); - checkBoxTriStates.setTextColor( + binding.nearbyFilterList.checkboxTriStates.setTextColor( getContext().getResources().getColor(R.color.contributionListDarkBackground)); - nearbyFilterList.setBackgroundColor( + binding.nearbyFilterList.getRoot().setBackgroundColor( getContext().getResources().getColor(android.R.color.white)); - nearbyFilterList.setBackgroundColor( + binding.nearbyFilterList.getRoot().setBackgroundColor( getContext().getResources().getColor(android.R.color.white)); } } private void initRvNearbyList() { - rvNearbyList.setLayoutManager(new LinearLayoutManager(getContext())); + binding.bottomSheetNearby.rvNearbyList.setLayoutManager(new LinearLayoutManager(getContext())); adapter = new PlaceAdapter(bookmarkLocationDao, place -> { moveCameraToPosition(new GeoPoint(place.location.getLatitude(),place.location.getLongitude())); @@ -604,17 +512,17 @@ private void initRvNearbyList() { }, (place, isBookmarked) -> { updateMarker(isBookmarked, place, null); - mapView.invalidate(); + binding.map.invalidate(); return Unit.INSTANCE; }, commonPlaceClickActions, inAppCameraLocationPermissionLauncher ); - rvNearbyList.setAdapter(adapter); + binding.bottomSheetNearby.rvNearbyList.setAdapter(adapter); } private void addCheckBoxCallback() { - checkBoxTriStates.setCallback( + binding.nearbyFilterList.checkboxTriStates.setCallback( (o, state, b, b1) -> presenter.filterByMarkerType(o, state, b, b1)); } @@ -638,7 +546,7 @@ private void locationPermissionGranted() { if (lastKnownLocation != null) { GeoPoint targetP = new GeoPoint(target.getLatitude(), target.getLongitude()); mapCenter = targetP; - mapView.getController().setCenter(targetP); + binding.map.getController().setCenter(targetP); recenterMarkerToPosition(targetP); moveCameraToPosition(targetP); } else if (locationManager.isGPSProviderEnabled() @@ -657,7 +565,7 @@ private void locationPermissionGranted() { @Override public void onResume() { super.onResume(); - mapView.onResume(); + binding.map.onResume(); presenter.attachView(this); registerNetworkReceiver(); if (isResumed() && ((MainActivity) getActivity()).activeFragment == ActiveFragment.NEARBY) { @@ -695,7 +603,7 @@ private void startMapWithCondition(final String condition) { lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550, -0.07520, 1f); } - if (mapView != null) { + if (binding.map != null) { recenterMap(lastKnownLocation); } } @@ -709,7 +617,7 @@ private void registerNetworkReceiver() { @Override public void onPause() { super.onPause(); - mapView.onPause(); + binding.map.onPause(); compositeDisposable.clear(); presenter.detachView(); registerUnregisterLocationListener(true); @@ -742,7 +650,7 @@ private void initViews() { decideButtonVisibilities(); addActionToTitle(); if (!Utils.isMonumentsEnabled(new Date())) { - chipWlm.setVisibility(View.GONE); + binding.nearbyFilter.chipView.choiceChipWlm.setVisibility(View.GONE); } } @@ -755,33 +663,33 @@ private void initViews() { */ @SuppressLint("ClickableViewAccessibility") private void initBottomSheets() { - bottomSheetListBehavior = BottomSheetBehavior.from(rlBottomSheet); - bottomSheetDetailsBehavior = BottomSheetBehavior.from(bottomSheetDetails); + bottomSheetListBehavior = BottomSheetBehavior.from(binding.bottomSheetNearby.bottomSheet); + bottomSheetDetailsBehavior = BottomSheetBehavior.from(binding.bottomSheetDetails.getRoot()); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); - bottomSheetDetails.setVisibility(View.VISIBLE); + binding.bottomSheetDetails.getRoot().setVisibility(View.VISIBLE); bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); } public void initNearbyFilter() { - nearbyFilterList.setVisibility(View.GONE); + binding.nearbyFilterList.getRoot().setVisibility(View.GONE); hideBottomSheet(); - searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> { - LayoutUtils.setLayoutHeightAllignedToWidth(1.25, nearbyFilterList); + binding.nearbyFilter.searchViewLayout.searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> { + LayoutUtils.setLayoutHeightAllignedToWidth(1.25, binding.nearbyFilterList.getRoot()); if (hasFocus) { - nearbyFilterList.setVisibility(View.VISIBLE); + binding.nearbyFilterList.getRoot().setVisibility(View.VISIBLE); presenter.searchViewGainedFocus(); } else { - nearbyFilterList.setVisibility(View.GONE); + binding.nearbyFilterList.getRoot().setVisibility(View.GONE); } }); - recyclerView.setHasFixedSize(true); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), + binding.nearbyFilterList.searchListView.setHasFixedSize(true); + binding.nearbyFilterList.searchListView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); - recyclerView.setLayoutManager(linearLayoutManager); + binding.nearbyFilterList.searchListView.setLayoutManager(linearLayoutManager); nearbyFilterSearchRecyclerViewAdapter = new NearbyFilterSearchRecyclerViewAdapter( - getContext(), new ArrayList<>(Label.valuesAsList()), recyclerView); + getContext(), new ArrayList<>(Label.valuesAsList()), binding.nearbyFilterList.searchListView); nearbyFilterSearchRecyclerViewAdapter.setCallback( new NearbyFilterSearchRecyclerViewAdapter.Callback() { @Override @@ -800,16 +708,16 @@ public boolean isDarkTheme() { return isDarkTheme; } }); - nearbyFilterList.getLayoutParams().width = (int) LayoutUtils.getScreenWidth(getActivity(), + binding.nearbyFilterList.getRoot().getLayoutParams().width = (int) LayoutUtils.getScreenWidth(getActivity(), 0.75); - recyclerView.setAdapter(nearbyFilterSearchRecyclerViewAdapter); - LayoutUtils.setLayoutHeightAllignedToWidth(1.25, nearbyFilterList); - compositeDisposable.add(RxSearchView.queryTextChanges(searchView) - .takeUntil(RxView.detaches(searchView)) + binding.nearbyFilterList.searchListView.setAdapter(nearbyFilterSearchRecyclerViewAdapter); + LayoutUtils.setLayoutHeightAllignedToWidth(1.25, binding.nearbyFilterList.getRoot()); + compositeDisposable.add(RxSearchView.queryTextChanges( binding.nearbyFilter.searchViewLayout.searchView) + .takeUntil(RxView.detaches(binding.nearbyFilter.searchViewLayout.searchView)) .debounce(500, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe(query -> { - ((NearbyFilterSearchRecyclerViewAdapter) recyclerView.getAdapter()).getFilter() + ((NearbyFilterSearchRecyclerViewAdapter) binding.nearbyFilterList.searchListView.getAdapter()).getFilter() .filter(query.toString()); })); initFilterChips(); @@ -817,63 +725,63 @@ public boolean isDarkTheme() { @Override public void setCheckBoxAction() { - checkBoxTriStates.addAction(); - checkBoxTriStates.setState(CheckBoxTriStates.UNKNOWN); + binding.nearbyFilterList.checkboxTriStates.addAction(); + binding.nearbyFilterList.checkboxTriStates.setState(CheckBoxTriStates.UNKNOWN); } @Override public void setCheckBoxState(final int state) { - checkBoxTriStates.setState(state); + binding.nearbyFilterList.checkboxTriStates.setState(state); } @Override public void setFilterState() { - chipNeedsPhoto.setChecked(NearbyFilterState.getInstance().isNeedPhotoSelected()); - chipExists.setChecked(NearbyFilterState.getInstance().isExistsSelected()); - chipWlm.setChecked(NearbyFilterState.getInstance().isWlmSelected()); + binding.nearbyFilter.chipView.choiceChipNeedsPhoto.setChecked(NearbyFilterState.getInstance().isNeedPhotoSelected()); + binding.nearbyFilter.chipView.choiceChipExists.setChecked(NearbyFilterState.getInstance().isExistsSelected()); + binding.nearbyFilter.chipView.choiceChipWlm.setChecked(NearbyFilterState.getInstance().isWlmSelected()); if (NearbyController.currentLocation != null) { presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, - checkBoxTriStates.getState(), true, false); + binding.nearbyFilterList.checkboxTriStates.getState(), true, false); } } private void initFilterChips() { - chipNeedsPhoto.setOnCheckedChangeListener((buttonView, isChecked) -> { + binding.nearbyFilter.chipView.choiceChipNeedsPhoto.setOnCheckedChangeListener((buttonView, isChecked) -> { if (NearbyController.currentLocation != null) { - checkBoxTriStates.setState(CheckBoxTriStates.CHECKED); + binding.nearbyFilterList.checkboxTriStates.setState(CheckBoxTriStates.CHECKED); NearbyFilterState.setNeedPhotoSelected(isChecked); presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, - checkBoxTriStates.getState(), true, true); - updatePlaceList(chipNeedsPhoto.isChecked(), - chipExists.isChecked(), chipWlm.isChecked()); + binding.nearbyFilterList.checkboxTriStates.getState(), true, true); + updatePlaceList( binding.nearbyFilter.chipView.choiceChipNeedsPhoto.isChecked(), + binding.nearbyFilter.chipView.choiceChipExists.isChecked(), binding.nearbyFilter.chipView.choiceChipWlm.isChecked()); } else { - chipNeedsPhoto.setChecked(!isChecked); + binding.nearbyFilter.chipView.choiceChipNeedsPhoto.setChecked(!isChecked); } }); - chipExists.setOnCheckedChangeListener((buttonView, isChecked) -> { + binding.nearbyFilter.chipView.choiceChipExists.setOnCheckedChangeListener((buttonView, isChecked) -> { if (NearbyController.currentLocation != null) { - checkBoxTriStates.setState(CheckBoxTriStates.CHECKED); + binding.nearbyFilterList.checkboxTriStates.setState(CheckBoxTriStates.CHECKED); NearbyFilterState.setExistsSelected(isChecked); presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, - checkBoxTriStates.getState(), true, true); - updatePlaceList(chipNeedsPhoto.isChecked(), - chipExists.isChecked(), chipWlm.isChecked()); + binding.nearbyFilterList.checkboxTriStates.getState(), true, true); + updatePlaceList( binding.nearbyFilter.chipView.choiceChipNeedsPhoto.isChecked(), + binding.nearbyFilter.chipView.choiceChipExists.isChecked(), binding.nearbyFilter.chipView.choiceChipWlm.isChecked()); } else { - chipExists.setChecked(!isChecked); + binding.nearbyFilter.chipView.choiceChipExists.setChecked(!isChecked); } }); - chipWlm.setOnCheckedChangeListener((buttonView, isChecked) -> { + binding.nearbyFilter.chipView.choiceChipWlm.setOnCheckedChangeListener((buttonView, isChecked) -> { if (NearbyController.currentLocation != null) { - checkBoxTriStates.setState(CheckBoxTriStates.CHECKED); + binding.nearbyFilterList.checkboxTriStates.setState(CheckBoxTriStates.CHECKED); NearbyFilterState.setWlmSelected(isChecked); presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, - checkBoxTriStates.getState(), true, true); - updatePlaceList(chipNeedsPhoto.isChecked(), - chipExists.isChecked(), chipWlm.isChecked()); + binding.nearbyFilterList.checkboxTriStates.getState(), true, true); + updatePlaceList( binding.nearbyFilter.chipView.choiceChipNeedsPhoto.isChecked(), + binding.nearbyFilter.chipView.choiceChipExists.isChecked(), binding.nearbyFilter.chipView.choiceChipWlm.isChecked()); } else { - chipWlm.setChecked(!isChecked); + binding.nearbyFilter.chipView.choiceChipWlm.setChecked(!isChecked); } }); } @@ -927,7 +835,7 @@ private void updatePlaceList(final boolean needsPhoto, final boolean exists, } adapter.setItems(updatedPlaces); - noResultsView.setVisibility(updatedPlaces.isEmpty() ? View.VISIBLE : View.GONE); + binding.bottomSheetNearby.noResultsMessage.setVisibility(updatedPlaces.isEmpty() ? View.VISIBLE : View.GONE); } /** @@ -947,7 +855,7 @@ public void onSlide(@NonNull final View bottomSheet, final float slideOffset) { } }); - bottomSheetDetails.setOnClickListener(v -> { + binding.bottomSheetDetails.getRoot().setOnClickListener(v -> { if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); } else if (bottomSheetDetailsBehavior.getState() @@ -956,9 +864,9 @@ public void onSlide(@NonNull final View bottomSheet, final float slideOffset) { } }); - rlBottomSheet.getLayoutParams().height = getActivity().getWindowManager() + binding.bottomSheetNearby.bottomSheet.getLayoutParams().height = getActivity().getWindowManager() .getDefaultDisplay().getHeight() / 16 * 9; - bottomSheetListBehavior = BottomSheetBehavior.from(rlBottomSheet); + bottomSheetListBehavior = BottomSheetBehavior.from(binding.bottomSheetNearby.bottomSheet); bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); bottomSheetListBehavior.setBottomSheetCallback(new BottomSheetBehavior .BottomSheetCallback() { @@ -992,11 +900,11 @@ private void loadAnimations() { private void decideButtonVisibilities() { // Remove button text if they exceed 1 line or if internal layout has not been built // Only need to check for directions button because it is the longest - if (directionsButtonText.getLineCount() > 1 || directionsButtonText.getLineCount() == 0) { - wikipediaButtonText.setVisibility(View.GONE); - wikidataButtonText.setVisibility(View.GONE); - commonsButtonText.setVisibility(View.GONE); - directionsButtonText.setVisibility(View.GONE); + if ( binding.bottomSheetDetails.directionsButtonText.getLineCount() > 1 || binding.bottomSheetDetails.directionsButtonText.getLineCount() == 0) { + binding.bottomSheetDetails.wikipediaButtonText.setVisibility(View.GONE); + binding.bottomSheetDetails.wikidataButtonText.setVisibility(View.GONE); + binding.bottomSheetDetails.commonsButtonText.setVisibility(View.GONE); + binding.bottomSheetDetails.directionsButtonText.setVisibility(View.GONE); } } @@ -1004,13 +912,13 @@ private void decideButtonVisibilities() { * */ private void addActionToTitle() { - title.setOnLongClickListener(view -> { - Utils.copy("place", title.getText().toString(), getContext()); + binding.bottomSheetDetails.title.setOnLongClickListener(view -> { + Utils.copy("place", binding.bottomSheetDetails.title.getText().toString(), getContext()); Toast.makeText(getContext(), R.string.text_copy, Toast.LENGTH_SHORT).show(); return true; }); - title.setOnClickListener(view -> { + binding.bottomSheetDetails.title.setOnClickListener(view -> { bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); @@ -1052,7 +960,7 @@ public void centerMapToPlace(@Nullable final Place place) { public void updateListFragment(final List placeList) { places = placeList; adapter.setItems(placeList); - noResultsView.setVisibility(placeList.isEmpty() ? View.VISIBLE : View.GONE); + binding.bottomSheetNearby.noResultsMessage.setVisibility(placeList.isEmpty() ? View.VISIBLE : View.GONE); } @Override @@ -1095,7 +1003,7 @@ public fr.free.nrw.commons.location.LatLng getMapCenter() { @Override public fr.free.nrw.commons.location.LatLng getMapFocus() { fr.free.nrw.commons.location.LatLng mapFocusedLatLng = new fr.free.nrw.commons.location.LatLng( - mapView.getMapCenter().getLatitude(), mapView.getMapCenter().getLongitude(), 100); + binding.map.getMapCenter().getLatitude(), binding.map.getMapCenter().getLongitude(), 100); return mapFocusedLatLng; } @@ -1107,7 +1015,7 @@ public boolean isAdvancedQueryFragmentVisible() { @Override public void showHideAdvancedQueryFragment(final boolean shouldShow) { setHasOptionsMenu(!shouldShow); - flConainerNearbyChildren.setVisibility(shouldShow ? View.VISIBLE : View.GONE); + binding.flContainerNearbyChildren.setVisibility(shouldShow ? View.VISIBLE : View.GONE); isAdvancedQueryFragmentVisible = shouldShow; } @@ -1166,8 +1074,8 @@ public void listOptionMenuItemClicked() { @Override public void populatePlaces(final fr.free.nrw.commons.location.LatLng currentLatLng) { - IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0); - IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight()); + IGeoPoint screenTopRight = binding.map.getProjection().fromPixels(binding.map.getWidth(), 0); + IGeoPoint screenBottomLeft = binding.map.getProjection().fromPixels(0, binding.map.getHeight()); fr.free.nrw.commons.location.LatLng screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng( screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0); fr.free.nrw.commons.location.LatLng screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng( @@ -1224,8 +1132,8 @@ public void populatePlaces(final fr.free.nrw.commons.location.LatLng currentLatL populatePlaces(currentLatLng); return; } - IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0); - IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight()); + IGeoPoint screenTopRight = binding.map.getProjection().fromPixels(binding.map.getWidth(), 0); + IGeoPoint screenBottomLeft = binding.map.getProjection().fromPixels(0, binding.map.getHeight()); fr.free.nrw.commons.location.LatLng screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng( screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0); fr.free.nrw.commons.location.LatLng screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng( @@ -1446,15 +1354,15 @@ public void setBottomSheetDetailsSmaller() { @Override public void addSearchThisAreaButtonAction() { - searchThisAreaButton.setOnClickListener(presenter.onSearchThisAreaClicked()); + binding.searchThisAreaButton.setOnClickListener(presenter.onSearchThisAreaClicked()); } @Override public void setSearchThisAreaButtonVisibility(final boolean isVisible) { if (isVisible) { - searchThisAreaButton.setVisibility(View.VISIBLE); + binding.searchThisAreaButton.setVisibility(View.VISIBLE); } else { - searchThisAreaButton.setVisibility(View.GONE); + binding.searchThisAreaButton.setVisibility(View.GONE); } } @@ -1477,9 +1385,9 @@ public void setRecyclerViewAdapterItemsGreyedOut() { @Override public void setProgressBarVisibility(final boolean isVisible) { if (isVisible) { - progressBar.setVisibility(View.VISIBLE); + binding.mapProgressBar.setVisibility(View.VISIBLE); } else { - progressBar.setVisibility(View.GONE); + binding.mapProgressBar.setVisibility(View.GONE); } } @@ -1499,7 +1407,7 @@ public void checkPermissionsAndPerformAction() { */ @Override public void animateFABs() { - if (fabPlus.isShown()) { + if (binding.fabPlus.isShown()) { if (isFABsExpanded) { collapseFABs(isFABsExpanded); } else { @@ -1509,12 +1417,14 @@ public void animateFABs() { } private void showFABs() { - NearbyFABUtils.addAnchorToBigFABs(fabPlus, bottomSheetDetails.getId()); - fabPlus.show(); - NearbyFABUtils.addAnchorToSmallFABs(fabGallery, + NearbyFABUtils.addAnchorToBigFABs(binding.fabPlus, binding.bottomSheetDetails.getRoot().getId()); + binding.fabPlus.show(); + NearbyFABUtils.addAnchorToSmallFABs(binding.fabGallery, getView().findViewById(R.id.empty_view).getId()); - NearbyFABUtils.addAnchorToSmallFABs(fabCamera, + NearbyFABUtils.addAnchorToSmallFABs(binding.fabCamera, getView().findViewById(R.id.empty_view1).getId()); + NearbyFABUtils.addAnchorToSmallFABs(binding.fabCustomGallery, + getView().findViewById(R.id.empty_view2).getId()); } /** @@ -1525,11 +1435,13 @@ private void showFABs() { private void expandFABs(final boolean isFABsExpanded) { if (!isFABsExpanded) { showFABs(); - fabPlus.startAnimation(rotate_forward); - fabCamera.startAnimation(fab_open); - fabGallery.startAnimation(fab_open); - fabCamera.show(); - fabGallery.show(); + binding.fabPlus.startAnimation(rotate_forward); + binding.fabCamera.startAnimation(fab_open); + binding.fabGallery.startAnimation(fab_open); + binding.fabCustomGallery.startAnimation(fab_open); + binding.fabCustomGallery.show(); + binding.fabCamera.show(); + binding.fabGallery.show(); this.isFABsExpanded = true; } } @@ -1538,12 +1450,14 @@ private void expandFABs(final boolean isFABsExpanded) { * Hides all fabs */ private void hideFABs() { - NearbyFABUtils.removeAnchorFromFAB(fabPlus); - fabPlus.hide(); - NearbyFABUtils.removeAnchorFromFAB(fabCamera); - fabCamera.hide(); - NearbyFABUtils.removeAnchorFromFAB(fabGallery); - fabGallery.hide(); + NearbyFABUtils.removeAnchorFromFAB(binding.fabPlus); + binding.fabPlus.hide(); + NearbyFABUtils.removeAnchorFromFAB(binding.fabCamera); + binding.fabCamera.hide(); + NearbyFABUtils.removeAnchorFromFAB(binding.fabGallery); + binding.fabGallery.hide(); + NearbyFABUtils.removeAnchorFromFAB(binding.fabCustomGallery); + binding.fabCustomGallery.hide(); } /** @@ -1553,11 +1467,13 @@ private void hideFABs() { */ private void collapseFABs(final boolean isFABsExpanded) { if (isFABsExpanded) { - fabPlus.startAnimation(rotate_backward); - fabCamera.startAnimation(fab_close); - fabGallery.startAnimation(fab_close); - fabCamera.hide(); - fabGallery.hide(); + binding.fabPlus.startAnimation(rotate_backward); + binding.fabCamera.startAnimation(fab_close); + binding.fabGallery.startAnimation(fab_close); + binding.fabCustomGallery.startAnimation(fab_close); + binding.fabCustomGallery.hide(); + binding.fabCamera.hide(); + binding.fabGallery.hide(); this.isFABsExpanded = false; } } @@ -1619,22 +1535,22 @@ public boolean backButtonClicked() { @Override public void setFABPlusAction(final View.OnClickListener onClickListener) { - fabPlus.setOnClickListener(onClickListener); + binding.fabPlus.setOnClickListener(onClickListener); } @Override public void setFABRecenterAction(final View.OnClickListener onClickListener) { - fabRecenter.setOnClickListener(onClickListener); + binding.fabRecenter.setOnClickListener(onClickListener); } @Override public void disableFABRecenter() { - fabRecenter.setEnabled(false); + binding.fabRecenter.setEnabled(false); } @Override public void enableFABRecenter() { - fabRecenter.setEnabled(true); + binding.fabRecenter.setEnabled(true); } /** @@ -1661,7 +1577,7 @@ public void addCurrentLocationMarker(final fr.free.nrw.commons.location.LatLng c @Override public void updateMapMarkers(final List BaseMarkers) { - if (mapView != null) { + if (binding.map != null) { presenter.updateMapMarkersToController(BaseMarkers); } } @@ -1746,7 +1662,7 @@ public void filterMarkersByLabels(final List