From 003b47ac59d327911f590ac1a026e273f9d96715 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Fri, 15 Sep 2017 13:24:37 +0800 Subject: [PATCH] added purchase introduction for advanced filter rule --- .../twidere/annotation/FilterScope.java | 2 +- .../twidere/extension/ViewExtensions.kt | 5 +++ .../fragment/filter/AddEditItemFragment.kt | 33 +++++++++++++++---- .../filter/FiltersSubscriptionsFragment.kt | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java index fc0168c20..7c7356cb0 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java @@ -57,5 +57,5 @@ public @interface FilterScope { // Contains all flags int ALL = 0xFFFFFFFF; @SuppressWarnings("PointlessBitwiseExpression") - int DEFAULT = ALL & ~FLAG_MATCH_NAME; + int DEFAULT = ALL & ~(FLAG_MATCH_NAME | FLAG_MATCH_DESCRIPTION); } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ViewExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ViewExtensions.kt index 32ec7bc4e..c63dfa2a8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ViewExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ViewExtensions.kt @@ -23,6 +23,7 @@ import android.graphics.Rect import android.graphics.RectF import android.support.annotation.UiThread import android.view.View +import android.view.ViewGroup import android.widget.TextView import org.mariotaku.ktextension.empty @@ -83,6 +84,10 @@ fun View.hideIfEmpty(dependency: TextView, hideVisibility: Int = View.GONE) { fun View.setVisible(visible: Boolean, hiddenVisibility: Int = View.GONE) { visibility = if (visible) View.VISIBLE else hiddenVisibility } + +val ViewGroup.children: List + get() = (0 until childCount).map { getChildAt(it) } + private fun offsetToRoot(view: View, rect: Rect) { var parent = view.parent as? View while (parent != null) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt index fcd0d1e42..ca54ab818 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt @@ -42,13 +42,13 @@ import org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter import org.mariotaku.twidere.adapter.SourceAutoCompleteAdapter import org.mariotaku.twidere.annotation.FilterScope import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.extension.applyOnShow -import org.mariotaku.twidere.extension.applyTheme -import org.mariotaku.twidere.extension.queryLong -import org.mariotaku.twidere.extension.setVisible +import org.mariotaku.twidere.extension.* +import org.mariotaku.twidere.extension.util.isAdvancedFiltersEnabled import org.mariotaku.twidere.fragment.BaseDialogFragment +import org.mariotaku.twidere.fragment.ExtraFeaturesIntroductionDialogFragment import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.provider.TwidereDataStore.Filters +import org.mariotaku.twidere.util.premium.ExtraFeaturesService class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListener { @@ -80,7 +80,11 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene } private var Dialog.scope: FilterScopes? - get() = defaultScope.also { saveScopes(it) } + get() = defaultScope.also { + if (extraFeaturesService.isAdvancedFiltersEnabled) { + saveScopes(it) + } + } set(value) { loadScopes(value ?: defaultScope) } @@ -153,11 +157,24 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene advancedToggle.setOnClickListener { advancedExpanded = !advancedExpanded } - advancedExpanded = false + advancedContainer.children.filter { it is CheckBox }.forEach { + val checkBox = it as CheckBox + checkBox.setOnClickListener onClick@ { + if (extraFeaturesService.isAdvancedFiltersEnabled) return@onClick + // Revert check state + checkBox.isChecked = !checkBox.isChecked + val df = ExtraFeaturesIntroductionDialogFragment.create( + ExtraFeaturesService.FEATURE_ADVANCED_FILTERS) + df.setTargetFragment(this@AddEditItemFragment, REQUEST_CHANGE_SCOPE_PURCHASE) + df.show(fragmentManager, ExtraFeaturesIntroductionDialogFragment.FRAGMENT_TAG) + } + } if (savedInstanceState == null) { value = defaultValue scope = defaultScope + advancedExpanded = false + editText.setSelection(editText.length().coerceAtLeast(0)) } else { value = savedInstanceState.getString(EXTRA_VALUE) scope = savedInstanceState.getParcelable(EXTRA_SCOPE) @@ -262,4 +279,8 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene } + companion object { + private const val REQUEST_CHANGE_SCOPE_PURCHASE = 101 + } + } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersSubscriptionsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersSubscriptionsFragment.kt index 24b69d276..a6edde7ad 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersSubscriptionsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersSubscriptionsFragment.kt @@ -334,9 +334,9 @@ class FiltersSubscriptionsFragment : BaseFragment(), LoaderManager.LoaderCallbac companion object { const val ACTION_ADD_URL_SUBSCRIPTION = "${INTENT_PACKAGE_PREFIX}ADD_URL_FILTERS_SUBSCRIPTION" - const val REQUEST_ADD_URL_SUBSCRIPTION_PURCHASE = 101 const val EXTRA_ADD_SUBSCRIPTION_URL = "add_subscription.url" const val EXTRA_ADD_SUBSCRIPTION_NAME = "add_subscription.name" + private const val REQUEST_ADD_URL_SUBSCRIPTION_PURCHASE = 101 private const val FRAGMENT_TAG_RREFRESH_FILTERS = "refresh_filters" } }