package com.malaspina.dashclocktimezone;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.google.android.apps.dashclock.api.DashClockExtension;
import com.google.android.apps.dashclock.api.ExtensionData;

import net.danlew.android.joda.DateUtils;

import org.joda.time.DateTime;

/**
 * Created by Ryan on 2/24/2016.
 */
public class ExtensionBase extends DashClockExtension {

    private String timezone_key;
    private String hour_format_key;
    private String ext_format_key;

    SharedPreferences prefs;

    @Override
    protected void onInitialize(boolean isReconnect) {
        setUpdateWhenScreenOn(true);
        super.onInitialize(isReconnect);
    }

    @Override
    protected void onUpdateData(int reason) {

        prefs = PreferenceManager.getDefaultSharedPreferences(this);

        String timezone = prefs.getString(getTimezone_key(),
                getString(R.string.default_timezone));
        String hourFormat = prefs.getString(getHour_format_key(),
                getString(R.string.default_hour_format));
        String extFormat  = prefs.getString(getExt_format_key(),
                getString(R.string.default_extended_format));

        ExtensionData data = new ExtensionData();

        data.visible(true);
        data.icon(R.mipmap.ic_stat);
        data.status(getTime());
        data.expandedTitle(getTimezone_key());
        data.expandedBody(timezone);

        publishUpdate(data);
    }

    private String getTime() {
        DateTime now = new DateTime();
        return DateUtils.formatDateTime(this, now, DateUtils.FORMAT_SHOW_TIME);
    }

    public String getTimezone_key() {
        return timezone_key;
    }

    public void setTimezone_key(String timezone_key) {
        this.timezone_key = timezone_key;
    }

    public String getHour_format_key() {
        return hour_format_key;
    }

    public void setHour_format_key(String hour_format_key) {
        this.hour_format_key = hour_format_key;
    }

    public String getExt_format_key() {
        return ext_format_key;
    }

    public void setExt_format_key(String ext_format_key) {
        this.ext_format_key = ext_format_key;
    }
}

@@ -35,16 +35,158 @@
 ezone;%0A%0A
+import android.content.BroadcastReceiver;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.content.IntentFilter;%0A
 import a
@@ -219,16 +219,16 @@
 rences;%0A
-
 import a
@@ -699,16 +699,318 @@
 prefs;%0A%0A
+    private final static IntentFilter INTENT_FILTER;%0A%0A    static %7B%0A        INTENT_FILTER = new IntentFilter();%0A        INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);%0A        INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);%0A        INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);%0A    %7D%0A%0A
     @Ove
@@ -1144,24 +1144,84 @@
 Reconnect);%0A
+        registerReceiver(mTimeInfoReceiver, INTENT_FILTER);%0A
     %7D%0A%0A    @
@@ -2049,24 +2049,24 @@
 DateTime();%0A
-
         retu
@@ -2132,32 +2132,664 @@
 W_TIME);%0A    %7D%0A%0A
+    // If time changed, update extension%0A    private BroadcastReceiver mTimeInfoReceiver = new BroadcastReceiver() %7B%0A        @Override%0A        public void onReceive(Context arg0, Intent intent) %7B%0A            final String action = intent.getAction();%0A            if (action.equals(Intent.ACTION_TIME_TICK) %7C%7C%0A                    action.equals(Intent.ACTION_TIME_CHANGED) %7C%7C%0A                    action.equals(Intent.ACTION_TIMEZONE_CHANGED)) %7B%0A                onUpdateData(0);%0A            %7D%0A        %7D%0A    %7D;%0A%0A    @Override%0A    public void onDestroy() %7B%0A        unregisterReceiver(mTimeInfoReceiver);%0A        super.onDestroy();%0A    %7D%0A%0A
     public Strin

Update time in extension automatically