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"
minSdk 23
targetSdk 31
versionCode 10
versionCode 11
versionName "0.1"
}

View File

@ -45,10 +45,11 @@ public class CacheController{
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();
databaseThread.postRunnable(()->{
try{
if(!forceReload){
SQLiteDatabase db=getOrOpenDatabase();
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+"")){
if(cursor.getCount()==count){
@ -65,6 +66,7 @@ public class CacheController{
}catch(IOException x){
Log.w(TAG, "getHomeTimeline: corrupted status object in database", x);
}
}
new GetHomeTimeline(maxID, null, count)
.setCallback(new Callback<>(){
@Override
@ -109,10 +111,11 @@ public class CacheController{
}, 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();
databaseThread.postRunnable(()->{
try{
if(!forceReload){
SQLiteDatabase db=getOrOpenDatabase();
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+"")){
if(cursor.getCount()==count){
@ -129,6 +132,7 @@ public class CacheController{
}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<>(){
@Override

View File

@ -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<Status> 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<Status> result){
onDataLoaded(result, !result.isEmpty());

View File

@ -78,24 +78,9 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
@Override
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()
.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<Notification> result){
if(refreshing)