mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Charts: Avoid crash if database fetch fails
This commit is contained in:
+10
-4
@@ -368,12 +368,18 @@ public abstract class AbstractChartFragment<D extends ChartsData> extends Abstra
|
||||
protected void onPostExecute(final Object o) {
|
||||
super.onPostExecute(o);
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||
updateChartsnUIThread(chartsData);
|
||||
renderCharts();
|
||||
} else {
|
||||
if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
|
||||
LOG.info("Not rendering charts because activity is not available anymore");
|
||||
return;
|
||||
}
|
||||
if (getTaskError() != null) {
|
||||
// Async task failed - we will have no data, so avoid NPE crashes
|
||||
// a log + toast were already displayed by the DBAccess class
|
||||
return;
|
||||
}
|
||||
|
||||
updateChartsnUIThread(chartsData);
|
||||
renderCharts();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -63,7 +65,10 @@ public abstract class DBAccess extends AsyncTask {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Exception getTaskError() {
|
||||
return mError;
|
||||
}
|
||||
|
||||
protected void displayError(Throwable error) {
|
||||
GB.toast(getContext(), getContext().getString(R.string.dbaccess_error_executing, error.getMessage()), Toast.LENGTH_LONG, GB.ERROR, error);
|
||||
|
||||
Reference in New Issue
Block a user