added purchase introduction for advanced filter rule

This commit is contained in:
Mariotaku Lee 2017-09-15 13:24:37 +08:00
parent 5066f36506
commit 003b47ac59
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 34 additions and 8 deletions

View File

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

View File

@ -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<View>
get() = (0 until childCount).map { getChildAt(it) }
private fun offsetToRoot(view: View, rect: Rect) {
var parent = view.parent as? View
while (parent != null) {

View File

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

View File

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