mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Migrated bookmarks locations to Kotlin and adapt room database (#6148)
* Rename .java to .kt
* Refactor: Migrate bookmark location logic to Kotlin
This commit migrates the bookmark location logic to Kotlin, enhancing code maintainability and readability.
- Removes the `BookmarkLocationsContentProvider`, `BookmarkLocationsController`, and `BookmarkLocationsDao` Java classes.
- Creates `BookmarkLocationsDao.kt` and `BookmarkLocationsContentProvider.kt` in Kotlin.
- Migrates the logic from `BookmarkLocationsFragment.java` to `BookmarkLocationsFragment.kt`.
- Updates test files to reflect these changes.
- Addresses associated code review comments.
* Refactor: Migrate to Room Database for Bookmark Locations
This commit migrates the bookmark locations functionality from a custom content provider to Room database.
Key changes:
* **Removal of `BookmarkLocationsContentProvider`:** This class, which previously handled data storage, has been removed.
* **Introduction of `BookmarksLocations`:** This data class now represents a bookmarked location, serving as the Room entity.
* **Creation of `BookmarkLocationsDao`:** This Room DAO handles database interactions for bookmark locations, including:
* Adding, deleting, and querying bookmarked locations.
* Checking if a location is already bookmarked.
* Updating the bookmark status of a location.
* Retrieving all bookmarked locations as `Place` objects.
* **`BookmarkLocationsViewModel`:** Added to manage the data layer for bookmark locations
* **`NearbyUtil`:** Created a Util class for Nearby to manage the bookmark locations.
* **Updates in `PlaceAdapter` and `PlaceAdapterDelegate`:** These classes have been modified to work with the new Room-based data layer.
* **Updates in `AppDatabase`:** The database now includes `BookmarksLocations` as an entity and exposes the `bookmarkLocationsDao`.
* **Updates in `FragmentBuilderModule` and `CommonsApplicationModule`**: for DI
* **Removal of `DBOpenHelper` upgrade for locations**: as it is no longer needed
* **Updates in `NearbyParentFragmentPresenter`**: refactored the logic to use the dao functions
* **Updates in `NearbyParentFragment`**: refactored the logic to use the util and dao functions
* **Update in `BookmarkLocationsController`**: removed as its no longer needed
* **Add `toPlace` and `toBookmarksLocations`**: extension functions to map between data class and entities
* **Update in `CommonsApplication`**: to remove old db table.
* Refactor: Improve bookmark location handling and update database version
This commit includes the following changes:
- Updates the database version to 20.
- Refactors bookmark location handling within `NearbyParentFragment` to improve logic and efficiency.
- Introduces `getBookmarkLocationExists` in `NearbyUtil` to directly update bookmark icons in the bottom sheet adapter.
- Removes unused provider.
- Adjusts `BookmarkLocationsFragment`'s `PlaceAdapter` to use `lifecycleScope` for better coroutine management.
- Refactors `updateBookmarkLocation` in `NearbyParentFragmentPresenter`.
* Toggle bookmark icon in BottomSheetAdapter instead of finding the location each time in the bookmark
* Update bookmark button image in `BottomSheetAdapter`
* Add new toggle function to `BottomSheetAdapter`
* Call the toggle function in `NearbyParentFragment`
* Refactor: Load bookmarked locations using Flow
* `BookmarkLocationsController`: Changed to use `Flow` to load bookmarked locations.
* `BookmarkLocationsDao`: Changed to return `Flow` of bookmark location instead of a list.
* `BookmarkLocationsFragment`: Used `LifecycleScope` to collect data from flow and display it.
* Removed unused `getAllBookmarkLocations()` from `BookmarkLocationsViewModel`.
* Used `map` in `BookmarkLocationsDao` to convert from `BookmarksLocations` to `Place` list.
* Loading locations data in fragment
* BookmarkLocationsController: Changed `loadFavoritesLocations` to be a suspend function.
* BookmarkLocationsFragment: Updated the `initList` function to call the controller's suspend function.
* BookmarkLocationsDao: Changed `getAllBookmarksLocations` and `getAllBookmarksLocationsPlace` to be suspend functions.
* Refactor BookmarkLocationControllerTest and related files to use coroutines
* Migrated `bookmarkDao!!.getAllBookmarksLocations()` to `bookmarkDao!!.getAllBookmarksLocationsPlace()` and added `runBlocking`
* Added `runBlocking` for `loadBookmarkedLocations()` and `testInitNonEmpty()`
* Added `runBlocking` for `getAllBookmarksLocations()` and update `updateMapMarkers`
These changes improve the test structure by ensuring the database functions are executed within a coroutine context.
* Refactor BookmarkLocationsFragment and add tests for BookmarkLocationsDao
* Moved `initList` to `BookmarkLocationsFragment` for better lifecycle handling.
* Added test case for `BookmarkLocationsFragment`'s onResume.
* Added test cases for `BookmarkLocationsDao` operations like adding, retrieving, finding, deleting and updating bookmarks.
* Refactor BookmarkLocationsFragment to load favorites only when view is not null
* BookmarkLocationsFragment: load favorites locations only when view is not null.
* BookmarkLocationsFragmentTest: added spy and verify to test onResume() call initList() method.
* Refactor database and add migration
* `AppDatabase`: Updated to use room migration.
* `CommonsApplicationModule`: added migration from version 19 to 20 to `appDatabase`
* Rename .java to .kt
* Refactor: Migrate bookmark location logic to Kotlin
This commit migrates the bookmark location logic to Kotlin, enhancing code maintainability and readability.
- Removes the `BookmarkLocationsContentProvider`, `BookmarkLocationsController`, and `BookmarkLocationsDao` Java classes.
- Creates `BookmarkLocationsDao.kt` and `BookmarkLocationsContentProvider.kt` in Kotlin.
- Migrates the logic from `BookmarkLocationsFragment.java` to `BookmarkLocationsFragment.kt`.
- Updates test files to reflect these changes.
- Addresses associated code review comments.
* Refactor: Migrate to Room Database for Bookmark Locations
This commit migrates the bookmark locations functionality from a custom content provider to Room database.
Key changes:
* **Removal of `BookmarkLocationsContentProvider`:** This class, which previously handled data storage, has been removed.
* **Introduction of `BookmarksLocations`:** This data class now represents a bookmarked location, serving as the Room entity.
* **Creation of `BookmarkLocationsDao`:** This Room DAO handles database interactions for bookmark locations, including:
* Adding, deleting, and querying bookmarked locations.
* Checking if a location is already bookmarked.
* Updating the bookmark status of a location.
* Retrieving all bookmarked locations as `Place` objects.
* **`BookmarkLocationsViewModel`:** Added to manage the data layer for bookmark locations
* **`NearbyUtil`:** Created a Util class for Nearby to manage the bookmark locations.
* **Updates in `PlaceAdapter` and `PlaceAdapterDelegate`:** These classes have been modified to work with the new Room-based data layer.
* **Updates in `AppDatabase`:** The database now includes `BookmarksLocations` as an entity and exposes the `bookmarkLocationsDao`.
* **Updates in `FragmentBuilderModule` and `CommonsApplicationModule`**: for DI
* **Removal of `DBOpenHelper` upgrade for locations**: as it is no longer needed
* **Updates in `NearbyParentFragmentPresenter`**: refactored the logic to use the dao functions
* **Updates in `NearbyParentFragment`**: refactored the logic to use the util and dao functions
* **Update in `BookmarkLocationsController`**: removed as its no longer needed
* **Add `toPlace` and `toBookmarksLocations`**: extension functions to map between data class and entities
* **Update in `CommonsApplication`**: to remove old db table.
* Refactor: Improve bookmark location handling and update database version
This commit includes the following changes:
- Updates the database version to 20.
- Refactors bookmark location handling within `NearbyParentFragment` to improve logic and efficiency.
- Introduces `getBookmarkLocationExists` in `NearbyUtil` to directly update bookmark icons in the bottom sheet adapter.
- Removes unused provider.
- Adjusts `BookmarkLocationsFragment`'s `PlaceAdapter` to use `lifecycleScope` for better coroutine management.
- Refactors `updateBookmarkLocation` in `NearbyParentFragmentPresenter`.
* Toggle bookmark icon in BottomSheetAdapter instead of finding the location each time in the bookmark
* Update bookmark button image in `BottomSheetAdapter`
* Add new toggle function to `BottomSheetAdapter`
* Call the toggle function in `NearbyParentFragment`
* Refactor: Load bookmarked locations using Flow
* `BookmarkLocationsController`: Changed to use `Flow` to load bookmarked locations.
* `BookmarkLocationsDao`: Changed to return `Flow` of bookmark location instead of a list.
* `BookmarkLocationsFragment`: Used `LifecycleScope` to collect data from flow and display it.
* Removed unused `getAllBookmarkLocations()` from `BookmarkLocationsViewModel`.
* Used `map` in `BookmarkLocationsDao` to convert from `BookmarksLocations` to `Place` list.
* Loading locations data in fragment
* BookmarkLocationsController: Changed `loadFavoritesLocations` to be a suspend function.
* BookmarkLocationsFragment: Updated the `initList` function to call the controller's suspend function.
* BookmarkLocationsDao: Changed `getAllBookmarksLocations` and `getAllBookmarksLocationsPlace` to be suspend functions.
* Refactor BookmarkLocationControllerTest and related files to use coroutines
* Migrated `bookmarkDao!!.getAllBookmarksLocations()` to `bookmarkDao!!.getAllBookmarksLocationsPlace()` and added `runBlocking`
* Added `runBlocking` for `loadBookmarkedLocations()` and `testInitNonEmpty()`
* Added `runBlocking` for `getAllBookmarksLocations()` and update `updateMapMarkers`
These changes improve the test structure by ensuring the database functions are executed within a coroutine context.
* Refactor BookmarkLocationsFragment and add tests for BookmarkLocationsDao
* Moved `initList` to `BookmarkLocationsFragment` for better lifecycle handling.
* Added test case for `BookmarkLocationsFragment`'s onResume.
* Added test cases for `BookmarkLocationsDao` operations like adding, retrieving, finding, deleting and updating bookmarks.
* Refactor BookmarkLocationsFragment to load favorites only when view is not null
* BookmarkLocationsFragment: load favorites locations only when view is not null.
* BookmarkLocationsFragmentTest: added spy and verify to test onResume() call initList() method.
* Refactor database and add migration
* `AppDatabase`: Updated to use room migration.
* `CommonsApplicationModule`: added migration from version 19 to 20 to `appDatabase`
* Resolve conflicts and attach the `commons.db` with `common_room.db` during the migration to persist the data
* Refactor database migration to handle null values and use direct insertion
* Modify the database migration from version 19 to 20 to properly handle null values and use direct data insertion.
* Create a new table `bookmarks_locations` with `NOT NULL` constraints.
* Directly insert data into the new table from old database, safely handling `NULL` values by using `DEFAULT` empty string value.
* Close old database cursor and the database connection.
* Drop the old `bookmarksLocations` table.
* Refactor database schema to delete `bookmarksLocations` table and migrate data
* Delete `bookmarksLocations` table from the database during schema upgrade
* Migrate data from `bookmarksLocations` to `bookmarks_locations` in new schema
* Add `INSERT OR REPLACE` to prevent duplication during migration
* Delete `CONTRIBUTIONS_TABLE` and `BOOKMARKS_LOCATIONS` in the application start-up to have a fresh DB for first start-up after update
* Update sqlite-based database version to 22.
* Update sqlite-based database version to 22.
* Refactor CommonsApplicationModule to utilize application context
* Initialize and use application context directly
* Utilize lateinit for application context
* Added line breaks for improved readability.
---------
Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
1c4797d3aa
commit
1c7dce9e12
26 changed files with 702 additions and 946 deletions
|
|
@ -68,7 +68,21 @@ class BottomSheetAdapter(
|
|||
item.imageResourceId == R.drawable.ic_round_star_border_24px
|
||||
) {
|
||||
item.imageResourceId = icon
|
||||
this.notifyItemChanged(index)
|
||||
notifyItemChanged(index)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleBookmarkIcon() {
|
||||
itemList.forEachIndexed { index, item ->
|
||||
if(item.imageResourceId == R.drawable.ic_round_star_filled_24px) {
|
||||
item.imageResourceId = R.drawable.ic_round_star_border_24px
|
||||
notifyItemChanged(index)
|
||||
return
|
||||
} else if(item.imageResourceId == R.drawable.ic_round_star_border_24px){
|
||||
item.imageResourceId = R.drawable.ic_round_star_filled_24px
|
||||
notifyItemChanged(index)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
app/src/main/java/fr/free/nrw/commons/nearby/NearbyUtil.kt
Normal file
28
app/src/main/java/fr/free/nrw/commons/nearby/NearbyUtil.kt
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package fr.free.nrw.commons.nearby
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
object NearbyUtil {
|
||||
|
||||
fun getBookmarkLocationExists(
|
||||
bookmarksLocationsDao: BookmarkLocationsDao,
|
||||
name: String,
|
||||
scope: LifecycleCoroutineScope?,
|
||||
bottomSheetAdapter: BottomSheetAdapter,
|
||||
) {
|
||||
scope?.launch {
|
||||
val isBookmarked = bookmarksLocationsDao.findBookmarkLocation(name)
|
||||
Timber.i("isBookmarked: $isBookmarked")
|
||||
if (isBookmarked) {
|
||||
bottomSheetAdapter.updateBookmarkIcon(R.drawable.ic_round_star_filled_24px)
|
||||
} else {
|
||||
bottomSheetAdapter.updateBookmarkIcon(R.drawable.ic_round_star_border_24px)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import android.view.View.INVISIBLE
|
|||
import android.view.View.VISIBLE
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.transition.TransitionManager
|
||||
|
|
@ -16,9 +17,11 @@ import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||
import fr.free.nrw.commons.databinding.ItemPlaceBinding
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
fun placeAdapterDelegate(
|
||||
bookmarkLocationDao: BookmarkLocationsDao,
|
||||
scope: LifecycleCoroutineScope?,
|
||||
onItemClick: ((Place) -> Unit)? = null,
|
||||
onCameraClicked: (Place, ActivityResultLauncher<Array<String>>, ActivityResultLauncher<Intent>) -> Unit,
|
||||
onCameraLongPressed: () -> Boolean,
|
||||
|
|
@ -61,7 +64,10 @@ fun placeAdapterDelegate(
|
|||
nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item, galleryPickLauncherForResult) }
|
||||
nearbyButtonLayout.galleryButton.setOnLongClickListener { onGalleryLongPressed() }
|
||||
bookmarkButtonImage.setOnClickListener {
|
||||
val isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item)
|
||||
var isBookmarked = false
|
||||
scope?.launch {
|
||||
isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item)
|
||||
}
|
||||
bookmarkButtonImage.setImageResource(
|
||||
if (isBookmarked) R.drawable.ic_round_star_filled_24px else R.drawable.ic_round_star_border_24px,
|
||||
)
|
||||
|
|
@ -93,13 +99,15 @@ fun placeAdapterDelegate(
|
|||
GONE
|
||||
}
|
||||
|
||||
bookmarkButtonImage.setImageResource(
|
||||
if (bookmarkLocationDao.findBookmarkLocation(item)) {
|
||||
R.drawable.ic_round_star_filled_24px
|
||||
} else {
|
||||
R.drawable.ic_round_star_border_24px
|
||||
},
|
||||
)
|
||||
scope?.launch {
|
||||
bookmarkButtonImage.setImageResource(
|
||||
if (bookmarkLocationDao.findBookmarkLocation(item.name)) {
|
||||
R.drawable.ic_round_star_filled_24px
|
||||
} else {
|
||||
R.drawable.ic_round_star_border_24px
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
nearbyButtonLayout.directionsButton.setOnLongClickListener { onDirectionsLongPressed() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ public interface NearbyParentFragmentContract {
|
|||
|
||||
void setAdvancedQuery(String query);
|
||||
|
||||
void toggleBookmarkedStatus(Place place);
|
||||
void toggleBookmarkedStatus(Place place, LifecycleCoroutineScope scope);
|
||||
|
||||
void handleMapScrolled(LifecycleCoroutineScope scope, boolean isNetworkAvailable);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ import fr.free.nrw.commons.nearby.MarkerPlaceGroup
|
|||
import fr.free.nrw.commons.nearby.NearbyController
|
||||
import fr.free.nrw.commons.nearby.NearbyFilterSearchRecyclerViewAdapter
|
||||
import fr.free.nrw.commons.nearby.NearbyFilterState
|
||||
import fr.free.nrw.commons.nearby.NearbyUtil
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
import fr.free.nrw.commons.nearby.PlacesRepository
|
||||
import fr.free.nrw.commons.nearby.WikidataFeedback
|
||||
|
|
@ -664,21 +665,23 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
private fun initRvNearbyList() {
|
||||
binding!!.bottomSheetNearby.rvNearbyList.layoutManager = LinearLayoutManager(context)
|
||||
adapter = PlaceAdapter(
|
||||
bookmarkLocationDao!!,
|
||||
{ place: Place ->
|
||||
bookmarkLocationsDao = bookmarkLocationDao,
|
||||
scope = scope,
|
||||
onPlaceClicked = { place: Place ->
|
||||
moveCameraToPosition(
|
||||
GeoPoint(place.location.latitude, place.location.longitude)
|
||||
GeoPoint(
|
||||
place.location.latitude,
|
||||
place.location.longitude
|
||||
)
|
||||
)
|
||||
Unit
|
||||
},
|
||||
{ place: Place?, isBookmarked: Boolean? ->
|
||||
presenter!!.toggleBookmarkedStatus(place)
|
||||
Unit
|
||||
onBookmarkClicked = { place: Place?, _: Boolean? ->
|
||||
presenter!!.toggleBookmarkedStatus(place, scope)
|
||||
},
|
||||
commonPlaceClickActions!!,
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
galleryPickLauncherForResult,
|
||||
cameraPickLauncherForResult
|
||||
commonPlaceClickActions = commonPlaceClickActions,
|
||||
inAppCameraLocationPermissionLauncher = inAppCameraLocationPermissionLauncher,
|
||||
galleryPickLauncherForResult = galleryPickLauncherForResult,
|
||||
cameraPickLauncherForResult = cameraPickLauncherForResult
|
||||
)
|
||||
binding!!.bottomSheetNearby.rvNearbyList.adapter = adapter
|
||||
}
|
||||
|
|
@ -2303,34 +2306,34 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
// 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,
|
||||
R.drawable.ic_round_star_border_24px,
|
||||
""
|
||||
)
|
||||
)
|
||||
(dataList as ArrayList<BottomSheetItem>).add(
|
||||
BottomSheetItem(
|
||||
fr.free.nrw.commons.R.drawable.ic_directions_black_24dp,
|
||||
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(
|
||||
fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp,
|
||||
R.drawable.ic_wikidata_logo_24dp,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_wikidata)
|
||||
)
|
||||
)
|
||||
}
|
||||
(dataList as ArrayList<BottomSheetItem>).add(
|
||||
BottomSheetItem(
|
||||
fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp,
|
||||
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(
|
||||
fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp,
|
||||
R.drawable.ic_wikipedia_logo_24dp,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_wikipedia)
|
||||
)
|
||||
)
|
||||
|
|
@ -2338,7 +2341,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
if (selectedPlace!!.hasCommonsLink()) {
|
||||
(dataList as ArrayList<BottomSheetItem>).add(
|
||||
BottomSheetItem(
|
||||
fr.free.nrw.commons.R.drawable.ic_commons_icon_vector,
|
||||
R.drawable.ic_commons_icon_vector,
|
||||
resources.getString(fr.free.nrw.commons.R.string.nearby_commons)
|
||||
)
|
||||
)
|
||||
|
|
@ -2566,12 +2569,16 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
}
|
||||
|
||||
private fun updateBookmarkButtonImage(place: Place) {
|
||||
val bookmarkIcon = if (bookmarkLocationDao!!.findBookmarkLocation(place)) {
|
||||
fr.free.nrw.commons.R.drawable.ic_round_star_filled_24px
|
||||
} else {
|
||||
fr.free.nrw.commons.R.drawable.ic_round_star_border_24px
|
||||
}
|
||||
bottomSheetAdapter!!.updateBookmarkIcon(bookmarkIcon)
|
||||
NearbyUtil.getBookmarkLocationExists(
|
||||
bookmarkLocationDao,
|
||||
place.getName(),
|
||||
scope,
|
||||
bottomSheetAdapter!!
|
||||
)
|
||||
}
|
||||
|
||||
private fun toggleBookmarkButtonImage() {
|
||||
bottomSheetAdapter?.toggleBookmarkIcon()
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
|
|
@ -2749,26 +2756,31 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
override fun onBottomSheetItemClick(view: View?, position: Int) {
|
||||
val item = dataList?.get(position) ?: return // Null check for dataList
|
||||
when (item.imageResourceId) {
|
||||
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)
|
||||
R.drawable.ic_round_star_border_24px -> {
|
||||
presenter?.toggleBookmarkedStatus(selectedPlace, scope)
|
||||
toggleBookmarkButtonImage()
|
||||
}
|
||||
|
||||
R.drawable.ic_round_star_filled_24px -> {
|
||||
presenter?.toggleBookmarkedStatus(selectedPlace, scope)
|
||||
toggleBookmarkButtonImage()
|
||||
selectedPlace?.let { updateBookmarkButtonImage(it) }
|
||||
}
|
||||
|
||||
fr.free.nrw.commons.R.drawable.ic_directions_black_24dp -> {
|
||||
R.drawable.ic_directions_black_24dp -> {
|
||||
selectedPlace?.let {
|
||||
Utils.handleGeoCoordinates(this.context, it.getLocation())
|
||||
binding?.map?.zoomLevelDouble ?: 0.0
|
||||
}
|
||||
}
|
||||
|
||||
fr.free.nrw.commons.R.drawable.ic_wikidata_logo_24dp -> {
|
||||
R.drawable.ic_wikidata_logo_24dp -> {
|
||||
selectedPlace?.siteLinks?.wikidataLink?.let {
|
||||
Utils.handleWebUrl(this.context, it)
|
||||
}
|
||||
}
|
||||
|
||||
fr.free.nrw.commons.R.drawable.ic_feedback_black_24dp -> {
|
||||
R.drawable.ic_feedback_black_24dp -> {
|
||||
selectedPlace?.let {
|
||||
val intent = Intent(this.context, WikidataFeedback::class.java).apply {
|
||||
putExtra("lat", it.location.latitude)
|
||||
|
|
@ -2780,13 +2792,13 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
}
|
||||
}
|
||||
|
||||
fr.free.nrw.commons.R.drawable.ic_wikipedia_logo_24dp -> {
|
||||
R.drawable.ic_wikipedia_logo_24dp -> {
|
||||
selectedPlace?.siteLinks?.wikipediaLink?.let {
|
||||
Utils.handleWebUrl(this.context, it)
|
||||
}
|
||||
}
|
||||
|
||||
fr.free.nrw.commons.R.drawable.ic_commons_icon_vector -> {
|
||||
R.drawable.ic_commons_icon_vector -> {
|
||||
selectedPlace?.siteLinks?.commonsLink?.let {
|
||||
Utils.handleWebUrl(this.context, it)
|
||||
}
|
||||
|
|
@ -2800,13 +2812,13 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
override fun onBottomSheetItemLongClick(view: View?, position: Int) {
|
||||
val item = dataList!![position]
|
||||
val message = when (item.imageResourceId) {
|
||||
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)
|
||||
R.drawable.ic_round_star_border_24px -> getString(fr.free.nrw.commons.R.string.menu_bookmark)
|
||||
R.drawable.ic_round_star_filled_24px -> getString(fr.free.nrw.commons.R.string.menu_bookmark)
|
||||
R.drawable.ic_directions_black_24dp -> getString(fr.free.nrw.commons.R.string.nearby_directions)
|
||||
R.drawable.ic_wikidata_logo_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikidata)
|
||||
R.drawable.ic_feedback_black_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikitalk)
|
||||
R.drawable.ic_wikipedia_logo_24dp -> getString(fr.free.nrw.commons.R.string.nearby_wikipedia)
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.nearby.fragments
|
|||
|
||||
import android.content.Intent
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
import fr.free.nrw.commons.nearby.placeAdapterDelegate
|
||||
|
|
@ -9,6 +10,7 @@ import fr.free.nrw.commons.upload.categories.BaseDelegateAdapter
|
|||
|
||||
class PlaceAdapter(
|
||||
bookmarkLocationsDao: BookmarkLocationsDao,
|
||||
scope: LifecycleCoroutineScope? = null,
|
||||
onPlaceClicked: ((Place) -> Unit)? = null,
|
||||
onBookmarkClicked: (Place, Boolean) -> Unit,
|
||||
commonPlaceClickActions: CommonPlaceClickActions,
|
||||
|
|
@ -18,6 +20,7 @@ class PlaceAdapter(
|
|||
) : BaseDelegateAdapter<Place>(
|
||||
placeAdapterDelegate(
|
||||
bookmarkLocationsDao,
|
||||
scope,
|
||||
onPlaceClicked,
|
||||
commonPlaceClickActions.onCameraClicked(),
|
||||
commonPlaceClickActions.onCameraLongPressed(),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import kotlinx.coroutines.delay
|
|||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.job
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.internal.wait
|
||||
import timber.log.Timber
|
||||
|
|
@ -136,25 +137,31 @@ class NearbyParentFragmentPresenter
|
|||
* @param place The place whose bookmarked status is to be toggled. If the place is `null`,
|
||||
* the operation is skipped.
|
||||
*/
|
||||
override fun toggleBookmarkedStatus(place: Place?) {
|
||||
override fun toggleBookmarkedStatus(
|
||||
place: Place?,
|
||||
scope: LifecycleCoroutineScope?
|
||||
) {
|
||||
if (place == null) return
|
||||
val nowBookmarked = bookmarkLocationDao.updateBookmarkLocation(place)
|
||||
bookmarkChangedPlaces.add(place)
|
||||
val placeIndex =
|
||||
NearbyController.markerLabelList.indexOfFirst { it.place.location == place.location }
|
||||
NearbyController.markerLabelList[placeIndex] = MarkerPlaceGroup(
|
||||
nowBookmarked,
|
||||
NearbyController.markerLabelList[placeIndex].place
|
||||
)
|
||||
nearbyParentFragmentView.setFilterState()
|
||||
var nowBookmarked: Boolean
|
||||
scope?.launch {
|
||||
nowBookmarked = bookmarkLocationDao.updateBookmarkLocation(place)
|
||||
bookmarkChangedPlaces.add(place)
|
||||
val placeIndex =
|
||||
NearbyController.markerLabelList.indexOfFirst { it.place.location == place.location }
|
||||
NearbyController.markerLabelList[placeIndex] = MarkerPlaceGroup(
|
||||
nowBookmarked,
|
||||
NearbyController.markerLabelList[placeIndex].place
|
||||
)
|
||||
nearbyParentFragmentView.setFilterState()
|
||||
}
|
||||
}
|
||||
|
||||
override fun attachView(view: NearbyParentFragmentContract.View) {
|
||||
this.nearbyParentFragmentView = view
|
||||
nearbyParentFragmentView = view
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
this.nearbyParentFragmentView = DUMMY
|
||||
nearbyParentFragmentView = DUMMY
|
||||
}
|
||||
|
||||
override fun removeNearbyPreferences(applicationKvStore: JsonKvStore) {
|
||||
|
|
@ -337,7 +344,7 @@ class NearbyParentFragmentPresenter
|
|||
for (i in 0..updatedGroups.lastIndex) {
|
||||
val repoPlace = placesRepository.fetchPlace(updatedGroups[i].place.entityID)
|
||||
if (repoPlace != null && repoPlace.name != null && repoPlace.name != ""){
|
||||
updatedGroups[i].isBookmarked = bookmarkLocationDao.findBookmarkLocation(repoPlace)
|
||||
updatedGroups[i].isBookmarked = bookmarkLocationDao.findBookmarkLocation(repoPlace.name)
|
||||
updatedGroups[i].place.apply {
|
||||
name = repoPlace.name
|
||||
isMonument = repoPlace.isMonument
|
||||
|
|
@ -375,7 +382,7 @@ class NearbyParentFragmentPresenter
|
|||
collectResults.send(
|
||||
fetchedPlaces.mapIndexed { index, place ->
|
||||
Pair(indices[index], MarkerPlaceGroup(
|
||||
bookmarkLocationDao.findBookmarkLocation(place),
|
||||
bookmarkLocationDao.findBookmarkLocation(place.name),
|
||||
place
|
||||
))
|
||||
}
|
||||
|
|
@ -393,7 +400,10 @@ class NearbyParentFragmentPresenter
|
|||
|
||||
onePlaceBatch.add(Pair(i, MarkerPlaceGroup(
|
||||
bookmarkLocationDao.findBookmarkLocation(
|
||||
fetchedPlace[0]),fetchedPlace[0])))
|
||||
fetchedPlace[0].name
|
||||
),
|
||||
fetchedPlace[0]
|
||||
)))
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("NearbyPinDetails").e(e)
|
||||
onePlaceBatch.add(Pair(i, updatedGroups[i]))
|
||||
|
|
@ -457,7 +467,7 @@ class NearbyParentFragmentPresenter
|
|||
if (bookmarkChangedPlacesBacklog.containsKey(group.place.location)) {
|
||||
updatedGroups[index] = MarkerPlaceGroup(
|
||||
bookmarkLocationDao
|
||||
.findBookmarkLocation(updatedGroups[index].place),
|
||||
.findBookmarkLocation(updatedGroups[index].place.name),
|
||||
updatedGroups[index].place
|
||||
)
|
||||
}
|
||||
|
|
@ -565,7 +575,7 @@ class NearbyParentFragmentPresenter
|
|||
).sortedBy { it.getDistanceInDouble(mapFocus) }.take(NearbyController.MAX_RESULTS)
|
||||
.map {
|
||||
MarkerPlaceGroup(
|
||||
bookmarkLocationDao.findBookmarkLocation(it), it
|
||||
bookmarkLocationDao.findBookmarkLocation(it.name), it
|
||||
)
|
||||
}
|
||||
ensureActive()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue