mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
converted/Migrated
This commit is contained in:
parent
9e08a09583
commit
98d95e6bd0
1 changed files with 192 additions and 118 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.nearby.fragments
|
||||
|
||||
import android.Manifest.permission
|
||||
import android.fr.free.nrw.commons.R
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.ProgressDialog
|
||||
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.jakewharton.rxbinding2.view.RxView
|
||||
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
|
||||
import dagger.Provides
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
|
||||
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.di.CommonsDaggerSupportFragment
|
||||
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.location.LatLng
|
||||
import fr.free.nrw.commons.location.LocationPermissionsHelper
|
||||
|
|
@ -127,6 +126,7 @@ import javax.inject.Inject
|
|||
import javax.inject.Named
|
||||
import kotlin.concurrent.Volatile
|
||||
|
||||
|
||||
class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmentContract.View,
|
||||
WikidataP18EditListener, LocationUpdateListener, LocationPermissionCallback, ItemClickListener {
|
||||
var binding: FragmentNearbyParentBinding? = null
|
||||
|
|
@ -221,6 +221,11 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
@Volatile
|
||||
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 searchRunnable: Runnable? = null
|
||||
|
||||
|
|
@ -278,10 +283,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
if (shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
|
||||
showAlertDialog(
|
||||
requireActivity(),
|
||||
getString(R.string.location_permission_title),
|
||||
getString(R.string.location_permission_rationale_nearby),
|
||||
getString(android.R.string.ok),
|
||||
getString(android.R.string.cancel),
|
||||
getString(fr.free.nrw.commons.R.string.location_permission_title),
|
||||
getString(fr.free.nrw.commons.R.string.location_permission_rationale_nearby),
|
||||
getString(fr.free.nrw.commons.R.string.ok),
|
||||
getString(fr.free.nrw.commons.R.string.cancel),
|
||||
{
|
||||
askForLocationPermission()
|
||||
},
|
||||
|
|
@ -292,7 +297,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
if (isPermissionDenied) {
|
||||
locationPermissionsHelper?.showAppSettingsDialog(
|
||||
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")
|
||||
|
|
@ -312,6 +317,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
loadExploreMapData();
|
||||
|
||||
binding = FragmentNearbyParentBinding.inflate(inflater, container, false)
|
||||
view = binding!!.root
|
||||
|
||||
|
|
@ -334,11 +341,12 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
menu: Menu,
|
||||
inflater: MenuInflater
|
||||
) {
|
||||
inflater.inflate(R.menu.nearby_fragment_menu, menu)
|
||||
val refreshButton = menu.findItem(R.id.item_refresh)
|
||||
val listMenu = menu.findItem(R.id.list_sheet)
|
||||
val saveAsGPXButton = menu.findItem(R.id.list_item_gpx)
|
||||
val saveAsKMLButton = menu.findItem(R.id.list_item_kml)
|
||||
inflater.inflate(fr.free.nrw.commons.R.menu.nearby_fragment_menu, menu)
|
||||
val refreshButton = menu.findItem(fr.free.nrw.commons.R.id.item_refresh)
|
||||
val listMenu = menu.findItem(fr.free.nrw.commons.R.id.list_sheet)
|
||||
val showInExploreButton = menu.findItem(fr.free.nrw.commons.R.id.list_item_show_in_explore)
|
||||
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 {
|
||||
try {
|
||||
emptyCache()
|
||||
|
|
@ -351,9 +359,21 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
listOptionMenuItemClicked()
|
||||
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 {
|
||||
try {
|
||||
progressDialog!!.setTitle(getString(R.string.saving_gpx_file))
|
||||
progressDialog!!.setTitle(getString(fr.free.nrw.commons.R.string.saving_gpx_file))
|
||||
progressDialog!!.show()
|
||||
savePlacesAsGPX()
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -363,7 +383,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
}
|
||||
saveAsKMLButton.setOnMenuItemClickListener {
|
||||
try {
|
||||
progressDialog!!.setTitle(getString(R.string.saving_kml_file))
|
||||
progressDialog!!.setTitle(getString(fr.free.nrw.commons.R.string.saving_kml_file))
|
||||
progressDialog!!.show()
|
||||
savePlacesAsKML()
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -390,7 +410,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
)
|
||||
} else {
|
||||
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?.getZoomController()?.setVisibility(CustomZoomButtonsController.Visibility.NEVER)
|
||||
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?.addMapListener(object : MapListener {
|
||||
|
|
@ -462,15 +491,18 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
nearbyParentFragmentInstanceReadyCallback?.onReady()
|
||||
initNearbyFilter()
|
||||
addCheckBoxCallback()
|
||||
if (!isCameFromExploreMap()) {
|
||||
moveCameraToPosition(lastMapFocus!!);
|
||||
}
|
||||
moveCameraToPosition(lastMapFocus!!)
|
||||
initRvNearbyList()
|
||||
onResume()
|
||||
|
||||
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 {
|
||||
@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()
|
||||
|
||||
|
|
@ -503,7 +535,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
}
|
||||
}
|
||||
childFragmentManager.beginTransaction()
|
||||
.replace(R.id.fl_container_nearby_children, fragment)
|
||||
.replace(fr.free.nrw.commons.R.id.fl_container_nearby_children, fragment)
|
||||
.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
|
||||
|
|
@ -524,31 +577,31 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
private fun initThemePreferences() {
|
||||
if (isDarkTheme) {
|
||||
binding!!.bottomSheetNearby.rvNearbyList.setBackgroundColor(
|
||||
requireContext().resources.getColor(R.color.contributionListDarkBackground)
|
||||
requireContext().resources.getColor(fr.free.nrw.commons.R.color.contributionListDarkBackground)
|
||||
)
|
||||
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(
|
||||
requireContext().resources.getColor(android.R.color.white)
|
||||
requireContext().resources.getColor(fr.free.nrw.commons.R.color.white)
|
||||
)
|
||||
binding!!.nearbyFilterList.root.setBackgroundColor(
|
||||
requireContext().resources.getColor(R.color.contributionListDarkBackground)
|
||||
requireContext().resources.getColor(fr.free.nrw.commons.R.color.contributionListDarkBackground)
|
||||
)
|
||||
binding!!.map.overlayManager.tilesOverlay
|
||||
.setColorFilter(TilesOverlay.INVERT_COLORS)
|
||||
} else {
|
||||
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(
|
||||
requireContext().resources.getColor(R.color.contributionListDarkBackground)
|
||||
requireContext().resources.getColor(fr.free.nrw.commons.R.color.contributionListDarkBackground)
|
||||
)
|
||||
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(
|
||||
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
|
||||
binding!!.map.controller.setCenter(targetP)
|
||||
recenterMarkerToPosition(targetP)
|
||||
moveCameraToPosition(targetP)
|
||||
if (!isCameFromExploreMap()) {
|
||||
moveCameraToPosition(targetP);
|
||||
}
|
||||
} else if (locationManager!!.isGPSProviderEnabled()
|
||||
|| locationManager!!.isNetworkProviderEnabled()
|
||||
) {
|
||||
|
|
@ -622,7 +677,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
} else {
|
||||
locationPermissionsHelper!!.showLocationOffDialog(
|
||||
requireActivity(),
|
||||
R.string.ask_to_turn_location_on_text
|
||||
fr.free.nrw.commons.R.string.ask_to_turn_location_on_text
|
||||
)
|
||||
}
|
||||
presenter!!.onMapReady()
|
||||
|
|
@ -660,7 +715,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
} else {
|
||||
lastKnownLocation = defaultLatLng
|
||||
}
|
||||
if (binding!!.map != null) {
|
||||
if (binding?.map ?: != null && !isCameFromExploreMap()) {
|
||||
moveCameraToPosition(
|
||||
GeoPoint(lastKnownLocation!!.latitude, lastKnownLocation!!.longitude)
|
||||
)
|
||||
|
|
@ -883,10 +938,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
* Loads animations will be used for FABs
|
||||
*/
|
||||
private fun loadAnimations() {
|
||||
fab_open = AnimationUtils.loadAnimation(activity, R.anim.fab_open)
|
||||
fab_close = AnimationUtils.loadAnimation(activity, R.anim.fab_close)
|
||||
rotate_forward = AnimationUtils.loadAnimation(activity, R.anim.rotate_forward)
|
||||
rotate_backward = AnimationUtils.loadAnimation(activity, R.anim.rotate_backward)
|
||||
fab_open = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_open)
|
||||
fab_close = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_close)
|
||||
rotate_forward = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.rotate_forward)
|
||||
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(),
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -1032,7 +1087,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
} else {
|
||||
if (snackbar == null) {
|
||||
snackbar = Snackbar.make(
|
||||
view!!, R.string.no_internet,
|
||||
view!!, fr.free.nrw.commons.R.string.no_internet,
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
)
|
||||
searchable = false
|
||||
|
|
@ -1057,9 +1112,9 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
return
|
||||
}
|
||||
if (offlinePinsShown) {
|
||||
snackbar!!.setText(R.string.nearby_showing_pins_offline)
|
||||
snackbar!!.setText(fr.free.nrw.commons.R.string.nearby_showing_pins_offline)
|
||||
} 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 {
|
||||
Toast.makeText(
|
||||
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
|
||||
).show()
|
||||
}
|
||||
|
|
@ -1271,7 +1326,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
{ throwable: Throwable ->
|
||||
Timber.d(throwable)
|
||||
showErrorMessage(
|
||||
getString(R.string.error_fetching_nearby_places)
|
||||
getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
|
||||
+ throwable.localizedMessage
|
||||
)
|
||||
setProgressBarVisibility(false)
|
||||
|
|
@ -1306,7 +1361,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
} else {
|
||||
Toast.makeText(
|
||||
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
|
||||
).show()
|
||||
}
|
||||
|
|
@ -1315,7 +1370,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
{ throwable: Throwable ->
|
||||
Timber.d(throwable)
|
||||
showErrorMessage(
|
||||
getString(R.string.error_fetching_nearby_places)
|
||||
getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
|
||||
+ throwable.localizedMessage
|
||||
)
|
||||
setProgressBarVisibility(false)
|
||||
|
|
@ -1347,12 +1402,12 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
|
||||
|
||||
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 =
|
||||
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
|
||||
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) }
|
||||
showAlertDialog(requireActivity(), title, message, runnable) {}
|
||||
}
|
||||
|
|
@ -1379,7 +1434,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
context.startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
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
|
||||
).show()
|
||||
}
|
||||
|
|
@ -1432,7 +1487,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
{ throwable: Throwable ->
|
||||
Timber.d(throwable)
|
||||
showErrorMessage(
|
||||
getString(R.string.could_not_load_place_data)
|
||||
getString(fr.free.nrw.commons.R.string.could_not_load_place_data)
|
||||
+ throwable.localizedMessage
|
||||
)
|
||||
})
|
||||
|
|
@ -1467,7 +1522,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
.subscribe(
|
||||
{ nearbyPlacesInfo: NearbyPlacesInfo ->
|
||||
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)
|
||||
presenter!!.lockUnlockNearby(false)
|
||||
} else {
|
||||
|
|
@ -1482,7 +1537,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
{ throwable: Throwable ->
|
||||
Timber.d(throwable)
|
||||
showErrorMessage(
|
||||
getString(R.string.error_fetching_nearby_places)
|
||||
getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
|
||||
+ throwable.localizedMessage
|
||||
)
|
||||
setProgressBarVisibility(false)
|
||||
|
|
@ -1520,7 +1575,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
.subscribe(
|
||||
{ nearbyPlacesInfo: NearbyPlacesInfo ->
|
||||
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)
|
||||
presenter!!.lockUnlockNearby(false)
|
||||
} else {
|
||||
|
|
@ -1543,7 +1598,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
{ throwable: Throwable ->
|
||||
Timber.e(throwable)
|
||||
showErrorMessage(
|
||||
getString(R.string.error_fetching_nearby_places)
|
||||
getString(fr.free.nrw.commons.R.string.error_fetching_nearby_places)
|
||||
+ throwable.localizedMessage
|
||||
)
|
||||
setProgressBarVisibility(false)
|
||||
|
|
@ -1651,15 +1706,15 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
binding!!.fabPlus.show()
|
||||
addAnchorToSmallFABs(
|
||||
binding!!.fabGallery,
|
||||
requireView().findViewById<View>(R.id.empty_view).id
|
||||
requireView().findViewById<View>(fr.free.nrw.commons.R.id.empty_view).id
|
||||
)
|
||||
addAnchorToSmallFABs(
|
||||
binding!!.fabCamera,
|
||||
requireView().findViewById<View>(R.id.empty_view1).id
|
||||
requireView().findViewById<View>(fr.free.nrw.commons.R.id.empty_view1).id
|
||||
)
|
||||
addAnchorToSmallFABs(
|
||||
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)) {
|
||||
// prompt the user to login
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setMessage(R.string.login_alert_message)
|
||||
.setMessage(fr.free.nrw.commons.R.string.login_alert_message)
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(R.string.cancel) { dialog, which -> }
|
||||
.setPositiveButton(R.string.login) { dialog, which ->
|
||||
.setNegativeButton(fr.free.nrw.commons.R.string.cancel) { dialog, which -> }
|
||||
.setPositiveButton(fr.free.nrw.commons.R.string.login) { dialog, which ->
|
||||
// logout of the app
|
||||
val logoutListener =
|
||||
CommonsApplication.BaseLogoutListener(
|
||||
|
|
@ -1921,25 +1976,25 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
if (nearestPlace != null && place.name == nearestPlace!!.name) {
|
||||
// Highlight nearest place only when user clicks on the home nearby banner
|
||||
// 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) {
|
||||
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()) {
|
||||
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
|
||||
return (R.drawable.ic_clear_black_24dp)
|
||||
return (fr.free.nrw.commons.R.drawable.ic_clear_black_24dp)
|
||||
}
|
||||
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) {
|
||||
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()
|
||||
} 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()
|
||||
}
|
||||
}
|
||||
|
|
@ -2125,40 +2180,40 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
selectedPlace = place
|
||||
dataList = ArrayList()
|
||||
// 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(
|
||||
BottomSheetItem(
|
||||
R.drawable.ic_directions_black_24dp,
|
||||
resources.getString(R.string.nearby_directions)
|
||||
fr.free.nrw.commons.R.drawable.ic_directions_black_24dp,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_directions)
|
||||
)
|
||||
)
|
||||
if (place.hasWikidataLink()) {
|
||||
(dataList as ArrayList<BottomSheetItem>).add(
|
||||
BottomSheetItem(
|
||||
R.drawable.ic_wikidata_logo_24dp,
|
||||
resources.getString(R.string.nearby_wikidata)
|
||||
fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_wikidata)
|
||||
)
|
||||
)
|
||||
}
|
||||
(dataList as ArrayList<BottomSheetItem>).add(
|
||||
BottomSheetItem(
|
||||
R.drawable.ic_feedback_black_24dp,
|
||||
resources.getString(R.string.nearby_wikitalk)
|
||||
fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_wikitalk)
|
||||
)
|
||||
)
|
||||
if (place.hasWikipediaLink()) {
|
||||
(dataList as ArrayList<BottomSheetItem>).add(
|
||||
BottomSheetItem(
|
||||
R.drawable.ic_wikipedia_logo_24dp,
|
||||
resources.getString(R.string.nearby_wikipedia)
|
||||
fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_wikipedia)
|
||||
)
|
||||
)
|
||||
}
|
||||
if (selectedPlace!!.hasCommonsLink()) {
|
||||
(dataList as ArrayList<BottomSheetItem>).add(
|
||||
BottomSheetItem(
|
||||
R.drawable.ic_commons_icon_vector,
|
||||
resources.getString(R.string.nearby_commons)
|
||||
fr.free.nrw.commons.R.drawable.ic_commons_icon_vector,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_commons)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -2229,9 +2284,9 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
|
||||
private fun updateBookmarkButtonImage(place: 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 {
|
||||
R.drawable.ic_round_star_border_24px
|
||||
fr.free.nrw.commons.R.drawable.ic_round_star_border_24px
|
||||
}
|
||||
bottomSheetAdapter!!.updateBookmarkIcon(bookmarkIcon)
|
||||
}
|
||||
|
|
@ -2325,7 +2380,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
Marker.ANCHOR_BOTTOM
|
||||
)
|
||||
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.textLabelFontSize = 24
|
||||
binding!!.map.overlays.add(startMarker)
|
||||
|
|
@ -2383,7 +2438,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
Marker.ANCHOR_BOTTOM
|
||||
)
|
||||
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.textLabelFontSize = 24
|
||||
binding!!.map.overlays.add(startMarker)
|
||||
|
|
@ -2394,61 +2449,80 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
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) {
|
||||
val item = dataList!![position]
|
||||
val item = dataList?.get(position) ?: return // Null check for dataList
|
||||
when (item.imageResourceId) {
|
||||
R.drawable.ic_round_star_border_24px -> {
|
||||
presenter!!.toggleBookmarkedStatus(selectedPlace)
|
||||
updateBookmarkButtonImage(selectedPlace!!)
|
||||
fr.free.nrw.commons.R.drawable.ic_round_star_border_24px,
|
||||
fr.free.nrw.commons.R.drawable.ic_round_star_filled_24px -> {
|
||||
presenter?.toggleBookmarkedStatus(selectedPlace)
|
||||
selectedPlace?.let { updateBookmarkButtonImage(it) }
|
||||
}
|
||||
|
||||
R.drawable.ic_round_star_filled_24px -> {
|
||||
presenter!!.toggleBookmarkedStatus(selectedPlace)
|
||||
updateBookmarkButtonImage(selectedPlace!!)
|
||||
fr.free.nrw.commons.R.drawable.ic_directions_black_24dp -> {
|
||||
selectedPlace?.let {
|
||||
Utils.handleGeoCoordinates(this.context, it.getLocation())
|
||||
binding?.map?.zoomLevelDouble ?: 0.0
|
||||
}
|
||||
}
|
||||
|
||||
R.drawable.ic_directions_black_24dp -> Utils.handleGeoCoordinates(
|
||||
this.context, selectedPlace!!.getLocation()
|
||||
)
|
||||
fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp -> {
|
||||
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)
|
||||
fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp -> {
|
||||
selectedPlace?.let {
|
||||
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_wikipedia_logo_24dp -> Utils.handleWebUrl(
|
||||
this.context,
|
||||
selectedPlace!!.siteLinks.wikipediaLink
|
||||
)
|
||||
fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp -> {
|
||||
selectedPlace?.siteLinks?.wikipediaLink?.let {
|
||||
Utils.handleWebUrl(this.context, it)
|
||||
}
|
||||
}
|
||||
|
||||
R.drawable.ic_commons_icon_vector -> Utils.handleWebUrl(
|
||||
this.context,
|
||||
selectedPlace!!.siteLinks.commonsLink
|
||||
)
|
||||
fr.free.nrw.commons.R.drawable.ic_commons_icon_vector -> {
|
||||
selectedPlace?.siteLinks?.commonsLink?.let {
|
||||
Utils.handleWebUrl(this.context, it)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onBottomSheetItemLongClick(view: View?, position: Int) {
|
||||
val item = dataList!![position]
|
||||
val message = when (item.imageResourceId) {
|
||||
R.drawable.ic_round_star_border_24px -> getString(R.string.menu_bookmark)
|
||||
R.drawable.ic_round_star_filled_24px -> getString(R.string.menu_bookmark)
|
||||
R.drawable.ic_directions_black_24dp -> getString(R.string.nearby_directions)
|
||||
R.drawable.ic_wikidata_logo_24dp -> getString(R.string.nearby_wikidata)
|
||||
R.drawable.ic_feedback_black_24dp -> getString(R.string.nearby_wikitalk)
|
||||
R.drawable.ic_wikipedia_logo_24dp -> getString(R.string.nearby_wikipedia)
|
||||
R.drawable.ic_commons_icon_vector -> getString(R.string.nearby_commons)
|
||||
fr.free.nrw.commons.R.drawable.ic_round_star_border_24px -> getString(fr.free.nrw.commons.R.string.menu_bookmark)
|
||||
fr.free.nrw.commons.R.drawable.ic_round_star_filled_24px -> getString(fr.free.nrw.commons.R.string.menu_bookmark)
|
||||
fr.free.nrw.commons.R.drawable.ic_directions_black_24dp -> getString(fr.free.nrw.commons.R.string.nearby_directions)
|
||||
fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikidata)
|
||||
fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikitalk)
|
||||
fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikipedia)
|
||||
fr.free.nrw.commons.R.drawable.ic_commons_icon_vector -> getString(fr.free.nrw.commons.R.string.nearby_commons)
|
||||
else -> "Long click"
|
||||
}
|
||||
Toast.makeText(this.context, message, Toast.LENGTH_SHORT).show()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue