Skip to content

Commit 8ccd9cf

Browse files
committed
Remove notifiers that are no longer in use
1 parent cab157c commit 8ccd9cf

10 files changed

Lines changed: 27 additions & 200 deletions

File tree

common/bookmark/src/main/java/com/quran/mobile/bookmark/importdata/MobileSyncImporter.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ package com.quran.mobile.bookmark.importdata
44

55
import com.quran.data.di.AppScope
66
import com.quran.mobile.bookmark.di.MobileSyncDatabase
7-
import com.quran.mobile.bookmark.sync.LocalDataChangeNotifier
8-
import com.quran.mobile.bookmark.sync.notifyLocalDataChanged
97
import com.quran.shared.persistence.input.ImportAyahBookmark
108
import com.quran.shared.persistence.input.ImportCollection
119
import com.quran.shared.persistence.input.ImportCollectionAyahBookmark
@@ -30,8 +28,7 @@ interface MobileSyncImporter {
3028
@SingleIn(AppScope::class)
3129
@ContributesBinding(AppScope::class)
3230
class MobileSyncImporterImpl @Inject constructor(
33-
mobileSyncDatabase: MobileSyncDatabase,
34-
private val localDataChangeNotifier: LocalDataChangeNotifier
31+
mobileSyncDatabase: MobileSyncDatabase
3532
) : MobileSyncImporter {
3633

3734
private val importRepository = PersistenceImportRepositoryImpl(mobileSyncDatabase.database)
@@ -40,13 +37,9 @@ class MobileSyncImporterImpl @Inject constructor(
4037
data: MobileSyncImportData,
4138
deleteExisting: Boolean
4239
): MobileSyncImportResult {
43-
val result = importRepository
40+
return importRepository
4441
.importData(data.toPersistenceImportData(), deleteExisting = deleteExisting)
4542
.toMobileSyncImportResult()
46-
if (!data.isEmpty() || deleteExisting) {
47-
localDataChangeNotifier.notifyLocalDataChanged()
48-
}
49-
return result
5043
}
5144
}
5245

common/bookmark/src/main/java/com/quran/mobile/bookmark/model/BookmarksDaoImpl.kt

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import com.quran.data.model.bookmark.Bookmark
1212
import com.quran.data.model.bookmark.Tag
1313
import com.quran.data.model.collection.ReadingCollection
1414
import com.quran.data.model.collection.ReadingCollectionBookmarks
15-
import com.quran.mobile.bookmark.sync.LocalDataChangeNotifier
16-
import com.quran.mobile.bookmark.sync.notifyLocalDataChanged
1715
import com.quran.mobile.bookmark.time.MobileSyncTimestampProvider
1816
import com.quran.shared.persistence.model.AyahBookmark
1917
import 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

common/bookmark/src/main/java/com/quran/mobile/bookmark/model/ReadingBookmarksDaoImpl.kt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import com.quran.data.model.SuraAyah
88
import com.quran.data.model.bookmark.AyahReadingBookmark
99
import com.quran.data.model.bookmark.PageReadingBookmark
1010
import com.quran.data.model.bookmark.ReadingBookmark
11-
import com.quran.mobile.bookmark.sync.LocalDataChangeNotifier
12-
import com.quran.mobile.bookmark.sync.notifyLocalDataChanged
1311
import com.quran.mobile.bookmark.time.MobileSyncTimestampProvider
1412
import com.quran.shared.persistence.repository.readingbookmark.repository.ReadingBookmarksRepository
1513
import com.quran.shared.persistence.util.fromPlatform
@@ -33,14 +31,12 @@ import com.quran.shared.persistence.model.ReadingBookmark as SyncReadingBookmark
3331
*
3432
* @param pageMapper maps between current UI page coordinates and canonical storage page coordinates.
3533
* @param readingBookmarksRepository mobile-sync repository that owns persisted reading bookmark rows.
36-
* @param localDataChangeNotifier notifies sync when this device changes reading bookmark data.
3734
* @param timestampProvider provides the timestamp assigned to locally written bookmarks.
3835
*/
3936
@SingleIn(AppScope::class)
4037
class ReadingBookmarksDaoImpl @Inject constructor(
4138
private val pageMapper: ReadingBookmarkPageMapper,
4239
private val readingBookmarksRepository: ReadingBookmarksRepository,
43-
private val localDataChangeNotifier: LocalDataChangeNotifier,
4440
private val timestampProvider: MobileSyncTimestampProvider
4541
) : ReadingBookmarksDao {
4642
override fun readingBookmarkFlow(): Flow<ReadingBookmark?> {
@@ -71,9 +67,6 @@ class ReadingBookmarksDaoImpl @Inject constructor(
7167
readingBookmarksRepository.addPageReadingBookmark(pageMapper.currentPageToStoragePage(page), timestamp)
7268
true
7369
}
74-
if (set) {
75-
localDataChangeNotifier.notifyLocalDataChanged()
76-
}
7770
return set
7871
}
7972

@@ -83,19 +76,13 @@ class ReadingBookmarksDaoImpl @Inject constructor(
8376
readingBookmarksRepository.addAyahReadingBookmark(suraAyah.sura, suraAyah.ayah, timestamp)
8477
true
8578
}
86-
if (set) {
87-
localDataChangeNotifier.notifyLocalDataChanged()
88-
}
8979
return set
9080
}
9181

9282
override suspend fun deleteReadingBookmark(): Boolean {
9383
val deleted = withContext(Dispatchers.IO) {
9484
readingBookmarksRepository.deleteReadingBookmark()
9585
}
96-
if (deleted) {
97-
localDataChangeNotifier.notifyLocalDataChanged()
98-
}
9986
return deleted
10087
}
10188

@@ -109,7 +96,7 @@ class ReadingBookmarksDaoImpl @Inject constructor(
10996

11097
override suspend fun togglePageReadingBookmark(page: Int): Boolean {
11198
val timestamp = timestampProvider.now()
112-
val (isBookmarked, updated) = withContext(Dispatchers.IO) {
99+
val (isBookmarked, _) = withContext(Dispatchers.IO) {
113100
val storagePage = pageMapper.currentPageToStoragePage(page)
114101
val bookmark = readingBookmarksRepository.getReadingBookmark()
115102
if (bookmark is SyncPageReadingBookmark && bookmark.page == storagePage) {
@@ -119,9 +106,6 @@ class ReadingBookmarksDaoImpl @Inject constructor(
119106
true to true
120107
}
121108
}
122-
if (updated) {
123-
localDataChangeNotifier.notifyLocalDataChanged()
124-
}
125109
return isBookmarked
126110
}
127111

common/bookmark/src/main/java/com/quran/mobile/bookmark/model/RecentPagesDaoImpl.kt

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import com.quran.data.dao.Settings
88
import com.quran.data.di.AppCoroutineScope
99
import com.quran.data.di.AppScope
1010
import com.quran.data.model.bookmark.RecentPage
11-
import com.quran.mobile.bookmark.sync.LocalDataChangeNotifier
12-
import com.quran.mobile.bookmark.sync.notifyLocalDataChanged
1311
import com.quran.mobile.bookmark.time.MobileSyncTimestampProvider
1412
import com.quran.shared.persistence.model.ReadingSession
1513
import com.quran.shared.persistence.repository.readingsession.repository.ReadingSessionsRepository
@@ -37,7 +35,6 @@ class RecentPagesDaoImpl @Inject constructor(
3735
private val quranInfoProvider: () -> QuranInfo,
3836
private val settings: Settings,
3937
private val readingSessionsRepository: ReadingSessionsRepository,
40-
private val localDataChangeNotifier: LocalDataChangeNotifier,
4138
private val timestampProvider: MobileSyncTimestampProvider,
4239
appCoroutineScope: AppCoroutineScope
4340
) : RecentPagesDao {
@@ -68,69 +65,51 @@ class RecentPagesDaoImpl @Inject constructor(
6865

6966
override suspend fun addRecentPage(page: Int) {
7067
val timestamp = timestampProvider.now()
71-
val updated = withContext(Dispatchers.IO) {
68+
withContext(Dispatchers.IO) {
7269
val quranInfo = quranInfoProvider()
73-
val added = addRecentPageInternal(page, quranInfo, timestamp)
74-
val pruned = pruneRecentSessions(quranInfo)
75-
added || pruned
76-
}
77-
if (updated) {
78-
localDataChangeNotifier.notifyLocalDataChanged()
70+
addRecentPageInternal(page, quranInfo, timestamp)
71+
pruneRecentSessions(quranInfo)
7972
}
8073
}
8174

8275
override suspend fun replaceRecentRangeWithPage(deleteRangeStart: Int, deleteRangeEnd: Int, page: Int) {
8376
val timestamp = timestampProvider.now()
84-
val updated = withContext(Dispatchers.IO) {
77+
withContext(Dispatchers.IO) {
8578
val quranInfo = quranInfoProvider()
86-
val deleted = deleteSessionsForPageRange(deleteRangeStart..deleteRangeEnd, quranInfo)
87-
val added = addRecentPageInternal(page, quranInfo, timestamp)
88-
val pruned = pruneRecentSessions(quranInfo)
89-
deleted || added || pruned
90-
}
91-
if (updated) {
92-
localDataChangeNotifier.notifyLocalDataChanged()
79+
deleteSessionsForPageRange(deleteRangeStart..deleteRangeEnd, quranInfo)
80+
addRecentPageInternal(page, quranInfo, timestamp)
81+
pruneRecentSessions(quranInfo)
9382
}
9483
}
9584

9685
override suspend fun removeRecentPages() {
97-
val removed = withContext(Dispatchers.IO) {
86+
withContext(Dispatchers.IO) {
9887
removeRecentPagesInternal()
9988
}
100-
if (removed) {
101-
localDataChangeNotifier.notifyLocalDataChanged()
102-
}
10389
}
10490

10591
override suspend fun replaceRecentPages(pages: List<RecentPage>) {
106-
val updated = withContext(Dispatchers.IO) {
92+
withContext(Dispatchers.IO) {
10793
val quranInfo = quranInfoProvider()
108-
var didWrite = removeRecentPagesInternal()
94+
removeRecentPagesInternal()
10995
pages
11096
.take(MAX_RECENT_PAGES)
11197
.asReversed()
11298
.forEach { recentPage ->
113-
didWrite = addRecentPageInternal(
99+
addRecentPageInternal(
114100
page = recentPage.page,
115101
quranInfo = quranInfo,
116102
timestamp = recentPage.timestamp.toPlatformDateTime()
117-
) || didWrite
103+
)
118104
}
119-
val pruned = pruneRecentSessions(quranInfo)
120-
didWrite || pruned
121-
}
122-
if (updated) {
123-
localDataChangeNotifier.notifyLocalDataChanged()
105+
pruneRecentSessions(quranInfo)
124106
}
125107
}
126108

127109
override suspend fun removeRecentsForPage(page: Int) {
128-
val removed = withContext(Dispatchers.IO) {
110+
withContext(Dispatchers.IO) {
129111
deleteSessionsForPageRange(page..page, quranInfoProvider())
130112
}
131-
if (removed) {
132-
localDataChangeNotifier.notifyLocalDataChanged()
133-
}
134113
}
135114

136115
private suspend fun addRecentPageInternal(

0 commit comments

Comments
 (0)