• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tv.util;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.preference.PreferenceManager;
23 
24 /**
25  * A utility class related to onboarding experience.
26  */
27 public final class OnboardingUtils {
28     private static final String PREF_KEY_IS_FIRST_BOOT = "pref_onbaording_is_first_boot";
29     private static final String PREF_KEY_ONBOARDING_VERSION_CODE = "pref_onbaording_versionCode";
30     private static final int ONBOARDING_VERSION = 1;
31 
32     private static final String MERCHANT_COLLECTION_URL_STRING = getMerchantCollectionUrl();
33 
34     /**
35      * Intent to show merchant collection in online store.
36      */
37     public static final Intent ONLINE_STORE_INTENT = new Intent(Intent.ACTION_VIEW,
38             Uri.parse(MERCHANT_COLLECTION_URL_STRING));
39 
40     /**
41      * Checks if this is the first boot after the onboarding experience has been applied.
42      */
isFirstBoot(Context context)43     public static boolean isFirstBoot(Context context) {
44         return PreferenceManager.getDefaultSharedPreferences(context)
45                 .getBoolean(PREF_KEY_IS_FIRST_BOOT, true);
46     }
47 
48     /**
49      * Marks that the first boot has been completed.
50      */
setFirstBootCompleted(Context context)51     public static void setFirstBootCompleted(Context context) {
52         PreferenceManager.getDefaultSharedPreferences(context)
53                 .edit()
54                 .putBoolean(PREF_KEY_IS_FIRST_BOOT, false)
55                 .apply();
56     }
57 
58     /**
59      * Checks if this is the first run of {@link com.android.tv.MainActivity} with the
60      * current onboarding version.
61      */
isFirstRunWithCurrentVersion(Context context)62     public static boolean isFirstRunWithCurrentVersion(Context context) {
63         int versionCode = PreferenceManager.getDefaultSharedPreferences(context)
64                 .getInt(PREF_KEY_ONBOARDING_VERSION_CODE, 0);
65         return versionCode != ONBOARDING_VERSION;
66     }
67 
68     /**
69      * Marks that the first run of {@link com.android.tv.MainActivity} with the current
70      * onboarding version has been completed.
71      */
setFirstRunWithCurrentVersionCompleted(Context context)72     public static void setFirstRunWithCurrentVersionCompleted(Context context) {
73         PreferenceManager.getDefaultSharedPreferences(context).edit()
74                 .putInt(PREF_KEY_ONBOARDING_VERSION_CODE, ONBOARDING_VERSION).apply();
75     }
76 
77     /**
78      * Returns merchant collection URL.
79      */
getMerchantCollectionUrl()80     private static String getMerchantCollectionUrl() {
81         return "TODO: add a merchant collection url";
82     }
83 
OnboardingUtils()84     private OnboardingUtils() {}
85 }
86