Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: smoother exceptions (fixes #4861) #4864

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.google.android.material.bottomnavigation.BottomNavigationView
import io.realm.Realm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.callback.OnRatingChangeListener
import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction
Expand Down Expand Up @@ -121,10 +124,24 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack
}

fun logSyncInSharedPrefs() {
lifecycleScope.launch {
if (isServerReachable(Utilities.getUrl())) {
startUpload("dashboard")
createAction(mRealm, "${profileDbHandler.userModel?.id}", null, "sync")
lifecycleScope.launch(Dispatchers.IO + SupervisorJob()) {
try {
val isReachable = isServerReachable(Utilities.getUrl())
if (isReachable) {
withContext(Dispatchers.Main) {
startUpload("dashboard")
}

withContext(Dispatchers.IO) {
Realm.getDefaultInstance().use { realm ->
realm.executeTransaction {
createAction(realm, "${profileDbHandler.userModel?.id}", null, "sync")
}
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Expand Down
Loading