Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #543 from rosenpin/fab-dismiss
Browse files Browse the repository at this point in the history
Fixed the issue with last PR where only some posts would be removed
  • Loading branch information
SlideCI committed Nov 15, 2015
2 parents 96e050b + 7ed424f commit 4fce03a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
import net.dean.jraw.managers.AccountManager;
import net.dean.jraw.models.Submission;

import java.util.ArrayList;

import me.ccrama.redditslide.Activities.CommentsScreen;
import me.ccrama.redditslide.Activities.CommentsScreenPopup;
import me.ccrama.redditslide.Activities.Profile;
import me.ccrama.redditslide.Activities.SubredditView;
import me.ccrama.redditslide.Authentication;
import me.ccrama.redditslide.DataShare;
import me.ccrama.redditslide.HasSeen;
import me.ccrama.redditslide.Hidden;
import me.ccrama.redditslide.R;
import me.ccrama.redditslide.Reddit;
Expand All @@ -47,14 +50,15 @@ public class SubmissionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
private final String subreddit;
private final boolean custom;
public SubredditPosts dataSet;
public ArrayList<Submission> seen;

public SubmissionAdapter(Activity mContext, SubredditPosts dataSet, RecyclerView listView, String subreddit) {

this.mContext = mContext;
this.subreddit = subreddit.toLowerCase();
this.listView = listView;
this.dataSet = dataSet;

this.seen = new ArrayList<>();
custom = SettingValues.prefs.contains("PRESET" + subreddit.toLowerCase());

Log.v("Slide", subreddit + " CUSTOM IS " + custom);
Expand Down Expand Up @@ -99,6 +103,9 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i)
final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;

final Submission submission = dataSet.posts.get(i);
if (HasSeen.getSeen(submission.getFullName())){
seen.add(submission);
}
CreateCardView.resetColorCard(holder.itemView);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(), holder.itemView, subreddit, custom);
holder.itemView.setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import android.view.View;
import android.view.ViewGroup;

import java.util.Iterator;
import java.util.concurrent.ExecutionException;

import me.ccrama.redditslide.Activities.Submit;
import me.ccrama.redditslide.Adapters.SubmissionAdapter;
import me.ccrama.redditslide.Adapters.SubredditPosts;
import me.ccrama.redditslide.ColorPreferences;
import me.ccrama.redditslide.HasSeen;
import me.ccrama.redditslide.R;
import me.ccrama.redditslide.Reddit;
import me.ccrama.redditslide.Views.PreCachingLayoutManager;
Expand Down Expand Up @@ -135,16 +135,20 @@ public void onClick(View v) {
}
});
} else {
fab.setImageResource(R.drawable.ic_clear);
fab.setImageResource(R.drawable.close);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < adapter.dataSet.posts.size(); i++) {
if (HasSeen.getSeen(adapter.dataSet.posts.get(i).getFullName())) {
adapter.dataSet.posts.remove(adapter.dataSet.posts.get(i));
adapter.notifyItemRemoved(adapter.dataSet.posts.indexOf(adapter.dataSet.posts.get(i)));
int i = 0;
Iterator<?> it = adapter.dataSet.posts.iterator();
while (it.hasNext()) {
i++;
if (adapter.seen.contains(it.next())) {
it.remove();
//adapter.notifyItemRemoved(i);
}
}
adapter.notifyDataSetChanged();
}
});
}
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/ic_clear.xml

This file was deleted.

0 comments on commit 4fce03a

Please sign in to comment.