Fix bug with unsubscribing from communities

This commit is contained in:
Balazs Toldi 2023-08-25 17:14:23 +02:00
parent 6542859892
commit 70cf6f3340
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
3 changed files with 16 additions and 21 deletions

View File

@ -118,25 +118,20 @@ public class InsertSubscribedThings {
(List<SubscribedSubredditData> newSubscribedSubreddits,
List<SubscribedSubredditData> oldSubscribedSubreddits,
List<String> unsubscribedSubredditNames) {
int newIndex = 0;
for (int oldIndex = 0; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
if (newIndex >= newSubscribedSubreddits.size()) {
for (; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
unsubscribedSubredditNames.add(oldSubscribedSubreddits.get(oldIndex).getQualified_name());
}
return;
}
List<String> oldSubredditNames = new ArrayList<>();
for (SubscribedSubredditData subredditData : oldSubscribedSubreddits) {
oldSubredditNames.add(subredditData.getQualified_name());
}
SubscribedSubredditData old = oldSubscribedSubreddits.get(oldIndex);
for (; newIndex < newSubscribedSubreddits.size(); newIndex++) {
if (newSubscribedSubreddits.get(newIndex).getQualified_name().compareToIgnoreCase(old.getQualified_name()) == 0) {
newIndex++;
break;
}
if (newSubscribedSubreddits.get(newIndex).getQualified_name().compareToIgnoreCase(old.getQualified_name()) > 0) {
unsubscribedSubredditNames.add(old.getQualified_name());
break;
}
List<String> newSubredditNames = new ArrayList<>();
for (SubscribedSubredditData subredditData : newSubscribedSubreddits) {
newSubredditNames.add(subredditData.getQualified_name());
}
for (String subredditName : oldSubredditNames) {
if (!newSubredditNames.contains(subredditName)) {
unsubscribedSubredditNames.add(subredditName);
}
}
}

View File

@ -31,7 +31,7 @@ public interface SubscribedSubredditDao {
@Query("SELECT * from subscribed_subreddits WHERE qualified_name = :qualified_name COLLATE NOCASE AND username = :accountName COLLATE NOCASE LIMIT 1")
SubscribedSubredditData getSubscribedSubredditByQualifiedName(String qualified_name, String accountName);
@Query("DELETE FROM subscribed_subreddits WHERE name = :subredditName COLLATE NOCASE AND username = :accountName COLLATE NOCASE")
@Query("DELETE FROM subscribed_subreddits WHERE qualified_name = :subredditName COLLATE NOCASE AND username = :accountName COLLATE NOCASE")
void deleteSubscribedSubreddit(String subredditName, String accountName);
@Query("SELECT * from subscribed_subreddits WHERE username = :qualified_name AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")

View File

@ -129,13 +129,13 @@ public class SubscribedSubredditData implements Parcelable {
@Override
public int hashCode() {
return id;
return id + username.hashCode();
}
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof SubscribedSubredditData) {
return id == ((SubscribedSubredditData) obj).getId();
return id == ((SubscribedSubredditData) obj).getId() && username.equalsIgnoreCase(((SubscribedSubredditData) obj).getUsername());
}
return false;
}