Handles refresh in activity
This commit is contained in:
parent
834e400be2
commit
a703a7f1ad
|
@ -17,8 +17,11 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -26,6 +29,7 @@ import android.graphics.drawable.BitmapDrawable;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
@ -109,6 +113,10 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
|
||||
filterToots = new FilterToots();
|
||||
|
||||
LocalBroadcastManager.getInstance(this)
|
||||
.registerReceiver(backupFinishedReceiver,
|
||||
new IntentFilter(Helper.INTENT_BACKUP_FINISH));
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
|
@ -274,6 +282,8 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
dateIni = new StatusCacheDAO(OwnerStatusActivity.this, db).getSmallerDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
if( dateEnd == null)
|
||||
dateEnd = new StatusCacheDAO(OwnerStatusActivity.this, db).getGreaterDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
if( dateIni == null || dateEnd == null)
|
||||
return true;
|
||||
String dateInitString = Helper.shortDateToString(dateIni);
|
||||
String dateEndString = Helper.shortDateToString(dateEnd);
|
||||
|
||||
|
@ -421,13 +431,33 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
this.statuses.addAll(statuses);
|
||||
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
||||
}else {
|
||||
if( textviewNoAction.getVisibility() != View.VISIBLE) {
|
||||
RelativeLayout no_result = findViewById(R.id.no_result);
|
||||
no_result.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
firstLoad = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BroadcastReceiver backupFinishedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
max_id = null;
|
||||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
swiped = true;
|
||||
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, null, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
LocalBroadcastManager.getInstance(this)
|
||||
.unregisterReceiver(backupFinishedReceiver);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -302,11 +302,13 @@ public class Helper {
|
|||
//Intent
|
||||
public static final String INTENT_ACTION = "intent_action";
|
||||
public static final String INTENT_TARGETED_ACCOUNT = "intent_targeted_account";
|
||||
public static final String INTENT_BACKUP_FINISH = "intent_backup_finish";
|
||||
//Receiver
|
||||
public static final String RECEIVE_DATA = "receive_data";
|
||||
public static final String RECEIVE_FEDERATED_DATA = "receive_federated_data";
|
||||
public static final String RECEIVE_LOCAL_DATA = "receive_local_data";
|
||||
public static final String RECEIVE_PICTURE = "receive_picture";
|
||||
|
||||
//User agent
|
||||
public static final String USER_AGENT = "Mastalab/"+ BuildConfig.VERSION_NAME + " Android/"+ Build.VERSION.RELEASE;
|
||||
|
||||
|
|
|
@ -23,11 +23,13 @@ import android.graphics.BitmapFactory;
|
|||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.widget.Toast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.OwnerStatusActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
|
@ -115,7 +117,10 @@ public class BackupStatusInDataBaseService extends IntentService {
|
|||
}
|
||||
}while (max_id != null && canContinue);
|
||||
|
||||
|
||||
if(backupStatus.size() > 0){
|
||||
Intent backupIntent = new Intent(Helper.INTENT_BACKUP_FINISH);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(backupIntent);
|
||||
}
|
||||
message = getString(R.string.data_backup_success, String.valueOf(backupStatus.size()));
|
||||
Intent mainActivity = new Intent(BackupStatusInDataBaseService.this, MainActivity.class);
|
||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_INTENT);
|
||||
|
|
Loading…
Reference in New Issue