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

Commit

Permalink
Fixed timeout on app start for some users
Browse files Browse the repository at this point in the history
  • Loading branch information
SlideCI committed Nov 16, 2015
2 parents edeb508 + 771e95a commit 46880fd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ android {
applicationId "me.ccrama.redditslide"
minSdkVersion 17
targetSdkVersion 23
versionCode 85
versionCode 86
versionName "4.3.25"
multiDexEnabled = true

}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -98,27 +97,26 @@ protected void onCreate(Bundle savedInstanceState) {
}

@Override
public void onResume(){
public void onResume() {
super.onResume();
Log.v("Slide", "DOING RELOAD");
if(adapter == null || tabs == null || usedArray == null || usedArray.size() == 0){
Log.v("Slide", "DOING RELOAD 2");
if (adapter == null || tabs == null || usedArray == null || usedArray.size() == 0) {

if(System.currentTimeMillis() - Reddit.time > 30) { //10 sec timeout, make sure we don't get into an endless loop
Log.v("Slide", "DOING RELOAD 3");

Reddit.time = System.currentTimeMillis();
if (System.currentTimeMillis() - Reddit.time > 100) { //10 sec timeout, make sure we don't get into an endless loop

Reddit.time = System.currentTimeMillis();

restartTheme();
}
}
}



public void doSubSidebar(final String subreddit) {
if (!subreddit.equals("all") && !subreddit.equals("frontpage")) {
if (drawerLayout != null)


drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
findViewById(R.id.info).setVisibility(View.VISIBLE);

Expand Down Expand Up @@ -541,7 +539,7 @@ public void setDataSet(List<String> data) {
getSupportActionBar().setTitle(usedArray.get(0));
}

} else if(SubredditStorage.subredditsForHome!= null) {
} else if (SubredditStorage.subredditsForHome != null) {
setDataSet(SubredditStorage.subredditsForHome);
}

Expand Down
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,6 +19,10 @@
import android.view.View;
import android.view.ViewGroup;


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 +147,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 +218,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 46880fd

Please sign in to comment.