Skip to content

Commit

Permalink
Add showJunk filter to FeedFilter and related components
Browse files Browse the repository at this point in the history
- Introduced a new property `showJunk` in `FeedFilter` to manage visibility of junk items.
- Updated `FeedService` to conditionally set `showJunk` based on feed type.
- Added `JUNK` type to `FeedType` enum.
- Enhanced `NavigationProvider` to include a menu item for the junk feed type.
- Updated UI components to reflect changes in filter options.
- Modified string resources for better localization support.
  • Loading branch information
G4m813R authored and mopsalarm committed Dec 24, 2024
1 parent 2c47943 commit 2016529
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 10 deletions.
27 changes: 24 additions & 3 deletions app/src/main/java/com/pr0gramm/app/feed/FeedFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class FeedFilter : DefaultParcelable {
var username: String? = null
private set

var showJunk: Boolean? = null
private set

/**
* Checks if this filter is a basic filter. A filter is basic, if
* it has no tag/likes or username-filter.
Expand All @@ -41,6 +44,7 @@ class FeedFilter : DefaultParcelable {
return copy {
tags = null
username = null
showJunk = null
}
}

Expand All @@ -59,6 +63,9 @@ class FeedFilter : DefaultParcelable {
fun withFeedType(type: FeedType): FeedFilter {
return copy {
feedType = type
if (type == FeedType.PROMOTED || type == FeedType.NEW) {
showJunk = false
}
}
}

Expand Down Expand Up @@ -115,6 +122,15 @@ class FeedFilter : DefaultParcelable {
return normalize(copy)
}

/**
* Returns a copy of this filter with the show_junk parameter set
*/
fun withShowJunk(showJunk: Boolean): FeedFilter {
return copy {
this.showJunk = showJunk
}
}

/**
* Normalizes the given string by trimming it and setting empty strings to null.
*/
Expand All @@ -127,28 +143,31 @@ class FeedFilter : DefaultParcelable {
copy.collection = collection
copy.collectionTitle = collectionTitle
copy.username = username
copy.showJunk = showJunk
copy.fn()
return normalize(copy)
}

override fun hashCode(): Int {
return Objects.hash(feedType, tags, collection, username)
return Objects.hash(feedType, tags, collection, username, showJunk)
}

override fun equals(other: Any?): Boolean {
return this === other || (other is FeedFilter
&& feedType === other.feedType
&& tags == other.tags
&& username == other.username
&& collection == other.collection)
&& collection == other.collection
&& showJunk == other.showJunk)
}

override fun toString(): String {
val fields = listOfNotNull(
feedType.toString(),
tags?.let { "tags=$tags" },
username?.let { "username=$username" },
collection?.let { "collection=$collection" }
collection?.let { "collection=$collection" },
showJunk?.let { "show_junk=$showJunk" }
)

return "FeedFilter(${fields.joinToString(", ")})"
Expand All @@ -161,6 +180,7 @@ class FeedFilter : DefaultParcelable {
dest.writeString(username)
dest.writeString(collection)
dest.writeString(collectionTitle)
dest.writeValue(showJunk)
}

companion object CREATOR : SimpleCreator<FeedFilter>(javaClassOf()) {
Expand All @@ -173,6 +193,7 @@ class FeedFilter : DefaultParcelable {
this.username = source.readString()?.ifBlank { null }
this.collection = source.readString()?.ifBlank { null }
this.collectionTitle = source.readString()?.ifBlank { null }
this.showJunk = source.readValue(Boolean::class.java.classLoader) as Boolean?
}
}

Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/pr0gramm/app/feed/FeedService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ class FeedServiceImpl(
val result = api.itemsGet(
promoted, following,
query.older, query.newer, query.around,
flags, tags, collection, self, user
flags, tags, collection, self, user,
showJunk = when {
// Don't set showJunk for user uploads
user != null -> null
// Set showJunk based on feed type
feedType == FeedType.JUNK -> true
feedType == FeedType.NEW || feedType == FeedType.PROMOTED -> false
else -> feedFilter.showJunk
}
)

result.also {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/pr0gramm/app/feed/FeedType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ enum class FeedType(val searchable: Boolean = true,
CONTROVERSIAL(sortable = false),
RANDOM(preloadable = false, sortable = false),
BESTOF,
JUNK,
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class NavigationProvider(
private val iconPremium by drawable(R.drawable.ic_action_premium)
private val iconLogin by drawable(R.drawable.ic_action_login)
private val iconLogout by drawable(R.drawable.ic_action_logout)
private val iconFeedTypeJunk by drawable(R.drawable.ic_action_bin)

// set value to true to trigger a refresh of the flow once.
private val refreshAfterNavItemWasDeletedStateFlow = MutableStateFlow(false)
Expand Down Expand Up @@ -184,13 +185,19 @@ class NavigationProvider(
items += makeItem(
title = getString(R.string.action_feed_type_promoted),
icon = iconFeedTypePromoted,
filter = FeedFilter().withFeedType(FeedType.PROMOTED)
filter = FeedFilter().withFeedType(FeedType.PROMOTED).withShowJunk(false)
)

items += makeItem(
title = getString(R.string.action_feed_type_new),
icon = iconFeedTypeNew,
filter = FeedFilter().withFeedType(FeedType.NEW)
filter = FeedFilter().withFeedType(FeedType.NEW).withShowJunk(false)
)

items += makeItem(
title = getString(R.string.action_feed_type_junk),
icon = iconFeedTypeJunk,
filter = FeedFilter().withFeedType(FeedType.JUNK).withShowJunk(true)
)

items += makeItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ object FeedFilterFormatter {
FeedType.STALK -> context.getString(R.string.filter_format_premium)
FeedType.PROMOTED -> context.getString(R.string.filter_format_top)
FeedType.CONTROVERSIAL -> context.getString(R.string.filter_format_controversial)
FeedType.JUNK -> context.getString(R.string.action_feed_type_junk)
}
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_action_bin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>
5 changes: 3 additions & 2 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<string name="dialog_action_add">Hinzufügen</string>
<string name="action_collections">Sammlungen</string>
<string name="action_feed_type_new">Neu</string>
<string name="action_feed_type_promoted">Top</string>
<string name="action_feed_type_promoted">Beliebt</string>
<string name="action_feed_type_junk">Müll</string>
<string name="action_search">Suche in %s…</string>
<string name="action_search_simple">Suchen</string>
<string name="action_upload">Hochladen</string>
Expand Down Expand Up @@ -591,7 +592,7 @@
<string name="pref_video_quality_human__adaptive">Adaptiv</string>
<string name="pref_video_quality_human__high">Hohe Qualität</string>
<string name="pref_video_quality_human__extrahigh">Extra hohe Qualität (nur wenige Videos)</string>
<string name="pref_video_quality_values_summary">Adaptiv verringt das Datenvolumen im Mobilfunk, sonst equivalent zu "Hohe Qualität"</string>
<string name="pref_video_quality_values_summary">Adaptiv verringert das Datenvolumen im Mobilfunk, sonst equivalent zu "Hohe Qualität"</string>
<string name="pref_video_quality_values_title">Video Qualität</string>

<string name="user_validate_success">Dein Alter wurde verifiziert</string>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<string name="action_add_tag">Add</string>
<string name="action_collections">Collections</string>
<string name="action_feed_type_new">New</string>
<string name="action_feed_type_promoted">Top</string>
<string name="action_feed_type_promoted">Popular</string>
<string name="action_search">Search in %s…</string>
<string name="action_search_simple">Search</string>
<string name="action_upload">Upload</string>
Expand Down Expand Up @@ -617,5 +617,6 @@
<string name="collection_x_of_user">%s of %s</string>
<string name="pref_video_quality_values_summary">Adaptive reduces the data usage on mobile networks.</string>
<string name="pref_video_quality_values_title">Video quality</string>
<string name="action_feed_type_junk">Junk</string>
</resources>

3 changes: 2 additions & 1 deletion model/src/main/java/com/pr0gramm/app/api/pr0gramm/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ interface Api {
@Query("tags") tags: String?,
@Query("collection") collection: String?,
@Query("self") self: Boolean?,
@Query("user") user: String?
@Query("user") user: String?,
@Query("show_junk") showJunk: Boolean?
): Feed

@FormUrlEncoded
Expand Down

0 comments on commit 2016529

Please sign in to comment.