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:exported="false"
|
||||||
android:label="@string/provider_bookmarks"
|
android:label="@string/provider_bookmarks"
|
||||||
android:syncable="false" />
|
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
|
<provider
|
||||||
android:name=".bookmarks.items.BookmarkItemsContentProvider"
|
android:name=".bookmarks.items.BookmarkItemsContentProvider"
|
||||||
android:authorities="${applicationId}.bookmarks.items.contentprovider"
|
android:authorities="${applicationId}.bookmarks.items.contentprovider"
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ class BookmarkLocationsFragment : DaggerFragment() {
|
||||||
|
|
||||||
adapter = PlaceAdapter(
|
adapter = PlaceAdapter(
|
||||||
bookmarkLocationDao,
|
bookmarkLocationDao,
|
||||||
scope = lifecycleScope,
|
lifecycleScope,
|
||||||
{ },
|
{ },
|
||||||
{ place, _ ->
|
{ place, _ ->
|
||||||
adapter.remove(place)
|
adapter.remove(place)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import fr.free.nrw.commons.upload.depicts.DepictsDao
|
||||||
*/
|
*/
|
||||||
@Database(
|
@Database(
|
||||||
entities = [Contribution::class, Depicts::class, UploadedStatus::class, NotForUploadStatus::class, ReviewEntity::class, Place::class, BookmarksCategoryModal::class, BookmarksLocations::class],
|
entities = [Contribution::class, Depicts::class, UploadedStatus::class, NotForUploadStatus::class, ReviewEntity::class, Place::class, BookmarksCategoryModal::class, BookmarksLocations::class],
|
||||||
version = 19,
|
version = 20,
|
||||||
exportSchema = false,
|
exportSchema = false,
|
||||||
)
|
)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
|
|
|
||||||
|
|
@ -111,11 +111,6 @@ open class CommonsApplicationModule(private val applicationContext: Context) {
|
||||||
fun provideBookmarkContentProviderClient(context: Context): ContentProviderClient? =
|
fun provideBookmarkContentProviderClient(context: Context): ContentProviderClient? =
|
||||||
context.contentResolver.acquireContentProviderClient(BuildConfig.BOOKMARK_AUTHORITY)
|
context.contentResolver.acquireContentProviderClient(BuildConfig.BOOKMARK_AUTHORITY)
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Named("bookmarksLocation")
|
|
||||||
fun provideBookmarkLocationContentProviderClient(context: Context): ContentProviderClient? =
|
|
||||||
context.contentResolver.acquireContentProviderClient(BuildConfig.BOOKMARK_LOCATIONS_AUTHORITY)
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Named("bookmarksItem")
|
@Named("bookmarksItem")
|
||||||
fun provideBookmarkItemContentProviderClient(context: Context): ContentProviderClient? =
|
fun provideBookmarkItemContentProviderClient(context: Context): ContentProviderClient? =
|
||||||
|
|
|
||||||
|
|
@ -101,9 +101,6 @@ abstract class FragmentBuilderModule {
|
||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
abstract fun bindBookmarkCategoriesListFragment(): BookmarkCategoriesFragment
|
abstract fun bindBookmarkCategoriesListFragment(): BookmarkCategoriesFragment
|
||||||
|
|
||||||
@ContributesAndroidInjector
|
|
||||||
abstract fun bindBookmarkLocationsListFragment(): BookmarkLocationsFragment
|
|
||||||
|
|
||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
abstract fun bindReviewOutOfContextFragment(): ReviewImageFragment
|
abstract fun bindReviewOutOfContextFragment(): ReviewImageFragment
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package fr.free.nrw.commons.nearby
|
package fr.free.nrw.commons.nearby
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.lifecycle.LifecycleCoroutineScope
|
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.BookmarkLocationsDao
|
||||||
import fr.free.nrw.commons.bookmarks.locations.BookmarksLocations
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
object NearbyUtil {
|
object NearbyUtil {
|
||||||
|
|
@ -10,13 +11,17 @@ object NearbyUtil {
|
||||||
fun getBookmarkLocationExists(
|
fun getBookmarkLocationExists(
|
||||||
bookmarksLocationsDao: BookmarkLocationsDao,
|
bookmarksLocationsDao: BookmarkLocationsDao,
|
||||||
name: String,
|
name: String,
|
||||||
scope: LifecycleCoroutineScope?
|
scope: LifecycleCoroutineScope?,
|
||||||
): Boolean {
|
bottomSheetAdapter: BottomSheetAdapter,
|
||||||
var isBookmarked = false
|
) {
|
||||||
scope?.launch {
|
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?
|
scope: LifecycleCoroutineScope?
|
||||||
) {
|
) {
|
||||||
if (place == null) return
|
if (place == null) return
|
||||||
var nowBookmarked: Boolean? = null
|
var nowBookmarked: Boolean
|
||||||
scope?.launch {
|
scope?.launch {
|
||||||
nowBookmarked = bookmarkLocationDao.updateBookmarkLocation(place)
|
nowBookmarked = bookmarkLocationDao.updateBookmarkLocation(place)
|
||||||
|
bookmarkChangedPlaces.add(place)
|
||||||
}
|
val placeIndex =
|
||||||
bookmarkChangedPlaces.add(place)
|
NearbyController.markerLabelList.indexOfFirst { it.place.location == place.location }
|
||||||
val placeIndex =
|
NearbyController.markerLabelList[placeIndex] = MarkerPlaceGroup(
|
||||||
NearbyController.markerLabelList.indexOfFirst { it.place.location == place.location }
|
nowBookmarked,
|
||||||
NearbyController.markerLabelList[placeIndex] = nowBookmarked?.let {
|
|
||||||
MarkerPlaceGroup(
|
|
||||||
it,
|
|
||||||
NearbyController.markerLabelList[placeIndex].place
|
NearbyController.markerLabelList[placeIndex].place
|
||||||
)
|
)
|
||||||
|
nearbyParentFragmentView.setFilterState()
|
||||||
}
|
}
|
||||||
nearbyParentFragmentView.setFilterState()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachView(view: NearbyParentFragmentContract.View) {
|
override fun attachView(view: NearbyParentFragmentContract.View) {
|
||||||
this.nearbyParentFragmentView = view
|
nearbyParentFragmentView = view
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
this.nearbyParentFragmentView = DUMMY
|
nearbyParentFragmentView = DUMMY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removeNearbyPreferences(applicationKvStore: JsonKvStore) {
|
override fun removeNearbyPreferences(applicationKvStore: JsonKvStore) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue