diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 41788128c7..f5bdfd05bf 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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) diff --git a/app/src/main/java/fr/free/nrw/commons/BaseMarker.kt b/app/src/main/java/fr/free/nrw/commons/BaseMarker.kt index 28b01d6031..ac5ac41b69 100644 --- a/app/src/main/java/fr/free/nrw/commons/BaseMarker.kt +++ b/app/src/main/java/fr/free/nrw/commons/BaseMarker.kt @@ -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 } + } } } diff --git a/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationsDao.kt b/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationsDao.kt index 2fa65b2d94..a022d91886 100644 --- a/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationsDao.kt +++ b/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationsDao.kt @@ -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()) diff --git a/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarksLocations.kt b/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarksLocations.kt index 66d670169a..e22400a634 100644 --- a/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarksLocations.kt +++ b/app/src/main/java/fr/free/nrw/commons/bookmarks/locations/BookmarksLocations.kt @@ -33,12 +33,6 @@ fun BookmarksLocations.toPlace(): Place { 1F ) - val builder = Sitelinks.Builder().apply { - setWikipediaLink(locationWikipediaLink) - setWikidataLink(locationWikidataLink) - setCommonsLink(locationCommonsLink) - } - return Place( locationLanguage, locationName, @@ -46,7 +40,7 @@ fun BookmarksLocations.toPlace(): Place { locationDescription, location, locationCategory, - builder.build(), + Sitelinks(locationWikipediaLink, locationCommonsLink, locationWikidataLink), locationPic, locationExists ) @@ -54,19 +48,19 @@ fun BookmarksLocations.toPlace(): Place { 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!! ) -} \ No newline at end of file +} diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.kt b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.kt index 537d805c54..52dc4c8bcb 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.kt @@ -542,7 +542,7 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On return } - binding!!.cardViewNearby.permissionRequestButton.setOnClickListener { v: View? -> + binding!!.cardViewNearby.permissionRequestButton?.setOnClickListener { showNearbyCardPermissionRationale() } @@ -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 } @@ -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 { diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.kt b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.kt index 0873572d1d..1a051f1bf1 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.kt +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.kt @@ -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 diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt index 93cbdb0409..9937f05b61 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt @@ -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 @@ -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 } @@ -735,8 +734,8 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi val items = mutableListOf() 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) @@ -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) @@ -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 diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java b/app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java deleted file mode 100644 index 323f9756ff..0000000000 --- a/app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java +++ /dev/null @@ -1,137 +0,0 @@ -package fr.free.nrw.commons.nearby; - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.CompoundButton; - -import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatCheckBox; - -import java.util.List; - -import fr.free.nrw.commons.R; - -/** - * Base on https://stackoverflow.com/a/40939367/3950497 answer. - */ -public class CheckBoxTriStates extends AppCompatCheckBox { - - static public final int UNKNOWN = -1; - - static public final int UNCHECKED = 0; - - static public final int CHECKED = 1; - - private int state=UNKNOWN; - - private Callback callback; - - public interface Callback{ - void filterByMarkerType(@Nullable List