Skip to content

Commit

Permalink
Merge branch 'master' of github.com:feelfreelinux/WykopMobilny
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Apr 9, 2019
2 parents 377a90e + baa21f2 commit 3933492
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 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 @@ -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) {
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 @@ -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")
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 3933492

Please sign in to comment.