
package com.battlelancer.seriesguide.settings;

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

/**
 * Access advanced settings for auto backup and auto update.
 */
public class AdvancedSettings {

    public static final String KEY_LASTUPDATE = "com.battlelancer.seriesguide.lastupdate";

    public static final String KEY_AUTOBACKUP = "com.battlelancer.seriesguide.autobackup";

    public static final String KEY_LASTBACKUP = "com.battlelancer.seriesguide.lastbackup";

    public static long getLastAutoUpdateTime(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        long time = prefs.getLong(KEY_LASTUPDATE, 0);
        if (time == 0) {
            // use now as default value, so auto-update will not run on first
            // launch
            time = System.currentTimeMillis();
            prefs.edit().putLong(KEY_LASTUPDATE, time).commit();
        }

        return time;
    }

    public static boolean isAutoBackupEnabled(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(KEY_AUTOBACKUP,
                true);
    }

    public static long getLastAutoBackupTime(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        long time = prefs.getLong(KEY_LASTBACKUP, 0);
        if (time == 0) {
            // use now as default value, so a re-install won't overwrite the old
            // auto-backup right away
            time = System.currentTimeMillis();
            prefs.edit().putLong(KEY_LASTBACKUP, time).commit();
        }

        return time;
    }
}

@@ -532,32 +532,138 @@
 e.lastbackup%22;%0A%0A
+    public static final String KEY_LAST_UPGRADE_STATE = %22com.battlelancer.seriesguide.lastupgradestate%22;%0A%0A
     public stati
@@ -1825,11 +1825,551 @@
 e;%0A    %7D
+%0A%0A    /**%0A     * Wether the user is qualified for the X upgrade since the last time we%0A     * checked.%0A     */%0A    public static boolean hasPurchasedX(Context context) %7B%0A        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(%0A                KEY_LAST_UPGRADE_STATE, false);%0A    %7D%0A%0A    public static void setLastUpgradeState(Context context, boolean hasXupgrade) %7B%0A        PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(%0A                KEY_LAST_UPGRADE_STATE, hasXupgrade).commit();%0A    %7D
 %0A%7D%0A

Add new temporary upgrade purchased state setting.