Repository navigation
Improve sync error handling #3401
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| package it.niedermann.owncloud.notes.main | ||
|
|
||
| import android.view.View | ||
| import androidx.fragment.app.FragmentActivity | ||
| import com.google.android.material.snackbar.Snackbar | ||
| import com.nextcloud.android.sso.AccountImporter | ||
| import com.nextcloud.android.sso.exceptions.SSOException | ||
| import com.nextcloud.android.sso.helper.SingleAccountHelper | ||
| import it.niedermann.owncloud.notes.R | ||
| import it.niedermann.owncloud.notes.branding.BrandedSnackbar | ||
| import it.niedermann.owncloud.notes.exception.ExceptionDialogFragment | ||
|
|
||
| object SyncErrorSnackbar { | ||
| @JvmStatic | ||
| fun show(activity: FragmentActivity, parent: View, anchor: View, exceptions: Collection<Throwable>) { | ||
| val snackbar = BrandedSnackbar.make(parent, SyncErrorMessage.of(exceptions), Snackbar.LENGTH_LONG) | ||
| .setAnchorView(anchor) | ||
| if (SyncErrorMessage.isTokenMismatch(exceptions)) { | ||
| snackbar.setAction(R.string.error_action_grant_access) { requestAccessAgain(activity) } | ||
| } else { | ||
| snackbar.setAction(R.string.simple_more) { showDetails(activity, exceptions) } | ||
| } | ||
| snackbar.show() | ||
| } | ||
|
|
||
| @JvmStatic | ||
| fun show(activity: FragmentActivity, parent: View, anchor: View, exception: Throwable) = | ||
| show(activity, parent, anchor, listOf(exception)) | ||
|
|
||
| private fun requestAccessAgain(activity: FragmentActivity) { | ||
| try { | ||
| val ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(activity) | ||
| AccountImporter.authenticateSingleSignAccount(activity, ssoAccount) | ||
| } catch (e: SSOException) { | ||
| showDetails(activity, listOf(e)) | ||
| } | ||
| } | ||
|
|
||
| private fun showDetails(activity: FragmentActivity, exceptions: Collection<Throwable>) { | ||
| ExceptionDialogFragment.newInstance(ArrayList(exceptions)) | ||
| .show(activity.supportFragmentManager, ExceptionDialogFragment::class.java.simpleName) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,7 @@ | |
| import it.niedermann.owncloud.notes.shared.util.ConnectionLiveData; | ||
| import it.niedermann.owncloud.notes.shared.util.NoteUtil; | ||
| import it.niedermann.owncloud.notes.shared.util.SSOUtil; | ||
| import it.niedermann.owncloud.notes.shared.util.SingleLiveEvent; | ||
| import retrofit2.Call; | ||
|
|
||
| @SuppressWarnings("UnusedReturnValue") | ||
|
|
@@ -109,7 +110,7 @@ public class NotesRepository { | |
| private String syncOnlyOnWifiKey; | ||
| private boolean syncOnlyOnWifi; | ||
| private final MutableLiveData<Boolean> syncStatus = new MutableLiveData<>(false); | ||
| private final MutableLiveData<ArrayList<Throwable>> syncErrors = new MutableLiveData<>(); | ||
| private final SingleLiveEvent<ArrayList<Throwable>> syncErrors = new SingleLiveEvent<>(); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MainActivity subscribed again it got the last sync failure again, even if later syncs had succeeded. SingleLiveEvent delivers each batch once. |
||
| private final Handler mainHandler = new Handler(Looper.getMainLooper()); | ||
|
|
||
| private final Observer<? super ConnectionLiveData.ConnectionType> syncObserver = (Observer<ConnectionLiveData.ConnectionType>) connectionType -> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,15 +31,15 @@ enum class SyncFailureReason(@StringRes val message: Int) { | |
| private const val HTTP_INSUFFICIENT_STORAGE = 507 | ||
| private const val SSO_LOCAL_FAILURE = 900 | ||
|
|
||
| fun fromStatusCode(statusCode: Int): SyncFailureReason = when (statusCode) { | ||
| fun fromStatusCode(statusCode: Int): SyncFailureReason? = when (statusCode) { | ||
| HTTP_UNAUTHORIZED -> UNAUTHORIZED | ||
| HTTP_FORBIDDEN -> PERMISSION | ||
| HTTP_NOT_FOUND -> NOTES_APP_UNAVAILABLE | ||
| HTTP_LOCKED -> LOCKED | ||
| HTTP_INTERNAL_ERROR -> SERVER_ERROR | ||
| HTTP_UNAVAILABLE -> MAINTENANCE | ||
| HTTP_INSUFFICIENT_STORAGE -> INSUFFICIENT_STORAGE | ||
| SSO_LOCAL_FAILURE -> SERVER_UNREACHABLE | ||
| SSO_LOCAL_FAILURE -> null | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 900 doesn't mean |
||
| else -> UNKNOWN | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| package it.niedermann.owncloud.notes.shared.util | ||
|
|
||
| import androidx.lifecycle.LifecycleOwner | ||
| import androidx.lifecycle.MutableLiveData | ||
| import androidx.lifecycle.Observer | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
|
|
||
| class SingleLiveEvent<T> : MutableLiveData<T>() { | ||
| private val pending = AtomicBoolean(false) | ||
|
|
||
| override fun observe(owner: LifecycleOwner, observer: Observer<in T>) { | ||
| super.observe(owner) { value -> | ||
| if (pending.compareAndSet(true, false)) { | ||
| observer.onChanged(value) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun setValue(value: T?) { | ||
| pending.set(true) | ||
| super.setValue(value) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clear cache and post new account