converted/Migrated

This commit is contained in:
Sujal-Gupta-SG 2025-02-03 18:30:07 +05:30
parent 6c8e1da420
commit c199e5278b

View file

@ -1,7 +1,6 @@
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
@ -51,7 +50,6 @@ import com.jakewharton.rxbinding2.view.RxView
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
import fr.free.nrw.commons.CommonsApplication
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
import fr.free.nrw.commons.R
import fr.free.nrw.commons.Utils
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
import fr.free.nrw.commons.contributions.ContributionController
@ -240,10 +238,16 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
private val galleryPickLauncherForResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
controller?.handleActivityResultWithCallback(requireActivity(), object : FilePicker.HandleActivityResult {
controller?.handleActivityResultWithCallback(
requireActivity(),
object : FilePicker.HandleActivityResult {
override fun onHandleActivityResult(callbacks: FilePicker.Callbacks) {
// Handle the result from the gallery
controller?.onPictureReturnedFromGallery(result, requireActivity(), callbacks)
controller?.onPictureReturnedFromGallery(
result,
requireActivity(),
callbacks
)
}
})
}
@ -251,7 +255,9 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
private val customSelectorLauncherForResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult? ->
controller?.handleActivityResultWithCallback(requireActivity(), object : FilePicker.HandleActivityResult {
controller?.handleActivityResultWithCallback(
requireActivity(),
object : FilePicker.HandleActivityResult {
override fun onHandleActivityResult(callbacks: FilePicker.Callbacks) {
controller?.onPictureReturnedFromCustomSelector(
result,
@ -265,9 +271,15 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
private val cameraPickLauncherForResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult? ->
controller?.handleActivityResultWithCallback(requireActivity(), object : FilePicker.HandleActivityResult {
controller?.handleActivityResultWithCallback(
requireActivity(),
object : FilePicker.HandleActivityResult {
override fun onHandleActivityResult(callbacks: FilePicker.Callbacks) {
controller?.onPictureReturnedFromCamera(result, requireActivity(), callbacks)
controller?.onPictureReturnedFromCamera(
result,
requireActivity(),
callbacks
)
}
})
}
@ -309,8 +321,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
/**
* WLM URL
*/
val WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app"
val WLM_URL =
"https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app"
override fun onCreateView(
@ -360,16 +372,15 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
false
}
showInExploreButton.setOnMenuItemClickListener(object : OnMenuItemClickListener() {
fun onMenuItemClick(@NonNull item: MenuItem?): Boolean {
showInExploreButton.setOnMenuItemClickListener { item ->
(context as MainActivity).loadExploreMapFromNearby(
binding!!.map.zoomLevelDouble,
binding!!.map.mapCenter.latitude,
binding!!.map.mapCenter.longitude
binding?.map?.zoomLevelDouble ?: 0.0, // Using safe calls to avoid NPE
binding?.map?.mapCenter?.latitude ?: 0.0,
binding?.map?.mapCenter?.longitude ?: 0.0
)
return false
return@setOnMenuItemClickListener true
}
})
saveAsGPXButton.setOnMenuItemClickListener {
try {
@ -396,7 +407,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Initialize the launcher in the appropriate lifecycle method (e.g., onViewCreated)
inAppCameraLocationPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { result ->
inAppCameraLocationPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { result ->
val areAllGranted = result.values.all { it }
if (areAllGranted) {
@ -439,14 +451,16 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
initThemePreferences()
initViews()
presenter?.setActionListeners(applicationKvStore)
org.osmdroid.config.Configuration.getInstance().load(requireContext(), PreferenceManager.getDefaultSharedPreferences(requireContext()))
org.osmdroid.config.Configuration.getInstance()
.load(requireContext(), PreferenceManager.getDefaultSharedPreferences(requireContext()))
// Use the Wikimedia tile server, rather than OpenStreetMap (Mapnik)
binding?.map?.setTileSource(TileSourceFactory.WIKIMEDIA)
binding?.map?.setTilesScaledToDpi(true)
// Add referer HTTP header because the Wikimedia tile server requires it.
org.osmdroid.config.Configuration.getInstance().getAdditionalHttpRequestProperties().put("Referer", "http://maps.wikimedia.org/")
org.osmdroid.config.Configuration.getInstance().getAdditionalHttpRequestProperties()
.put("Referer", "http://maps.wikimedia.org/")
if (applicationKvStore?.getString("LastLocation") != null) { // Checking for last searched location
val locationLatLng = applicationKvStore!!.getString("LastLocation")!!.split(",")
@ -463,7 +477,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
scaleBarOverlay.setBackgroundPaint(barPaint)
scaleBarOverlay.enableScaleBar()
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())
// if we came from Explore map using 'Show in Nearby', load Explore map camera position
@ -499,10 +514,14 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
onResume()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
binding?.tvAttribution?.text = Html.fromHtml(getString(fr.free.nrw.commons.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(fr.free.nrw.commons.R.string.map_attribution))
binding?.tvAttribution?.text =
Html.fromHtml(getString(fr.free.nrw.commons.R.string.map_attribution))
}
binding?.tvAttribution?.movementMethod = LinkMovementMethod.getInstance()
@ -512,7 +531,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
val fragment = AdvanceQueryFragment()
val bundle = Bundle()
try {
bundle.putString("query", FileUtils.readFromResource("/queries/radius_query_for_upload_wizard.rq"))
bundle.putString(
"query",
FileUtils.readFromResource("/queries/radius_query_for_upload_wizard.rq")
)
} catch (e: IOException) {
Timber.e(e)
}
@ -554,9 +576,9 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
fun loadExploreMapData() {
// get fragment arguments
if (arguments != null) {
prevZoom = arguments!!.getDouble("prev_zoom")
prevLatitude = arguments!!.getDouble("prev_latitude")
prevLongitude = arguments!!.getDouble("prev_longitude")
prevZoom = requireArguments().getDouble("prev_zoom")
prevLatitude = requireArguments().getDouble("prev_latitude")
prevLongitude = requireArguments().getDouble("prev_longitude")
}
}
@ -580,7 +602,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
requireContext().resources.getColor(fr.free.nrw.commons.R.color.contributionListDarkBackground)
)
binding!!.nearbyFilterList.checkboxTriStates.setTextColor(
requireContext().resources.getColor(android.fr.free.nrw.commons.R.color.white)
requireContext().resources.getColor(fr.free.nrw.commons.R.color.white)
)
binding!!.nearbyFilterList.checkboxTriStates.setTextColor(
requireContext().resources.getColor(fr.free.nrw.commons.R.color.white)
@ -715,7 +737,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
} else {
lastKnownLocation = defaultLatLng
}
if (binding?.map ?: != null && !isCameFromExploreMap()) {
if (binding!!.map != null && !isCameFromExploreMap()) {
moveCameraToPosition(
GeoPoint(lastKnownLocation!!.latitude, lastKnownLocation!!.longitude)
)
@ -940,8 +962,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
private fun loadAnimations() {
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)
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)
}
/**
@ -953,7 +977,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
"place", binding!!.bottomSheetDetails.title.text.toString(),
context
)
Toast.makeText(context, fr.free.nrw.commons.R.string.text_copy, Toast.LENGTH_SHORT).show()
Toast.makeText(context, fr.free.nrw.commons.R.string.text_copy, Toast.LENGTH_SHORT)
.show()
true
}
@ -1379,6 +1404,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
})
)
}
fun saveFile(string: String, fileName: String?): Boolean {
if (!isExternalStorageWritable) {
return false
@ -2129,10 +2155,18 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
Toast.makeText(context, fr.free.nrw.commons.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, fr.free.nrw.commons.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()
}
}
@ -2180,7 +2214,12 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
selectedPlace = place
dataList = ArrayList()
// TODO: Decide button text for fitting in the screen
(dataList as ArrayList<BottomSheetItem>).add(BottomSheetItem(fr.free.nrw.commons.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(
fr.free.nrw.commons.R.drawable.ic_directions_black_24dp,
@ -2220,7 +2259,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
val spanCount = spanCount
gridLayoutManager = GridLayoutManager(this.context, spanCount)
binding!!.bottomSheetDetails.bottomSheetRecyclerView.layoutManager = gridLayoutManager
bottomSheetAdapter = BottomSheetAdapter(this.context,
bottomSheetAdapter = BottomSheetAdapter(
this.context,
dataList as ArrayList<BottomSheetItem>
)
bottomSheetAdapter!!.setClickListener(this)
@ -2277,7 +2317,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
private fun storeSharedPrefs(selectedPlace: Place) {
applicationKvStore!!.putJson<Place>(WikidataConstants.PLACE_OBJECT, selectedPlace)
val place = applicationKvStore!!.getJson<Place>(WikidataConstants.PLACE_OBJECT, Place::class.java)
val place =
applicationKvStore!!.getJson<Place>(WikidataConstants.PLACE_OBJECT, Place::class.java)
Timber.d("Stored place object %s", place.toString())
}
@ -2380,7 +2421,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
Marker.ANCHOR_BOTTOM
)
startMarker.icon =
ContextCompat.getDrawable(this.requireContext(), fr.free.nrw.commons.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)
@ -2438,7 +2482,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
Marker.ANCHOR_BOTTOM
)
startMarker.icon =
ContextCompat.getDrawable(this.requireContext(), fr.free.nrw.commons.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)
@ -2573,7 +2620,6 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentF
}
private val isExternalStorageWritable: Boolean
get() {
val state = Environment.getExternalStorageState()