Skip to content

Commit

Permalink
Add option to clear filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerbwong committed Mar 19, 2023
1 parent a997fd7 commit 43ee68d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class ContentFilter @Inject constructor(
clearFilteredContent(USER_ID_CONTENT_FILTER)
}

fun clearAllFilters() {
clearFilteredQuestionIds()
clearFilteredAnswerIds()
clearFilteredCommentIds()
clearFilteredUserIds()
}

fun List<Question>.applyQuestionFilter(): List<Question> {
val questionIds = filteredQuestionIds
val userIds = filteredUserIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class CommentsViewModel @Inject constructor(
with(contentFilter) { finalComments.applyCommentFilter() }.map {
CommentItem(
comment = it,
hideComment = { id -> contentFilter.addFilteredCommentId(id) },
hideComment = { id ->
contentFilter.addFilteredCommentId(id)
fetchComments()
},
) { commentId, upvoteValue ->
toggleAction(commentId = commentId, isSelected = upvoteValue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class QuestionDetailMainViewModel @Inject constructor(
internal fun getQuestionDetails(
question: Question? = null,
answers: List<Answer> = emptyList(),
removeAnswers: List<Answer> = emptyList(),
) {
launchRequest {
val questionResult = question ?: questionRepository.getQuestion(questionId)
Expand Down Expand Up @@ -180,7 +179,7 @@ class QuestionDetailMainViewModel @Inject constructor(
downVoteCount = answer.downVoteCount,
hideAnswer = {
contentFilter.addFilteredAnswerId(it)
getQuestionDetails(question = null, removeAnswers = listOf(answer))
getQuestionDetails()
},
handler = this@QuestionDetailMainViewModel,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.fragment.app.viewModels
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
Expand All @@ -19,6 +20,7 @@ import dagger.hilt.android.AndroidEntryPoint
import dev.chrisbanes.insetter.applyInsetter
import me.tylerbwong.stack.BuildConfig
import me.tylerbwong.stack.R
import me.tylerbwong.stack.data.content.ContentFilter
import me.tylerbwong.stack.ui.MainActivity
import me.tylerbwong.stack.ui.profile.ProfileActivity
import me.tylerbwong.stack.ui.settings.donation.DonationActivity
Expand Down Expand Up @@ -47,6 +49,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
@Inject
lateinit var experimental: Experimental

@Inject
lateinit var contentFilter: ContentFilter

private val viewModel by viewModels<SettingsViewModel>()
private val donationViewModel by viewModels<DonationViewModel>()

Expand Down Expand Up @@ -84,6 +89,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}

findPreference<Preference>(getString(R.string.content_filters_clear))?.apply {
setOnPreferenceClickListener {
contentFilter.clearAllFilters()
Toast.makeText(
requireContext(),
R.string.content_filters_cleared,
Toast.LENGTH_SHORT
).show()
true
}
}

setUpAppSection()
setUpAboutSection()
}
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,17 @@
<string name="shortcut_search_long_label">Buscar</string>

<!-- Content Filter -->
<string name="content_filters">Filtros de contenido</string>
<string name="content_filters_clear">Borrar todos los filtros de contenido</string>
<string name="content_filters_cleared">Filtros de contenido borrados</string>
<string name="hide">Esconder</string>
<string name="hide_post_hidden">Esta publicación se ha ocultado globalmente. Esto se puede deshacer en la configuración.</string>
<string name="hide_post_hidden">Esta publicación se ha ocultado globalmente.</string>
<string name="hide_question">Ocultar pregunta</string>
<string name="hide_question_message">Oculte esta pregunta globalmente. Esto se puede revertir en la configuración.</string>
<string name="hide_question_message">Oculte esta pregunta globalmente. Si hay un problema con esta pregunta, márquelo primero.</string>
<string name="hide_answer">Ocultar respuesta</string>
<string name="hide_answer_message">Oculte esta respuesta globalmente. Esto se puede revertir en la configuración.</string>
<string name="hide_answer_message">Oculte esta respuesta globalmente. Si hay un problema con esta respuesta, márquelo primero.</string>
<string name="hide_comment">Ocultar comentario</string>
<string name="hide_comment_message">Ocultar este comentario globalmente. Esto se puede revertir en la configuración.</string>
<string name="hide_comment_message">Ocultar este comentario globalmente. Si hay un problema con este comentario, márcalo primero.</string>
<string name="hide_user">Ocultar usuario</string>
<string name="hide_user_message">Oculte este usuario y todo el contenido asociado globalmente. Esto se puede revertir en la configuración.</string>
<string name="hide_user_message">Oculte este usuario y todo el contenido asociado globalmente. Si hay un problema con una publicación específica, márquelo primero.</string>
</resources>
13 changes: 8 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,17 @@
<string name="shortcut_search_long_label">Search</string>

<!-- Content Filter -->
<string name="content_filters">Content filters</string>
<string name="content_filters_clear">Clear all content filters</string>
<string name="content_filters_cleared">Cleared content filters</string>
<string name="hide">Hide</string>
<string name="hide_post_hidden">This post has been hidden globally. This can be undone in settings.</string>
<string name="hide_post_hidden">This post has been hidden globally.</string>
<string name="hide_question">Hide question</string>
<string name="hide_question_message">Hide this question globally. This can be reverted in settings.</string>
<string name="hide_question_message">Hide this question globally. If there is an issue with this question, please flag it first.</string>
<string name="hide_answer">Hide answer</string>
<string name="hide_answer_message">Hide this answer globally. This can be reverted in settings.</string>
<string name="hide_answer_message">Hide this answer globally. If there is an issue with this answer, please flag it first.</string>
<string name="hide_comment">Hide comment</string>
<string name="hide_comment_message">Hide this comment globally. This can be reverted in settings.</string>
<string name="hide_comment_message">Hide this comment globally. If there is an issue with this comment, please flag it first.</string>
<string name="hide_user">Hide user</string>
<string name="hide_user_message">Hide this user and all associated content globally. This can be reverted in settings.</string>
<string name="hide_user_message">Hide this user and all associated content globally. If there is an issue with a specific post, please flag it first.</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
android:title="@string/inspect_network_traffic" />
</PreferenceCategory>

<PreferenceCategory
android:key="@string/content_filters"
android:layout="@layout/preference_category_layout"
android:title="@string/content_filters">

<Preference
android:icon="@drawable/ic_baseline_filter_list"
android:key="@string/content_filters_clear"
android:title="@string/content_filters_clear" />
</PreferenceCategory>

<PreferenceCategory
android:layout="@layout/preference_category_layout"
android:title="@string/app">
Expand Down

0 comments on commit 43ee68d

Please sign in to comment.