mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-26 01:34:45 +01:00
Fix unsubscribed subreddits and deleted multireddits still show in lists.
This commit is contained in:
parent
ff5a60c827
commit
119afb6084
@ -183,7 +183,7 @@ public class MultiRedditListingActivity extends BaseActivity {
|
|||||||
|
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(this,
|
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(this,
|
||||||
mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken);
|
mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName);
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
mMultiRedditViewModel = new ViewModelProvider(this,
|
mMultiRedditViewModel = new ViewModelProvider(this,
|
||||||
@ -218,7 +218,7 @@ public class MultiRedditListingActivity extends BaseActivity {
|
|||||||
GetMultiReddit.getMyMultiReddits(mOauthRetrofit, mAccessToken, new GetMultiReddit.GetMultiRedditListener() {
|
GetMultiReddit.getMyMultiReddits(mOauthRetrofit, mAccessToken, new GetMultiReddit.GetMultiRedditListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ArrayList<MultiReddit> multiReddits) {
|
public void success(ArrayList<MultiReddit> multiReddits) {
|
||||||
new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, () -> {
|
new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
|
||||||
mInsertSuccess = true;
|
mInsertSuccess = true;
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
}).execute();
|
}).execute();
|
||||||
|
@ -1003,17 +1003,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
mActivity.startActivity(intent);
|
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 -> {
|
((CommentViewHolder) holder).expandButton.setOnClickListener(view -> {
|
||||||
if (((CommentViewHolder) holder).expandButton.getVisibility() == View.VISIBLE) {
|
if (((CommentViewHolder) holder).expandButton.getVisibility() == View.VISIBLE) {
|
||||||
int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1;
|
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);
|
mGlide.clear(((CommentViewHolder) holder).authorTypeImageView);
|
||||||
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
|
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
|
||||||
((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.GONE);
|
((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.GONE);
|
||||||
//((CommentViewHolder) holder).moreButton.setVisibility(View.GONE);
|
|
||||||
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
|
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
|
||||||
((CommentViewHolder) holder).upVoteButton.clearColorFilter();
|
((CommentViewHolder) holder).upVoteButton.clearColorFilter();
|
||||||
((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
|
((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
|
||||||
|
@ -42,18 +42,19 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
|
private String mAccountName;
|
||||||
private List<MultiReddit> mMultiReddits;
|
private List<MultiReddit> mMultiReddits;
|
||||||
private List<MultiReddit> mFavoriteMultiReddits;
|
private List<MultiReddit> mFavoriteMultiReddits;
|
||||||
|
|
||||||
public MultiRedditListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
|
public MultiRedditListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
String accessToken) {
|
String accessToken, String accountName) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mGlide = Glide.with(context.getApplicationContext());
|
mGlide = Glide.with(context.getApplicationContext());
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
mAccessToken = accessToken;
|
mAccessToken = accessToken;
|
||||||
|
mAccountName = accountName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -114,8 +115,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
if(multiReddit.isFavorite()) {
|
if(multiReddit.isFavorite()) {
|
||||||
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||||
multiReddit.setFavorite(false);
|
multiReddit.setFavorite(false);
|
||||||
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
|
||||||
false, multiReddit,
|
mAccessToken, mAccountName, false, multiReddit,
|
||||||
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
@ -140,8 +141,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
} else {
|
} else {
|
||||||
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||||
multiReddit.setFavorite(true);
|
multiReddit.setFavorite(true);
|
||||||
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
|
||||||
true, multiReddit,
|
mAccessToken, mAccountName, true, multiReddit,
|
||||||
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
@ -197,8 +198,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
if(multiReddit.isFavorite()) {
|
if(multiReddit.isFavorite()) {
|
||||||
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||||
multiReddit.setFavorite(false);
|
multiReddit.setFavorite(false);
|
||||||
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
|
||||||
false, multiReddit,
|
mAccessToken, mAccountName, false, multiReddit,
|
||||||
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
@ -223,8 +224,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
} else {
|
} else {
|
||||||
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||||
multiReddit.setFavorite(true);
|
multiReddit.setFavorite(true);
|
||||||
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
|
||||||
true, multiReddit,
|
mAccessToken, mAccountName, true, multiReddit,
|
||||||
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
|
@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit.AsyncTask;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
|
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditDao;
|
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditDao;
|
||||||
@ -11,18 +13,29 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|||||||
public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> {
|
public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
private MultiRedditDao multiRedditDao;
|
private MultiRedditDao multiRedditDao;
|
||||||
private ArrayList<MultiReddit> multiReddits;
|
private ArrayList<MultiReddit> multiReddits;
|
||||||
|
private String accountName;
|
||||||
private InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener;
|
private InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener;
|
||||||
|
|
||||||
public InsertMultiRedditAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
|
public InsertMultiRedditAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
ArrayList<MultiReddit> multiReddits,
|
ArrayList<MultiReddit> multiReddits, String accountName,
|
||||||
InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener) {
|
InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener) {
|
||||||
multiRedditDao = redditDataRoomDatabase.multiRedditDao();
|
multiRedditDao = redditDataRoomDatabase.multiRedditDao();
|
||||||
this.multiReddits = multiReddits;
|
this.multiReddits = multiReddits;
|
||||||
|
this.accountName = accountName;
|
||||||
this.insertMultiRedditAsyncTaskListener = insertMultiRedditAsyncTaskListener;
|
this.insertMultiRedditAsyncTaskListener = insertMultiRedditAsyncTaskListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
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) {
|
for (MultiReddit multiReddit : multiReddits) {
|
||||||
multiRedditDao.insert(multiReddit);
|
multiRedditDao.insert(multiReddit);
|
||||||
}
|
}
|
||||||
@ -35,6 +48,32 @@ public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||||||
insertMultiRedditAsyncTaskListener.success();
|
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 {
|
public interface InsertMultiRedditAsyncTaskListener {
|
||||||
void success();
|
void success();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import android.os.AsyncTask;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
@ -23,15 +25,15 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||||||
private SubredditDao mSubredditDao;
|
private SubredditDao mSubredditDao;
|
||||||
private SubscribedSubredditData mSingleSubscribedSubredditData;
|
private SubscribedSubredditData mSingleSubscribedSubredditData;
|
||||||
private SubscribedUserData mSingleSubscribedUserData;
|
private SubscribedUserData mSingleSubscribedUserData;
|
||||||
private List<SubscribedSubredditData> subscribedSubredditData;
|
private List<SubscribedSubredditData> subscribedSubredditDataList;
|
||||||
private List<SubscribedUserData> subscribedUserData;
|
private List<SubscribedUserData> subscribedUserDataList;
|
||||||
private List<SubredditData> subredditData;
|
private List<SubredditData> subredditDataList;
|
||||||
private InsertSubscribedThingListener mInsertSubscribedThingListener;
|
private InsertSubscribedThingListener mInsertSubscribedThingListener;
|
||||||
|
|
||||||
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName,
|
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName,
|
||||||
List<SubscribedSubredditData> subscribedSubredditData,
|
List<SubscribedSubredditData> subscribedSubredditDataList,
|
||||||
List<SubscribedUserData> subscribedUserData,
|
List<SubscribedUserData> subscribedUserDataList,
|
||||||
List<SubredditData> subredditData,
|
List<SubredditData> subredditDataList,
|
||||||
InsertSubscribedThingListener insertSubscribedThingListener) {
|
InsertSubscribedThingListener insertSubscribedThingListener) {
|
||||||
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
mAccountName = accountName;
|
mAccountName = accountName;
|
||||||
@ -39,29 +41,29 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||||||
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
|
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
|
||||||
mSubredditDao = redditDataRoomDatabase.subredditDao();
|
mSubredditDao = redditDataRoomDatabase.subredditDao();
|
||||||
|
|
||||||
this.subscribedSubredditData = subscribedSubredditData;
|
this.subscribedSubredditDataList = subscribedSubredditDataList;
|
||||||
this.subscribedUserData = subscribedUserData;
|
this.subscribedUserDataList = subscribedUserDataList;
|
||||||
this.subredditData = subredditData;
|
this.subredditDataList = subredditDataList;
|
||||||
mInsertSubscribedThingListener = insertSubscribedThingListener;
|
mInsertSubscribedThingListener = insertSubscribedThingListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
|
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
SubscribedSubredditData subscribedSubredditData,
|
SubscribedSubredditData subscribedSubredditDataList,
|
||||||
InsertSubscribedThingListener insertSubscribedThingListener) {
|
InsertSubscribedThingListener insertSubscribedThingListener) {
|
||||||
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao();
|
mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao();
|
||||||
mAccountName = subscribedSubredditData.getUsername();
|
mAccountName = subscribedSubredditDataList.getUsername();
|
||||||
mSingleSubscribedSubredditData = subscribedSubredditData;
|
mSingleSubscribedSubredditData = subscribedSubredditDataList;
|
||||||
mInsertSubscribedThingListener = insertSubscribedThingListener;
|
mInsertSubscribedThingListener = insertSubscribedThingListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
|
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
SubscribedUserData subscribedUserData,
|
SubscribedUserData subscribedUserDataList,
|
||||||
InsertSubscribedThingListener insertSubscribedThingListener) {
|
InsertSubscribedThingListener insertSubscribedThingListener) {
|
||||||
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
|
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
|
||||||
mAccountName = subscribedUserData.getUsername();
|
mAccountName = subscribedUserDataList.getUsername();
|
||||||
mSingleSubscribedUserData = subscribedUserData;
|
mSingleSubscribedUserData = subscribedUserDataList;
|
||||||
mInsertSubscribedThingListener = insertSubscribedThingListener;
|
mInsertSubscribedThingListener = insertSubscribedThingListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,20 +78,42 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||||||
} else if (mSingleSubscribedUserData != null) {
|
} else if (mSingleSubscribedUserData != null) {
|
||||||
mSubscribedUserDao.insert(mSingleSubscribedUserData);
|
mSubscribedUserDao.insert(mSingleSubscribedUserData);
|
||||||
} else {
|
} else {
|
||||||
if (subscribedSubredditData != null) {
|
if (subscribedSubredditDataList != null) {
|
||||||
for (SubscribedSubredditData s : subscribedSubredditData) {
|
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);
|
mSubscribedSubredditDao.insert(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subscribedUserData != null) {
|
if (subscribedUserDataList != null) {
|
||||||
for (SubscribedUserData s : subscribedUserData) {
|
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);
|
mSubscribedUserDao.insert(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subredditData != null) {
|
if (subredditDataList != null) {
|
||||||
for (SubredditData s : subredditData) {
|
for (SubredditData s : subredditDataList) {
|
||||||
mSubredditDao.insert(s);
|
mSubredditDao.insert(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,6 +126,58 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||||||
mInsertSubscribedThingListener.insertSuccess();
|
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 {
|
public interface InsertSubscribedThingListener {
|
||||||
void insertSuccess();
|
void insertSuccess();
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ public class FavoriteMultiReddit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void favoriteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
|
public static void favoriteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
String accessToken, boolean makeFavorite, MultiReddit multiReddit,
|
String accessToken, String accountName, boolean makeFavorite,
|
||||||
FavoriteMultiRedditListener favoriteMultiRedditListener) {
|
MultiReddit multiReddit, FavoriteMultiRedditListener favoriteMultiRedditListener) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put(RedditUtils.MULTIPATH_KEY, multiReddit.getPath());
|
params.put(RedditUtils.MULTIPATH_KEY, multiReddit.getPath());
|
||||||
params.put(RedditUtils.MAKE_FAVORITE_KEY, String.valueOf(makeFavorite));
|
params.put(RedditUtils.MAKE_FAVORITE_KEY, String.valueOf(makeFavorite));
|
||||||
@ -36,7 +36,7 @@ public class FavoriteMultiReddit {
|
|||||||
multiReddit.setFavorite(true);
|
multiReddit.setFavorite(true);
|
||||||
ArrayList<MultiReddit> singleMultiRedditList = new ArrayList<>();
|
ArrayList<MultiReddit> singleMultiRedditList = new ArrayList<>();
|
||||||
singleMultiRedditList.add(multiReddit);
|
singleMultiRedditList.add(multiReddit);
|
||||||
new InsertMultiRedditAsyncTask(redditDataRoomDatabase, singleMultiRedditList,
|
new InsertMultiRedditAsyncTask(redditDataRoomDatabase, singleMultiRedditList, accountName,
|
||||||
favoriteMultiRedditListener::success).execute();
|
favoriteMultiRedditListener::success).execute();
|
||||||
} else {
|
} else {
|
||||||
favoriteMultiRedditListener.failed();
|
favoriteMultiRedditListener.failed();
|
||||||
|
@ -16,6 +16,9 @@ public interface MultiRedditDao {
|
|||||||
@Query("SELECT * FROM multi_reddits WHERE username = :username ORDER BY name COLLATE NOCASE ASC")
|
@Query("SELECT * FROM multi_reddits WHERE username = :username ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<MultiReddit>> getAllMultiReddits(String username);
|
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")
|
@Query("SELECT * FROM multi_reddits WHERE username = :username AND is_favorite ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<MultiReddit>> getAllFavoriteMultiReddits(String username);
|
LiveData<List<MultiReddit>> getAllFavoriteMultiReddits(String username);
|
||||||
|
|
||||||
@ -24,4 +27,7 @@ public interface MultiRedditDao {
|
|||||||
|
|
||||||
@Query("DELETE FROM multi_reddits WHERE name = :name AND username = :username")
|
@Query("DELETE FROM multi_reddits WHERE name = :name AND username = :username")
|
||||||
void deleteMultiReddit(String name, String username);
|
void deleteMultiReddit(String name, String username);
|
||||||
|
|
||||||
|
@Query("DELETE FROM multi_reddits WHERE username = :username")
|
||||||
|
void deleteAllUserMultiReddits(String username);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ public interface SubscribedSubredditDao {
|
|||||||
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
|
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits(String accountName);
|
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")
|
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<SubscribedSubredditData>> getAllFavoriteSubscribedSubreddits(String accountName);
|
LiveData<List<SubscribedSubredditData>> getAllFavoriteSubscribedSubreddits(String accountName);
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ public interface SubscribedUserDao {
|
|||||||
@Query("SELECT * FROM subscribed_users WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
|
@Query("SELECT * FROM subscribed_users WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<SubscribedUserData>> getAllSubscribedUsers(String accountName);
|
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")
|
@Query("SELECT * FROM subscribed_users WHERE username = :accountName AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsers(String accountName);
|
LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsers(String accountName);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user