From 895f4096f43ec9e9563054157486455979ce551b Mon Sep 17 00:00:00 2001 From: Tomer Rosenfeld Date: Mon, 16 Nov 2015 19:15:10 +0200 Subject: [PATCH] Really fixed the issue where not all read posts would dismiss, also long press dimiss fab to hide forever --- .../Adapters/SubmissionAdapter.java | 3 -- .../Fragments/SubmissionsView.java | 52 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/me/ccrama/redditslide/Adapters/SubmissionAdapter.java b/app/src/main/java/me/ccrama/redditslide/Adapters/SubmissionAdapter.java index 09ebe1b9b3..3a585270a6 100644 --- a/app/src/main/java/me/ccrama/redditslide/Adapters/SubmissionAdapter.java +++ b/app/src/main/java/me/ccrama/redditslide/Adapters/SubmissionAdapter.java @@ -98,9 +98,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i) { - if (HasSeen.getSeen(dataSet.posts.get(i).getFullName())){ - seen.add(dataSet.posts.get(i)); - } if (holder2 instanceof SubmissionViewHolder) { final SubmissionViewHolder holder = (SubmissionViewHolder) holder2; diff --git a/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java b/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java index 555153ffe3..33ee2a51c1 100644 --- a/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java +++ b/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java @@ -1,10 +1,12 @@ package me.ccrama.redditslide.Fragments; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.internal.view.ContextThemeWrapper; @@ -17,7 +19,9 @@ import android.view.View; import android.view.ViewGroup; -import java.util.Iterator; +import net.dean.jraw.models.Submission; + +import java.util.ArrayList; import java.util.concurrent.ExecutionException; import me.ccrama.redditslide.Activities.Submit; @@ -142,9 +146,27 @@ public void onClick(View v) { fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - clearSeenPosts(); - //Rechecking arrays, I'm note sure why is it necessary but it is. - clearSeenPosts(); + clearSeenPosts(false); + } + }); + fab.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + clearSeenPosts(true); + /* + ToDo Make a sncakbar with an undo option of the clear all + View.OnClickListener undoAction = new View.OnClickListener() { + @Override + public void onClick(View v) { + adapter.dataSet.posts = original; + for(Submission post : adapter.dataSet.posts){ + if(HasSeen.getSeen(post.getFullName())) + Hidden.undoHidden(post); + } + } + };*/ + Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG).show(); + return false; } }); } @@ -190,17 +212,27 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { } } }); + Reddit.isLoading = false; + return v; } - private void clearSeenPosts() { - for (int i = 0; i < adapter.dataSet.posts.size(); i++) { - if (HasSeen.getSeen(adapter.dataSet.posts.get(i).getFullName())) { - Hidden.setHidden(adapter.dataSet.posts.get(i)); - adapter.dataSet.posts.remove(adapter.dataSet.posts.get(i)); - adapter.notifyItemRemoved(adapter.dataSet.posts.indexOf(adapter.dataSet.posts.get(i))); + private ArrayList clearSeenPosts(boolean forever) { + ArrayList originalDataSetPosts = adapter.dataSet.posts; + System.out.println("Posts number is " + adapter.dataSet.posts.size()); + for (int i = adapter.dataSet.posts.size(); i > -1; i--) { + try { + if (HasSeen.getSeen(adapter.dataSet.posts.get(i).getFullName())) { + if (forever) + Hidden.setHidden(adapter.dataSet.posts.get(i)); + adapter.dataSet.posts.remove(i); + adapter.notifyItemRemoved(i); + } + } catch (IndexOutOfBoundsException e) { + //Let the loop reset itself } } + return originalDataSetPosts; } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index da3c4657c7..4bd00e9d38 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -469,6 +469,7 @@ Mod Mail Unread Uh oh, post not found! Sorry, this post could not be found + Posts hidden forever %d minute ago diff --git a/build.gradle b/build.gradle index 5a85670a69..4ecb47dc9c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' + classpath 'com.android.tools.build:gradle:1.5+' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files