Skip to content

Commit

Permalink
telegram + twitter filter
Browse files Browse the repository at this point in the history
  • Loading branch information
GewoonJaap committed May 8, 2022
1 parent 4dcc0ab commit 5620f5e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@ class NewsFeedHelper {
if(!PreferenceHelper.shouldShowUkrainianSources(context)){
filteredMessages = removeMessagesWithCategory(filteredMessages, "ukraine")
}
if(!PreferenceHelper.shouldShowTwitterSources(context)){
filteredMessages = removeMessagesByType(filteredMessages, "twitter")
}
if(!PreferenceHelper.shouldShowTelegramSources(context)){
filteredMessages = removeMessagesByType(filteredMessages, "telegram")
}
return filteredMessages
}

private fun removeMessagesWithCategory(messages: List<FeedMessageResponse>, category: String): List<FeedMessageResponse> {
return messages.filter { message -> message.categories.indexOf(category) == -1 }
}

private fun removeMessagesByType(messages: List<FeedMessageResponse>, type: String): List<FeedMessageResponse> {
return messages.filter { message -> message.type != type }
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@ class PreferenceHelper {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
return sharedPreferences.getBoolean("ukraineNewsSources", true)
}
fun shouldShowTwitterSources(context: Context): Boolean {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
return sharedPreferences.getBoolean("twitterSources", true)
}
fun shouldShowTelegramSources(context: Context): Boolean {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
return sharedPreferences.getBoolean("telegramSources", true)
}
}
}
2 changes: 2 additions & 0 deletions app/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
<string name="show_russian_sources">Show Russian news sources</string>
<string name="show_ukraine_sources">Show Ukrainian news sources</string>
<string name="no_news_found">No news found, try changing your filters on the Settings page</string>
<string name="show_telegram_sources">Show Telegram sources</string>
<string name="show_twitter_sources">Show Twitter sources</string>
</resources>
8 changes: 8 additions & 0 deletions app/app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
app:key="ukraineNewsSources"
app:title="@string/show_ukraine_sources"
app:defaultValue="true"/>
<SwitchPreferenceCompat
app:key="twitterSources"
app:title="@string/show_twitter_sources"
app:defaultValue="true"/>
<SwitchPreferenceCompat
app:key="telegramSources"
app:title="@string/show_telegram_sources"
app:defaultValue="true"/>
</PreferenceCategory>


Expand Down

0 comments on commit 5620f5e

Please sign in to comment.