mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
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`.
This commit is contained in:
parent
7894f4a026
commit
442e72dcb1
7 changed files with 23 additions and 35 deletions
|
|
@ -232,12 +232,6 @@
|
|||
android:exported="false"
|
||||
android:label="@string/provider_bookmarks"
|
||||
android:syncable="false" />
|
||||
<provider
|
||||
android:name=".bookmarks.locations.BookmarkLocationsContentProvider"
|
||||
android:authorities="${applicationId}.bookmarks.locations.contentprovider"
|
||||
android:exported="false"
|
||||
android:label="@string/provider_bookmarks_location"
|
||||
android:syncable="false" />
|
||||
<provider
|
||||
android:name=".bookmarks.items.BookmarkItemsContentProvider"
|
||||
android:authorities="${applicationId}.bookmarks.items.contentprovider"
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class BookmarkLocationsFragment : DaggerFragment() {
|
|||
|
||||
adapter = PlaceAdapter(
|
||||
bookmarkLocationDao,
|
||||
scope = lifecycleScope,
|
||||
lifecycleScope,
|
||||
{ },
|
||||
{ place, _ ->
|
||||
adapter.remove(place)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import fr.free.nrw.commons.upload.depicts.DepictsDao
|
|||
*/
|
||||
@Database(
|
||||
entities = [Contribution::class, Depicts::class, UploadedStatus::class, NotForUploadStatus::class, ReviewEntity::class, Place::class, BookmarksCategoryModal::class, BookmarksLocations::class],
|
||||
version = 19,
|
||||
version = 20,
|
||||
exportSchema = false,
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
|
|
|
|||
|
|
@ -111,11 +111,6 @@ open class CommonsApplicationModule(private val applicationContext: Context) {
|
|||
fun provideBookmarkContentProviderClient(context: Context): ContentProviderClient? =
|
||||
context.contentResolver.acquireContentProviderClient(BuildConfig.BOOKMARK_AUTHORITY)
|
||||
|
||||
@Provides
|
||||
@Named("bookmarksLocation")
|
||||
fun provideBookmarkLocationContentProviderClient(context: Context): ContentProviderClient? =
|
||||
context.contentResolver.acquireContentProviderClient(BuildConfig.BOOKMARK_LOCATIONS_AUTHORITY)
|
||||
|
||||
@Provides
|
||||
@Named("bookmarksItem")
|
||||
fun provideBookmarkItemContentProviderClient(context: Context): ContentProviderClient? =
|
||||
|
|
|
|||
|
|
@ -101,9 +101,6 @@ abstract class FragmentBuilderModule {
|
|||
@ContributesAndroidInjector
|
||||
abstract fun bindBookmarkCategoriesListFragment(): BookmarkCategoriesFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindBookmarkLocationsListFragment(): BookmarkLocationsFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindReviewOutOfContextFragment(): ReviewImageFragment
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
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 fr.free.nrw.commons.bookmarks.locations.BookmarksLocations
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
object NearbyUtil {
|
||||
|
|
@ -10,13 +11,17 @@ object NearbyUtil {
|
|||
fun getBookmarkLocationExists(
|
||||
bookmarksLocationsDao: BookmarkLocationsDao,
|
||||
name: String,
|
||||
scope: LifecycleCoroutineScope?
|
||||
): Boolean {
|
||||
var isBookmarked = false
|
||||
scope: LifecycleCoroutineScope?,
|
||||
bottomSheetAdapter: BottomSheetAdapter,
|
||||
) {
|
||||
scope?.launch {
|
||||
isBookmarked = bookmarksLocationsDao.findBookmarkLocation(name)
|
||||
val isBookmarked = bookmarksLocationsDao.findBookmarkLocation(name)
|
||||
Log.d("isBookmarked", isBookmarked.toString())
|
||||
if (isBookmarked) {
|
||||
bottomSheetAdapter.updateBookmarkIcon(R.drawable.ic_round_star_filled_24px)
|
||||
} else {
|
||||
bottomSheetAdapter.updateBookmarkIcon(R.drawable.ic_round_star_border_24px)
|
||||
}
|
||||
}
|
||||
|
||||
return isBookmarked
|
||||
}
|
||||
}
|
||||
|
|
@ -142,29 +142,26 @@ class NearbyParentFragmentPresenter
|
|||
scope: LifecycleCoroutineScope?
|
||||
) {
|
||||
if (place == null) return
|
||||
var nowBookmarked: Boolean? = null
|
||||
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] = nowBookmarked?.let {
|
||||
MarkerPlaceGroup(
|
||||
it,
|
||||
bookmarkChangedPlaces.add(place)
|
||||
val placeIndex =
|
||||
NearbyController.markerLabelList.indexOfFirst { it.place.location == place.location }
|
||||
NearbyController.markerLabelList[placeIndex] = MarkerPlaceGroup(
|
||||
nowBookmarked,
|
||||
NearbyController.markerLabelList[placeIndex].place
|
||||
)
|
||||
nearbyParentFragmentView.setFilterState()
|
||||
}
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue