converted/Migrated

This commit is contained in:
Sujal-Gupta-SG 2025-02-03 17:45:51 +05:30
parent 9e08a09583
commit 98d95e6bd0

View file

@ -1,6 +1,7 @@
package fr.free.nrw.commons.nearby.fragments package fr.free.nrw.commons.nearby.fragments
import android.Manifest.permission import android.Manifest.permission
import android.fr.free.nrw.commons.R
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.ProgressDialog import android.app.ProgressDialog
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
@ -48,7 +49,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCa
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.jakewharton.rxbinding2.view.RxView import com.jakewharton.rxbinding2.view.RxView
import com.jakewharton.rxbinding3.appcompat.queryTextChanges import com.jakewharton.rxbinding3.appcompat.queryTextChanges
import dagger.Provides
import fr.free.nrw.commons.CommonsApplication import fr.free.nrw.commons.CommonsApplication
import fr.free.nrw.commons.MapController.NearbyPlacesInfo import fr.free.nrw.commons.MapController.NearbyPlacesInfo
import fr.free.nrw.commons.R import fr.free.nrw.commons.R
@ -60,7 +60,6 @@ import fr.free.nrw.commons.contributions.MainActivity.ActiveFragment
import fr.free.nrw.commons.databinding.FragmentNearbyParentBinding import fr.free.nrw.commons.databinding.FragmentNearbyParentBinding
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
import fr.free.nrw.commons.filepicker.FilePicker import fr.free.nrw.commons.filepicker.FilePicker
import fr.free.nrw.commons.filepicker.FilePicker.HandleActivityResult
import fr.free.nrw.commons.kvstore.JsonKvStore import fr.free.nrw.commons.kvstore.JsonKvStore
import fr.free.nrw.commons.location.LatLng import fr.free.nrw.commons.location.LatLng
import fr.free.nrw.commons.location.LocationPermissionsHelper import fr.free.nrw.commons.location.LocationPermissionsHelper
@ -127,7 +126,8 @@ import javax.inject.Inject
import javax.inject.Named import javax.inject.Named
import kotlin.concurrent.Volatile import kotlin.concurrent.Volatile
class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmentContract.View,
class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmentContract.View,
WikidataP18EditListener, LocationUpdateListener, LocationPermissionCallback, ItemClickListener { WikidataP18EditListener, LocationUpdateListener, LocationPermissionCallback, ItemClickListener {
var binding: FragmentNearbyParentBinding? = null var binding: FragmentNearbyParentBinding? = null
@ -221,6 +221,11 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
@Volatile @Volatile
private var stopQuery = false private var stopQuery = false
// Explore map data (for if we came from Explore)
private var prevZoom = 0.0
private var prevLatitude = 0.0
private var prevLongitude = 0.0
private val searchHandler = Handler() private val searchHandler = Handler()
private val searchRunnable: Runnable? = null private val searchRunnable: Runnable? = null
@ -278,10 +283,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) { if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
showAlertDialog( showAlertDialog(
requireActivity(), requireActivity(),
getString(R.string.location_permission_title), getString(fr.free.nrw.commons.R.string.location_permission_title),
getString(R.string.location_permission_rationale_nearby), getString(fr.free.nrw.commons.R.string.location_permission_rationale_nearby),
getString(android.R.string.ok), getString(fr.free.nrw.commons.R.string.ok),
getString(android.R.string.cancel), getString(fr.free.nrw.commons.R.string.cancel),
{ {
askForLocationPermission() askForLocationPermission()
}, },
@ -292,7 +297,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
if (isPermissionDenied) { if (isPermissionDenied) {
locationPermissionsHelper?.showAppSettingsDialog( locationPermissionsHelper?.showAppSettingsDialog(
requireActivity(), requireActivity(),
R.string.nearby_needs_location fr.free.nrw.commons.R.string.nearby_needs_location
) )
} }
Timber.d("The user checked 'Don't ask again' or denied the permission twice") Timber.d("The user checked 'Don't ask again' or denied the permission twice")
@ -312,6 +317,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
loadExploreMapData();
binding = FragmentNearbyParentBinding.inflate(inflater, container, false) binding = FragmentNearbyParentBinding.inflate(inflater, container, false)
view = binding!!.root view = binding!!.root
@ -334,11 +341,12 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
menu: Menu, menu: Menu,
inflater: MenuInflater inflater: MenuInflater
) { ) {
inflater.inflate(R.menu.nearby_fragment_menu, menu) inflater.inflate(fr.free.nrw.commons.R.menu.nearby_fragment_menu, menu)
val refreshButton = menu.findItem(R.id.item_refresh) val refreshButton = menu.findItem(fr.free.nrw.commons.R.id.item_refresh)
val listMenu = menu.findItem(R.id.list_sheet) val listMenu = menu.findItem(fr.free.nrw.commons.R.id.list_sheet)
val saveAsGPXButton = menu.findItem(R.id.list_item_gpx) val showInExploreButton = menu.findItem(fr.free.nrw.commons.R.id.list_item_show_in_explore)
val saveAsKMLButton = menu.findItem(R.id.list_item_kml) val saveAsGPXButton = menu.findItem(fr.free.nrw.commons.R.id.list_item_gpx)
val saveAsKMLButton = menu.findItem(fr.free.nrw.commons.R.id.list_item_kml)
refreshButton.setOnMenuItemClickListener { refreshButton.setOnMenuItemClickListener {
try { try {
emptyCache() emptyCache()
@ -351,9 +359,21 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
listOptionMenuItemClicked() listOptionMenuItemClicked()
false false
} }
showInExploreButton.setOnMenuItemClickListener(object : OnMenuItemClickListener() {
fun onMenuItemClick(@NonNull item: MenuItem?): Boolean {
(context as MainActivity).loadExploreMapFromNearby(
binding!!.map.zoomLevelDouble,
binding!!.map.mapCenter.latitude,
binding!!.map.mapCenter.longitude
)
return false
}
})
saveAsGPXButton.setOnMenuItemClickListener { saveAsGPXButton.setOnMenuItemClickListener {
try { try {
progressDialog!!.setTitle(getString(R.string.saving_gpx_file)) progressDialog!!.setTitle(getString(fr.free.nrw.commons.R.string.saving_gpx_file))
progressDialog!!.show() progressDialog!!.show()
savePlacesAsGPX() savePlacesAsGPX()
} catch (e: Exception) { } catch (e: Exception) {
@ -363,7 +383,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} }
saveAsKMLButton.setOnMenuItemClickListener { saveAsKMLButton.setOnMenuItemClickListener {
try { try {
progressDialog!!.setTitle(getString(R.string.saving_kml_file)) progressDialog!!.setTitle(getString(fr.free.nrw.commons.R.string.saving_kml_file))
progressDialog!!.show() progressDialog!!.show()
savePlacesAsKML() savePlacesAsKML()
} catch (e: Exception) { } catch (e: Exception) {
@ -390,7 +410,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
) )
} else { } else {
controller?.locationPermissionCallback?.onLocationPermissionDenied( controller?.locationPermissionCallback?.onLocationPermissionDenied(
getString(R.string.in_app_camera_location_permission_denied) getString(fr.free.nrw.commons.R.string.in_app_camera_location_permission_denied)
) )
} }
} }
@ -445,6 +465,15 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
binding?.map?.overlays?.add(scaleBarOverlay) binding?.map?.overlays?.add(scaleBarOverlay)
binding?.map?.getZoomController()?.setVisibility(CustomZoomButtonsController.Visibility.NEVER) binding?.map?.getZoomController()?.setVisibility(CustomZoomButtonsController.Visibility.NEVER)
binding?.map?.controller?.setZoom(ZOOM_LEVEL.toInt()) binding?.map?.controller?.setZoom(ZOOM_LEVEL.toInt())
// if we came from Explore map using 'Show in Nearby', load Explore map camera position
if (isCameFromExploreMap()) {
moveCameraToPosition(
GeoPoint(prevLatitude, prevLongitude),
prevZoom,
1L
)
}
binding?.map?.getOverlays()?.add(mapEventsOverlay) binding?.map?.getOverlays()?.add(mapEventsOverlay)
binding?.map?.addMapListener(object : MapListener { binding?.map?.addMapListener(object : MapListener {
@ -462,15 +491,18 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
nearbyParentFragmentInstanceReadyCallback?.onReady() nearbyParentFragmentInstanceReadyCallback?.onReady()
initNearbyFilter() initNearbyFilter()
addCheckBoxCallback() addCheckBoxCallback()
if (!isCameFromExploreMap()) {
moveCameraToPosition(lastMapFocus!!);
}
moveCameraToPosition(lastMapFocus!!) moveCameraToPosition(lastMapFocus!!)
initRvNearbyList() initRvNearbyList()
onResume() onResume()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
binding?.tvAttribution?.text = Html.fromHtml(getString(R.string.map_attribution), Html.FROM_HTML_MODE_LEGACY) binding?.tvAttribution?.text = Html.fromHtml(getString(fr.free.nrw.commons.R.string.map_attribution), Html.FROM_HTML_MODE_LEGACY)
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
binding?.tvAttribution?.text = Html.fromHtml(getString(R.string.map_attribution)) binding?.tvAttribution?.text = Html.fromHtml(getString(fr.free.nrw.commons.R.string.map_attribution))
} }
binding?.tvAttribution?.movementMethod = LinkMovementMethod.getInstance() binding?.tvAttribution?.movementMethod = LinkMovementMethod.getInstance()
@ -503,7 +535,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} }
} }
childFragmentManager.beginTransaction() childFragmentManager.beginTransaction()
.replace(R.id.fl_container_nearby_children, fragment) .replace(fr.free.nrw.commons.R.id.fl_container_nearby_children, fragment)
.commit() .commit()
} }
@ -516,6 +548,27 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} }
} }
/**
* Fetch Explore map camera data from fragment arguments if any.
*/
fun loadExploreMapData() {
// get fragment arguments
if (arguments != null) {
prevZoom = arguments!!.getDouble("prev_zoom")
prevLatitude = arguments!!.getDouble("prev_latitude")
prevLongitude = arguments!!.getDouble("prev_longitude")
}
}
/**
* Checks if fragment arguments contain data from Explore map. if present, then the user
* navigated from Explore using 'Show in Nearby'.
*
* @return true if user navigated from Explore map
*/
fun isCameFromExploreMap(): Boolean {
return prevZoom != 0.0 || prevLatitude != 0.0 || prevLongitude != 0.0
}
/** /**
* Initialise background based on theme, this should be doe ideally via styles, that would need * Initialise background based on theme, this should be doe ideally via styles, that would need
@ -524,31 +577,31 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
private fun initThemePreferences() { private fun initThemePreferences() {
if (isDarkTheme) { if (isDarkTheme) {
binding!!.bottomSheetNearby.rvNearbyList.setBackgroundColor( binding!!.bottomSheetNearby.rvNearbyList.setBackgroundColor(
requireContext().resources.getColor(R.color.contributionListDarkBackground) requireContext().resources.getColor(fr.free.nrw.commons.R.color.contributionListDarkBackground)
) )
binding!!.nearbyFilterList.checkboxTriStates.setTextColor( binding!!.nearbyFilterList.checkboxTriStates.setTextColor(
requireContext().resources.getColor(android.R.color.white) requireContext().resources.getColor(android.fr.free.nrw.commons.R.color.white)
) )
binding!!.nearbyFilterList.checkboxTriStates.setTextColor( binding!!.nearbyFilterList.checkboxTriStates.setTextColor(
requireContext().resources.getColor(android.R.color.white) requireContext().resources.getColor(fr.free.nrw.commons.R.color.white)
) )
binding!!.nearbyFilterList.root.setBackgroundColor( binding!!.nearbyFilterList.root.setBackgroundColor(
requireContext().resources.getColor(R.color.contributionListDarkBackground) requireContext().resources.getColor(fr.free.nrw.commons.R.color.contributionListDarkBackground)
) )
binding!!.map.overlayManager.tilesOverlay binding!!.map.overlayManager.tilesOverlay
.setColorFilter(TilesOverlay.INVERT_COLORS) .setColorFilter(TilesOverlay.INVERT_COLORS)
} else { } else {
binding!!.bottomSheetNearby.rvNearbyList.setBackgroundColor( binding!!.bottomSheetNearby.rvNearbyList.setBackgroundColor(
requireContext().resources.getColor(android.R.color.white) requireContext().resources.getColor(fr.free.nrw.commons.R.color.white)
) )
binding!!.nearbyFilterList.checkboxTriStates.setTextColor( binding!!.nearbyFilterList.checkboxTriStates.setTextColor(
requireContext().resources.getColor(R.color.contributionListDarkBackground) requireContext().resources.getColor(fr.free.nrw.commons.R.color.contributionListDarkBackground)
) )
binding!!.nearbyFilterList.root.setBackgroundColor( binding!!.nearbyFilterList.root.setBackgroundColor(
requireContext().resources.getColor(android.R.color.white) requireContext().resources.getColor(fr.free.nrw.commons.R.color.white)
) )
binding!!.nearbyFilterList.root.setBackgroundColor( binding!!.nearbyFilterList.root.setBackgroundColor(
requireContext().resources.getColor(android.R.color.white) requireContext().resources.getColor(fr.free.nrw.commons.R.color.white)
) )
} }
} }
@ -612,7 +665,9 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
mapCenter = targetP mapCenter = targetP
binding!!.map.controller.setCenter(targetP) binding!!.map.controller.setCenter(targetP)
recenterMarkerToPosition(targetP) recenterMarkerToPosition(targetP)
moveCameraToPosition(targetP) if (!isCameFromExploreMap()) {
moveCameraToPosition(targetP);
}
} else if (locationManager!!.isGPSProviderEnabled() } else if (locationManager!!.isGPSProviderEnabled()
|| locationManager!!.isNetworkProviderEnabled() || locationManager!!.isNetworkProviderEnabled()
) { ) {
@ -622,7 +677,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} else { } else {
locationPermissionsHelper!!.showLocationOffDialog( locationPermissionsHelper!!.showLocationOffDialog(
requireActivity(), requireActivity(),
R.string.ask_to_turn_location_on_text fr.free.nrw.commons.R.string.ask_to_turn_location_on_text
) )
} }
presenter!!.onMapReady() presenter!!.onMapReady()
@ -660,7 +715,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} else { } else {
lastKnownLocation = defaultLatLng lastKnownLocation = defaultLatLng
} }
if (binding!!.map != null) { if (binding?.map ?: != null && !isCameFromExploreMap()) {
moveCameraToPosition( moveCameraToPosition(
GeoPoint(lastKnownLocation!!.latitude, lastKnownLocation!!.longitude) GeoPoint(lastKnownLocation!!.latitude, lastKnownLocation!!.longitude)
) )
@ -883,10 +938,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
* Loads animations will be used for FABs * Loads animations will be used for FABs
*/ */
private fun loadAnimations() { private fun loadAnimations() {
fab_open = AnimationUtils.loadAnimation(activity, R.anim.fab_open) fab_open = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_open)
fab_close = AnimationUtils.loadAnimation(activity, R.anim.fab_close) fab_close = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_close)
rotate_forward = AnimationUtils.loadAnimation(activity, R.anim.rotate_forward) rotate_forward = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.rotate_forward)
rotate_backward = AnimationUtils.loadAnimation(activity, R.anim.rotate_backward) rotate_backward = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.rotate_backward)
} }
/** /**
@ -898,7 +953,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
"place", binding!!.bottomSheetDetails.title.text.toString(), "place", binding!!.bottomSheetDetails.title.text.toString(),
context context
) )
Toast.makeText(context, R.string.text_copy, Toast.LENGTH_SHORT).show() Toast.makeText(context, fr.free.nrw.commons.R.string.text_copy, Toast.LENGTH_SHORT).show()
true true
} }
@ -1032,7 +1087,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} else { } else {
if (snackbar == null) { if (snackbar == null) {
snackbar = Snackbar.make( snackbar = Snackbar.make(
view!!, R.string.no_internet, view!!, fr.free.nrw.commons.R.string.no_internet,
Snackbar.LENGTH_INDEFINITE Snackbar.LENGTH_INDEFINITE
) )
searchable = false searchable = false
@ -1057,9 +1112,9 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
return return
} }
if (offlinePinsShown) { if (offlinePinsShown) {
snackbar!!.setText(R.string.nearby_showing_pins_offline) snackbar!!.setText(fr.free.nrw.commons.R.string.nearby_showing_pins_offline)
} else { } else {
snackbar!!.setText(R.string.no_internet) snackbar!!.setText(fr.free.nrw.commons.R.string.no_internet)
} }
} }
@ -1262,7 +1317,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} else { } else {
Toast.makeText( Toast.makeText(
this.context, this.context,
getString(R.string.failed_to_save_kml_file), getString(fr.free.nrw.commons.R.string.failed_to_save_kml_file),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} }
@ -1271,7 +1326,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
{ throwable: Throwable -> { throwable: Throwable ->
Timber.d(throwable) Timber.d(throwable)
showErrorMessage( showErrorMessage(
getString(R.string.error_fetching_nearby_places) getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
+ throwable.localizedMessage + throwable.localizedMessage
) )
setProgressBarVisibility(false) setProgressBarVisibility(false)
@ -1306,7 +1361,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
} else { } else {
Toast.makeText( Toast.makeText(
this.context, this.context,
getString(R.string.failed_to_save_gpx_file), getString(fr.free.nrw.commons.R.string.failed_to_save_gpx_file),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} }
@ -1315,7 +1370,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
{ throwable: Throwable -> { throwable: Throwable ->
Timber.d(throwable) Timber.d(throwable)
showErrorMessage( showErrorMessage(
getString(R.string.error_fetching_nearby_places) getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
+ throwable.localizedMessage + throwable.localizedMessage
) )
setProgressBarVisibility(false) setProgressBarVisibility(false)
@ -1347,12 +1402,12 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
private fun showOpenFileDialog(context: Context, fileName: String, isGPX: Boolean) { private fun showOpenFileDialog(context: Context, fileName: String, isGPX: Boolean) {
val title = getString(R.string.file_saved_successfully) val title = getString(fr.free.nrw.commons.R.string.file_saved_successfully)
val message = val message =
if ((isGPX)) if ((isGPX))
getString(R.string.do_you_want_to_open_gpx_file) getString(fr.free.nrw.commons.R.string.do_you_want_to_open_gpx_file)
else else
getString(R.string.do_you_want_to_open_kml_file) getString(fr.free.nrw.commons.R.string.do_you_want_to_open_kml_file)
val runnable = Runnable { openFile(context, fileName, isGPX) } val runnable = Runnable { openFile(context, fileName, isGPX) }
showAlertDialog(requireActivity(), title, message, runnable) {} showAlertDialog(requireActivity(), title, message, runnable) {}
} }
@ -1379,7 +1434,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
context.startActivity(intent) context.startActivity(intent)
} catch (e: ActivityNotFoundException) { } catch (e: ActivityNotFoundException) {
Toast.makeText( Toast.makeText(
context, R.string.no_application_available_to_open_gpx_files, context, fr.free.nrw.commons.R.string.no_application_available_to_open_gpx_files,
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} }
@ -1432,7 +1487,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
{ throwable: Throwable -> { throwable: Throwable ->
Timber.d(throwable) Timber.d(throwable)
showErrorMessage( showErrorMessage(
getString(R.string.could_not_load_place_data) getString(fr.free.nrw.commons.R.string.could_not_load_place_data)
+ throwable.localizedMessage + throwable.localizedMessage
) )
}) })
@ -1467,7 +1522,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
.subscribe( .subscribe(
{ nearbyPlacesInfo: NearbyPlacesInfo -> { nearbyPlacesInfo: NearbyPlacesInfo ->
if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) { if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
showErrorMessage(getString(R.string.no_nearby_places_around)) showErrorMessage(getString(fr.free.nrw.commons.R.string.no_nearby_places_around))
setProgressBarVisibility(false) setProgressBarVisibility(false)
presenter!!.lockUnlockNearby(false) presenter!!.lockUnlockNearby(false)
} else { } else {
@ -1482,7 +1537,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
{ throwable: Throwable -> { throwable: Throwable ->
Timber.d(throwable) Timber.d(throwable)
showErrorMessage( showErrorMessage(
getString(R.string.error_fetching_nearby_places) getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
+ throwable.localizedMessage + throwable.localizedMessage
) )
setProgressBarVisibility(false) setProgressBarVisibility(false)
@ -1520,7 +1575,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
.subscribe( .subscribe(
{ nearbyPlacesInfo: NearbyPlacesInfo -> { nearbyPlacesInfo: NearbyPlacesInfo ->
if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) { if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
showErrorMessage(getString(R.string.no_nearby_places_around)) showErrorMessage(getString(fr.free.nrw.commons.R.string.no_nearby_places_around))
setProgressBarVisibility(false) setProgressBarVisibility(false)
presenter!!.lockUnlockNearby(false) presenter!!.lockUnlockNearby(false)
} else { } else {
@ -1543,7 +1598,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
{ throwable: Throwable -> { throwable: Throwable ->
Timber.e(throwable) Timber.e(throwable)
showErrorMessage( showErrorMessage(
getString(R.string.error_fetching_nearby_places) getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
+ throwable.localizedMessage + throwable.localizedMessage
) )
setProgressBarVisibility(false) setProgressBarVisibility(false)
@ -1651,15 +1706,15 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
binding!!.fabPlus.show() binding!!.fabPlus.show()
addAnchorToSmallFABs( addAnchorToSmallFABs(
binding!!.fabGallery, binding!!.fabGallery,
requireView().findViewById<View>(R.id.empty_view).id requireView().findViewById<View>(fr.free.nrw.commons.R.id.empty_view).id
) )
addAnchorToSmallFABs( addAnchorToSmallFABs(
binding!!.fabCamera, binding!!.fabCamera,
requireView().findViewById<View>(R.id.empty_view1).id requireView().findViewById<View>(fr.free.nrw.commons.R.id.empty_view1).id
) )
addAnchorToSmallFABs( addAnchorToSmallFABs(
binding!!.fabCustomGallery, binding!!.fabCustomGallery,
requireView().findViewById<View>(R.id.empty_view2).id requireView().findViewById<View>(fr.free.nrw.commons.R.id.empty_view2).id
) )
} }
@ -1718,10 +1773,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
if (applicationKvStore!!.getBoolean("login_skipped", false)) { if (applicationKvStore!!.getBoolean("login_skipped", false)) {
// prompt the user to login // prompt the user to login
AlertDialog.Builder(requireContext()) AlertDialog.Builder(requireContext())
.setMessage(R.string.login_alert_message) .setMessage(fr.free.nrw.commons.R.string.login_alert_message)
.setCancelable(false) .setCancelable(false)
.setNegativeButton(R.string.cancel) { dialog, which -> } .setNegativeButton(fr.free.nrw.commons.R.string.cancel) { dialog, which -> }
.setPositiveButton(R.string.login) { dialog, which -> .setPositiveButton(fr.free.nrw.commons.R.string.login) { dialog, which ->
// logout of the app // logout of the app
val logoutListener = val logoutListener =
CommonsApplication.BaseLogoutListener( CommonsApplication.BaseLogoutListener(
@ -1921,25 +1976,25 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
if (nearestPlace != null && place.name == nearestPlace!!.name) { if (nearestPlace != null && place.name == nearestPlace!!.name) {
// Highlight nearest place only when user clicks on the home nearby banner // Highlight nearest place only when user clicks on the home nearby banner
// highlightNearestPlace(place); // highlightNearestPlace(place);
return (if (isBookmarked) R.drawable.ic_custom_map_marker_purple_bookmarked else R.drawable.ic_custom_map_marker_purple return (if (isBookmarked) fr.free.nrw.commons.R.drawable.ic_custom_map_marker_purple_bookmarked else fr.free.nrw.commons.R.drawable.ic_custom_map_marker_purple
) )
} }
if (place.isMonument) { if (place.isMonument) {
return R.drawable.ic_custom_map_marker_monuments return fr.free.nrw.commons.R.drawable.ic_custom_map_marker_monuments
} }
if (!place.pic.trim { it <= ' ' }.isEmpty()) { if (!place.pic.trim { it <= ' ' }.isEmpty()) {
return (if (isBookmarked) R.drawable.ic_custom_map_marker_green_bookmarked else R.drawable.ic_custom_map_marker_green return (if (isBookmarked) fr.free.nrw.commons.R.drawable.ic_custom_map_marker_green_bookmarked else fr.free.nrw.commons.R.drawable.ic_custom_map_marker_green
) )
} }
if (!place.exists) { // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed if (!place.exists) { // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed
return (R.drawable.ic_clear_black_24dp) return (fr.free.nrw.commons.R.drawable.ic_clear_black_24dp)
} }
if (place.name.isEmpty()) { if (place.name.isEmpty()) {
return (if (isBookmarked) R.drawable.ic_custom_map_marker_grey_bookmarked else R.drawable.ic_custom_map_marker_grey return (if (isBookmarked) fr.free.nrw.commons.R.drawable.ic_custom_map_marker_grey_bookmarked else fr.free.nrw.commons.R.drawable.ic_custom_map_marker_grey
) )
} }
return (if (isBookmarked) R.drawable.ic_custom_map_marker_red_bookmarked else R.drawable.ic_custom_map_marker_red return (if (isBookmarked) fr.free.nrw.commons.R.drawable.ic_custom_map_marker_red_bookmarked else fr.free.nrw.commons.R.drawable.ic_custom_map_marker_red
) )
} }
@ -2074,10 +2129,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
if (intent.resolveActivity(packageManager) != null) { if (intent.resolveActivity(packageManager) != null) {
startActivity(intent) startActivity(intent)
Toast.makeText(context, R.string.recommend_high_accuracy_mode, Toast.LENGTH_LONG) Toast.makeText(context, fr.free.nrw.commons.R.string.recommend_high_accuracy_mode, Toast.LENGTH_LONG)
.show() .show()
} else { } else {
Toast.makeText(context, R.string.cannot_open_location_settings, Toast.LENGTH_LONG) Toast.makeText(context, fr.free.nrw.commons.R.string.cannot_open_location_settings, Toast.LENGTH_LONG)
.show() .show()
} }
} }
@ -2125,40 +2180,40 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
selectedPlace = place selectedPlace = place
dataList = ArrayList() dataList = ArrayList()
// TODO: Decide button text for fitting in the screen // TODO: Decide button text for fitting in the screen
(dataList as ArrayList<BottomSheetItem>).add(BottomSheetItem(R.drawable.ic_round_star_border_24px, "")) (dataList as ArrayList<BottomSheetItem>).add(BottomSheetItem(fr.free.nrw.commons.R.drawable.ic_round_star_border_24px, ""))
(dataList as ArrayList<BottomSheetItem>).add( (dataList as ArrayList<BottomSheetItem>).add(
BottomSheetItem( BottomSheetItem(
R.drawable.ic_directions_black_24dp, fr.free.nrw.commons.R.drawable.ic_directions_black_24dp,
resources.getString(R.string.nearby_directions) resources.getString(fr.free.nrw.commons.R.string.nearby_directions)
) )
) )
if (place.hasWikidataLink()) { if (place.hasWikidataLink()) {
(dataList as ArrayList<BottomSheetItem>).add( (dataList as ArrayList<BottomSheetItem>).add(
BottomSheetItem( BottomSheetItem(
R.drawable.ic_wikidata_logo_24dp, fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp,
resources.getString(R.string.nearby_wikidata) resources.getString(fr.free.nrw.commons.R.string.nearby_wikidata)
) )
) )
} }
(dataList as ArrayList<BottomSheetItem>).add( (dataList as ArrayList<BottomSheetItem>).add(
BottomSheetItem( BottomSheetItem(
R.drawable.ic_feedback_black_24dp, fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp,
resources.getString(R.string.nearby_wikitalk) resources.getString(fr.free.nrw.commons.R.string.nearby_wikitalk)
) )
) )
if (place.hasWikipediaLink()) { if (place.hasWikipediaLink()) {
(dataList as ArrayList<BottomSheetItem>).add( (dataList as ArrayList<BottomSheetItem>).add(
BottomSheetItem( BottomSheetItem(
R.drawable.ic_wikipedia_logo_24dp, fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp,
resources.getString(R.string.nearby_wikipedia) resources.getString(fr.free.nrw.commons.R.string.nearby_wikipedia)
) )
) )
} }
if (selectedPlace!!.hasCommonsLink()) { if (selectedPlace!!.hasCommonsLink()) {
(dataList as ArrayList<BottomSheetItem>).add( (dataList as ArrayList<BottomSheetItem>).add(
BottomSheetItem( BottomSheetItem(
R.drawable.ic_commons_icon_vector, fr.free.nrw.commons.R.drawable.ic_commons_icon_vector,
resources.getString(R.string.nearby_commons) resources.getString(fr.free.nrw.commons.R.string.nearby_commons)
) )
) )
} }
@ -2229,9 +2284,9 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
private fun updateBookmarkButtonImage(place: Place) { private fun updateBookmarkButtonImage(place: Place) {
val bookmarkIcon = if (bookmarkLocationDao!!.findBookmarkLocation(place)) { val bookmarkIcon = if (bookmarkLocationDao!!.findBookmarkLocation(place)) {
R.drawable.ic_round_star_filled_24px fr.free.nrw.commons.R.drawable.ic_round_star_filled_24px
} else { } else {
R.drawable.ic_round_star_border_24px fr.free.nrw.commons.R.drawable.ic_round_star_border_24px
} }
bottomSheetAdapter!!.updateBookmarkIcon(bookmarkIcon) bottomSheetAdapter!!.updateBookmarkIcon(bookmarkIcon)
} }
@ -2325,7 +2380,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
Marker.ANCHOR_BOTTOM Marker.ANCHOR_BOTTOM
) )
startMarker.icon = startMarker.icon =
ContextCompat.getDrawable(this.requireContext(), R.drawable.current_location_marker) ContextCompat.getDrawable(this.requireContext(), fr.free.nrw.commons.R.drawable.current_location_marker)
startMarker.title = "Your Location" startMarker.title = "Your Location"
startMarker.textLabelFontSize = 24 startMarker.textLabelFontSize = 24
binding!!.map.overlays.add(startMarker) binding!!.map.overlays.add(startMarker)
@ -2383,7 +2438,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
Marker.ANCHOR_BOTTOM Marker.ANCHOR_BOTTOM
) )
startMarker.icon = startMarker.icon =
ContextCompat.getDrawable(this.requireContext(), R.drawable.current_location_marker) ContextCompat.getDrawable(this.requireContext(), fr.free.nrw.commons.R.drawable.current_location_marker)
startMarker.title = "Your Location" startMarker.title = "Your Location"
startMarker.textLabelFontSize = 24 startMarker.textLabelFontSize = 24
binding!!.map.overlays.add(startMarker) binding!!.map.overlays.add(startMarker)
@ -2394,61 +2449,80 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
binding!!.map.controller.animateTo(geoPoint) binding!!.map.controller.animateTo(geoPoint)
} }
/**
* Moves the camera of the map view to the specified GeoPoint at specified zoom level and speed
* using an animation.
*
* @param geoPoint The GeoPoint representing the new camera position for the map.
* @param zoom Zoom level of the map camera
* @param speed Speed of animation
*/
private fun moveCameraToPosition(geoPoint: GeoPoint, zoom: Double, speed: Long) {
binding!!.map.controller.animateTo(geoPoint, zoom, speed)
}
override fun onBottomSheetItemClick(view: View?, position: Int) { override fun onBottomSheetItemClick(view: View?, position: Int) {
val item = dataList!![position] val item = dataList?.get(position) ?: return // Null check for dataList
when (item.imageResourceId) { when (item.imageResourceId) {
R.drawable.ic_round_star_border_24px -> { fr.free.nrw.commons.R.drawable.ic_round_star_border_24px,
presenter!!.toggleBookmarkedStatus(selectedPlace) fr.free.nrw.commons.R.drawable.ic_round_star_filled_24px -> {
updateBookmarkButtonImage(selectedPlace!!) presenter?.toggleBookmarkedStatus(selectedPlace)
selectedPlace?.let { updateBookmarkButtonImage(it) }
} }
R.drawable.ic_round_star_filled_24px -> { fr.free.nrw.commons.R.drawable.ic_directions_black_24dp -> {
presenter!!.toggleBookmarkedStatus(selectedPlace) selectedPlace?.let {
updateBookmarkButtonImage(selectedPlace!!) Utils.handleGeoCoordinates(this.context, it.getLocation())
binding?.map?.zoomLevelDouble ?: 0.0
}
} }
R.drawable.ic_directions_black_24dp -> Utils.handleGeoCoordinates( fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp -> {
this.context, selectedPlace!!.getLocation() selectedPlace?.siteLinks?.wikidataLink?.let {
) Utils.handleWebUrl(this.context, it)
}
R.drawable.ic_wikidata_logo_24dp -> Utils.handleWebUrl(
this.context,
selectedPlace!!.siteLinks.wikidataLink
)
R.drawable.ic_feedback_black_24dp -> {
val intent = Intent(this.context, WikidataFeedback::class.java)
intent.putExtra("lat", selectedPlace!!.location.latitude)
intent.putExtra("lng", selectedPlace!!.location.longitude)
intent.putExtra("place", selectedPlace!!.name)
intent.putExtra("qid", selectedPlace!!.wikiDataEntityId)
startActivity(intent)
} }
R.drawable.ic_wikipedia_logo_24dp -> Utils.handleWebUrl( fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp -> {
this.context, selectedPlace?.let {
selectedPlace!!.siteLinks.wikipediaLink val intent = Intent(this.context, WikidataFeedback::class.java).apply {
) putExtra("lat", it.location.latitude)
putExtra("lng", it.location.longitude)
putExtra("place", it.name)
putExtra("qid", it.wikiDataEntityId)
}
startActivity(intent)
}
}
R.drawable.ic_commons_icon_vector -> Utils.handleWebUrl( fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp -> {
this.context, selectedPlace?.siteLinks?.wikipediaLink?.let {
selectedPlace!!.siteLinks.commonsLink Utils.handleWebUrl(this.context, it)
) }
}
fr.free.nrw.commons.R.drawable.ic_commons_icon_vector -> {
selectedPlace?.siteLinks?.commonsLink?.let {
Utils.handleWebUrl(this.context, it)
}
}
else -> {} else -> {}
} }
} }
override fun onBottomSheetItemLongClick(view: View?, position: Int) { override fun onBottomSheetItemLongClick(view: View?, position: Int) {
val item = dataList!![position] val item = dataList!![position]
val message = when (item.imageResourceId) { val message = when (item.imageResourceId) {
R.drawable.ic_round_star_border_24px -> getString(R.string.menu_bookmark) fr.free.nrw.commons.R.drawable.ic_round_star_border_24px -> getString(fr.free.nrw.commons.R.string.menu_bookmark)
R.drawable.ic_round_star_filled_24px -> getString(R.string.menu_bookmark) fr.free.nrw.commons.R.drawable.ic_round_star_filled_24px -> getString(fr.free.nrw.commons.R.string.menu_bookmark)
R.drawable.ic_directions_black_24dp -> getString(R.string.nearby_directions) fr.free.nrw.commons.R.drawable.ic_directions_black_24dp -> getString(fr.free.nrw.commons.R.string.nearby_directions)
R.drawable.ic_wikidata_logo_24dp -> getString(R.string.nearby_wikidata) fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikidata)
R.drawable.ic_feedback_black_24dp -> getString(R.string.nearby_wikitalk) fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikitalk)
R.drawable.ic_wikipedia_logo_24dp -> getString(R.string.nearby_wikipedia) fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikipedia)
R.drawable.ic_commons_icon_vector -> getString(R.string.nearby_commons) fr.free.nrw.commons.R.drawable.ic_commons_icon_vector -> getString(fr.free.nrw.commons.R.string.nearby_commons)
else -> "Long click" else -> "Long click"
} }
Toast.makeText(this.context, message, Toast.LENGTH_SHORT).show() Toast.makeText(this.context, message, Toast.LENGTH_SHORT).show()