From 160b32f0e8a7cee6240ec0b14b58516b727360a0 Mon Sep 17 00:00:00 2001 From: Grishka Date: Sat, 12 Mar 2022 00:28:40 +0300 Subject: [PATCH] I'm so stupid --- mastodon/build.gradle | 2 +- .../android/api/CacheController.java | 64 ++++++++++--------- .../fragments/HomeTimelineFragment.java | 10 +-- .../fragments/NotificationsListFragment.java | 17 +---- 4 files changed, 37 insertions(+), 56 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 1982229e..8cf87b53 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -10,7 +10,7 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 31 - versionCode 10 + versionCode 11 versionName "0.1" } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java b/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java index 427e93dc..7a4a7f88 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java @@ -45,25 +45,27 @@ public class CacheController{ this.accountID=accountID; } - public void getHomeTimeline(String maxID, int count, Callback> callback){ + public void getHomeTimeline(String maxID, int count, boolean forceReload, Callback> callback){ cancelDelayedClose(); databaseThread.postRunnable(()->{ try{ - SQLiteDatabase db=getOrOpenDatabase(); - try(Cursor cursor=db.query("home_timeline", new String[]{"json"}, maxID==null ? null : "`id` result=new ArrayList<>(); - cursor.moveToFirst(); - do{ - Status status=MastodonAPIController.gson.fromJson(cursor.getString(0), Status.class); - status.postprocess(); - result.add(status); - }while(cursor.moveToNext()); - uiHandler.post(()->callback.onSuccess(result)); - return; + if(!forceReload){ + SQLiteDatabase db=getOrOpenDatabase(); + try(Cursor cursor=db.query("home_timeline", new String[]{"json"}, maxID==null ? null : "`id` result=new ArrayList<>(); + cursor.moveToFirst(); + do{ + Status status=MastodonAPIController.gson.fromJson(cursor.getString(0), Status.class); + status.postprocess(); + result.add(status); + }while(cursor.moveToNext()); + uiHandler.post(()->callback.onSuccess(result)); + return; + } + }catch(IOException x){ + Log.w(TAG, "getHomeTimeline: corrupted status object in database", x); } - }catch(IOException x){ - Log.w(TAG, "getHomeTimeline: corrupted status object in database", x); } new GetHomeTimeline(maxID, null, count) .setCallback(new Callback<>(){ @@ -109,25 +111,27 @@ public class CacheController{ }, 0); } - public void getNotifications(String maxID, int count, boolean onlyMentions, Callback> callback){ + public void getNotifications(String maxID, int count, boolean onlyMentions, boolean forceReload, Callback> callback){ cancelDelayedClose(); databaseThread.postRunnable(()->{ try{ - SQLiteDatabase db=getOrOpenDatabase(); - try(Cursor cursor=db.query(onlyMentions ? "notifications_mentions" : "notifications_all", new String[]{"json"}, maxID==null ? null : "`id` result=new ArrayList<>(); - cursor.moveToFirst(); - do{ - Notification ntf=MastodonAPIController.gson.fromJson(cursor.getString(0), Notification.class); - ntf.postprocess(); - result.add(ntf); - }while(cursor.moveToNext()); - uiHandler.post(()->callback.onSuccess(result)); - return; + if(!forceReload){ + SQLiteDatabase db=getOrOpenDatabase(); + try(Cursor cursor=db.query(onlyMentions ? "notifications_mentions" : "notifications_all", new String[]{"json"}, maxID==null ? null : "`id` result=new ArrayList<>(); + cursor.moveToFirst(); + do{ + Notification ntf=MastodonAPIController.gson.fromJson(cursor.getString(0), Notification.class); + ntf.postprocess(); + result.add(ntf); + }while(cursor.moveToNext()); + uiHandler.post(()->callback.onSuccess(result)); + return; + } + }catch(IOException x){ + Log.w(TAG, "getNotifications: corrupted notification object in database", x); } - }catch(IOException x){ - Log.w(TAG, "getNotifications: corrupted notification object in database", x); } new GetNotifications(maxID, count, onlyMentions ? EnumSet.complementOf(EnumSet.of(Notification.Type.MENTION)): null) .setCallback(new Callback<>(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index 2de9dc3b..37fba175 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -58,17 +58,9 @@ public class HomeTimelineFragment extends StatusListFragment{ @Override protected void doLoadData(int offset, int count){ -// currentRequest=new GetHomeTimeline(offset>0 ? getMaxID() : null, null, count) -// .setCallback(new SimpleCallback<>(this){ -// @Override -// public void onSuccess(List result){ -// onDataLoaded(result, !result.isEmpty()); -// } -// }) -// .exec(accountID); AccountSessionManager.getInstance() .getAccount(accountID).getCacheController() - .getHomeTimeline(offset>0 ? getMaxID() : null, count, new SimpleCallback<>(this){ + .getHomeTimeline(offset>0 ? getMaxID() : null, count, refreshing, new SimpleCallback<>(this){ @Override public void onSuccess(List result){ onDataLoaded(result, !result.isEmpty()); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java index 2f780b65..fa7e39a6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java @@ -78,24 +78,9 @@ public class NotificationsListFragment extends BaseStatusListFragment0 ? getMaxID() : null, count, types) -// .setCallback(new SimpleCallback<>(this){ -// @Override -// public void onSuccess(List result){ -// if(refreshing) -// relationships.clear(); -// onDataLoaded(result, !result.isEmpty()); -// Set needRelationships=result.stream() -// .filter(ntf->ntf.status==null && !relationships.containsKey(ntf.account.id)) -// .map(ntf->ntf.account.id) -// .collect(Collectors.toSet()); -// loadRelationships(needRelationships); -// } -// }) -// .exec(accountID); AccountSessionManager.getInstance() .getAccount(accountID).getCacheController() - .getNotifications(offset>0 ? getMaxID() : null, count, onlyMentions, new SimpleCallback<>(this){ + .getNotifications(offset>0 ? getMaxID() : null, count, onlyMentions, refreshing, new SimpleCallback<>(this){ @Override public void onSuccess(List result){ if(refreshing)