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

Commit 875b3314 authored by Luca Stefani's avatar Luca Stefani
Browse files

ThemePicker: Properly update clock face setting

Change-Id: I7877c52052dada7205ce16f00211603967393eb2
parent 5ad0a99e
Loading
Loading
Loading
Loading
+2 −26
Original line number Diff line number Diff line
@@ -17,13 +17,9 @@ package com.android.customization.model.clock;

import android.content.ContentResolver;
import android.provider.Settings.Secure;
import android.text.TextUtils;

import com.android.customization.module.ThemesUserEventLogger;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * {@link CustomizationManager} for clock faces that implements apply by writing to secure settings.
 */
@@ -31,8 +27,6 @@ public class ClockManager extends BaseClockManager {

    // TODO: use constant from Settings.Secure
    static final String CLOCK_FACE_SETTING = "lock_screen_custom_clock_face";
    private static final String CLOCK_FIELD = "clock";
    private static final String TIMESTAMP_FIELD = "_applied_timestamp";
    private final ContentResolver mContentResolver;
    private final ThemesUserEventLogger mEventLogger;

@@ -45,16 +39,7 @@ public class ClockManager extends BaseClockManager {

    @Override
    protected void handleApply(Clockface option, Callback callback) {
        boolean stored;
        try {
            final JSONObject json = new JSONObject();
            json.put(CLOCK_FIELD, option.getId());
            json.put(TIMESTAMP_FIELD, System.currentTimeMillis());
            stored = Secure.putString(mContentResolver, CLOCK_FACE_SETTING, json.toString());
        } catch (JSONException ex) {
            stored = false;
        }
        if (stored) {
        if (Secure.putString(mContentResolver, CLOCK_FACE_SETTING, option.getId())) {
            mEventLogger.logClockApplied(option);
            callback.onSuccess();
        } else {
@@ -64,15 +49,6 @@ public class ClockManager extends BaseClockManager {

    @Override
    protected String lookUpCurrentClock() {
        final String value = Secure.getString(mContentResolver, CLOCK_FACE_SETTING);
        if (TextUtils.isEmpty(value)) {
            return value;
        }
        try {
            final JSONObject json = new JSONObject(value);
            return json.getString(CLOCK_FIELD);
        } catch (JSONException ex) {
            return value;
        }
        return Secure.getString(mContentResolver, CLOCK_FACE_SETTING);
    }
}