updated extra features code
This commit is contained in:
parent
3dbaf3726d
commit
3f95583d2f
|
@ -68,7 +68,7 @@
|
||||||
-keep class * extends org.mariotaku.twidere.util.MapFragmentFactory
|
-keep class * extends org.mariotaku.twidere.util.MapFragmentFactory
|
||||||
-keep class * extends org.mariotaku.twidere.util.TwitterCardFragmentFactory
|
-keep class * extends org.mariotaku.twidere.util.TwitterCardFragmentFactory
|
||||||
-keep class * extends org.mariotaku.twidere.util.Analyzer
|
-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 * {
|
-keepclassmembers class * {
|
||||||
private <fields>;
|
private <fields>;
|
||||||
|
|
|
@ -8,10 +8,11 @@ import org.mariotaku.twidere.R
|
||||||
* Created by mariotaku on 2016/12/25.
|
* 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 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 isSupported(): Boolean = false
|
||||||
|
|
||||||
override fun isEnabled(): Boolean = false
|
override fun isEnabled(): Boolean = false
|
|
@ -1 +0,0 @@
|
||||||
org.mariotaku.twidere.util.premium.DummyExtraFeaturesChecker
|
|
|
@ -0,0 +1 @@
|
||||||
|
org.mariotaku.twidere.util.premium.DummyExtraFeaturesService
|
|
@ -5,7 +5,7 @@ import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
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.kpreferences.get
|
||||||
import org.mariotaku.twidere.R
|
import org.mariotaku.twidere.R
|
||||||
import org.mariotaku.twidere.activity.DropboxAuthStarterActivity
|
import org.mariotaku.twidere.activity.DropboxAuthStarterActivity
|
||||||
|
@ -17,7 +17,7 @@ import org.mariotaku.twidere.service.DropboxDataSyncService
|
||||||
* Created by mariotaku on 2016/12/28.
|
* Created by mariotaku on 2016/12/28.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class PlayStoreExtraFeaturesStatusFragment : BaseSupportFragment() {
|
class PlayStoreExtraFeaturesSyncStatusFragment : BaseSupportFragment() {
|
||||||
private val REQUEST_DROPBOX_AUTH: Int = 201
|
private val REQUEST_DROPBOX_AUTH: Int = 201
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
|
@ -51,6 +51,6 @@ class PlayStoreExtraFeaturesStatusFragment : BaseSupportFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,13 +11,15 @@ import org.mariotaku.twidere.activity.GooglePlayInAppPurchaseActivity
|
||||||
* Created by mariotaku on 2016/12/25.
|
* Created by mariotaku on 2016/12/25.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class GooglePlayExtraFeaturesChecker() : ExtraFeaturesChecker() {
|
class GooglePlayExtraFeaturesService() : ExtraFeaturesService() {
|
||||||
override val statusLayout: Int = R.layout.card_item_extra_features_status
|
|
||||||
override val introductionLayout: Int = R.layout.card_item_extra_features_purchase_introduction
|
|
||||||
private val EXTRA_FEATURE_PRODUCT_ID = "twidere.extra.features"
|
private val EXTRA_FEATURE_PRODUCT_ID = "twidere.extra.features"
|
||||||
|
|
||||||
private lateinit var bp: BillingProcessor
|
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) {
|
override fun init(context: Context) {
|
||||||
super.init(context)
|
super.init(context)
|
||||||
bp = BillingProcessor(context, GOOGLE_PLAY_LICENCING_PUBKEY, null)
|
bp = BillingProcessor(context, GOOGLE_PLAY_LICENCING_PUBKEY, null)
|
|
@ -1,17 +1,16 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.v7.widget.CardView
|
<android.support.v7.widget.CardView
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:cardBackgroundColor="?cardItemBackgroundColor"
|
app:cardBackgroundColor="?cardItemBackgroundColor">
|
||||||
tools:showIn="@layout/activity_premium_dashboard">
|
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/extra_features_status"
|
android:id="@+id/extra_features_sync_status"
|
||||||
class="org.mariotaku.twidere.fragment.premium.PlayStoreExtraFeaturesStatusFragment"
|
class="org.mariotaku.twidere.fragment.premium.PlayStoreExtraFeaturesSyncStatusFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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>
|
</android.support.v7.widget.CardView>
|
|
@ -1 +0,0 @@
|
||||||
org.mariotaku.twidere.util.premium.GooglePlayExtraFeaturesChecker
|
|
|
@ -0,0 +1 @@
|
||||||
|
org.mariotaku.twidere.util.premium.GooglePlayExtraFeaturesService
|
|
@ -14,29 +14,32 @@ import nl.komponents.kovenant.ui.successUi
|
||||||
import org.mariotaku.twidere.BuildConfig
|
import org.mariotaku.twidere.BuildConfig
|
||||||
import org.mariotaku.twidere.R
|
import org.mariotaku.twidere.R
|
||||||
import org.mariotaku.twidere.fragment.ProgressDialogFragment
|
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.lang.ref.WeakReference
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
class PremiumDashboardActivity : BaseActivity() {
|
class PremiumDashboardActivity : BaseActivity() {
|
||||||
|
|
||||||
private lateinit var extraFeaturesChecker: ExtraFeaturesChecker
|
private lateinit var extraFeaturesService: ExtraFeaturesService
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
extraFeaturesChecker = ExtraFeaturesChecker.newInstance(this)
|
extraFeaturesService = ExtraFeaturesService.newInstance(this)
|
||||||
setContentView(R.layout.activity_premium_dashboard)
|
setContentView(R.layout.activity_premium_dashboard)
|
||||||
if (extraFeaturesChecker.isSupported()) {
|
if (extraFeaturesService.isSupported()) {
|
||||||
if (extraFeaturesChecker.isEnabled()) {
|
if (extraFeaturesService.isEnabled()) {
|
||||||
View.inflate(this, extraFeaturesChecker.statusLayout, cardsContainer)
|
extraFeaturesService.dashboardLayouts.forEach {
|
||||||
|
layout ->
|
||||||
|
View.inflate(this, layout, cardsContainer)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
View.inflate(this, extraFeaturesChecker.introductionLayout, cardsContainer)
|
View.inflate(this, extraFeaturesService.introductionLayout, cardsContainer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
extraFeaturesChecker.release()
|
extraFeaturesService.release()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +58,7 @@ class PremiumDashboardActivity : BaseActivity() {
|
||||||
val recreate = AtomicBoolean()
|
val recreate = AtomicBoolean()
|
||||||
task {
|
task {
|
||||||
val activity = weakThis.get() ?: throw IllegalStateException()
|
val activity = weakThis.get() ?: throw IllegalStateException()
|
||||||
if (!activity.extraFeaturesChecker.destroyPurchase()) {
|
if (!activity.extraFeaturesService.destroyPurchase()) {
|
||||||
throw IllegalStateException()
|
throw IllegalStateException()
|
||||||
}
|
}
|
||||||
}.successUi {
|
}.successUi {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.os.Bundle
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import org.mariotaku.twidere.R
|
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.
|
* Created by mariotaku on 2016/12/25.
|
||||||
|
@ -13,25 +13,25 @@ import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker
|
||||||
|
|
||||||
class ExtraFeaturesIntroductionDialogFragment : BaseDialogFragment() {
|
class ExtraFeaturesIntroductionDialogFragment : BaseDialogFragment() {
|
||||||
|
|
||||||
private lateinit var extraFeaturesChecker: ExtraFeaturesChecker
|
private lateinit var extraFeaturesService: ExtraFeaturesService
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
extraFeaturesChecker.release()
|
extraFeaturesService.release()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
extraFeaturesChecker = ExtraFeaturesChecker.newInstance(context)
|
extraFeaturesService = ExtraFeaturesService.newInstance(context)
|
||||||
val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
builder.setTitle(R.string.title_extra_features)
|
builder.setTitle(R.string.title_extra_features)
|
||||||
builder.setView(R.layout.dialog_extra_features_introduction)
|
builder.setView(R.layout.dialog_extra_features_introduction)
|
||||||
builder.setPositiveButton(R.string.action_purchase) { dialog, which ->
|
builder.setPositiveButton(R.string.action_purchase) { dialog, which ->
|
||||||
startActivity(extraFeaturesChecker.createPurchaseIntent(context))
|
startActivity(extraFeaturesService.createPurchaseIntent(context))
|
||||||
}
|
}
|
||||||
builder.setNegativeButton(R.string.action_later) { dialog, which ->
|
builder.setNegativeButton(R.string.action_later) { dialog, which ->
|
||||||
|
|
||||||
}
|
}
|
||||||
val restorePurchaseIntent = extraFeaturesChecker.createRestorePurchaseIntent(context)
|
val restorePurchaseIntent = extraFeaturesService.createRestorePurchaseIntent(context)
|
||||||
if (restorePurchaseIntent != null) {
|
if (restorePurchaseIntent != null) {
|
||||||
builder.setNeutralButton(R.string.action_restore_purchase) { dialog, which ->
|
builder.setNeutralButton(R.string.action_restore_purchase) { dialog, which ->
|
||||||
startActivity(restorePurchaseIntent)
|
startActivity(restorePurchaseIntent)
|
||||||
|
|
|
@ -30,12 +30,12 @@ import org.mariotaku.twidere.provider.TwidereDataStore
|
||||||
import org.mariotaku.twidere.util.ContentValuesCreator
|
import org.mariotaku.twidere.util.ContentValuesCreator
|
||||||
import org.mariotaku.twidere.util.UserColorNameManager
|
import org.mariotaku.twidere.util.UserColorNameManager
|
||||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
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
|
import javax.inject.Inject
|
||||||
|
|
||||||
class FilteredUsersFragment : BaseFiltersFragment() {
|
class FilteredUsersFragment : BaseFiltersFragment() {
|
||||||
|
|
||||||
private lateinit var extraFeaturesChecker: ExtraFeaturesChecker
|
private lateinit var extraFeaturesService: ExtraFeaturesService
|
||||||
|
|
||||||
public override val contentColumns: Array<String>
|
public override val contentColumns: Array<String>
|
||||||
get() = TwidereDataStore.Filters.Users.COLUMNS
|
get() = TwidereDataStore.Filters.Users.COLUMNS
|
||||||
|
@ -45,11 +45,11 @@ class FilteredUsersFragment : BaseFiltersFragment() {
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
extraFeaturesChecker = ExtraFeaturesChecker.newInstance(context)
|
extraFeaturesService = ExtraFeaturesService.newInstance(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
extraFeaturesChecker.release()
|
extraFeaturesService.release()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class FilteredUsersFragment : BaseFiltersFragment() {
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
super.onPrepareOptionsMenu(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_single, !isFeaturesSupported)
|
||||||
menu.setItemAvailability(R.id.add_user_submenu, isFeaturesSupported)
|
menu.setItemAvailability(R.id.add_user_submenu, isFeaturesSupported)
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ class FilteredUsersFragment : BaseFiltersFragment() {
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isExtraFeatures || extraFeaturesChecker.isEnabled()) {
|
if (!isExtraFeatures || extraFeaturesService.isEnabled()) {
|
||||||
startActivityForResult(intent, requestCode)
|
startActivityForResult(intent, requestCode)
|
||||||
} else {
|
} else {
|
||||||
val df = ExtraFeaturesIntroductionDialogFragment()
|
val df = ExtraFeaturesIntroductionDialogFragment()
|
||||||
|
|
|
@ -12,7 +12,7 @@ import kotlinx.android.synthetic.main.layout_extra_features_introduction.*
|
||||||
import org.mariotaku.twidere.R
|
import org.mariotaku.twidere.R
|
||||||
import org.mariotaku.twidere.constant.PURCHASE_RESPONSE_NOT_PURCHASED
|
import org.mariotaku.twidere.constant.PURCHASE_RESPONSE_NOT_PURCHASED
|
||||||
import org.mariotaku.twidere.fragment.BaseSupportFragment
|
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.
|
* Created by mariotaku on 2016/12/25.
|
||||||
|
@ -20,7 +20,7 @@ import org.mariotaku.twidere.util.premium.ExtraFeaturesChecker
|
||||||
|
|
||||||
class ExtraFeaturesIntroductionCardFragment : BaseSupportFragment() {
|
class ExtraFeaturesIntroductionCardFragment : BaseSupportFragment() {
|
||||||
|
|
||||||
lateinit var extraFeaturesChecker: ExtraFeaturesChecker
|
lateinit var extraFeaturesService: ExtraFeaturesService
|
||||||
|
|
||||||
private val REQUEST_PURCHASE: Int = 301
|
private val REQUEST_PURCHASE: Int = 301
|
||||||
private val REQUEST_RESTORE_PURCHASE: Int = 302
|
private val REQUEST_RESTORE_PURCHASE: Int = 302
|
||||||
|
@ -28,11 +28,11 @@ class ExtraFeaturesIntroductionCardFragment : BaseSupportFragment() {
|
||||||
// MARK: Fragment lifecycle
|
// MARK: Fragment lifecycle
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
extraFeaturesChecker = ExtraFeaturesChecker.newInstance(context)
|
extraFeaturesService = ExtraFeaturesService.newInstance(context)
|
||||||
purchaseButton.setOnClickListener {
|
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) {
|
if (restorePurchaseIntent != null) {
|
||||||
restorePurchaseHint.visibility = View.VISIBLE
|
restorePurchaseHint.visibility = View.VISIBLE
|
||||||
restorePurchaseButton.visibility = View.VISIBLE
|
restorePurchaseButton.visibility = View.VISIBLE
|
||||||
|
|
|
@ -9,11 +9,12 @@ import java.util.*
|
||||||
* Created by mariotaku on 2016/12/25.
|
* Created by mariotaku on 2016/12/25.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class ExtraFeaturesChecker {
|
abstract class ExtraFeaturesService {
|
||||||
protected lateinit var context: Context
|
protected lateinit var context: Context
|
||||||
|
|
||||||
abstract val introductionLayout: Int
|
abstract val introductionLayout: Int
|
||||||
abstract val statusLayout: Int
|
|
||||||
|
abstract val dashboardLayouts: IntArray
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
protected open fun init(context: Context) {
|
protected open fun init(context: Context) {
|
||||||
|
@ -39,8 +40,8 @@ abstract class ExtraFeaturesChecker {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance(context: Context): ExtraFeaturesChecker {
|
fun newInstance(context: Context): ExtraFeaturesService {
|
||||||
val instance = ServiceLoader.load(ExtraFeaturesChecker::class.java).first()
|
val instance = ServiceLoader.load(ExtraFeaturesService::class.java).first()
|
||||||
instance.init(context)
|
instance.init(context)
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
Loading…
Reference in New Issue