mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
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.
This commit is contained in:
parent
86d0475637
commit
32f7b4c887
3 changed files with 10 additions and 9 deletions
|
|
@ -15,6 +15,6 @@ class BookmarkLocationsController @Inject constructor(
|
||||||
* Load bookmarked locations from the database.
|
* Load bookmarked locations from the database.
|
||||||
* @return a list of Place objects.
|
* @return a list of Place objects.
|
||||||
*/
|
*/
|
||||||
fun loadFavoritesLocations(): Flow<List<Place>> =
|
suspend fun loadFavoritesLocations(): List<Place> =
|
||||||
bookmarkLocationDao.getAllBookmarksLocationsPlace()
|
bookmarkLocationDao.getAllBookmarksLocationsPlace()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ abstract class BookmarkLocationsDao {
|
||||||
abstract suspend fun addBookmarkLocation(bookmarkLocation: BookmarksLocations)
|
abstract suspend fun addBookmarkLocation(bookmarkLocation: BookmarksLocations)
|
||||||
|
|
||||||
@Query("SELECT * FROM bookmarks_locations")
|
@Query("SELECT * FROM bookmarks_locations")
|
||||||
abstract fun getAllBookmarksLocations(): Flow<List<BookmarksLocations>>
|
abstract suspend fun getAllBookmarksLocations(): List<BookmarksLocations>
|
||||||
|
|
||||||
@Query("SELECT EXISTS (SELECT 1 FROM bookmarks_locations WHERE location_name = :name)")
|
@Query("SELECT EXISTS (SELECT 1 FROM bookmarks_locations WHERE location_name = :name)")
|
||||||
abstract suspend fun findBookmarkLocation(name: String): Boolean
|
abstract suspend fun findBookmarkLocation(name: String): Boolean
|
||||||
|
|
@ -44,7 +44,7 @@ abstract class BookmarkLocationsDao {
|
||||||
return !bookmarkLocationExists
|
return !bookmarkLocationExists
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllBookmarksLocationsPlace(): Flow<List<Place>> {
|
suspend fun getAllBookmarksLocationsPlace(): List<Place> {
|
||||||
return flow { getAllBookmarksLocations().map { it.map { it1 -> it1.toPlace() } } }
|
return getAllBookmarksLocations().map { it.toPlace() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,13 +130,14 @@ class BookmarkLocationsFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initList() {
|
private fun initList() {
|
||||||
var places: List<Place> = listOf()
|
var places: List<Place>
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
controller.loadFavoritesLocations().collect {
|
places = controller.loadFavoritesLocations()
|
||||||
adapter.items = it
|
updateUIList(places)
|
||||||
places = it
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateUIList(places: List<Place>) {
|
||||||
adapter.items = places
|
adapter.items = places
|
||||||
binding?.loadingImagesProgressBar?.visibility = View.GONE
|
binding?.loadingImagesProgressBar?.visibility = View.GONE
|
||||||
if (places.isEmpty()) {
|
if (places.isEmpty()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue