Skip to content

Commit

Permalink
Hide content without tags (#175)
Browse files Browse the repository at this point in the history
* add filter_without_tags and missed strings

* add hideContentWithoutTags checkbox; remove hardcoded strings

* feat: add hideContentWithoutTags support
  • Loading branch information
karmil32 authored and feelfreelinux committed Feb 28, 2019
1 parent cc33210 commit baa21f2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.patrons.PatronBadg
import io.github.feelfreelinux.wykopmobilny.utils.preferences.BlacklistPreferencesApi
import io.github.feelfreelinux.wykopmobilny.utils.preferences.LinksPreferencesApi
import io.github.feelfreelinux.wykopmobilny.utils.preferences.SettingsPreferencesApi
import io.github.feelfreelinux.wykopmobilny.utils.textview.removeHtml
import java.util.Collections
import javax.inject.Inject

Expand All @@ -31,7 +32,8 @@ class OWMContentFilter @Inject constructor(
isBlocked ||
body.bodyContainsBlockedTags() ||
author.nick.isUserBlocked() ||
(settingsPreferencesApi.hideLowRangeAuthors && author.group == 0)
(settingsPreferencesApi.hideLowRangeAuthors && author.group == 0) ||
(settingsPreferencesApi.hideContentWithoutTags && !body.bodyContainsTags())
}

fun filterEntryComment(comment: EntryComment) =
Expand Down Expand Up @@ -66,8 +68,11 @@ class OWMContentFilter @Inject constructor(

}

private val tagsRegex = "(^|\\s)(#[a-z\\d-]+)".toRegex()

private fun String.bodyContainsTags() = tagsRegex.containsMatchIn(this.removeHtml())

private fun String.bodyContainsBlockedTags(): Boolean {
val tagsRegex = "(^|\\s)(#[a-z\\d-]+)".toRegex()
return !Collections.disjoint(
blacklistPreferences.blockedTags,
tagsRegex.matchEntire(this)?.groupValues?.map { it.removePrefix("#") } ?: emptyList<String>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface SettingsPreferencesApi {
var cutImages: Boolean
var openSpoilersDialog: Boolean
var hideLowRangeAuthors: Boolean
var hideContentWithoutTags: Boolean
var cutImageProportion: Int
var fontSize: String?
var hideLinkCommentsByDefault: Boolean
Expand All @@ -37,6 +38,7 @@ class SettingsPreferences(context: Context) : Preferences(context, true), Settin
override var showAdultContent by booleanPref(defaultValue = false)
override var hideNsfw: Boolean by booleanPref(defaultValue = true)
override var hideLowRangeAuthors: Boolean by booleanPref(defaultValue = false)
override var hideContentWithoutTags: Boolean by booleanPref(defaultValue = false)
override var hotEntriesScreen by stringPref(defaultValue = "newest")
override var defaultScreen by stringPref(defaultValue = "mainpage")
override var fontSize by stringPref(defaultValue = "normal")
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<string name="digged">Wykopywane</string>
<string name="entries">Wpisy</string>

<string name="pref_appearance_settings">Ustawienia wyglądu aplikacji</string>
<string name="pref_appearance">Wygląd</string>
<string name="pref_dark_style">Styl nocny</string>
<string name="useAmoledTheme">Tryb AMOLED dla stylu nocnego</string>
Expand All @@ -43,7 +44,13 @@
<string name="pref_notifications_frequency">Częstotliwość sprawdzania</string>
<string name="pref_content_filter">Filtrowanie treści</string>
<string name="pref_content_plus18">Pokazuj treści 18+</string>
<string name="pref_content_filternsfw">Ukryj treści z tagiem #nsfw</string>
<string name="pref_content_filter_nsfw">Ukryj treści z tagiem #nsfw</string>
<string name="pref_content_filter_low_range_authors">Ukrywaj treści zielonek</string>
<string name="pref_content_filter_without_tags">Ukrywaj treści bez tagów (tylko mirko)</string>
<string name="pref_content_hide_blacklisted">Nie pokazuj ukrytych treści</string>
<string name="pref_manage_blacklist">Zarządzaj czarną listą</string>
<string name="pref_use_built_in_browser">Użyj wbudowanej przeglądarki</string>
<string name="pref_clear_history">Wyczyść historie wyszukiwarki</string>
<string name="pref_disable_exit_confirmation">Wyłącz potwierdzenie wyjścia z aplikacji</string>

<string name="license">Publikacja aplikacji na licencji MIT</string>
Expand Down
21 changes: 13 additions & 8 deletions app/src/main/res/xml/app_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<androidx.preference.Preference
app:iconSpaceReserved="false"
android:key="appearance"
android:title="Ustawienia wyglądu aplikacji"/>
android:title="@string/pref_appearance_settings"/>

<com.takisoft.preferencex.PreferenceCategory
app:iconSpaceReserved="false"
Expand Down Expand Up @@ -52,37 +52,42 @@
<androidx.preference.CheckBoxPreference
app:iconSpaceReserved="false"
android:key="hideNsfw"
android:title="@string/pref_content_filternsfw"
android:title="@string/pref_content_filter_nsfw"
android:defaultValue="true"/>

<androidx.preference.CheckBoxPreference
app:iconSpaceReserved="false"
android:key="hideLowRangeAuthors"
android:title="Ukrywaj treści zielonek"
android:title="@string/pref_content_filter_low_range_authors"
android:defaultValue="false"/>

<androidx.preference.CheckBoxPreference
app:iconSpaceReserved="false"
android:key="hideBlacklistedViews"
android:title="Nie pokazuj ukrytych treści"
android:key="hideContentWithoutTags"
android:title="@string/pref_content_filter_without_tags"
android:defaultValue="false"/>

<androidx.preference.CheckBoxPreference
app:iconSpaceReserved="false"
android:key="hideBlacklistedViews"
android:title="@string/pref_content_hide_blacklisted"
android:defaultValue="false"/>

</com.takisoft.preferencex.PreferenceCategory>

<androidx.preference.Preference
app:iconSpaceReserved="false"
android:key="blacklist"
android:title="Zarządzaj czarną listą"/>
android:title="@string/pref_manage_blacklist"/>

<androidx.preference.CheckBoxPreference
app:iconSpaceReserved="false"
android:key="useBuiltInBrowser"
android:title="Użyj wbudowanej przeglądarki"
android:title="@string/pref_use_built_in_browser"
android:defaultValue="true"/>

<androidx.preference.Preference
app:iconSpaceReserved="false"
android:key="clearhistory"
android:title="Wyczyść historie wyszukiwarki"/>
android:title="@string/pref_clear_history"/>
</androidx.preference.PreferenceScreen>

0 comments on commit baa21f2

Please sign in to comment.