I'm so stupid

This commit is contained in:
Grishka 2022-03-12 00:28:40 +03:00
parent 8ba3fecca3
commit 160b32f0e8
4 changed files with 37 additions and 56 deletions

View File

@ -10,7 +10,7 @@ android {
applicationId "org.joinmastodon.android" applicationId "org.joinmastodon.android"
minSdk 23 minSdk 23
targetSdk 31 targetSdk 31
versionCode 10 versionCode 11
versionName "0.1" versionName "0.1"
} }

View File

@ -45,25 +45,27 @@ public class CacheController{
this.accountID=accountID; this.accountID=accountID;
} }
public void getHomeTimeline(String maxID, int count, Callback<List<Status>> callback){ public void getHomeTimeline(String maxID, int count, boolean forceReload, Callback<List<Status>> callback){
cancelDelayedClose(); cancelDelayedClose();
databaseThread.postRunnable(()->{ databaseThread.postRunnable(()->{
try{ try{
SQLiteDatabase db=getOrOpenDatabase(); if(!forceReload){
try(Cursor cursor=db.query("home_timeline", new String[]{"json"}, maxID==null ? null : "`id`<?", maxID==null ? null : new String[]{maxID}, null, null, "`id` DESC", count+"")){ SQLiteDatabase db=getOrOpenDatabase();
if(cursor.getCount()==count){ try(Cursor cursor=db.query("home_timeline", new String[]{"json"}, maxID==null ? null : "`id`<?", maxID==null ? null : new String[]{maxID}, null, null, "`id` DESC", count+"")){
ArrayList<Status> result=new ArrayList<>(); if(cursor.getCount()==count){
cursor.moveToFirst(); ArrayList<Status> result=new ArrayList<>();
do{ cursor.moveToFirst();
Status status=MastodonAPIController.gson.fromJson(cursor.getString(0), Status.class); do{
status.postprocess(); Status status=MastodonAPIController.gson.fromJson(cursor.getString(0), Status.class);
result.add(status); status.postprocess();
}while(cursor.moveToNext()); result.add(status);
uiHandler.post(()->callback.onSuccess(result)); }while(cursor.moveToNext());
return; 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) new GetHomeTimeline(maxID, null, count)
.setCallback(new Callback<>(){ .setCallback(new Callback<>(){
@ -109,25 +111,27 @@ public class CacheController{
}, 0); }, 0);
} }
public void getNotifications(String maxID, int count, boolean onlyMentions, Callback<List<Notification>> callback){ public void getNotifications(String maxID, int count, boolean onlyMentions, boolean forceReload, Callback<List<Notification>> callback){
cancelDelayedClose(); cancelDelayedClose();
databaseThread.postRunnable(()->{ databaseThread.postRunnable(()->{
try{ try{
SQLiteDatabase db=getOrOpenDatabase(); if(!forceReload){
try(Cursor cursor=db.query(onlyMentions ? "notifications_mentions" : "notifications_all", new String[]{"json"}, maxID==null ? null : "`id`<?", maxID==null ? null : new String[]{maxID}, null, null, "`id` DESC", count+"")){ SQLiteDatabase db=getOrOpenDatabase();
if(cursor.getCount()==count){ try(Cursor cursor=db.query(onlyMentions ? "notifications_mentions" : "notifications_all", new String[]{"json"}, maxID==null ? null : "`id`<?", maxID==null ? null : new String[]{maxID}, null, null, "`id` DESC", count+"")){
ArrayList<Notification> result=new ArrayList<>(); if(cursor.getCount()==count){
cursor.moveToFirst(); ArrayList<Notification> result=new ArrayList<>();
do{ cursor.moveToFirst();
Notification ntf=MastodonAPIController.gson.fromJson(cursor.getString(0), Notification.class); do{
ntf.postprocess(); Notification ntf=MastodonAPIController.gson.fromJson(cursor.getString(0), Notification.class);
result.add(ntf); ntf.postprocess();
}while(cursor.moveToNext()); result.add(ntf);
uiHandler.post(()->callback.onSuccess(result)); }while(cursor.moveToNext());
return; 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) new GetNotifications(maxID, count, onlyMentions ? EnumSet.complementOf(EnumSet.of(Notification.Type.MENTION)): null)
.setCallback(new Callback<>(){ .setCallback(new Callback<>(){

View File

@ -58,17 +58,9 @@ public class HomeTimelineFragment extends StatusListFragment{
@Override @Override
protected void doLoadData(int offset, int count){ 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<Status> result){
// onDataLoaded(result, !result.isEmpty());
// }
// })
// .exec(accountID);
AccountSessionManager.getInstance() AccountSessionManager.getInstance()
.getAccount(accountID).getCacheController() .getAccount(accountID).getCacheController()
.getHomeTimeline(offset>0 ? getMaxID() : null, count, new SimpleCallback<>(this){ .getHomeTimeline(offset>0 ? getMaxID() : null, count, refreshing, new SimpleCallback<>(this){
@Override @Override
public void onSuccess(List<Status> result){ public void onSuccess(List<Status> result){
onDataLoaded(result, !result.isEmpty()); onDataLoaded(result, !result.isEmpty());

View File

@ -78,24 +78,9 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
@Override @Override
protected void doLoadData(int offset, int count){ protected void doLoadData(int offset, int count){
// new GetNotifications(offset>0 ? getMaxID() : null, count, types)
// .setCallback(new SimpleCallback<>(this){
// @Override
// public void onSuccess(List<Notification> result){
// if(refreshing)
// relationships.clear();
// onDataLoaded(result, !result.isEmpty());
// Set<String> 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() AccountSessionManager.getInstance()
.getAccount(accountID).getCacheController() .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 @Override
public void onSuccess(List<Notification> result){ public void onSuccess(List<Notification> result){
if(refreshing) if(refreshing)