• 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 /** A utility class related to onboarding experience. */
25 public final class OnboardingUtils {
26     private static final String PREF_KEY_IS_FIRST_BOOT = "pref_onbaording_is_first_boot";
27     private static final String PREF_KEY_ONBOARDING_VERSION_CODE = "pref_onbaording_versionCode";
28     private static final int ONBOARDING_VERSION = 1;
29 
30     private static final String MERCHANT_COLLECTION_URL_STRING = getMerchantCollectionUrl();
31 
32     /** Intent to show merchant collection in online store. */
33     public static final Intent ONLINE_STORE_INTENT =
34             new Intent(Intent.ACTION_VIEW, Uri.parse(MERCHANT_COLLECTION_URL_STRING));
35 
36     /** Checks if this is the first boot after the onboarding experience has been applied. */
isFirstBoot(Context context)37     public static boolean isFirstBoot(Context context) {
38         return PreferenceManager.getDefaultSharedPreferences(context)
39                 .getBoolean(PREF_KEY_IS_FIRST_BOOT, true);
40     }
41 
42     /** Marks that the first boot has been completed. */
setFirstBootCompleted(Context context)43     public static void setFirstBootCompleted(Context context) {
44         PreferenceManager.getDefaultSharedPreferences(context)
45                 .edit()
46                 .putBoolean(PREF_KEY_IS_FIRST_BOOT, false)
47                 .apply();
48     }
49 
50     /**
51      * Checks if this is the first run of {@link com.android.tv.MainActivity} with the current
52      * onboarding version.
53      */
isFirstRunWithCurrentVersion(Context context)54     public static boolean isFirstRunWithCurrentVersion(Context context) {
55         int versionCode =
56                 PreferenceManager.getDefaultSharedPreferences(context)
57                         .getInt(PREF_KEY_ONBOARDING_VERSION_CODE, 0);
58         return versionCode != ONBOARDING_VERSION;
59     }
60 
61     /**
62      * Marks that the first run of {@link com.android.tv.MainActivity} with the current onboarding
63      * version has been completed.
64      */
setFirstRunWithCurrentVersionCompleted(Context context)65     public static void setFirstRunWithCurrentVersionCompleted(Context context) {
66         PreferenceManager.getDefaultSharedPreferences(context)
67                 .edit()
68                 .putInt(PREF_KEY_ONBOARDING_VERSION_CODE, ONBOARDING_VERSION)
69                 .apply();
70     }
71 
72     /** Returns merchant collection URL. */
getMerchantCollectionUrl()73     private static String getMerchantCollectionUrl() {
74         return "TODO: add a merchant collection url";
75     }
76 
OnboardingUtils()77     private OnboardingUtils() {}
78 }
79