|
15 | 15 | import static it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt; |
16 | 16 | import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets; |
17 | 17 | import static it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget.updateSingleNoteWidgets; |
| 18 | + |
18 | 19 | import android.accounts.NetworkErrorException; |
19 | 20 | import android.content.Context; |
20 | 21 | import android.content.Intent; |
|
25 | 26 | import android.net.ConnectivityManager; |
26 | 27 | import android.net.Network; |
27 | 28 | import android.net.NetworkCapabilities; |
| 29 | +import android.os.Handler; |
| 30 | +import android.os.Looper; |
28 | 31 | import android.text.TextUtils; |
29 | 32 | import android.util.Log; |
| 33 | + |
30 | 34 | import androidx.annotation.AnyThread; |
31 | 35 | import androidx.annotation.ColorInt; |
32 | 36 | import androidx.annotation.MainThread; |
|
37 | 41 | import androidx.lifecycle.MutableLiveData; |
38 | 42 | import androidx.lifecycle.Observer; |
39 | 43 | import androidx.preference.PreferenceManager; |
| 44 | + |
40 | 45 | import com.nextcloud.android.sso.AccountImporter; |
41 | 46 | import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; |
42 | 47 | import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; |
43 | 48 | import com.nextcloud.android.sso.helper.SingleAccountHelper; |
44 | 49 | import com.nextcloud.android.sso.model.SingleSignOnAccount; |
| 50 | + |
45 | 51 | import java.util.ArrayList; |
46 | 52 | import java.util.Calendar; |
47 | 53 | import java.util.Collections; |
|
51 | 57 | import java.util.concurrent.ConcurrentHashMap; |
52 | 58 | import java.util.concurrent.ExecutorService; |
53 | 59 | import java.util.concurrent.Executors; |
| 60 | + |
54 | 61 | import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData; |
55 | 62 | import it.niedermann.owncloud.notes.BuildConfig; |
56 | 63 | import it.niedermann.owncloud.notes.R; |
@@ -100,6 +107,7 @@ public class NotesRepository { |
100 | 107 | private boolean syncOnlyOnWifi; |
101 | 108 | private final MutableLiveData<Boolean> syncStatus = new MutableLiveData<>(false); |
102 | 109 | private final MutableLiveData<ArrayList<Throwable>> syncErrors = new MutableLiveData<>(); |
| 110 | + private final Handler mainHandler = new Handler(Looper.getMainLooper()); |
103 | 111 |
|
104 | 112 | private final Observer<? super ConnectionLiveData.ConnectionType> syncObserver = (Observer<ConnectionLiveData.ConnectionType>) connectionType -> { |
105 | 113 | observeNetworkStatus(connectionType); |
@@ -158,7 +166,7 @@ private NotesRepository(@NonNull final Context context, @NonNull final NotesData |
158 | 166 | this.syncOnlyOnWifiKey = context.getApplicationContext().getResources().getString(R.string.pref_key_wifi_only); |
159 | 167 | this.connectionLiveData = new ConnectionLiveData(context); |
160 | 168 |
|
161 | | - connectionLiveData.observeForever(syncObserver); |
| 169 | + mainHandler.post(() -> connectionLiveData.observeForever(syncObserver)); |
162 | 170 |
|
163 | 171 | final var prefs = PreferenceManager.getDefaultSharedPreferences(this.context); |
164 | 172 | prefs.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener); |
@@ -218,7 +226,7 @@ private void handleNetworkStatus(boolean isWifiActive) { |
218 | 226 |
|
219 | 227 | @Override |
220 | 228 | protected void finalize() throws Throwable { |
221 | | - connectionLiveData.removeObserver(syncObserver); |
| 229 | + mainHandler.post(() -> connectionLiveData.removeObserver(syncObserver)); |
222 | 230 | super.finalize(); |
223 | 231 | } |
224 | 232 |
|
|
0 commit comments