diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-02-24 12:43:55 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-02-24 12:43:55 +0000 |
commit | 64330146790cf3b216f32801f3e19a778bbc18b8 (patch) | |
tree | 8d3e9e3ceeecbafd1c619c3200c404f807cc748e /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | c0c24a2613734e1067cc4a928ffa7a13890cc137 (diff) | |
download | infinity-for-reddit-64330146790cf3b216f32801f3e19a778bbc18b8.tar infinity-for-reddit-64330146790cf3b216f32801f3e19a778bbc18b8.tar.gz infinity-for-reddit-64330146790cf3b216f32801f3e19a778bbc18b8.tar.bz2 infinity-for-reddit-64330146790cf3b216f32801f3e19a778bbc18b8.tar.lz infinity-for-reddit-64330146790cf3b216f32801f3e19a778bbc18b8.tar.xz infinity-for-reddit-64330146790cf3b216f32801f3e19a778bbc18b8.tar.zst infinity-for-reddit-64330146790cf3b216f32801f3e19a778bbc18b8.zip |
Fix stack overflow error when syncing subscribed subreddits and users and multireddits. Fix app crashes when creating multireddits without selecting any subreddits. Version 2.2.3.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
4 files changed, 65 insertions, 61 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java index 6db86514..7435e216 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java @@ -93,6 +93,8 @@ public class CreateMultiRedditActivity extends BaseActivity { bindView(); } } else { + mSelectedSubscribedSubreddits = new ArrayList<>(); + mSelectedOtherSubreddits = new ArrayList<>(); getCurrentAccountAndBindView(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java index c76b726e..2c15fa33 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit.AsyncTask; import android.os.AsyncTask; +import android.util.Log; import java.util.ArrayList; import java.util.Collections; @@ -30,9 +31,10 @@ public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> { List<MultiReddit> existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName); Collections.sort(multiReddits, (multiReddit, t1) -> multiReddit.getName().compareToIgnoreCase(t1.getName())); List<String> deletedMultiredditNames = new ArrayList<>(); - compareTwoMultiRedditList(multiReddits, existingMultiReddits, deletedMultiredditNames, 0, 0); + compareTwoMultiRedditList(multiReddits, existingMultiReddits, deletedMultiredditNames); for (String deleted : deletedMultiredditNames) { + Log.i("asdfasdfs", "s " + deleted + accountName); multiRedditDao.deleteMultiReddit(deleted, accountName); } @@ -49,27 +51,27 @@ public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> { } private void compareTwoMultiRedditList(List<MultiReddit> newMultiReddits, - List<MultiReddit> oldMultiReddits, - List<String> deletedMultiReddits, int i1, int i2) { - if (newMultiReddits.size() <= i1 && oldMultiReddits.size() <= i2) { - return; - } - - if (newMultiReddits.size() <= i1) { - for (int i = 0; i < oldMultiReddits.size(); i++) { - deletedMultiReddits.add(oldMultiReddits.get(i).getName()); + List<MultiReddit> oldMultiReddits, + List<String> deletedMultiReddits) { + int newIndex = 0; + for (int oldIndex = 0; oldIndex < oldMultiReddits.size(); oldIndex++) { + if (newIndex >= newMultiReddits.size()) { + for (; oldIndex < oldMultiReddits.size(); oldIndex++) { + deletedMultiReddits.add(oldMultiReddits.get(oldIndex).getName()); + } + return; } - return; - } - if (oldMultiReddits.size() > i2) { - if (newMultiReddits.get(i1).getName().compareToIgnoreCase(oldMultiReddits.get(i2).getName()) == 0) { - compareTwoMultiRedditList(newMultiReddits, oldMultiReddits, deletedMultiReddits, i1 + 1, i2 + 1); - } else if (newMultiReddits.get(i1).getName().compareToIgnoreCase(oldMultiReddits.get(i2).getName()) < 0) { - compareTwoMultiRedditList(newMultiReddits, oldMultiReddits, deletedMultiReddits, i1 + 1, i2); - } else { - deletedMultiReddits.add(oldMultiReddits.get(i2).getName()); - compareTwoMultiRedditList(newMultiReddits, oldMultiReddits, deletedMultiReddits, i1, i2 + 1); + MultiReddit old = oldMultiReddits.get(oldIndex); + for (; newIndex < newMultiReddits.size(); newIndex++) { + if (newMultiReddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) == 0) { + newIndex++; + break; + } + if (newMultiReddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) > 0) { + deletedMultiReddits.add(old.getName()); + break; + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertSubscribedThingsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertSubscribedThingsAsyncTask.java index a1ea1b68..0d46da69 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertSubscribedThingsAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertSubscribedThingsAsyncTask.java @@ -84,7 +84,7 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void> Collections.sort(subscribedSubredditDataList, (subscribedSubredditData, t1) -> subscribedSubredditData.getName().compareToIgnoreCase(t1.getName())); List<String> unsubscribedSubreddits = new ArrayList<>(); compareTwoSubscribedSubredditList(subscribedSubredditDataList, existingSubscribedSubredditDataList, - unsubscribedSubreddits, 0, 0); + unsubscribedSubreddits); for (String unsubscribed : unsubscribedSubreddits) { mSubscribedSubredditDao.deleteSubscribedSubreddit(unsubscribed, mAccountName); @@ -101,7 +101,7 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void> Collections.sort(subscribedUserDataList, (subscribedUserData, t1) -> subscribedUserData.getName().compareToIgnoreCase(t1.getName())); List<String> unsubscribedUsers = new ArrayList<>(); compareTwoSubscribedUserList(subscribedUserDataList, existingSubscribedUserDataList, - unsubscribedUsers, 0, 0); + unsubscribedUsers); for (String unsubscribed : unsubscribedUsers) { mSubscribedUserDao.deleteSubscribedUser(unsubscribed, mAccountName); @@ -128,52 +128,52 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void> private void compareTwoSubscribedSubredditList(List<SubscribedSubredditData> newSubscribedSubreddits, List<SubscribedSubredditData> oldSubscribedSubreddits, - List<String> unsubscribedSubredditNames, int i1, int i2) { - if (newSubscribedSubreddits.size() <= i1 && oldSubscribedSubreddits.size() <= i2) { - return; - } - - if (newSubscribedSubreddits.size() <= i1) { - for (int i = 0; i < oldSubscribedSubreddits.size(); i++) { - unsubscribedSubredditNames.add(oldSubscribedSubreddits.get(i).getName()); + 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).getName()); + } + return; } - return; - } - if (oldSubscribedSubreddits.size() > i2) { - if (newSubscribedSubreddits.get(i1).getName().compareToIgnoreCase(oldSubscribedSubreddits.get(i2).getName()) == 0) { - compareTwoSubscribedSubredditList(newSubscribedSubreddits, oldSubscribedSubreddits, unsubscribedSubredditNames, i1 + 1, i2 + 1); - } else if (newSubscribedSubreddits.get(i1).getName().compareToIgnoreCase(oldSubscribedSubreddits.get(i2).getName()) < 0) { - compareTwoSubscribedSubredditList(newSubscribedSubreddits, oldSubscribedSubreddits, unsubscribedSubredditNames, i1 + 1, i2); - } else { - unsubscribedSubredditNames.add(oldSubscribedSubreddits.get(i2).getName()); - compareTwoSubscribedSubredditList(newSubscribedSubreddits, oldSubscribedSubreddits, unsubscribedSubredditNames, i1, i2 + 1); + SubscribedSubredditData old = oldSubscribedSubreddits.get(oldIndex); + for (; newIndex < newSubscribedSubreddits.size(); newIndex++) { + if (newSubscribedSubreddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) == 0) { + newIndex++; + break; + } + if (newSubscribedSubreddits.get(newIndex).getName().compareToIgnoreCase(old.getName()) > 0) { + unsubscribedSubredditNames.add(old.getName()); + break; + } } } } private void compareTwoSubscribedUserList(List<SubscribedUserData> newSubscribedUsers, - List<SubscribedUserData> oldSubscribedUsers, - List<String> unsubscribedUserNames, int i1, int i2) { - if (newSubscribedUsers.size() <= i1 && oldSubscribedUsers.size() <= i2) { - return; - } - - if (newSubscribedUsers.size() <= i1) { - for (int i = 0; i < oldSubscribedUsers.size(); i++) { - unsubscribedUserNames.add(oldSubscribedUsers.get(i).getName()); + List<SubscribedUserData> oldSubscribedUsers, + List<String> unsubscribedUserNames) { + int newIndex = 0; + for (int oldIndex = 0; oldIndex < oldSubscribedUsers.size(); oldIndex++) { + if (newIndex >= newSubscribedUsers.size()) { + for (; oldIndex < oldSubscribedUsers.size(); oldIndex++) { + unsubscribedUserNames.add(oldSubscribedUsers.get(oldIndex).getName()); + } + return; } - return; - } - if (oldSubscribedUsers.size() > i2) { - if (newSubscribedUsers.get(i1).getName().compareToIgnoreCase(oldSubscribedUsers.get(i2).getName()) == 0) { - compareTwoSubscribedUserList(newSubscribedUsers, oldSubscribedUsers, unsubscribedUserNames, i1 + 1, i2 + 1); - } else if (newSubscribedUsers.get(i1).getName().compareToIgnoreCase(oldSubscribedUsers.get(i2).getName()) < 0) { - compareTwoSubscribedUserList(newSubscribedUsers, oldSubscribedUsers, unsubscribedUserNames, i1 + 1, i2); - } else { - unsubscribedUserNames.add(oldSubscribedUsers.get(i2).getName()); - compareTwoSubscribedUserList(newSubscribedUsers, oldSubscribedUsers, unsubscribedUserNames, i1, i2 + 1); + SubscribedUserData old = oldSubscribedUsers.get(oldIndex); + for (; newIndex < newSubscribedUsers.size(); newIndex++) { + if (newSubscribedUsers.get(newIndex).getName().compareToIgnoreCase(old.getName()) == 0) { + newIndex++; + break; + } + if (newSubscribedUsers.get(newIndex).getName().compareToIgnoreCase(old.getName()) > 0) { + unsubscribedUserNames.add(old.getName()); + break; + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java index 198e610e..7d3654c8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java @@ -25,8 +25,8 @@ public interface MultiRedditDao { @Query("SELECT * FROM multi_reddits WHERE name = :name AND username = :username COLLATE NOCASE LIMIT 1") MultiReddit getMultiReddit(String name, String username); - @Query("DELETE FROM multi_reddits WHERE path = :multipath AND username = :username") - void deleteMultiReddit(String multipath, String username); + @Query("DELETE FROM multi_reddits WHERE name = :name AND username = :username") + void deleteMultiReddit(String name, String username); @Query("DELETE FROM multi_reddits WHERE username = :username") void deleteAllUserMultiReddits(String username); |