From 81ec6352fccdc1f496515b432080218c310293af Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 24 Dec 2017 23:47:36 +0800 Subject: [PATCH] improved promotion offer controller --- .../premium/PromotionOfferViewController.kt | 24 ++++++++++--------- twidere/src/main/res/values/strings.xml | 7 +++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/premium/PromotionOfferViewController.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/premium/PromotionOfferViewController.kt index d1c7af1f6..8b0718db8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/premium/PromotionOfferViewController.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/premium/PromotionOfferViewController.kt @@ -21,6 +21,7 @@ package org.mariotaku.twidere.view.controller.premium import android.view.View import org.mariotaku.chameleon.ChameleonUtils +import org.mariotaku.kpreferences.get import org.mariotaku.kpreferences.set import org.mariotaku.twidere.R import org.mariotaku.twidere.activity.PremiumDashboardActivity @@ -33,29 +34,30 @@ class PromotionOfferViewController : PremiumDashboardActivity.ExtraFeatureViewCo super.onCreate() titleView.setText(R.string.title_promotions_reward) messageView.text = context.getString(R.string.message_promotions_reward) - button1.setText(R.string.action_enable) + if (preferences[promotionsEnabledKey]) { + button1.setText(R.string.action_disable) + } else { + button1.setText(R.string.action_enable) + } button1.visibility = View.VISIBLE button2.visibility = View.GONE button1.setOnClickListener { - enablePromotions() + togglePromotions() } } override fun onViewCreated(view: View) { - if (extraFeaturesService.isEnabled(ExtraFeaturesService.FEATURE_FEATURES_PACK)) { - view.visibility = View.GONE - } else { + if (preferences[promotionsEnabledKey] || !extraFeaturesService.isPurchased(ExtraFeaturesService.FEATURE_FEATURES_PACK)) { view.visibility = View.VISIBLE + } else { + view.visibility = View.GONE } } - private fun enablePromotions() { - preferences[promotionsEnabledKey] = true - val activity = ChameleonUtils.getActivity(context) - if (activity != null) { - activity.recreate() - } + private fun togglePromotions() { + preferences[promotionsEnabledKey] = !preferences[promotionsEnabledKey] + ChameleonUtils.getActivity(context)?.recreate() } } \ No newline at end of file diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index a378fd0e5..bdb33c8ba 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -49,6 +49,7 @@ Delete Delete messages + Disable Disable promotions Don\'t restart Don\'t quit @@ -737,6 +738,7 @@ Unable to remove account Reported %s for spam Retweet cancelled + Not supported to retweet this Storage permission is needed to save media Saved to gallery Date/time should be in future @@ -982,12 +984,12 @@ Projects we took part - App default App default - Twitter + App default Fanfou Mastodon + Twitter Proxy Proxy host @@ -1389,5 +1391,4 @@ Blocked these users. %s\'s lists - Not supported to retweet this