Skip to content

Commit

Permalink
sync: smoother exceptions (fixes #4861) (#4864)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Dec 11, 2024
1 parent 69bc403 commit 5d55762
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2132
versionName "0.21.32"
versionCode 2133
versionName "0.21.33"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
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

0 comments on commit 5d55762

Please sign in to comment.