Skip to content

Commit

Permalink
Fix #2792 (add little ui indicator to toolbar about cloud sync)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Sep 14, 2023
1 parent 62b2d53 commit 9287309
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import net.bible.service.device.ScreenSettings
import net.bible.service.device.speak.event.SpeakEvent
import net.bible.service.download.DownloadManager
import net.bible.service.cloudsync.CloudSync
import net.bible.service.cloudsync.CloudSyncEvent
import net.bible.service.download.FakeBookFactory
import net.bible.service.sword.BookAndKey
import net.bible.service.sword.BookAndKeySerialized
Expand Down Expand Up @@ -1064,6 +1065,10 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
updateTitle()
}

fun onEventMainThread(event: CloudSyncEvent) {
binding.syncIcon.visibility = if(event.running) View.VISIBLE else View.INVISIBLE
}

private fun openLink(uri: Uri) {
when (uri.host) {
"read.andbible.org" -> {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/net/bible/service/cloudsync/SyncService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import net.bible.android.activity.R
import net.bible.android.control.event.ABEventBus
import net.bible.service.common.BuildVariant
import net.bible.service.common.CALC_NOTIFICATION_CHANNEL
import net.bible.service.common.CommonUtils
Expand All @@ -38,6 +39,8 @@ private const val SYNC_NOTIFICATION_ID=2
const val SYNC_NOTIFICATION_CHANNEL="sync-notifications"
private const val WAKELOCK_TAG = "andbible:sync-wakelock"

class CloudSyncEvent(val running: Boolean = false)

class SyncService: Service() {
companion object {
const val START_SERVICE="action_start_service"
Expand Down Expand Up @@ -92,12 +95,14 @@ class SyncService: Service() {
wakeLock.acquire(5*60*1000) // 5 minutes

scope.launch {
ABEventBus.post(CloudSyncEvent(true))
CloudSync.synchronize()
CloudSync.waitUntilFinished(true)
Log.i(TAG, "Synchronize finished")
if(wakeLock.isHeld) {
wakeLock.release()
}
ABEventBus.post(CloudSyncEvent(false))
stop()
}
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/main_bible_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@
/>

</LinearLayout>

<ImageView
android:id="@+id/syncIcon"
android:layout_width="15dp"
android:layout_height="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_backup_restore_24dp"
app:tint="?attr/toolbarTextColor"
android:visibility="invisible"
/>

</androidx.constraintlayout.widget.ConstraintLayout>

<LinearLayout
Expand Down

0 comments on commit 9287309

Please sign in to comment.