@@ -12,8 +12,6 @@ import com.quran.data.model.bookmark.Bookmark
1212import com.quran.data.model.bookmark.Tag
1313import com.quran.data.model.collection.ReadingCollection
1414import com.quran.data.model.collection.ReadingCollectionBookmarks
15- import com.quran.mobile.bookmark.sync.LocalDataChangeNotifier
16- import com.quran.mobile.bookmark.sync.notifyLocalDataChanged
1715import com.quran.mobile.bookmark.time.MobileSyncTimestampProvider
1816import com.quran.shared.persistence.model.AyahBookmark
1917import com.quran.shared.persistence.model.CollectionWithAyahBookmarks
@@ -47,7 +45,6 @@ class BookmarksDaoImpl @Inject constructor(
4745 private val collectionsRepository : CollectionsRepository ,
4846 private val collectionBookmarksRepository : CollectionBookmarksRepository ,
4947 private val bookmarkCollectionsState : BookmarkCollectionsState ,
50- private val localDataChangeNotifier : LocalDataChangeNotifier ,
5148 private val timestampProvider : MobileSyncTimestampProvider ,
5249 appCoroutineScope : AppCoroutineScope
5350) : BookmarksDao {
@@ -139,7 +136,6 @@ class BookmarksDaoImpl @Inject constructor(
139136 val tagId = withContext(Dispatchers .IO ) {
140137 collectionsRepository.addCollection(name, timestamp).id
141138 }
142- localDataChangeNotifier.notifyLocalDataChanged()
143139 return tagId
144140 }
145141
@@ -164,21 +160,14 @@ class BookmarksDaoImpl @Inject constructor(
164160 false
165161 }
166162 }
167- if (updated) {
168- localDataChangeNotifier.notifyLocalDataChanged()
169- }
170163 return updated
171164 }
172165
173166 override suspend fun removeTags (tags : List <Tag >) {
174- val removed = withContext(Dispatchers .IO ) {
167+ withContext(Dispatchers .IO ) {
175168 val collectionsById = bookmarkCollectionData().collectionsById
176169 val tagsToRemove = tags.filter { tag -> collectionsById.containsKey(tag.id) }
177170 tagsToRemove.forEach { tag -> collectionsRepository.deleteCollection(tag.id) }
178- tagsToRemove.isNotEmpty()
179- }
180- if (removed) {
181- localDataChangeNotifier.notifyLocalDataChanged()
182171 }
183172 }
184173
@@ -201,13 +190,12 @@ class BookmarksDaoImpl @Inject constructor(
201190 deleteNonTagged : Boolean
202191 ): Boolean {
203192 val timestamp = timestampProvider.now()
204- val updated = withContext(Dispatchers .IO ) {
193+ withContext(Dispatchers .IO ) {
205194 val bookmarkCollectionData = bookmarkCollectionData()
206195 val collectionsById = bookmarkCollectionData.collectionsById
207196 val targetTagIds = validTagIds(tagIds, collectionsById)
208197 val bookmarksById = bookmarksRepository.getAllBookmarks()
209198 .associateBy { bookmark -> bookmark.id }
210- var didWrite = false
211199 bookmarkIds
212200 .filter { bookmarkId -> bookmarkId.isNotBlank() }
213201 .distinct()
@@ -218,19 +206,14 @@ class BookmarksDaoImpl @Inject constructor(
218206 } else {
219207 bookmarkCollectionData.tagsByBookmarkId[bookmarkId].orEmpty().toSet() + targetTagIds
220208 }
221- didWrite = replaceBookmarkMemberships(
209+ replaceBookmarkMemberships(
222210 bookmark = bookmark,
223211 tagIds = nextTagIds,
224212 isInDefaultCollection = bookmarkId in bookmarkCollectionData.defaultBookmarkIds,
225213 collectionsById = collectionsById,
226214 timestamp = timestamp
227- ) ||
228- didWrite
215+ )
229216 }
230- didWrite
231- }
232- if (updated) {
233- localDataChangeNotifier.notifyLocalDataChanged()
234217 }
235218 return true
236219 }
@@ -242,7 +225,7 @@ class BookmarksDaoImpl @Inject constructor(
242225 deleteNonTagged : Boolean
243226 ): Boolean {
244227 val timestamp = timestampProvider.now()
245- val updated = withContext(Dispatchers .IO ) {
228+ withContext(Dispatchers .IO ) {
246229 val bookmarkCollectionData = bookmarkCollectionData()
247230 val collectionsById = bookmarkCollectionData.collectionsById
248231 val targetTagIds = validTagIds(tagIds, collectionsById)
@@ -272,43 +255,30 @@ class BookmarksDaoImpl @Inject constructor(
272255 false
273256 }
274257 }
275- if (updated) {
276- localDataChangeNotifier.notifyLocalDataChanged()
277- }
278258 return true
279259 }
280260
281261 override suspend fun removeBookmarkFromTag (bookmark : Bookmark , tagId : String ): Boolean {
282- val removed = withContext(Dispatchers .IO ) {
262+ return withContext(Dispatchers .IO ) {
283263 val ayahBookmark = findAyahBookmark(bookmark) ? : return @withContext false
284264 val collection = collectionsById()[tagId] ? : return @withContext false
285265 collectionBookmarksRepository.removeBookmarkFromCollection(collection.id, ayahBookmark)
286266 }
287- if (removed) {
288- localDataChangeNotifier.notifyLocalDataChanged()
289- }
290- return removed
291267 }
292268
293269 override suspend fun removeBookmarks (bookmarks : List <Bookmark >) {
294- val removed = withContext(Dispatchers .IO ) {
295- var didWrite = false
270+ withContext(Dispatchers .IO ) {
296271 bookmarks
297272 .filterNot { it.isPageBookmark() }
298273 .forEach { bookmark ->
299274 val ayahBookmark = findAyahBookmark(bookmark) ? : return @forEach
300275 bookmarksRepository.deleteBookmark(ayahBookmark.id)
301- didWrite = true
302276 }
303- didWrite
304- }
305- if (removed) {
306- localDataChangeNotifier.notifyLocalDataChanged()
307277 }
308278 }
309279
310280 override suspend fun removeBookmarksForPage (page : Int ) {
311- val removed = withContext(Dispatchers .IO ) {
281+ withContext(Dispatchers .IO ) {
312282 val quranInfo = quranInfoProvider()
313283 val bookmarksToRemove = bookmarksRepository.getAllBookmarks()
314284 .filter { bookmark ->
@@ -317,10 +287,6 @@ class BookmarksDaoImpl @Inject constructor(
317287 bookmarksToRemove.forEach { bookmark ->
318288 bookmarksRepository.deleteBookmark(bookmark.id)
319289 }
320- bookmarksToRemove.isNotEmpty()
321- }
322- if (removed) {
323- localDataChangeNotifier.notifyLocalDataChanged()
324290 }
325291 }
326292
@@ -331,7 +297,7 @@ class BookmarksDaoImpl @Inject constructor(
331297 }
332298
333299 override suspend fun replaceAyahBookmarks (bookmarks : List <Bookmark >) {
334- val replaced = withContext(Dispatchers .IO ) {
300+ withContext(Dispatchers .IO ) {
335301 val quranInfo = quranInfoProvider()
336302 val ayahBookmarks = bookmarks.normalizedAyahBookmarks(quranInfo)
337303 bookmarksRepository.getAllBookmarks().forEach { bookmark ->
@@ -349,10 +315,6 @@ class BookmarksDaoImpl @Inject constructor(
349315 }
350316 }
351317 }
352- true
353- }
354- if (replaced) {
355- localDataChangeNotifier.notifyLocalDataChanged()
356318 }
357319 }
358320
@@ -387,7 +349,6 @@ class BookmarksDaoImpl @Inject constructor(
387349 true
388350 }
389351 }
390- localDataChangeNotifier.notifyLocalDataChanged()
391352 return bookmarked
392353 }
393354
0 commit comments