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.

This commit is contained in:
Alex Ning 2020-02-24 20:43:55 +08:00
parent c0c24a2613
commit 6433014679
5 changed files with 67 additions and 63 deletions

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21
targetSdkVersion 29
versionCode 28
versionName "2.2.2"
versionCode 29
versionName "2.2.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@ -93,6 +93,8 @@ public class CreateMultiRedditActivity extends BaseActivity {
bindView();
}
} else {
mSelectedSubscribedSubreddits = new ArrayList<>();
mSelectedOtherSubreddits = new ArrayList<>();
getCurrentAccountAndBindView();
}
}

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -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);