Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f16109a authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Handle no clocks case as error

If we have a provider but for some reason it returns no
clockfaces, show error message instead of crashing

Fixes: 134611165
Change-Id: I3a9e50b5d821469284c5b9ef837170ffb3ff1fd9
parent 212e2635
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -37,27 +37,35 @@ public class ContentProviderClockProvider implements ClockProvider {

    @Override
    public boolean isAvailable() {
        return mProviderInfo != null;
        return mProviderInfo != null && (mClocks == null || !mClocks.isEmpty());
    }

    @Override
    public void fetch(OptionsFetchedListener<Clockface> callback, boolean reload) {
        if (!isAvailable()) {
            if (callback != null) {
                callback.onOptionsLoaded(null);
                callback.onError(null);
            }
            return;
        }
        if (mClocks != null && !reload) {
            if (callback != null) {
                if (!mClocks.isEmpty()) {
                    callback.onOptionsLoaded(mClocks);
                } else {
                    callback.onError(null);
                }
            }
            return;
        }
        new ClocksFetchTask(mContext, mProviderInfo, options -> {
            mClocks = options;
            if (callback != null) {
                if (!mClocks.isEmpty()) {
                    callback.onOptionsLoaded(mClocks);
                } else {
                    callback.onError(null);
                }
            }
        }).execute();
    }