diff --git a/.travis.yml b/.travis.yml index 7f6f4013a..23df9c016 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,7 +62,7 @@ before_install: install: # Extracts build configs into source tree - tar zxf travis/configs/twidere_private_config.tar.gz - - GIT_SSH_COMMAND='ssh -i priv_components_ssh_key' git clone $COMPONENT_GOOGLE_REPO > /dev/null 2>&1 + - GIT_SSH_COMMAND='ssh -i priv_components_ssh_key' git clone $COMPONENT_GOOGLE_REPO twidere/src/google > /dev/null 2>&1 before_script: # Validate if patches work diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/PreferenceExtension.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/PreferenceExtension.kt new file mode 100644 index 000000000..79cd2807e --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/PreferenceExtension.kt @@ -0,0 +1,41 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.extension + +import android.support.v7.preference.Preference +import android.support.v7.preference.PreferenceGroup +import android.support.v7.preference.PreferenceScreen +import java.util.* + +fun Preference.findParent(screen: PreferenceScreen): PreferenceGroup? { + val curParents = Stack() + curParents.add(screen) + while (!curParents.isEmpty()) { + val parent = curParents.pop() + for (i in 0 until parent.preferenceCount) { + val child = parent.getPreference(i) + if (child == this) return parent + if (child is PreferenceGroup) { + curParents.push(child) + } + } + } + return null +} \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/preference/PremiumEntryPreference.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/PremiumEntryPreference.kt index 9f51057b0..69b451dee 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/preference/PremiumEntryPreference.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/PremiumEntryPreference.kt @@ -7,6 +7,7 @@ import android.util.AttributeSet import org.mariotaku.chameleon.ChameleonUtils import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.REQUEST_PURCHASE_EXTRA_FEATURES +import org.mariotaku.twidere.extension.findParent import org.mariotaku.twidere.fragment.ExtraFeaturesIntroductionDialogFragment import org.mariotaku.twidere.util.dagger.GeneralComponentHelper import org.mariotaku.twidere.util.premium.ExtraFeaturesService @@ -40,4 +41,13 @@ class PremiumEntryPreference(context: Context, attrs: AttributeSet) : Preference return@setOnPreferenceClickListener false } } + + override fun onAttached() { + super.onAttached() + if (!extraFeaturesService.isSupported()) { + preferenceManager.preferenceScreen?.let { screen -> + findParent(screen)?.removePreference(this) + } + } + } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/preference/PremiumEntryPreferenceCategory.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/PremiumEntryPreferenceCategory.kt new file mode 100644 index 000000000..0d3993d95 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/PremiumEntryPreferenceCategory.kt @@ -0,0 +1,55 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.preference + +import android.content.Context +import android.util.AttributeSet +import org.mariotaku.twidere.R +import org.mariotaku.twidere.extension.findParent +import org.mariotaku.twidere.util.dagger.GeneralComponentHelper +import org.mariotaku.twidere.util.premium.ExtraFeaturesService +import javax.inject.Inject + + +/** + * Created by mariotaku on 2017/1/12. + */ +class PremiumEntryPreferenceCategory(context: Context, attrs: AttributeSet) : TintedPreferenceCategory(context, attrs) { + + @Inject + internal lateinit var extraFeaturesService: ExtraFeaturesService + + init { + GeneralComponentHelper.build(context).inject(this) + val a = context.obtainStyledAttributes(attrs, R.styleable.PremiumEntryPreference) + a.recycle() + isEnabled = extraFeaturesService.isSupported() + } + + override fun onAttached() { + super.onAttached() + if (!extraFeaturesService.isSupported()) { + preferenceManager.preferenceScreen?.let { screen -> + findParent(screen)?.removePreference(this) + } + } + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt index c1d4dd3dd..e7909107c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt @@ -33,6 +33,7 @@ import org.mariotaku.twidere.loader.* import org.mariotaku.twidere.preference.AccountsListPreference import org.mariotaku.twidere.preference.KeyboardShortcutPreference import org.mariotaku.twidere.preference.PremiumEntryPreference +import org.mariotaku.twidere.preference.PremiumEntryPreferenceCategory import org.mariotaku.twidere.preference.sync.SyncItemPreference import org.mariotaku.twidere.provider.CacheProvider import org.mariotaku.twidere.provider.TwidereDataProvider @@ -130,6 +131,8 @@ interface GeneralComponent { fun inject(preference: PremiumEntryPreference) + fun inject(preference: PremiumEntryPreferenceCategory) + fun inject(loader: CacheUserSearchLoader) fun inject(loader: BaseUserListsLoader) diff --git a/twidere/src/main/res/xml/preferences_filters.xml b/twidere/src/main/res/xml/preferences_filters.xml index b4cee5f9c..681e20f4d 100644 --- a/twidere/src/main/res/xml/preferences_filters.xml +++ b/twidere/src/main/res/xml/preferences_filters.xml @@ -10,7 +10,7 @@ android:defaultValue="false" android:key="filter_possibility_sensitive_statuses" android:title="@string/preference_filter_possibility_sensitive_statuses"/> - + - + \ No newline at end of file