Fix loop issue #274
This commit is contained in:
parent
f3cb4ede15
commit
19d3779a6d
|
@ -22,14 +22,13 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
import android.graphics.BitmapFactory;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.os.SystemClock;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
|
@ -120,22 +119,25 @@ public class BackupNotificationInDataBaseService extends IntentService {
|
|||
//new NotificationCacheDAO(getApplicationContext(), db).removeAll();
|
||||
try {
|
||||
//Starts from the last recorded ID
|
||||
Date sinceDate = new NotificationCacheDAO(BackupNotificationInDataBaseService.this, db).getLastNotificationDateCache(userId, instance);
|
||||
String lastId = new NotificationCacheDAO(BackupNotificationInDataBaseService.this, db).getLastNotificationIDCache(userId, instance);
|
||||
String max_id = null;
|
||||
List<Notification> backupNotifications = new ArrayList<>();
|
||||
boolean canContinue = true;
|
||||
do {
|
||||
APIResponse apiResponse = api.getNotifications(max_id);
|
||||
|
||||
max_id = apiResponse.getMax_id();
|
||||
List<Notification> notifications = apiResponse.getNotifications();
|
||||
for(Notification tmpNotification : notifications) {
|
||||
if(sinceDate != null && tmpNotification.getCreated_at().before(sinceDate)){
|
||||
if(lastId != null && tmpNotification.getId().compareTo(lastId) <= 0){
|
||||
canContinue = false;
|
||||
break;
|
||||
}
|
||||
|
||||
new NotificationCacheDAO(BackupNotificationInDataBaseService.this, db).insertNotification(tmpNotification, userId, instance);
|
||||
backupNotifications.add(tmpNotification);
|
||||
}
|
||||
SystemClock.sleep(1000);
|
||||
}while (max_id != null && canContinue);
|
||||
|
||||
if(backupNotifications.size() > 0){
|
||||
|
|
|
@ -24,6 +24,8 @@ import android.os.Handler;
|
|||
import android.os.Looper;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -133,6 +135,7 @@ public class BackupStatusInDataBaseService extends IntentService {
|
|||
new StatusCacheDAO(BackupStatusInDataBaseService.this, db).insertStatus(StatusCacheDAO.ARCHIVE_CACHE, tmpStatus, userId, instance);
|
||||
backupStatus.add(tmpStatus);
|
||||
}
|
||||
SystemClock.sleep(1000);
|
||||
}while (max_id != null && canContinue);
|
||||
|
||||
if(backupStatus.size() > 0){
|
||||
|
|
|
@ -26,6 +26,8 @@ import android.os.Environment;
|
|||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.text.Html;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -117,6 +119,7 @@ public class BackupStatusService extends IntentService {
|
|||
List<Status> statuses = apiResponse.getStatuses();
|
||||
if (statuses.size() > 0)
|
||||
backupStatus.addAll(statuses);
|
||||
SystemClock.sleep(1000);
|
||||
}while (max_id != null);
|
||||
|
||||
String fileName = account.getAcct()+"@"+account.getInstance()+ Helper.dateFileToString(getApplicationContext(), new Date())+".csv";
|
||||
|
|
|
@ -322,10 +322,7 @@ public class NotificationCacheDAO {
|
|||
* Returns the last id of backup for a use
|
||||
* @return Date
|
||||
*/
|
||||
public String getLastNotificationIDCache(){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
public String getLastNotificationIDCache(String userId, String instance){
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_NOTIFICATION_CACHE, null, Sqlite.COL_INSTANCE + " = '" + instance+ "' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_NOTIFICATION_ID + " DESC", "1");
|
||||
//No element found
|
||||
|
|
Loading…
Reference in New Issue