1 /* 2 * Copyright (C) 2018 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.dialer.promotion.impl; 18 19 import android.content.Context; 20 import android.content.SharedPreferences; 21 import android.support.annotation.DrawableRes; 22 import com.android.dialer.common.LogUtil; 23 import com.android.dialer.configprovider.ConfigProvider; 24 import com.android.dialer.inject.ApplicationContext; 25 import com.android.dialer.promotion.Promotion; 26 import com.android.dialer.spannable.ContentWithLearnMoreSpanner; 27 import com.android.dialer.storage.StorageComponent; 28 import com.android.dialer.storage.Unencrypted; 29 import javax.inject.Inject; 30 31 /** RTT promotion. */ 32 public final class RttPromotion implements Promotion { 33 private static final String SHARED_PREFERENCE_KEY_ENABLED = "rtt_promotion_enabled"; 34 private static final String SHARED_PREFERENCE_KEY_DISMISSED = "rtt_promotion_dismissed"; 35 private final Context appContext; 36 private final SharedPreferences sharedPreferences; 37 private final ConfigProvider configProvider; 38 39 @Override getType()40 public int getType() { 41 return PromotionType.BOTTOM_SHEET; 42 } 43 44 @Inject RttPromotion( @pplicationContext Context context, @Unencrypted SharedPreferences sharedPreferences, ConfigProvider configProvider)45 RttPromotion( 46 @ApplicationContext Context context, 47 @Unencrypted SharedPreferences sharedPreferences, 48 ConfigProvider configProvider) { 49 appContext = context; 50 this.sharedPreferences = sharedPreferences; 51 this.configProvider = configProvider; 52 } 53 54 @Override isEligibleToBeShown()55 public boolean isEligibleToBeShown() { 56 return sharedPreferences.getBoolean(SHARED_PREFERENCE_KEY_ENABLED, false) 57 && !sharedPreferences.getBoolean(SHARED_PREFERENCE_KEY_DISMISSED, false); 58 } 59 60 @Override getTitle()61 public CharSequence getTitle() { 62 return appContext.getString(R.string.rtt_promotion_title); 63 } 64 65 @Override getDetails()66 public CharSequence getDetails() { 67 return new ContentWithLearnMoreSpanner(appContext) 68 .create( 69 appContext.getString(R.string.rtt_promotion_details), 70 configProvider.getString( 71 "rtt_promo_learn_more_link_full_url", 72 "http://support.google.com/pixelphone/?p=dialer_rtt")); 73 } 74 75 @Override 76 @DrawableRes getIconRes()77 public int getIconRes() { 78 return R.drawable.quantum_ic_rtt_vd_theme_24; 79 } 80 setEnabled(Context context)81 public static void setEnabled(Context context) { 82 LogUtil.enterBlock("RttPromotion.setEnabled"); 83 StorageComponent.get(context) 84 .unencryptedSharedPrefs() 85 .edit() 86 .putBoolean(SHARED_PREFERENCE_KEY_ENABLED, true) 87 .apply(); 88 } 89 90 @Override dismiss()91 public void dismiss() { 92 sharedPreferences.edit().putBoolean(SHARED_PREFERENCE_KEY_DISMISSED, true).apply(); 93 } 94 } 95