From 3f95583d2fc4b727381fc90342a4d262b9874af8 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 1 Jan 2017 23:28:00 +0800 Subject: [PATCH] updated extra features code --- twidere/proguard-rules.pro | 2 +- ...hecker.kt => DummyExtraFeaturesService.kt} | 5 +++-- ....twidere.util.premium.ExtraFeaturesChecker | 1 - ....twidere.util.premium.ExtraFeaturesService | 1 + ...ayStoreExtraFeaturesSyncStatusFragment.kt} | 6 +++--- ...r.kt => GooglePlayExtraFeaturesService.kt} | 8 ++++--- ... card_item_extra_features_sync_status.xml} | 11 +++++----- ...extra_features_sync_status_play_store.xml} | 0 ....twidere.util.premium.ExtraFeaturesChecker | 1 - ....twidere.util.premium.ExtraFeaturesService | 1 + .../activity/PremiumDashboardActivity.kt | 21 +++++++++++-------- ...ExtraFeaturesIntroductionDialogFragment.kt | 12 +++++------ .../fragment/filter/FilteredUsersFragment.kt | 12 +++++------ .../ExtraFeaturesIntroductionCardFragment.kt | 10 ++++----- ...uresChecker.kt => ExtraFeaturesService.kt} | 9 ++++---- 15 files changed, 53 insertions(+), 47 deletions(-) rename twidere/src/fdroid/kotlin/org/mariotaku/twidere/util/premium/{DummyExtraFeaturesChecker.kt => DummyExtraFeaturesService.kt} (81%) delete mode 100644 twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker create mode 100644 twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService rename twidere/src/google/kotlin/org/mariotaku/twidere/fragment/premium/{PlayStoreExtraFeaturesStatusFragment.kt => PlayStoreExtraFeaturesSyncStatusFragment.kt} (92%) rename twidere/src/google/kotlin/org/mariotaku/twidere/util/premium/{GooglePlayExtraFeaturesChecker.kt => GooglePlayExtraFeaturesService.kt} (91%) rename twidere/src/google/res/layout/{card_item_extra_features_status.xml => card_item_extra_features_sync_status.xml} (62%) rename twidere/src/google/res/layout/{fragment_extra_features_status_play_store.xml => fragment_extra_features_sync_status_play_store.xml} (100%) delete mode 100644 twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker create mode 100644 twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService rename twidere/src/main/kotlin/org/mariotaku/twidere/util/premium/{ExtraFeaturesChecker.kt => ExtraFeaturesService.kt} (79%) diff --git a/twidere/proguard-rules.pro b/twidere/proguard-rules.pro index 7fd58f8b8..66f0bba12 100644 --- a/twidere/proguard-rules.pro +++ b/twidere/proguard-rules.pro @@ -68,7 +68,7 @@ -keep class * extends org.mariotaku.twidere.util.MapFragmentFactory -keep class * extends org.mariotaku.twidere.util.TwitterCardFragmentFactory -keep class * extends org.mariotaku.twidere.util.Analyzer --keep class * extends org.mariotaku.twidere.util.premium.ExtraFeaturesChecker +-keep class * extends org.mariotaku.twidere.util.premium.ExtraFeaturesService -keepclassmembers class * { private ; diff --git a/twidere/src/fdroid/kotlin/org/mariotaku/twidere/util/premium/DummyExtraFeaturesChecker.kt b/twidere/src/fdroid/kotlin/org/mariotaku/twidere/util/premium/DummyExtraFeaturesService.kt similarity index 81% rename from twidere/src/fdroid/kotlin/org/mariotaku/twidere/util/premium/DummyExtraFeaturesChecker.kt rename to twidere/src/fdroid/kotlin/org/mariotaku/twidere/util/premium/DummyExtraFeaturesService.kt index 6d9891256..5c5056cf6 100644 --- a/twidere/src/fdroid/kotlin/org/mariotaku/twidere/util/premium/DummyExtraFeaturesChecker.kt +++ b/twidere/src/fdroid/kotlin/org/mariotaku/twidere/util/premium/DummyExtraFeaturesService.kt @@ -8,10 +8,11 @@ import org.mariotaku.twidere.R * Created by mariotaku on 2016/12/25. */ -class DummyExtraFeaturesChecker : ExtraFeaturesChecker() { +class DummyExtraFeaturesService : ExtraFeaturesService() { override val introductionLayout: Int = R.layout.card_item_extra_features_purchase_introduction - override val statusLayout: Int = throw UnsupportedOperationException() + override val dashboardLayouts: IntArray = throw UnsupportedOperationException() + override fun isSupported(): Boolean = false override fun isEnabled(): Boolean = false diff --git a/twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker b/twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker deleted file mode 100644 index 64bcad4e4..000000000 --- a/twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker +++ /dev/null @@ -1 +0,0 @@ -org.mariotaku.twidere.util.premium.DummyExtraFeaturesChecker \ No newline at end of file diff --git a/twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService b/twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService new file mode 100644 index 000000000..03cfe20d2 --- /dev/null +++ b/twidere/src/fdroid/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService @@ -0,0 +1 @@ +org.mariotaku.twidere.util.premium.DummyExtraFeaturesService \ No newline at end of file diff --git a/twidere/src/google/kotlin/org/mariotaku/twidere/fragment/premium/PlayStoreExtraFeaturesStatusFragment.kt b/twidere/src/google/kotlin/org/mariotaku/twidere/fragment/premium/PlayStoreExtraFeaturesSyncStatusFragment.kt similarity index 92% rename from twidere/src/google/kotlin/org/mariotaku/twidere/fragment/premium/PlayStoreExtraFeaturesStatusFragment.kt rename to twidere/src/google/kotlin/org/mariotaku/twidere/fragment/premium/PlayStoreExtraFeaturesSyncStatusFragment.kt index 56b29a59c..47065214f 100644 --- a/twidere/src/google/kotlin/org/mariotaku/twidere/fragment/premium/PlayStoreExtraFeaturesStatusFragment.kt +++ b/twidere/src/google/kotlin/org/mariotaku/twidere/fragment/premium/PlayStoreExtraFeaturesSyncStatusFragment.kt @@ -5,7 +5,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import kotlinx.android.synthetic.google.fragment_extra_features_status_play_store.* +import kotlinx.android.synthetic.google.fragment_extra_features_sync_status_play_store.* import org.mariotaku.kpreferences.get import org.mariotaku.twidere.R import org.mariotaku.twidere.activity.DropboxAuthStarterActivity @@ -17,7 +17,7 @@ import org.mariotaku.twidere.service.DropboxDataSyncService * Created by mariotaku on 2016/12/28. */ -class PlayStoreExtraFeaturesStatusFragment : BaseSupportFragment() { +class PlayStoreExtraFeaturesSyncStatusFragment : BaseSupportFragment() { private val REQUEST_DROPBOX_AUTH: Int = 201 override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -51,6 +51,6 @@ class PlayStoreExtraFeaturesStatusFragment : BaseSupportFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_extra_features_status_play_store, container, false) + return inflater.inflate(R.layout.fragment_extra_features_sync_status_play_store, container, false) } } diff --git a/twidere/src/google/kotlin/org/mariotaku/twidere/util/premium/GooglePlayExtraFeaturesChecker.kt b/twidere/src/google/kotlin/org/mariotaku/twidere/util/premium/GooglePlayExtraFeaturesService.kt similarity index 91% rename from twidere/src/google/kotlin/org/mariotaku/twidere/util/premium/GooglePlayExtraFeaturesChecker.kt rename to twidere/src/google/kotlin/org/mariotaku/twidere/util/premium/GooglePlayExtraFeaturesService.kt index 8182a2597..e4581f075 100644 --- a/twidere/src/google/kotlin/org/mariotaku/twidere/util/premium/GooglePlayExtraFeaturesChecker.kt +++ b/twidere/src/google/kotlin/org/mariotaku/twidere/util/premium/GooglePlayExtraFeaturesService.kt @@ -11,13 +11,15 @@ import org.mariotaku.twidere.activity.GooglePlayInAppPurchaseActivity * Created by mariotaku on 2016/12/25. */ -class GooglePlayExtraFeaturesChecker() : ExtraFeaturesChecker() { - override val statusLayout: Int = R.layout.card_item_extra_features_status - override val introductionLayout: Int = R.layout.card_item_extra_features_purchase_introduction +class GooglePlayExtraFeaturesService() : ExtraFeaturesService() { private val EXTRA_FEATURE_PRODUCT_ID = "twidere.extra.features" private lateinit var bp: BillingProcessor + override val dashboardLayouts: IntArray = intArrayOf(R.layout.card_item_extra_features_sync_status) + + override val introductionLayout: Int = R.layout.card_item_extra_features_purchase_introduction + override fun init(context: Context) { super.init(context) bp = BillingProcessor(context, GOOGLE_PLAY_LICENCING_PUBKEY, null) diff --git a/twidere/src/google/res/layout/card_item_extra_features_status.xml b/twidere/src/google/res/layout/card_item_extra_features_sync_status.xml similarity index 62% rename from twidere/src/google/res/layout/card_item_extra_features_status.xml rename to twidere/src/google/res/layout/card_item_extra_features_sync_status.xml index b5f73d489..7069ecfbe 100644 --- a/twidere/src/google/res/layout/card_item_extra_features_status.xml +++ b/twidere/src/google/res/layout/card_item_extra_features_sync_status.xml @@ -1,17 +1,16 @@ + app:cardBackgroundColor="?cardItemBackgroundColor"> + tools:layout="@layout/fragment_extra_features_sync_status_play_store"/> \ No newline at end of file diff --git a/twidere/src/google/res/layout/fragment_extra_features_status_play_store.xml b/twidere/src/google/res/layout/fragment_extra_features_sync_status_play_store.xml similarity index 100% rename from twidere/src/google/res/layout/fragment_extra_features_status_play_store.xml rename to twidere/src/google/res/layout/fragment_extra_features_sync_status_play_store.xml diff --git a/twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker b/twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker deleted file mode 100644 index 2ffa493bc..000000000 --- a/twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesChecker +++ /dev/null @@ -1 +0,0 @@ -org.mariotaku.twidere.util.premium.GooglePlayExtraFeaturesChecker \ No newline at end of file diff --git a/twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService b/twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService new file mode 100644 index 000000000..0f7cf3736 --- /dev/null +++ b/twidere/src/google/resources/META-INF/services/org.mariotaku.twidere.util.premium.ExtraFeaturesService @@ -0,0 +1 @@ +org.mariotaku.twidere.util.premium.GooglePlayExtraFeaturesService \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt index c483ddcd2..4be3ecd21 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt @@ -14,29 +14,32 @@ import nl.komponents.kovenant.ui.successUi import org.mariotaku.twidere.BuildConfig import org.mariotaku.twidere.R import org.mariotaku.twidere.fragment.ProgressDialogFragment -import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker +import org.mariotaku.twidere.util.premium.ExtraFeaturesService import java.lang.ref.WeakReference import java.util.concurrent.atomic.AtomicBoolean class PremiumDashboardActivity : BaseActivity() { - private lateinit var extraFeaturesChecker: ExtraFeaturesChecker + private lateinit var extraFeaturesService: ExtraFeaturesService override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - extraFeaturesChecker = ExtraFeaturesChecker.newInstance(this) + extraFeaturesService = ExtraFeaturesService.newInstance(this) setContentView(R.layout.activity_premium_dashboard) - if (extraFeaturesChecker.isSupported()) { - if (extraFeaturesChecker.isEnabled()) { - View.inflate(this, extraFeaturesChecker.statusLayout, cardsContainer) + if (extraFeaturesService.isSupported()) { + if (extraFeaturesService.isEnabled()) { + extraFeaturesService.dashboardLayouts.forEach { + layout -> + View.inflate(this, layout, cardsContainer) + } } else { - View.inflate(this, extraFeaturesChecker.introductionLayout, cardsContainer) + View.inflate(this, extraFeaturesService.introductionLayout, cardsContainer) } } } override fun onDestroy() { - extraFeaturesChecker.release() + extraFeaturesService.release() super.onDestroy() } @@ -55,7 +58,7 @@ class PremiumDashboardActivity : BaseActivity() { val recreate = AtomicBoolean() task { val activity = weakThis.get() ?: throw IllegalStateException() - if (!activity.extraFeaturesChecker.destroyPurchase()) { + if (!activity.extraFeaturesService.destroyPurchase()) { throw IllegalStateException() } }.successUi { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtraFeaturesIntroductionDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtraFeaturesIntroductionDialogFragment.kt index 2b9f351f9..5c81932f9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtraFeaturesIntroductionDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ExtraFeaturesIntroductionDialogFragment.kt @@ -5,7 +5,7 @@ import android.os.Bundle import android.support.v7.app.AlertDialog import android.view.View import org.mariotaku.twidere.R -import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker +import org.mariotaku.twidere.util.premium.ExtraFeaturesService /** * Created by mariotaku on 2016/12/25. @@ -13,25 +13,25 @@ import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker class ExtraFeaturesIntroductionDialogFragment : BaseDialogFragment() { - private lateinit var extraFeaturesChecker: ExtraFeaturesChecker + private lateinit var extraFeaturesService: ExtraFeaturesService override fun onDestroy() { - extraFeaturesChecker.release() + extraFeaturesService.release() super.onDestroy() } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - extraFeaturesChecker = ExtraFeaturesChecker.newInstance(context) + extraFeaturesService = ExtraFeaturesService.newInstance(context) val builder = AlertDialog.Builder(context) builder.setTitle(R.string.title_extra_features) builder.setView(R.layout.dialog_extra_features_introduction) builder.setPositiveButton(R.string.action_purchase) { dialog, which -> - startActivity(extraFeaturesChecker.createPurchaseIntent(context)) + startActivity(extraFeaturesService.createPurchaseIntent(context)) } builder.setNegativeButton(R.string.action_later) { dialog, which -> } - val restorePurchaseIntent = extraFeaturesChecker.createRestorePurchaseIntent(context) + val restorePurchaseIntent = extraFeaturesService.createRestorePurchaseIntent(context) if (restorePurchaseIntent != null) { builder.setNeutralButton(R.string.action_restore_purchase) { dialog, which -> startActivity(restorePurchaseIntent) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt index 731f0eba4..c11f7a529 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt @@ -30,12 +30,12 @@ import org.mariotaku.twidere.provider.TwidereDataStore import org.mariotaku.twidere.util.ContentValuesCreator import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.dagger.GeneralComponentHelper -import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker +import org.mariotaku.twidere.util.premium.ExtraFeaturesService import javax.inject.Inject class FilteredUsersFragment : BaseFiltersFragment() { - private lateinit var extraFeaturesChecker: ExtraFeaturesChecker + private lateinit var extraFeaturesService: ExtraFeaturesService public override val contentColumns: Array get() = TwidereDataStore.Filters.Users.COLUMNS @@ -45,11 +45,11 @@ class FilteredUsersFragment : BaseFiltersFragment() { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - extraFeaturesChecker = ExtraFeaturesChecker.newInstance(context) + extraFeaturesService = ExtraFeaturesService.newInstance(context) } override fun onDestroy() { - extraFeaturesChecker.release() + extraFeaturesService.release() super.onDestroy() } @@ -95,7 +95,7 @@ class FilteredUsersFragment : BaseFiltersFragment() { override fun onPrepareOptionsMenu(menu: Menu) { super.onPrepareOptionsMenu(menu) - val isFeaturesSupported = extraFeaturesChecker.isSupported() + val isFeaturesSupported = extraFeaturesService.isSupported() menu.setItemAvailability(R.id.add_user_single, !isFeaturesSupported) menu.setItemAvailability(R.id.add_user_submenu, isFeaturesSupported) } @@ -119,7 +119,7 @@ class FilteredUsersFragment : BaseFiltersFragment() { else -> return false } - if (!isExtraFeatures || extraFeaturesChecker.isEnabled()) { + if (!isExtraFeatures || extraFeaturesService.isEnabled()) { startActivityForResult(intent, requestCode) } else { val df = ExtraFeaturesIntroductionDialogFragment() diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/premium/ExtraFeaturesIntroductionCardFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/premium/ExtraFeaturesIntroductionCardFragment.kt index 50bb887de..fa4e7cd0b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/premium/ExtraFeaturesIntroductionCardFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/premium/ExtraFeaturesIntroductionCardFragment.kt @@ -12,7 +12,7 @@ import kotlinx.android.synthetic.main.layout_extra_features_introduction.* import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.PURCHASE_RESPONSE_NOT_PURCHASED import org.mariotaku.twidere.fragment.BaseSupportFragment -import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker +import org.mariotaku.twidere.util.premium.ExtraFeaturesService /** * Created by mariotaku on 2016/12/25. @@ -20,7 +20,7 @@ import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker class ExtraFeaturesIntroductionCardFragment : BaseSupportFragment() { - lateinit var extraFeaturesChecker: ExtraFeaturesChecker + lateinit var extraFeaturesService: ExtraFeaturesService private val REQUEST_PURCHASE: Int = 301 private val REQUEST_RESTORE_PURCHASE: Int = 302 @@ -28,11 +28,11 @@ class ExtraFeaturesIntroductionCardFragment : BaseSupportFragment() { // MARK: Fragment lifecycle override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - extraFeaturesChecker = ExtraFeaturesChecker.newInstance(context) + extraFeaturesService = ExtraFeaturesService.newInstance(context) purchaseButton.setOnClickListener { - startActivityForResult(extraFeaturesChecker.createPurchaseIntent(context), REQUEST_PURCHASE) + startActivityForResult(extraFeaturesService.createPurchaseIntent(context), REQUEST_PURCHASE) } - val restorePurchaseIntent = extraFeaturesChecker.createRestorePurchaseIntent(context) + val restorePurchaseIntent = extraFeaturesService.createRestorePurchaseIntent(context) if (restorePurchaseIntent != null) { restorePurchaseHint.visibility = View.VISIBLE restorePurchaseButton.visibility = View.VISIBLE diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/premium/ExtraFeaturesChecker.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/premium/ExtraFeaturesService.kt similarity index 79% rename from twidere/src/main/kotlin/org/mariotaku/twidere/util/premium/ExtraFeaturesChecker.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/util/premium/ExtraFeaturesService.kt index d0416c4ae..905ff32fc 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/premium/ExtraFeaturesChecker.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/premium/ExtraFeaturesService.kt @@ -9,11 +9,12 @@ import java.util.* * Created by mariotaku on 2016/12/25. */ -abstract class ExtraFeaturesChecker { +abstract class ExtraFeaturesService { protected lateinit var context: Context abstract val introductionLayout: Int - abstract val statusLayout: Int + + abstract val dashboardLayouts: IntArray @CallSuper protected open fun init(context: Context) { @@ -39,8 +40,8 @@ abstract class ExtraFeaturesChecker { companion object { - fun newInstance(context: Context): ExtraFeaturesChecker { - val instance = ServiceLoader.load(ExtraFeaturesChecker::class.java).first() + fun newInstance(context: Context): ExtraFeaturesService { + val instance = ServiceLoader.load(ExtraFeaturesService::class.java).first() instance.init(context) return instance }