Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
auto load posts when going back into activity after 15 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
l3d00m committed May 9, 2017
1 parent 4fdc7d3 commit 14d3d84
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/de/pscom/pietsmiet/view/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, Navi
private MenuItem pietstream_banner;

public PostPresenter postPresenter;
private long exitTime;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -157,8 +158,6 @@ public void onHidden(FloatingActionButton fab) {

new SecretConstants(this);

DatabaseHelper.getInstance(this).displayPostsFromCache(postPresenter);

if (BuildConfig.DEBUG) {
Thread.setDefaultUncaughtExceptionHandler((paramThread, paramThrowable) -> {
PsLog.w("Uncaught Exception!", paramThrowable);
Expand Down Expand Up @@ -191,12 +190,20 @@ public void onDestroy() {
@Override
protected void onStart() {
super.onStart();
if (postPresenter.getPostsToDisplay().isEmpty()) {
// Load posts from db
DatabaseHelper.getInstance(this).displayPostsFromCache(postPresenter);
} else if ((exitTime - System.currentTimeMillis()) < (15 * 60 * 1000)) {
// Auto reload posts if going back to activity after more than 15 minutes
postPresenter.fetchNewPosts();
}
mCustomTabActivityHelper.bindCustomTabsService(this);
}

@Override
protected void onStop() {
super.onStop();
exitTime = System.currentTimeMillis();
mCustomTabActivityHelper.unbindCustomTabsService(this);
}

Expand Down

0 comments on commit 14d3d84

Please sign in to comment.