aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java41
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertSubscribedThingsAsyncTask.java118
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDatabase/SubscribedSubredditDao.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDatabase/SubscribedUserDao.java3
9 files changed, 165 insertions, 49 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java
index a4d9d6d0..7acda3c9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java
@@ -183,7 +183,7 @@ public class MultiRedditListingActivity extends BaseActivity {
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(this,
- mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken);
+ mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName);
mRecyclerView.setAdapter(adapter);
mMultiRedditViewModel = new ViewModelProvider(this,
@@ -218,7 +218,7 @@ public class MultiRedditListingActivity extends BaseActivity {
GetMultiReddit.getMyMultiReddits(mOauthRetrofit, mAccessToken, new GetMultiReddit.GetMultiRedditListener() {
@Override
public void success(ArrayList<MultiReddit> multiReddits) {
- new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, () -> {
+ new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
mInsertSuccess = true;
mSwipeRefreshLayout.setRefreshing(false);
}).execute();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index 9fd8ffc6..b58c87ee 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -1003,17 +1003,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mActivity.startActivity(intent);
});
- /*((CommentViewHolder) holder).shareButton.setOnClickListener(view -> {
- try {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setType("text/plain");
- intent.putExtra(Intent.EXTRA_TEXT, comment.getPermalink());
- mActivity.startActivity(Intent.createChooser(intent, mActivity.getString(R.string.share)));
- } catch (ActivityNotFoundException e) {
- Toast.makeText(mActivity, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show();
- }
- });*/
-
((CommentViewHolder) holder).expandButton.setOnClickListener(view -> {
if (((CommentViewHolder) holder).expandButton.getVisibility() == View.VISIBLE) {
int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1;
@@ -1579,7 +1568,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mGlide.clear(((CommentViewHolder) holder).authorTypeImageView);
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.GONE);
- //((CommentViewHolder) holder).moreButton.setVisibility(View.GONE);
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
((CommentViewHolder) holder).upVoteButton.clearColorFilter();
((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java
index e8c656e4..119e78ff 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java
@@ -42,18 +42,19 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
private RequestManager mGlide;
private String mAccessToken;
+ private String mAccountName;
private List<MultiReddit> mMultiReddits;
private List<MultiReddit> mFavoriteMultiReddits;
public MultiRedditListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
- String accessToken) {
+ String accessToken, String accountName) {
mContext = context;
mGlide = Glide.with(context.getApplicationContext());
mOauthRetrofit = oauthRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase;
mAccessToken = accessToken;
-
+ mAccountName = accountName;
}
@Override
@@ -114,8 +115,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
if(multiReddit.isFavorite()) {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false);
- FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
- false, multiReddit,
+ FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
+ mAccessToken, mAccountName, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
@@ -140,8 +141,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
} else {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true);
- FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
- true, multiReddit,
+ FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
+ mAccessToken, mAccountName, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
@@ -197,8 +198,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
if(multiReddit.isFavorite()) {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false);
- FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
- false, multiReddit,
+ FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
+ mAccessToken, mAccountName, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
@@ -223,8 +224,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
} else {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true);
- FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
- true, multiReddit,
+ FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
+ mAccessToken, mAccountName, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
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 22613362..91d72ae1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java
@@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit.AsyncTask;
import android.os.AsyncTask;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditDao;
@@ -11,18 +13,29 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> {
private MultiRedditDao multiRedditDao;
private ArrayList<MultiReddit> multiReddits;
+ private String accountName;
private InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener;
public InsertMultiRedditAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
- ArrayList<MultiReddit> multiReddits,
+ ArrayList<MultiReddit> multiReddits, String accountName,
InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener) {
multiRedditDao = redditDataRoomDatabase.multiRedditDao();
this.multiReddits = multiReddits;
+ this.accountName = accountName;
this.insertMultiRedditAsyncTaskListener = insertMultiRedditAsyncTaskListener;
}
@Override
protected Void doInBackground(Void... voids) {
+ 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);
+
+ for (String deleted : deletedMultiredditNames) {
+ multiRedditDao.deleteMultiReddit(deleted, accountName);
+ }
+
for (MultiReddit multiReddit : multiReddits) {
multiRedditDao.insert(multiReddit);
}
@@ -35,6 +48,32 @@ public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> {
insertMultiRedditAsyncTaskListener.success();
}
+ 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());
+ }
+ 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);
+ }
+ }
+ }
+
public interface InsertMultiRedditAsyncTaskListener {
void success();
}
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 00c6c3e7..a1ea1b68 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertSubscribedThingsAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertSubscribedThingsAsyncTask.java
@@ -4,6 +4,8 @@ import android.os.AsyncTask;
import androidx.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
@@ -23,15 +25,15 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
private SubredditDao mSubredditDao;
private SubscribedSubredditData mSingleSubscribedSubredditData;
private SubscribedUserData mSingleSubscribedUserData;
- private List<SubscribedSubredditData> subscribedSubredditData;
- private List<SubscribedUserData> subscribedUserData;
- private List<SubredditData> subredditData;
+ private List<SubscribedSubredditData> subscribedSubredditDataList;
+ private List<SubscribedUserData> subscribedUserDataList;
+ private List<SubredditData> subredditDataList;
private InsertSubscribedThingListener mInsertSubscribedThingListener;
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName,
- List<SubscribedSubredditData> subscribedSubredditData,
- List<SubscribedUserData> subscribedUserData,
- List<SubredditData> subredditData,
+ List<SubscribedSubredditData> subscribedSubredditDataList,
+ List<SubscribedUserData> subscribedUserDataList,
+ List<SubredditData> subredditDataList,
InsertSubscribedThingListener insertSubscribedThingListener) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
mAccountName = accountName;
@@ -39,29 +41,29 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
mSubredditDao = redditDataRoomDatabase.subredditDao();
- this.subscribedSubredditData = subscribedSubredditData;
- this.subscribedUserData = subscribedUserData;
- this.subredditData = subredditData;
+ this.subscribedSubredditDataList = subscribedSubredditDataList;
+ this.subscribedUserDataList = subscribedUserDataList;
+ this.subredditDataList = subredditDataList;
mInsertSubscribedThingListener = insertSubscribedThingListener;
}
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
- SubscribedSubredditData subscribedSubredditData,
+ SubscribedSubredditData subscribedSubredditDataList,
InsertSubscribedThingListener insertSubscribedThingListener) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao();
- mAccountName = subscribedSubredditData.getUsername();
- mSingleSubscribedSubredditData = subscribedSubredditData;
+ mAccountName = subscribedSubredditDataList.getUsername();
+ mSingleSubscribedSubredditData = subscribedSubredditDataList;
mInsertSubscribedThingListener = insertSubscribedThingListener;
}
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
- SubscribedUserData subscribedUserData,
+ SubscribedUserData subscribedUserDataList,
InsertSubscribedThingListener insertSubscribedThingListener) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
- mAccountName = subscribedUserData.getUsername();
- mSingleSubscribedUserData = subscribedUserData;
+ mAccountName = subscribedUserDataList.getUsername();
+ mSingleSubscribedUserData = subscribedUserDataList;
mInsertSubscribedThingListener = insertSubscribedThingListener;
}
@@ -76,20 +78,42 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
} else if (mSingleSubscribedUserData != null) {
mSubscribedUserDao.insert(mSingleSubscribedUserData);
} else {
- if (subscribedSubredditData != null) {
- for (SubscribedSubredditData s : subscribedSubredditData) {
+ if (subscribedSubredditDataList != null) {
+ List<SubscribedSubredditData> existingSubscribedSubredditDataList =
+ mSubscribedSubredditDao.getAllSubscribedSubredditsList(mAccountName);
+ Collections.sort(subscribedSubredditDataList, (subscribedSubredditData, t1) -> subscribedSubredditData.getName().compareToIgnoreCase(t1.getName()));
+ List<String> unsubscribedSubreddits = new ArrayList<>();
+ compareTwoSubscribedSubredditList(subscribedSubredditDataList, existingSubscribedSubredditDataList,
+ unsubscribedSubreddits, 0, 0);
+
+ for (String unsubscribed : unsubscribedSubreddits) {
+ mSubscribedSubredditDao.deleteSubscribedSubreddit(unsubscribed, mAccountName);
+ }
+
+ for (SubscribedSubredditData s : subscribedSubredditDataList) {
mSubscribedSubredditDao.insert(s);
}
}
- if (subscribedUserData != null) {
- for (SubscribedUserData s : subscribedUserData) {
+ if (subscribedUserDataList != null) {
+ List<SubscribedUserData> existingSubscribedUserDataList =
+ mSubscribedUserDao.getAllSubscribedUsersList(mAccountName);
+ Collections.sort(subscribedUserDataList, (subscribedUserData, t1) -> subscribedUserData.getName().compareToIgnoreCase(t1.getName()));
+ List<String> unsubscribedUsers = new ArrayList<>();
+ compareTwoSubscribedUserList(subscribedUserDataList, existingSubscribedUserDataList,
+ unsubscribedUsers, 0, 0);
+
+ for (String unsubscribed : unsubscribedUsers) {
+ mSubscribedUserDao.deleteSubscribedUser(unsubscribed, mAccountName);
+ }
+
+ for (SubscribedUserData s : subscribedUserDataList) {
mSubscribedUserDao.insert(s);
}
}
- if (subredditData != null) {
- for (SubredditData s : subredditData) {
+ if (subredditDataList != null) {
+ for (SubredditData s : subredditDataList) {
mSubredditDao.insert(s);
}
}
@@ -102,6 +126,58 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
mInsertSubscribedThingListener.insertSuccess();
}
+ 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());
+ }
+ 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);
+ }
+ }
+ }
+
+ 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());
+ }
+ 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);
+ }
+ }
+ }
+
public interface InsertSubscribedThingListener {
void insertSuccess();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java
index d05e917b..8c7a8947 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java
@@ -22,8 +22,8 @@ public class FavoriteMultiReddit {
}
public static void favoriteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
- String accessToken, boolean makeFavorite, MultiReddit multiReddit,
- FavoriteMultiRedditListener favoriteMultiRedditListener) {
+ String accessToken, String accountName, boolean makeFavorite,
+ MultiReddit multiReddit, FavoriteMultiRedditListener favoriteMultiRedditListener) {
Map<String, String> params = new HashMap<>();
params.put(RedditUtils.MULTIPATH_KEY, multiReddit.getPath());
params.put(RedditUtils.MAKE_FAVORITE_KEY, String.valueOf(makeFavorite));
@@ -36,7 +36,7 @@ public class FavoriteMultiReddit {
multiReddit.setFavorite(true);
ArrayList<MultiReddit> singleMultiRedditList = new ArrayList<>();
singleMultiRedditList.add(multiReddit);
- new InsertMultiRedditAsyncTask(redditDataRoomDatabase, singleMultiRedditList,
+ new InsertMultiRedditAsyncTask(redditDataRoomDatabase, singleMultiRedditList, accountName,
favoriteMultiRedditListener::success).execute();
} else {
favoriteMultiRedditListener.failed();
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 1e72966d..7d3654c8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java
@@ -16,6 +16,9 @@ public interface MultiRedditDao {
@Query("SELECT * FROM multi_reddits WHERE username = :username ORDER BY name COLLATE NOCASE ASC")
LiveData<List<MultiReddit>> getAllMultiReddits(String username);
+ @Query("SELECT * FROM multi_reddits WHERE username = :username ORDER BY name COLLATE NOCASE ASC")
+ List<MultiReddit> getAllMultiRedditsList(String username);
+
@Query("SELECT * FROM multi_reddits WHERE username = :username AND is_favorite ORDER BY name COLLATE NOCASE ASC")
LiveData<List<MultiReddit>> getAllFavoriteMultiReddits(String username);
@@ -24,4 +27,7 @@ public interface MultiRedditDao {
@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);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDatabase/SubscribedSubredditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDatabase/SubscribedSubredditDao.java
index 6bfa103e..cc0434d7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDatabase/SubscribedSubredditDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDatabase/SubscribedSubredditDao.java
@@ -19,6 +19,9 @@ public interface SubscribedSubredditDao {
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits(String accountName);
+ @Query("SELECT * from subscribed_subreddits WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
+ List<SubscribedSubredditData> getAllSubscribedSubredditsList(String accountName);
+
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedSubredditData>> getAllFavoriteSubscribedSubreddits(String accountName);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDatabase/SubscribedUserDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDatabase/SubscribedUserDao.java
index c085f298..661eb988 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDatabase/SubscribedUserDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDatabase/SubscribedUserDao.java
@@ -16,6 +16,9 @@ public interface SubscribedUserDao {
@Query("SELECT * FROM subscribed_users WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedUserData>> getAllSubscribedUsers(String accountName);
+ @Query("SELECT * FROM subscribed_users WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
+ List<SubscribedUserData> getAllSubscribedUsersList(String accountName);
+
@Query("SELECT * FROM subscribed_users WHERE username = :accountName AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsers(String accountName);