updated extra features code

This commit is contained in:
Mariotaku Lee 2017-01-01 23:28:00 +08:00
parent 3dbaf3726d
commit 3f95583d2f
15 changed files with 53 additions and 47 deletions

View File

@ -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 <fields>;

View File

@ -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

View File

@ -1 +0,0 @@
org.mariotaku.twidere.util.premium.DummyExtraFeaturesChecker

View File

@ -0,0 +1 @@
org.mariotaku.twidere.util.premium.DummyExtraFeaturesService

View File

@ -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)
}
}

View File

@ -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)

View File

@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="?cardItemBackgroundColor"
tools:showIn="@layout/activity_premium_dashboard">
app:cardBackgroundColor="?cardItemBackgroundColor">
<fragment
android:id="@+id/extra_features_status"
class="org.mariotaku.twidere.fragment.premium.PlayStoreExtraFeaturesStatusFragment"
android:id="@+id/extra_features_sync_status"
class="org.mariotaku.twidere.fragment.premium.PlayStoreExtraFeaturesSyncStatusFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_extra_features_status_play_store"/>
tools:layout="@layout/fragment_extra_features_sync_status_play_store"/>
</android.support.v7.widget.CardView>

View File

@ -1 +0,0 @@
org.mariotaku.twidere.util.premium.GooglePlayExtraFeaturesChecker

View File

@ -0,0 +1 @@
org.mariotaku.twidere.util.premium.GooglePlayExtraFeaturesService

View File

@ -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 {

View File

@ -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)

View File

@ -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<String>
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()

View File

@ -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

View File

@ -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
}