aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/util/OnboardingUtils.java
blob: 49b02b822a2da37f23b918ac3f3615f2b582f1ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.tv.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.preference.PreferenceManager;

/**
 * A utility class related to onboarding experience.
 */
public final class OnboardingUtils {
    private static final String PREF_KEY_IS_FIRST_BOOT = "pref_onbaording_is_first_boot";
    private static final String PREF_KEY_ONBOARDING_VERSION_CODE = "pref_onbaording_versionCode";
    private static final int ONBOARDING_VERSION = 1;

    private static final String MERCHANT_COLLECTION_URL_STRING = getMerchantCollectionUrl();

    /**
     * Intent to show merchant collection in online store.
     */
    public static final Intent ONLINE_STORE_INTENT = new Intent(Intent.ACTION_VIEW,
            Uri.parse(MERCHANT_COLLECTION_URL_STRING));

    /**
     * Checks if this is the first boot after the onboarding experience has been applied.
     */
    public static boolean isFirstBoot(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context)
                .getBoolean(PREF_KEY_IS_FIRST_BOOT, true);
    }

    /**
     * Marks that the first boot has been completed.
     */
    public static void setFirstBootCompleted(Context context) {
        PreferenceManager.getDefaultSharedPreferences(context)
                .edit()
                .putBoolean(PREF_KEY_IS_FIRST_BOOT, false)
                .apply();
    }

    /**
     * Checks if this is the first run of {@link com.android.tv.MainActivity} with the
     * current onboarding version.
     */
    public static boolean isFirstRunWithCurrentVersion(Context context) {
        int versionCode = PreferenceManager.getDefaultSharedPreferences(context)
                .getInt(PREF_KEY_ONBOARDING_VERSION_CODE, 0);
        return versionCode != ONBOARDING_VERSION;
    }

    /**
     * Marks that the first run of {@link com.android.tv.MainActivity} with the current
     * onboarding version has been completed.
     */
    public static void setFirstRunWithCurrentVersionCompleted(Context context) {
        PreferenceManager.getDefaultSharedPreferences(context).edit()
                .putInt(PREF_KEY_ONBOARDING_VERSION_CODE, ONBOARDING_VERSION).apply();
    }

    /**
     * Returns merchant collection URL.
     */
    private static String getMerchantCollectionUrl() {
        return "TODO: add a merchant collection url";
    }

    private OnboardingUtils() {}
}