Skip to content

Commit df7e6bf

Browse files
Surjit Kumar SahooSurjit Kumar Sahoo
authored andcommitted
feat: progress sync fixes and app rename
1 parent cb86e43 commit df7e6bf

File tree

7 files changed

+66
-11
lines changed

7 files changed

+66
-11
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
2-
<string name="app_name">Lissen (DEBUG)</string>
2+
<string name="app_name">Kahani (DEBUG)</string>
33
</resources>

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
android:roundIcon="@mipmap/ic_launcher_round"
2727
android:supportsRtl="true"
2828
android:largeHeap="true"
29-
android:theme="@style/Theme.Lissen"
29+
android:theme="@style/Theme.Kahani"
3030
tools:ignore="DiscouragedApi,UnusedAttribute"
3131
android:manageSpaceActivity="org.grakovne.lissen.content.LissenDataManagementActivity"
3232
tools:targetApi="36">
@@ -41,7 +41,7 @@
4141
android:name=".ui.activity.AppActivity"
4242
android:exported="true"
4343
android:launchMode="singleTop"
44-
android:theme="@style/Theme.Lissen"
44+
android:theme="@style/Theme.Kahani"
4545
tools:ignore="LockedOrientationActivity">
4646
<intent-filter>
4747
<action android:name="android.intent.action.MAIN" />
@@ -68,7 +68,7 @@
6868
<category android:name="android.intent.category.BROWSABLE" />
6969

7070
<data
71-
android:scheme="lissen"
71+
android:scheme="kahani"
7272
android:host="oauth" />
7373
</intent-filter>
7474
</activity>

app/src/main/kotlin/org/grakovne/lissen/content/BookRepository.kt

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ class BookRepository
8282
}
8383
}
8484

85+
suspend fun syncLocalProgress(
86+
itemId: String,
87+
progress: PlaybackProgress,
88+
): OperationResult<Unit> {
89+
Timber.d("Syncing LOCAL Progress only for $itemId. $progress")
90+
localCacheRepository.syncProgress(itemId, progress)
91+
return OperationResult.Success(Unit)
92+
}
93+
8594
suspend fun fetchBookCover(
8695
bookId: String,
8796
width: Int? = null,
@@ -312,11 +321,36 @@ class BookRepository
312321
val remoteTime = remote?.listenedLastUpdate ?: 0L
313322
val localTime = local?.listenedLastUpdate ?: 0L
314323

315-
if (remoteTime > localTime) {
316-
providePreferredChannel().fetchBook(id).foldAsync(
317-
onSuccess = { localCacheRepository.cacheBookMetadata(it) },
318-
onFailure = {},
319-
)
324+
when {
325+
remoteTime > localTime -> {
326+
providePreferredChannel().fetchBook(id).foldAsync(
327+
onSuccess = { localCacheRepository.cacheBookMetadata(it) },
328+
onFailure = {},
329+
)
330+
}
331+
332+
localTime > remoteTime -> {
333+
val book = localCacheRepository.fetchBook(id) ?: continue
334+
val progress = book.progress ?: continue
335+
336+
val session =
337+
providePreferredChannel()
338+
.startPlayback(
339+
bookId = id,
340+
episodeId = book.chapters.firstOrNull()?.id ?: continue,
341+
supportedMimeTypes = emptyList(),
342+
deviceId = preferences.getDeviceId(),
343+
).getOrNull() ?: continue
344+
345+
providePreferredChannel().syncProgress(
346+
sessionId = session.sessionId,
347+
progress =
348+
PlaybackProgress(
349+
currentTotalTime = progress.currentTime,
350+
currentChapterTime = 0.0, // Server will recalculate based on total time
351+
),
352+
)
353+
}
320354
}
321355
}
322356
}

app/src/main/kotlin/org/grakovne/lissen/content/LissenMediaProvider.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class LissenMediaProvider
7979
}
8080
}
8181

82+
suspend fun syncLocalProgress(
83+
itemId: String,
84+
progress: PlaybackProgress,
85+
): OperationResult<Unit> = localCacheRepository.syncProgress(itemId, progress)
86+
8287
suspend fun fetchBookCover(
8388
bookId: String,
8489
width: Int? = null,

app/src/main/kotlin/org/grakovne/lissen/playback/service/PlaybackSynchronizationService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class PlaybackSynchronizationService
5656

5757
fun cancelSynchronization() {
5858
syncJob?.cancel()
59+
runSync()
5960
}
6061

6162
private fun handleSyncEvent() {
@@ -111,6 +112,7 @@ class PlaybackSynchronizationService
111112
currentChapterIndex = currentIndex
112113
}
113114

115+
mediaChannel.syncLocalProgress(currentItem?.id ?: return@launch, overallProgress)
114116
playbackSession?.let { requestSync(it, overallProgress) }
115117
} catch (e: Exception) {
116118
Timber.e(e, "Error during sync")
@@ -180,7 +182,7 @@ class PlaybackSynchronizationService
180182
}
181183

182184
companion object {
183-
private const val SYNC_INTERVAL_LONG = 30_000L
185+
private const val SYNC_INTERVAL_LONG = 10_000L
184186
private const val SHORT_SYNC_WINDOW = SYNC_INTERVAL_LONG * 2 - 1
185187

186188
private const val SYNC_INTERVAL_SHORT = 5_000L

app/src/main/kotlin/org/grakovne/lissen/viewmodel/LibraryViewModel.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.grakovne.lissen.lib.domain.RecentBook
3333
import org.grakovne.lissen.persistence.preferences.LissenSharedPreferences
3434
import org.grakovne.lissen.ui.screens.library.paging.LibraryDefaultPagingSource
3535
import org.grakovne.lissen.ui.screens.library.paging.LibrarySearchPagingSource
36+
import timber.log.Timber
3637
import javax.inject.Inject
3738

3839
@HiltViewModel
@@ -124,6 +125,19 @@ class LibraryViewModel
124125
_recentBooks.postValue(it)
125126
}
126127
}
128+
129+
viewModelScope.launch {
130+
networkService
131+
.isServerAvailable
132+
.collect { isAvailable ->
133+
if (isAvailable) {
134+
Timber.d("Server is reachable. Triggering repository sync.")
135+
bookRepository.syncRepositories()
136+
refreshRecentListening()
137+
refreshLibrary()
138+
}
139+
}
140+
}
127141
}
128142

129143
fun getPager(isSearchRequested: Boolean) =

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<style name="Theme.Lissen" parent="Theme.Material3.DayNight.NoActionBar" />
3+
<style name="Theme.Kahani" parent="Theme.Material3.DayNight.NoActionBar" />
44

55
<style name="Theme.Transparent" parent="Theme.Material3.DayNight.NoActionBar">
66
<item name="android:windowIsTranslucent">true</item>

0 commit comments

Comments
 (0)