prevent null-pointer in case remote file listing UI gets closed before the async loading comes back

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-03-16 16:57:13 +01:00
parent 7db5c5ed76
commit 766d07d3fa
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -2,6 +2,8 @@
* Nextcloud Talk application
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
@ -20,20 +22,26 @@
package com.nextcloud.talk.components.filebrowser.operations;
import androidx.annotation.Nullable;
import android.util.Log;
import com.nextcloud.talk.components.filebrowser.interfaces.ListingInterface;
import com.nextcloud.talk.components.filebrowser.models.DavResponse;
import com.nextcloud.talk.components.filebrowser.webdav.ReadFilesystemOperation;
import com.nextcloud.talk.models.database.UserEntity;
import java.util.concurrent.Callable;
import androidx.annotation.Nullable;
import io.reactivex.Single;
import io.reactivex.SingleObserver;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import java.util.concurrent.Callable;
public class DavListing extends ListingAbstractClass {
private static final String TAG = DavListing.class.getSimpleName();
private DavResponse davResponse = new DavResponse();
public DavListing(ListingInterface listingInterface) {
@ -50,18 +58,22 @@ public class DavListing extends ListingAbstractClass {
}).subscribeOn(Schedulers.io())
.subscribe(new SingleObserver<ReadFilesystemOperation>() {
@Override
public void onSubscribe(Disposable d) {
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onSuccess(ReadFilesystemOperation readFilesystemOperation) {
public void onSuccess(@NonNull ReadFilesystemOperation readFilesystemOperation) {
davResponse = readFilesystemOperation.readRemotePath();
listingInterface.listingResult(davResponse);
try {
listingInterface.listingResult(davResponse);
} catch (NullPointerException npe) {
Log.i(TAG, "Error loading remote folder - due to view already been terminated", npe);
}
}
@Override
public void onError(Throwable e) {
public void onError(@NonNull Throwable e) {
listingInterface.listingResult(davResponse);
}
});