diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/filters/OWMContentFilter.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/filters/OWMContentFilter.kt index 434fa6d87..72f45d79a 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/filters/OWMContentFilter.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/filters/OWMContentFilter.kt @@ -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 @@ -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) = @@ -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()) diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/linkdetails/LinkDetailsActivity.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/linkdetails/LinkDetailsActivity.kt index efbabdf01..a400318c4 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/linkdetails/LinkDetailsActivity.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/linkdetails/LinkDetailsActivity.kt @@ -212,16 +212,39 @@ class LinkDetailsActivity : BaseActivity(), LinkDetailsView, androidx.swiperefre adapter.notifyDataSetChanged() inputToolbar.show() if (linkCommentId != -1 && adapter.link != null) { - scrollToComment(linkCommentId) + if (settingsApi.hideLinkCommentsByDefault) { + expandAndScrollToComment(linkCommentId) + } else { + scrollToComment(linkCommentId) + } } } - override fun scrollToComment(id: Int) { - adapter.link!!.comments.forEachIndexed({ index, comment -> - if (comment.id == id) { - recyclerView?.scrollToPosition(index + 1) + private fun expandAndScrollToComment(linkCommentId: Int) { + adapter.link?.comments?.let { allComments -> + val parentId = allComments.find { it.id == linkCommentId }?.parentId + allComments.forEach { + if (it.parentId == parentId) { + it.isCollapsed = false + it.isParentCollapsed = false + } } - }) + } + adapter.notifyDataSetChanged() + + val comments = adapter.link!!.comments + var index = 0 + for (i in 0 until comments.size) { + if (!comments[i].isParentCollapsed) index++ + if (comments[i].id == linkCommentId) break + } + + recyclerView?.scrollToPosition(index + 1) + } + + override fun scrollToComment(id: Int) { + val index = adapter.link!!.comments.indexOfFirst { it.id == id } + recyclerView?.scrollToPosition(index + 1) } override fun updateLink(link: Link) { diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/preferences/SettingsPreferences.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/preferences/SettingsPreferences.kt index 77a8570de..3408c721a 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/preferences/SettingsPreferences.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/preferences/SettingsPreferences.kt @@ -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 @@ -38,6 +39,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") diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c97acc3f9..c075c85aa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,6 +26,7 @@ Wykopywane Wpisy + Ustawienia wyglądu aplikacji Wygląd Styl nocny Tryb AMOLED dla stylu nocnego @@ -43,7 +44,13 @@ Częstotliwość sprawdzania Filtrowanie treści Pokazuj treści 18+ - Ukryj treści z tagiem #nsfw + Ukryj treści z tagiem #nsfw + Ukrywaj treści zielonek + Ukrywaj treści bez tagów (tylko mirko) + Nie pokazuj ukrytych treści + Zarządzaj czarną listą + Użyj wbudowanej przeglądarki + Wyczyść historie wyszukiwarki Wyłącz potwierdzenie wyjścia z aplikacji Publikacja aplikacji na licencji MIT diff --git a/app/src/main/res/xml/app_preferences.xml b/app/src/main/res/xml/app_preferences.xml index b76d3af0e..aadc22eb3 100644 --- a/app/src/main/res/xml/app_preferences.xml +++ b/app/src/main/res/xml/app_preferences.xml @@ -4,7 +4,7 @@ + android:title="@string/pref_appearance_settings"/> + + android:title="@string/pref_manage_blacklist"/> + android:title="@string/pref_clear_history"/>