Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ dependencies {
implementation(libs.androidx.material3)
implementation(libs.androidx.foundation)
implementation(libs.androidx.foundation.layout)
implementation(libs.androidx.annotation)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
Expand Down
58 changes: 14 additions & 44 deletions app/src/main/java/fr/free/nrw/commons/BaseMarker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,29 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.appcompat.content.res.AppCompatResources
import fr.free.nrw.commons.location.LatLng
import fr.free.nrw.commons.nearby.Place
import androidx.core.graphics.createBitmap

class BaseMarker {
private var _position: LatLng = LatLng(0.0, 0.0, 0f)
private var _title: String = ""
private var _place: Place = Place()
private var _icon: Bitmap? = null
var position: LatLng = LatLng(0.0, 0.0, 0f)
var title: String = ""
var icon: Bitmap? = null
var place: Place = Place()

var position: LatLng
get() = _position
set(value) {
_position = value
}
var title: String
get() = _title
set(value) {
_title = value
}

var place: Place
get() = _place
set(value) {
_place = value
}
var icon: Bitmap?
get() = _icon
set(value) {
_icon = value
}

constructor() {
}

fun fromResource(
context: Context,
drawableResId: Int,
) {
val drawable: Drawable = context.resources.getDrawable(drawableResId)
icon =
if (drawable is BitmapDrawable) {
drawable.bitmap
} else {
val bitmap =
Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888,
)
fun fromResource(context: Context, drawableResId: Int) {
val drawable: Drawable? = AppCompatResources.getDrawable(context, drawableResId)
icon = when (drawable) {
null -> null
is BitmapDrawable -> drawable.bitmap
else -> {
val bitmap = createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
bitmap
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class BookmarkLocationsDao {
* @return `true` if added, `false` if removed.
*/
suspend fun updateBookmarkLocation(bookmarkLocation: Place): Boolean {
val exists = findBookmarkLocation(bookmarkLocation.name)
val exists = findBookmarkLocation(bookmarkLocation.name!!)

if (exists) {
deleteBookmarkLocation(bookmarkLocation.toBookmarksLocations())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,34 @@ fun BookmarksLocations.toPlace(): Place {
1F
)

val builder = Sitelinks.Builder().apply {
setWikipediaLink(locationWikipediaLink)
setWikidataLink(locationWikidataLink)
setCommonsLink(locationCommonsLink)
}

return Place(
locationLanguage,
locationName,
Label.fromText(locationLabelText),
locationDescription,
location,
locationCategory,
builder.build(),
Sitelinks(locationWikipediaLink, locationCommonsLink, locationWikidataLink),
locationPic,
locationExists
)
}

fun Place.toBookmarksLocations(): BookmarksLocations {
return BookmarksLocations(
locationName = name,
locationLanguage = language,
locationDescription = longDescription,
locationCategory = category,
locationLat = location.latitude,
locationLong = location.longitude,
locationName = name!!,
locationLanguage = language!!,
locationDescription = longDescription!!,
locationCategory = category!!,
locationLat = location!!.latitude,
locationLong = location!!.longitude,
locationLabelText = label?.text ?: "",
locationLabelIcon = label?.icon,
locationImageUrl = pic,
locationWikipediaLink = siteLinks.wikipediaLink.toString(),
locationWikidataLink = siteLinks.wikidataLink.toString(),
locationCommonsLink = siteLinks.commonsLink.toString(),
locationPic = pic,
locationExists = exists
locationImageUrl = pic!!,
locationWikipediaLink = siteLinks?.wikipediaLink ?: "",
locationWikidataLink = siteLinks?.wikidataLink ?: "",
locationCommonsLink = siteLinks?.commonsLink ?: "",
locationPic = pic!!,
locationExists = exists!!
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On
return
}

binding!!.cardViewNearby.permissionRequestButton.setOnClickListener { v: View? ->
binding!!.cardViewNearby.permissionRequestButton?.setOnClickListener {
showNearbyCardPermissionRationale()
}

Expand Down Expand Up @@ -658,7 +658,7 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On
var closestNearbyPlace: Place? = null
// Find the first nearby place that has no image and exists
for (place in nearbyPlacesInfo.placeList) {
if (place.pic == "" && place.exists) {
if (place.pic == "" && place.exists == true) {
closestNearbyPlace = place
break
}
Expand All @@ -668,8 +668,8 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On
binding!!.cardViewNearby.visibility = View.GONE
} else {
val distance = formatDistanceBetween(currentLatLng, closestNearbyPlace.location)
closestNearbyPlace.setDistance(distance)
direction = computeBearing(currentLatLng!!, closestNearbyPlace.location).toFloat()
closestNearbyPlace.distance = distance
direction = computeBearing(currentLatLng!!, closestNearbyPlace.location!!).toFloat()
binding!!.cardViewNearby.updateContent(closestNearbyPlace)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ class ExploreMapController @Inject constructor(
for (explorePlace in placeList) {
val baseMarker = BaseMarker()
val distance = formatDistanceBetween(currentLatLng, explorePlace.location)
explorePlace.setDistance(distance)
explorePlace.distance = distance

baseMarker.title =
explorePlace.name.substring(5, explorePlace.name.lastIndexOf("."))
explorePlace.name!!.substring(5, explorePlace.name!!.lastIndexOf("."))
baseMarker.position = LatLng(
explorePlace.location.latitude,
explorePlace.location.longitude, 0f
explorePlace.location!!.latitude,
explorePlace.location!!.longitude, 0f
)
baseMarker.place = explorePlace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
*/
private fun passInfoToSheet(place: Place) {
binding!!.bottomSheetDetailsBinding.directionsButton.setOnClickListener {
handleGeoCoordinates(requireActivity(), place.getLocation(), binding!!.mapView.zoomLevelDouble)
handleGeoCoordinates(requireActivity(), place.location!!, binding!!.mapView.zoomLevelDouble)
}

binding!!.bottomSheetDetailsBinding.commonsButton.visibility = if (place.hasCommonsLink()) View.VISIBLE else View.GONE
binding!!.bottomSheetDetailsBinding.commonsButton.setOnClickListener {
handleWebUrl(requireContext(), place.siteLinks.commonsLink)
handleWebUrl(requireContext(), place.siteLinks!!.commonsUri!!)
}

var index = 0
Expand All @@ -666,15 +666,14 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
}
index++
}
binding!!.bottomSheetDetailsBinding.title.text = place.name.substring(5, place.name.lastIndexOf("."))
binding!!.bottomSheetDetailsBinding.title.text = place.name!!.substring(5, place.name!!.lastIndexOf("."))
binding!!.bottomSheetDetailsBinding.category.text = place.distance
// Remove label since it is double information
var descriptionText = place.longDescription
.replace(place.getName() + " (", "")
var descriptionText = place.longDescription?.replace(place.name + " (", "")
descriptionText = (if (descriptionText == place.longDescription)
descriptionText
else
descriptionText.replaceFirst(".$".toRegex(), ""))
descriptionText?.replaceFirst(".$".toRegex(), ""))
// Set the short description after we remove place name from long description
binding!!.bottomSheetDetailsBinding.description.text = descriptionText
}
Expand Down Expand Up @@ -735,8 +734,8 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
val items = mutableListOf<OverlayItem?>()
val d: Drawable = nearbyBaseMarker.icon!!.toDrawable(resources)
val point = GeoPoint(
nearbyBaseMarker.place.location.latitude,
nearbyBaseMarker.place.location.longitude
nearbyBaseMarker.place.location!!.latitude,
nearbyBaseMarker.place.location!!.longitude
)

val markerMedia = getMediaFromImageURL(nearbyBaseMarker.place.pic)
Expand All @@ -752,7 +751,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi

var title = nearbyBaseMarker.place.name
// Remove "File:" if present at start
if (title.startsWith("File:")) {
if (title!!.startsWith("File:")) {
title = title.substring(5)
}
// Remove extensions like .jpg, .jpeg, .png, .svg (case insensitive)
Expand Down Expand Up @@ -870,7 +869,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
*/
private fun removeMarker(nearbyBaseMarker: BaseMarker?) {
if (nearbyBaseMarker == null ||
nearbyBaseMarker.place.getName() == null ||
nearbyBaseMarker.place.name == null ||
baseMarkerOverlayMap == null ||
!baseMarkerOverlayMap!!.containsKey(nearbyBaseMarker)) {
return
Expand Down
137 changes: 0 additions & 137 deletions app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java

This file was deleted.

Loading