Implement missing equals and hashcode methods for feeditem #7132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes: #7108
The episodes were never removed from the Queue screen or the queue segment on the homescreen because no
QueueEvent
was emitted.However, after closer inspection I found that there was already code in
DBWriter
to remove all such items:AntennaPod/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBWriter.java
Line 197 in c56facd
With more debugging I discovered that the
queue.remove
always returned false and never removed any items even if they were structurally equal. SinceFeedItem
doesn't override equal the two identical items are only equal if they are the same instance which is here never the case and therefore this never finds the matching items in the queue.By adding the equals method the bug is fixed as the code now works as intended.
Questions:
I implemented
equals
by just comparing the feedid and id of the item. This is mostly cause I don't want to cyclic equals where a feeditem defines equals with it's feed and the feed with all the items it holds. However, I am not sure if the assumption is save to make that twoFeedItems
are always equal if those two id's match so maybe someone with more experience can verify that.Also while we're at it should we implement
equals
for more classes like theFeed
andFeedMedia
?Checklist
./gradlew checkstyle spotbugsPlayDebug spotbugsDebug :app:lintPlayDebug