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 #551 from rosenpin/better-dismiss-fab
Browse files Browse the repository at this point in the history
Long press dimiss fab to hide read posts forever + bug fixes and faster performence.
  • Loading branch information
SlideCI committed Nov 16, 2015
2 parents f27138d + 895f409 commit 771e95a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -141,9 +145,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;
}
});
}
Expand Down Expand Up @@ -194,14 +216,22 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
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<Submission> clearSeenPosts(boolean forever) {
ArrayList<Submission> 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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
<string name="mod_mail_unread">Mod Mail Unread</string>
<string name="post_not_found">Uh oh, post not found!</string>
<string name="post_not_found_msg">Sorry, this post could not be found</string>
<string name="posts_hidden_forever">Posts hidden forever</string>

<plurals name="time_minutes_ago">
<item quantity="one">%d minute ago</item>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 771e95a

Please sign in to comment.