improved extra features screen
This commit is contained in:
parent
85a2d6984b
commit
700aa76d60
|
@ -5,9 +5,11 @@ import android.content.Intent
|
|||
import com.anjlab.android.iab.v3.BillingProcessor
|
||||
import nl.komponents.kovenant.task
|
||||
import org.mariotaku.twidere.Constants.GOOGLE_PLAY_LICENCING_PUBKEY
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.activity.GooglePlayInAppPurchaseActivity
|
||||
import org.mariotaku.twidere.activity.premium.AbsExtraFeaturePurchaseActivity
|
||||
import org.mariotaku.twidere.view.controller.premium.GoogleFiltersImportViewController
|
||||
import org.mariotaku.twidere.view.controller.premium.GoogleFiltersSubscriptionsViewController
|
||||
import org.mariotaku.twidere.view.controller.premium.SyncStatusViewController
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/25.
|
||||
|
@ -17,7 +19,11 @@ class GooglePlayExtraFeaturesService : ExtraFeaturesService() {
|
|||
|
||||
private lateinit var bp: BillingProcessor
|
||||
|
||||
override fun getDashboardLayouts() = intArrayOf(R.layout.card_item_extra_features_sync_status)
|
||||
override fun getDashboardControllers() = listOf(
|
||||
SyncStatusViewController::class.java,
|
||||
GoogleFiltersImportViewController::class.java,
|
||||
GoogleFiltersSubscriptionsViewController::class.java
|
||||
)
|
||||
|
||||
override fun init(context: Context) {
|
||||
super.init(context)
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.mariotaku.twidere.view.controller.premium
|
||||
|
||||
import android.view.View
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.REQUEST_PURCHASE_EXTRA_FEATURES
|
||||
import org.mariotaku.twidere.activity.PremiumDashboardActivity
|
||||
import org.mariotaku.twidere.fragment.ExtraFeaturesIntroductionDialogFragment
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/2/4.
|
||||
*/
|
||||
|
||||
abstract class AbsGoogleInAppItemViewController : PremiumDashboardActivity.ExtraFeatureViewController() {
|
||||
abstract val title: String
|
||||
abstract val summary: String
|
||||
abstract val feature: String
|
||||
abstract val availableLabel: String
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
titleView.text = title
|
||||
messageView.text = summary
|
||||
|
||||
button1.setText(R.string.action_purchase)
|
||||
button2.text = availableLabel
|
||||
|
||||
button1.setOnClickListener {
|
||||
ExtraFeaturesIntroductionDialogFragment.show(activity.supportFragmentManager,
|
||||
feature = this.feature, requestCode = REQUEST_PURCHASE_EXTRA_FEATURES)
|
||||
}
|
||||
button2.setOnClickListener {
|
||||
onAvailableButtonClick()
|
||||
}
|
||||
|
||||
updateEnabledState()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateEnabledState()
|
||||
}
|
||||
|
||||
abstract fun onAvailableButtonClick()
|
||||
|
||||
private fun updateEnabledState() {
|
||||
if (extraFeaturesService.isEnabled(feature)) {
|
||||
button1.visibility = View.GONE
|
||||
button2.visibility = View.VISIBLE
|
||||
} else {
|
||||
button1.visibility = View.VISIBLE
|
||||
button2.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.mariotaku.twidere.view.controller.premium
|
||||
|
||||
import android.widget.Toast
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.util.IntentUtils
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/2/4.
|
||||
*/
|
||||
|
||||
class GoogleFiltersImportViewController : AbsGoogleInAppItemViewController() {
|
||||
override val feature: String
|
||||
get() = ExtraFeaturesService.FEATURE_FILTERS_IMPORT
|
||||
override val summary: String
|
||||
get() = context.getString(R.string.extra_feature_description_filters_import)
|
||||
override val title: String
|
||||
get() = context.getString(R.string.extra_feature_title_filters_import)
|
||||
override val availableLabel: String
|
||||
get() = context.getString(R.string.action_import)
|
||||
|
||||
override fun onAvailableButtonClick() {
|
||||
IntentUtils.openFilters(context, "users")
|
||||
Toast.makeText(context, R.string.message_toast_filters_import_hint, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.mariotaku.twidere.view.controller.premium
|
||||
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.util.IntentUtils
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/2/4.
|
||||
*/
|
||||
|
||||
class GoogleFiltersSubscriptionsViewController : AbsGoogleInAppItemViewController() {
|
||||
override val feature: String
|
||||
get() = ExtraFeaturesService.FEATURE_FILTERS_SUBSCRIPTION
|
||||
override val summary: String
|
||||
get() = context.getString(R.string.extra_feature_description_filters_subscription)
|
||||
override val title: String
|
||||
get() = context.getString(R.string.extra_feature_title_filters_subscription)
|
||||
override val availableLabel: String
|
||||
get() = context.getString(R.string.action_filter_subscriptions_card_manage)
|
||||
|
||||
override fun onAvailableButtonClick() {
|
||||
IntentUtils.openFilters(context, "settings")
|
||||
}
|
||||
}
|
|
@ -1,33 +1,72 @@
|
|||
package org.mariotaku.twidere.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.NavUtils
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.*
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import kotlinx.android.synthetic.main.activity_premium_dashboard.*
|
||||
import kotlinx.android.synthetic.main.card_item_extra_feature.view.*
|
||||
import nl.komponents.kovenant.task
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import org.mariotaku.twidere.BuildConfig
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.REQUEST_PURCHASE_EXTRA_FEATURES
|
||||
import org.mariotaku.twidere.adapter.BaseRecyclerViewAdapter
|
||||
import org.mariotaku.twidere.fragment.ProgressDialogFragment
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseFinished
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
import org.mariotaku.twidere.view.ContainerView
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.inject.Inject
|
||||
|
||||
class PremiumDashboardActivity : BaseActivity() {
|
||||
|
||||
private lateinit var adapter: ControllersAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_premium_dashboard)
|
||||
adapter = ControllersAdapter(this)
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
if (extraFeaturesService.isSupported()) {
|
||||
extraFeaturesService.getDashboardLayouts().forEach { layout ->
|
||||
View.inflate(this, layout, cardsContainer)
|
||||
}
|
||||
adapter.controllers = extraFeaturesService.getDashboardControllers()
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
val lm = recyclerView.layoutManager as LinearLayoutManager
|
||||
for (pos in lm.findFirstVisibleItemPosition()..lm.findLastVisibleItemPosition()) {
|
||||
val holder = recyclerView.findViewHolderForLayoutPosition(pos) as? ControllerViewHolder ?: return
|
||||
val controller = holder.controller as? ExtraFeatureViewController ?: return
|
||||
controller.onPause()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val lm = recyclerView.layoutManager as LinearLayoutManager
|
||||
for (pos in lm.findFirstVisibleItemPosition()..lm.findLastVisibleItemPosition()) {
|
||||
val holder = recyclerView.findViewHolderForLayoutPosition(pos) as? ControllerViewHolder ?: return
|
||||
val controller = holder.controller as? ExtraFeatureViewController ?: return
|
||||
controller.onResume()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +75,24 @@ class PremiumDashboardActivity : BaseActivity() {
|
|||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (resultCode) {
|
||||
REQUEST_PURCHASE_EXTRA_FEATURES -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Analyzer.log(PurchaseFinished.create(data!!))
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val position = ((requestCode and 0xFF00) shr 8) - 1
|
||||
if (position >= 0) {
|
||||
val holder = recyclerView.findViewHolderForLayoutPosition(position) as? ControllerViewHolder ?: return
|
||||
val controller = holder.controller as? ExtraFeatureViewController ?: return
|
||||
controller.onActivityResult(requestCode and 0xFF, resultCode, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menuInflater.inflate(R.menu.menu_premium_dashboard, menu)
|
||||
|
@ -48,7 +105,7 @@ class PremiumDashboardActivity : BaseActivity() {
|
|||
NavUtils.navigateUpFromSameTask(this)
|
||||
}
|
||||
R.id.consume_purchase -> {
|
||||
if (BuildConfig.DEBUG) {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
return true
|
||||
}
|
||||
val dfRef = WeakReference(ProgressDialogFragment.show(supportFragmentManager, "consume_purchase_progress"))
|
||||
|
@ -78,4 +135,80 @@ class PremiumDashboardActivity : BaseActivity() {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun startActivityForControllerResult(intent: Intent, position: Int, requestCode: Int) {
|
||||
if (position + 1 > 0xFF || requestCode > 0xFF) throw IllegalArgumentException()
|
||||
startActivityForResult(intent, ((position + 1) shl 8) or requestCode)
|
||||
}
|
||||
|
||||
class ControllerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val containerView by lazy { itemView.containerView }
|
||||
var controller: ContainerView.ViewController?
|
||||
get() = containerView.viewController
|
||||
set(value) {
|
||||
containerView.viewController = value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
open class ExtraFeatureViewController : ContainerView.ViewController() {
|
||||
protected val titleView by lazy { view.findViewById(R.id.title) as TextView }
|
||||
protected val messageView by lazy { view.findViewById(R.id.message) as TextView }
|
||||
protected val button1 by lazy { view.findViewById(R.id.button1) as Button }
|
||||
|
||||
protected val button2 by lazy { view.findViewById(R.id.button2) as Button }
|
||||
@Inject
|
||||
protected lateinit var extraFeaturesService: ExtraFeaturesService
|
||||
|
||||
@Inject
|
||||
protected lateinit var preferences: SharedPreferencesWrapper
|
||||
|
||||
var position: Int = RecyclerView.NO_POSITION
|
||||
internal set
|
||||
|
||||
protected val activity: PremiumDashboardActivity get() = context as PremiumDashboardActivity
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
GeneralComponentHelper.build(context).inject(this)
|
||||
}
|
||||
|
||||
override fun onCreateView(parent: ContainerView): View {
|
||||
return LayoutInflater.from(parent.context).inflate(R.layout.layout_controller_extra_feature,
|
||||
parent, false)
|
||||
}
|
||||
|
||||
open fun onPause() {}
|
||||
open fun onResume() {}
|
||||
|
||||
open fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {}
|
||||
|
||||
}
|
||||
|
||||
class ControllersAdapter(context: Context) : BaseRecyclerViewAdapter<ControllerViewHolder>(context) {
|
||||
|
||||
var controllers: List<Class<out ContainerView.ViewController>>? = null
|
||||
set(value) {
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return controllers?.size ?: 0
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ControllerViewHolder, position: Int) {
|
||||
val controller = controllers!![position].newInstance()
|
||||
if (controller is ExtraFeatureViewController) {
|
||||
controller.position = holder.layoutPosition
|
||||
}
|
||||
holder.controller = controller
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ControllerViewHolder {
|
||||
return ControllerViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.card_item_extra_feature,
|
||||
parent, false))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.mariotaku.twidere.activity.LinkHandlerActivity.HideUiOnScroll
|
|||
import org.mariotaku.twidere.activity.iface.IControlBarActivity
|
||||
import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener
|
||||
import org.mariotaku.twidere.adapter.SupportTabsAdapter
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_INITIAL_TAB
|
||||
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.*
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
import org.mariotaku.twidere.fragment.iface.IToolBarSupportFragment
|
||||
|
@ -37,7 +38,7 @@ abstract class AbsToolbarTabPagesFragment : BaseFragment(), RefreshScrollTopInte
|
|||
SupportFragmentCallback, IBaseFragment.SystemWindowsInsetsCallback, ControlBarOffsetListener,
|
||||
HideUiOnScroll, OnPageChangeListener, IToolBarSupportFragment, KeyboardShortcutCallback {
|
||||
|
||||
private var pagerAdapter: SupportTabsAdapter? = null
|
||||
private lateinit var pagerAdapter: SupportTabsAdapter
|
||||
override val toolbar: Toolbar
|
||||
get() = toolbarContainer.toolbar
|
||||
private var mControlBarHeight: Int = 0
|
||||
|
@ -53,20 +54,32 @@ abstract class AbsToolbarTabPagesFragment : BaseFragment(), RefreshScrollTopInte
|
|||
toolbarTabs.setTabDisplayOption(TabPagerIndicator.DisplayOption.LABEL)
|
||||
|
||||
|
||||
addTabs(pagerAdapter!!)
|
||||
addTabs(pagerAdapter)
|
||||
toolbarContainer.setOnSizeChangedListener { view, w, h, oldw, oldh ->
|
||||
val pageLimit = viewPager.offscreenPageLimit
|
||||
val currentItem = viewPager.currentItem
|
||||
val count = pagerAdapter!!.count
|
||||
val count = pagerAdapter.count
|
||||
for (i in 0 until count) {
|
||||
if (i > currentItem - pageLimit - 1 || i < currentItem + pageLimit) {
|
||||
val obj = pagerAdapter!!.instantiateItem(viewPager, i)
|
||||
val obj = pagerAdapter.instantiateItem(viewPager, i)
|
||||
if (obj is IBaseFragment<*>) {
|
||||
obj.requestFitSystemWindows()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
val initialTab = arguments?.getString(EXTRA_INITIAL_TAB)
|
||||
if (initialTab != null) {
|
||||
for (i in 0 until pagerAdapter.count) {
|
||||
if (initialTab == pagerAdapter.getTab(i).tag) {
|
||||
viewPager.currentItem = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun addTabs(adapter: SupportTabsAdapter)
|
||||
|
@ -100,7 +113,7 @@ abstract class AbsToolbarTabPagesFragment : BaseFragment(), RefreshScrollTopInte
|
|||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
val o = pagerAdapter!!.instantiateItem(viewPager, viewPager.currentItem)
|
||||
val o = pagerAdapter.instantiateItem(viewPager, viewPager.currentItem)
|
||||
if (o is Fragment) {
|
||||
o.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
@ -119,8 +132,8 @@ abstract class AbsToolbarTabPagesFragment : BaseFragment(), RefreshScrollTopInte
|
|||
override val currentVisibleFragment: Fragment?
|
||||
get() {
|
||||
val currentItem = viewPager.currentItem
|
||||
if (currentItem < 0 || currentItem >= pagerAdapter!!.count) return null
|
||||
return pagerAdapter!!.instantiateItem(viewPager, currentItem) as Fragment
|
||||
if (currentItem < 0 || currentItem >= pagerAdapter.count) return null
|
||||
return pagerAdapter.instantiateItem(viewPager, currentItem)
|
||||
}
|
||||
|
||||
override fun triggerRefresh(position: Int): Boolean {
|
||||
|
@ -181,14 +194,14 @@ abstract class AbsToolbarTabPagesFragment : BaseFragment(), RefreshScrollTopInte
|
|||
when (action) {
|
||||
ACTION_NAVIGATION_PREVIOUS_TAB -> {
|
||||
val previous = viewPager.currentItem - 1
|
||||
if (previous >= 0 && previous < pagerAdapter!!.count) {
|
||||
if (previous >= 0 && previous < pagerAdapter.count) {
|
||||
viewPager.setCurrentItem(previous, true)
|
||||
}
|
||||
return true
|
||||
}
|
||||
ACTION_NAVIGATION_NEXT_TAB -> {
|
||||
val next = viewPager.currentItem + 1
|
||||
if (next >= 0 && next < pagerAdapter!!.count) {
|
||||
if (next >= 0 && next < pagerAdapter.count) {
|
||||
viewPager.setCurrentItem(next, true)
|
||||
}
|
||||
return true
|
||||
|
|
|
@ -32,11 +32,11 @@ class FiltersFragment : AbsToolbarTabPagesFragment() {
|
|||
}
|
||||
|
||||
override fun addTabs(adapter: SupportTabsAdapter) {
|
||||
adapter.addTab(cls = FilteredUsersFragment::class.java, name = getString(R.string.filter_type_users))
|
||||
adapter.addTab(cls = FilteredKeywordsFragment::class.java, name = getString(R.string.filter_type_keywords))
|
||||
adapter.addTab(cls = FilteredSourcesFragment::class.java, name = getString(R.string.filter_type_sources))
|
||||
adapter.addTab(cls = FilteredLinksFragment::class.java, name = getString(R.string.filter_type_links))
|
||||
adapter.addTab(cls = FilterSettingsFragment::class.java, name = getString(R.string.settings))
|
||||
adapter.addTab(cls = FilteredUsersFragment::class.java, name = getString(R.string.filter_type_users), tag = "users")
|
||||
adapter.addTab(cls = FilteredKeywordsFragment::class.java, name = getString(R.string.filter_type_keywords), tag = "keywords")
|
||||
adapter.addTab(cls = FilteredSourcesFragment::class.java, name = getString(R.string.filter_type_sources), tag = "sources")
|
||||
adapter.addTab(cls = FilteredLinksFragment::class.java, name = getString(R.string.filter_type_links), tag = "links")
|
||||
adapter.addTab(cls = FilterSettingsFragment::class.java, name = getString(R.string.settings), tag = "settings")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -700,13 +700,14 @@ object IntentUtils {
|
|||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
fun openFilters(context: Context) {
|
||||
fun openFilters(context: Context, initialTab: String? = null) {
|
||||
val intent = Intent()
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_TWIDERE)
|
||||
builder.authority(AUTHORITY_FILTERS)
|
||||
intent.data = builder.build()
|
||||
intent.`package` = BuildConfig.APPLICATION_ID
|
||||
intent.putExtra(EXTRA_INITIAL_TAB, initialTab)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import dagger.Component
|
|||
import org.mariotaku.twidere.activity.BaseActivity
|
||||
import org.mariotaku.twidere.activity.ComposeActivity
|
||||
import org.mariotaku.twidere.activity.MediaViewerActivity
|
||||
import org.mariotaku.twidere.activity.PremiumDashboardActivity
|
||||
import org.mariotaku.twidere.adapter.*
|
||||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
import org.mariotaku.twidere.fragment.*
|
||||
|
@ -152,4 +153,6 @@ interface GeneralComponent {
|
|||
fun inject(loader: CacheUserSearchLoader)
|
||||
|
||||
fun inject(loader: BaseUserListsLoader)
|
||||
|
||||
fun inject(controller: PremiumDashboardActivity.ExtraFeatureViewController)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.mariotaku.twidere.util.premium
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import org.mariotaku.twidere.view.ContainerView
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/25.
|
||||
|
@ -9,7 +10,7 @@ import android.content.Intent
|
|||
|
||||
class DummyExtraFeaturesService : ExtraFeaturesService() {
|
||||
|
||||
override fun getDashboardLayouts() = intArrayOf()
|
||||
override fun getDashboardControllers() = emptyList<Class<ContainerView.ViewController>>()
|
||||
|
||||
override fun isSupported(): Boolean = false
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.support.annotation.CallSuper
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.view.ContainerView
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -13,7 +14,7 @@ import java.util.*
|
|||
abstract class ExtraFeaturesService {
|
||||
protected lateinit var context: Context
|
||||
|
||||
abstract fun getDashboardLayouts(): IntArray
|
||||
abstract fun getDashboardControllers(): List<Class<out ContainerView.ViewController>>
|
||||
|
||||
@CallSuper
|
||||
protected open fun init(context: Context) {
|
||||
|
|
|
@ -1,67 +1,54 @@
|
|||
package org.mariotaku.twidere.fragment.premium
|
||||
package org.mariotaku.twidere.view.controller.premium
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import kotlinx.android.synthetic.main.fragment_extra_features_sync_status.*
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.Bundle
|
||||
import org.mariotaku.ktextension.set
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.REQUEST_PURCHASE_EXTRA_FEATURES
|
||||
import org.mariotaku.twidere.activity.FragmentContentActivity
|
||||
import org.mariotaku.twidere.activity.PremiumDashboardActivity
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_POSITION
|
||||
import org.mariotaku.twidere.constant.dataSyncProviderInfoKey
|
||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
import org.mariotaku.twidere.fragment.BaseFragment
|
||||
import org.mariotaku.twidere.fragment.ExtraFeaturesIntroductionDialogFragment
|
||||
import org.mariotaku.twidere.fragment.sync.SyncSettingsFragment
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseFinished
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
import org.mariotaku.twidere.util.sync.SyncProviderInfoFactory
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/28.
|
||||
* Created by mariotaku on 2017/2/3.
|
||||
*/
|
||||
|
||||
class SyncStatusFragment : BaseFragment() {
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
class SyncStatusViewController : PremiumDashboardActivity.ExtraFeatureViewController() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
updateSyncSettingActions()
|
||||
connectButton.setOnClickListener {
|
||||
titleView.setText(R.string.title_sync)
|
||||
button1.setText(R.string.action_sync_connect_to_storage)
|
||||
button2.setText(R.string.action_sync_settings)
|
||||
button1.setOnClickListener {
|
||||
if (!extraFeaturesService.isEnabled(ExtraFeaturesService.FEATURE_SYNC_DATA)) {
|
||||
showExtraFeaturesIntroduction()
|
||||
return@setOnClickListener
|
||||
}
|
||||
val df = ConnectNetworkStorageSelectionDialogFragment()
|
||||
df.show(childFragmentManager, "connect_to_storage")
|
||||
df.arguments = Bundle { this[EXTRA_POSITION] = position }
|
||||
df.show(activity.supportFragmentManager, "connect_to_storage")
|
||||
}
|
||||
settingsButton.setOnClickListener {
|
||||
button2.setOnClickListener {
|
||||
if (!extraFeaturesService.isEnabled(ExtraFeaturesService.FEATURE_SYNC_DATA)) {
|
||||
showExtraFeaturesIntroduction()
|
||||
return@setOnClickListener
|
||||
}
|
||||
val intent = Intent(context, FragmentContentActivity::class.java)
|
||||
intent.putExtra(FragmentContentActivity.EXTRA_FRAGMENT, SyncSettingsFragment::class.java.name)
|
||||
intent.putExtra(FragmentContentActivity.EXTRA_TITLE, getString(R.string.title_sync_settings))
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_CONNECT_NETWORK_STORAGE -> {
|
||||
updateSyncSettingActions()
|
||||
}
|
||||
REQUEST_PURCHASE_EXTRA_FEATURES -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Analyzer.log(PurchaseFinished.create(data!!))
|
||||
}
|
||||
}
|
||||
intent.putExtra(FragmentContentActivity.EXTRA_TITLE, context.getString(R.string.title_sync_settings))
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,29 +57,26 @@ class SyncStatusFragment : BaseFragment() {
|
|||
updateSyncSettingActions()
|
||||
}
|
||||
|
||||
private fun updateSyncSettingActions() {
|
||||
val providerInfo = preferences[dataSyncProviderInfoKey]
|
||||
if (providerInfo == null) {
|
||||
messageView.text = context.getString(R.string.message_sync_data_connect_hint)
|
||||
button1.visibility = View.VISIBLE
|
||||
button2.visibility = View.GONE
|
||||
} else {
|
||||
val providerEntry = SyncProviderInfoFactory.getProviderEntry(context, providerInfo.type)!!
|
||||
messageView.text = context.getString(R.string.message_sync_data_synced_with_name, providerEntry.name)
|
||||
button1.visibility = View.GONE
|
||||
button2.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
private fun showExtraFeaturesIntroduction() {
|
||||
ExtraFeaturesIntroductionDialogFragment.show(childFragmentManager,
|
||||
ExtraFeaturesIntroductionDialogFragment.show(activity.supportFragmentManager,
|
||||
feature = ExtraFeaturesService.FEATURE_SYNC_DATA,
|
||||
requestCode = REQUEST_PURCHASE_EXTRA_FEATURES)
|
||||
}
|
||||
|
||||
private fun updateSyncSettingActions() {
|
||||
val providerInfo = preferences[dataSyncProviderInfoKey]
|
||||
if (providerInfo == null) {
|
||||
statusText.text = getText(R.string.message_sync_data_connect_hint)
|
||||
connectButton.visibility = View.VISIBLE
|
||||
settingsButton.visibility = View.GONE
|
||||
} else {
|
||||
val providerEntry = SyncProviderInfoFactory.getProviderEntry(context, providerInfo.type)!!
|
||||
statusText.text = getString(R.string.message_sync_data_synced_with_name, providerEntry.name)
|
||||
connectButton.visibility = View.GONE
|
||||
settingsButton.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_extra_features_sync_status, container, false)
|
||||
}
|
||||
|
||||
class ConnectNetworkStorageSelectionDialogFragment : BaseDialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
|
@ -102,14 +86,23 @@ class SyncStatusFragment : BaseFragment() {
|
|||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(R.string.title_dialog_sync_connect_to)
|
||||
builder.setItems(itemNames) { dialog, which ->
|
||||
activity.startActivityForResult(providers[which].authIntent, REQUEST_CONNECT_NETWORK_STORAGE)
|
||||
val activity = activity as PremiumDashboardActivity
|
||||
activity.startActivityForControllerResult(providers[which].authIntent,
|
||||
arguments.getInt(EXTRA_POSITION), REQUEST_CONNECT_NETWORK_STORAGE)
|
||||
}
|
||||
return builder.create()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_CONNECT_NETWORK_STORAGE -> {
|
||||
updateSyncSettingActions()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val REQUEST_CONNECT_NETWORK_STORAGE: Int = 201
|
||||
}
|
||||
|
||||
}
|
|
@ -1,21 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.mariotaku.twidere.activity.PremiumDashboardActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:id="@+id/cardsContainer"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin">
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="@dimen/element_spacing_normal"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/element_spacing_normal"
|
||||
tools:context="org.mariotaku.twidere.activity.PremiumDashboardActivity"/>
|
|
@ -2,15 +2,14 @@
|
|||
<android.support.v7.widget.CardView
|
||||
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"
|
||||
android:layout_marginBottom="@dimen/element_spacing_small"
|
||||
android:layout_marginTop="@dimen/element_spacing_small"
|
||||
app:cardBackgroundColor="?cardItemBackgroundColor">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/extra_features_sync_status"
|
||||
class="org.mariotaku.twidere.fragment.premium.SyncStatusFragment"
|
||||
<org.mariotaku.twidere.view.ContainerView
|
||||
android:id="@+id/containerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:layout="@layout/fragment_extra_features_sync_status"/>
|
||||
android:layout_height="wrap_content"/>
|
||||
</android.support.v7.widget.CardView>
|
|
@ -22,6 +22,7 @@
|
|||
android:id="@+id/featureIcon"
|
||||
android:layout_width="@dimen/element_size_small"
|
||||
android:layout_height="@dimen/element_size_small"
|
||||
android:layout_weight="0"
|
||||
app:iabColor="?android:textColorSecondary"
|
||||
tools:src="@drawable/ic_action_refresh"/>
|
||||
|
||||
|
@ -29,6 +30,7 @@
|
|||
android:id="@+id/featureDescription"
|
||||
android:layout_marginLeft="@dimen/element_spacing_normal"
|
||||
android:layout_marginStart="@dimen/element_spacing_normal"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/element_size_small"
|
||||
android:textSize="15sp"
|
||||
|
|
|
@ -8,22 +8,23 @@
|
|||
android:padding="@dimen/element_spacing_normal">
|
||||
|
||||
<org.mariotaku.twidere.view.FixedTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/element_spacing_normal"
|
||||
android:text="@string/title_sync"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textStyle="bold"/>
|
||||
android:textStyle="bold"
|
||||
tools:text="Title"/>
|
||||
|
||||
<org.mariotaku.twidere.view.FixedTextView
|
||||
android:id="@+id/message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/statusText"
|
||||
android:layout_margin="@dimen/element_spacing_normal"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:textSize="16sp"
|
||||
tools:text="@string/message_sync_data_synced_with_name"/>
|
||||
tools:text="Message"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -36,27 +37,27 @@
|
|||
android:layout_weight="1"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/connectButton"
|
||||
android:id="@+id/button1"
|
||||
style="?borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/action_sync_connect_to_storage"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
android:textColor="?colorAccent"
|
||||
android:textStyle="bold"/>
|
||||
android:textStyle="bold"
|
||||
tools:text="Button 1"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/settingsButton"
|
||||
android:id="@+id/button2"
|
||||
style="?borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/action_sync_settings"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
android:textColor="?colorAccent"
|
||||
android:textStyle="bold"/>
|
||||
android:textStyle="bold"
|
||||
tools:text="Button 2"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -38,6 +38,7 @@
|
|||
<string name="action_favoriting">favoriting</string>
|
||||
<string name="action_filter_import_from_blocked_users">Import from blocked users</string>
|
||||
<string name="action_filter_import_from_muted_users">Import from muted users</string>
|
||||
<string name="action_filter_subscriptions_card_manage">Manage subscriptions</string>
|
||||
<string name="action_finish">Finish</string>
|
||||
<string name="action_follow">Follow</string>
|
||||
<string name="action_following">following</string>
|
||||
|
@ -457,9 +458,11 @@
|
|||
|
||||
<string name="extra_configurations">Extra configurations</string>
|
||||
<string name="extra_feature_description_filters_import">Import filter list from blocks/mutes</string>
|
||||
<string name="extra_feature_description_filters_subscription">Filters list subscription</string>
|
||||
<string name="extra_feature_description_filters_subscription">Subscribe to mute filters and sync automatically</string>
|
||||
<string name="extra_feature_description_schedule_status">Schedule tweet (send later)</string>
|
||||
<string name="extra_feature_description_sync_data">Sync data with Dropbox, Google Drive etc</string>
|
||||
<string name="extra_feature_title_filters_import">Filters import</string>
|
||||
<string name="extra_feature_title_filters_subscription">Filters subscription</string>
|
||||
<!-- Enhanced (paid) features description -->
|
||||
<string name="extra_features_description">Support Twidere and get enhanced features</string>
|
||||
<string name="extra_features_pack_description">Or buy features pack to get all features (including features in future releases)</string>
|
||||
|
@ -695,6 +698,7 @@
|
|||
<string name="message_toast_error_occurred">An error occurred, please try again</string>
|
||||
<!-- Toast message for enhanced (paid) features not purchased while trying to restore purchase -->
|
||||
<string name="message_toast_extra_features_not_purchased">Enhanced features not purchased</string>
|
||||
<string name="message_toast_filters_import_hint">Press \"+\" to import</string>
|
||||
<string name="message_toast_link_copied_to_clipboard">Link copied to clipboard</string>
|
||||
<string name="message_toast_livewp_daydream_enabled_message">Here\'s a little present for you, find it in your system settings :)</string>
|
||||
<string name="message_toast_login_verification_failed">Login verification failed</string>
|
||||
|
|
Loading…
Reference in New Issue