Skip to content

Commit 0c75ba5

Browse files
committed
fix crashes
Signed-off-by: alperozturk <[email protected]>
1 parent 1a00750 commit 0c75ba5

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt;
1616
import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets;
1717
import static it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget.updateSingleNoteWidgets;
18+
1819
import android.accounts.NetworkErrorException;
1920
import android.content.Context;
2021
import android.content.Intent;
@@ -25,8 +26,11 @@
2526
import android.net.ConnectivityManager;
2627
import android.net.Network;
2728
import android.net.NetworkCapabilities;
29+
import android.os.Handler;
30+
import android.os.Looper;
2831
import android.text.TextUtils;
2932
import android.util.Log;
33+
3034
import androidx.annotation.AnyThread;
3135
import androidx.annotation.ColorInt;
3236
import androidx.annotation.MainThread;
@@ -37,11 +41,13 @@
3741
import androidx.lifecycle.MutableLiveData;
3842
import androidx.lifecycle.Observer;
3943
import androidx.preference.PreferenceManager;
44+
4045
import com.nextcloud.android.sso.AccountImporter;
4146
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
4247
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
4348
import com.nextcloud.android.sso.helper.SingleAccountHelper;
4449
import com.nextcloud.android.sso.model.SingleSignOnAccount;
50+
4551
import java.util.ArrayList;
4652
import java.util.Calendar;
4753
import java.util.Collections;
@@ -51,6 +57,7 @@
5157
import java.util.concurrent.ConcurrentHashMap;
5258
import java.util.concurrent.ExecutorService;
5359
import java.util.concurrent.Executors;
60+
5461
import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData;
5562
import it.niedermann.owncloud.notes.BuildConfig;
5663
import it.niedermann.owncloud.notes.R;
@@ -100,6 +107,7 @@ public class NotesRepository {
100107
private boolean syncOnlyOnWifi;
101108
private final MutableLiveData<Boolean> syncStatus = new MutableLiveData<>(false);
102109
private final MutableLiveData<ArrayList<Throwable>> syncErrors = new MutableLiveData<>();
110+
private final Handler mainHandler = new Handler(Looper.getMainLooper());
103111

104112
private final Observer<? super ConnectionLiveData.ConnectionType> syncObserver = (Observer<ConnectionLiveData.ConnectionType>) connectionType -> {
105113
observeNetworkStatus(connectionType);
@@ -158,7 +166,7 @@ private NotesRepository(@NonNull final Context context, @NonNull final NotesData
158166
this.syncOnlyOnWifiKey = context.getApplicationContext().getResources().getString(R.string.pref_key_wifi_only);
159167
this.connectionLiveData = new ConnectionLiveData(context);
160168

161-
connectionLiveData.observeForever(syncObserver);
169+
mainHandler.post(() -> connectionLiveData.observeForever(syncObserver));
162170

163171
final var prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
164172
prefs.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
@@ -218,7 +226,7 @@ private void handleNetworkStatus(boolean isWifiActive) {
218226

219227
@Override
220228
protected void finalize() throws Throwable {
221-
connectionLiveData.removeObserver(syncObserver);
229+
mainHandler.post(() -> connectionLiveData.removeObserver(syncObserver));
222230
super.finalize();
223231
}
224232

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/ShareeListAdapter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@ public ShareeListAdapter(Activity activity,
4949

5050
@Override
5151
public int getItemViewType(int position) {
52-
return shares.get(position).getShareType().getValue();
52+
if (position < 0 || position >= shares.size()) {
53+
return 0;
54+
}
55+
56+
final var share = shares.get(position);
57+
if (share == null) {
58+
return 0;
59+
}
60+
61+
final var shareType = share.getShareType();
62+
if (shareType == null) {
63+
return 0;
64+
}
65+
66+
return shareType.getValue();
5367
}
5468

5569
@NonNull

0 commit comments

Comments
 (0)