Improves behavior when searching missing toots in federated timeline
This commit is contained in:
parent
336acdc30c
commit
15b1809d87
|
@ -90,7 +90,6 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
|||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface;
|
||||
import fr.gouv.etalab.mastodon.services.StreamingFederatedTimelineService;
|
||||
import fr.gouv.etalab.mastodon.services.StreamingService;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
|
||||
|
|
|
@ -158,7 +158,7 @@ public class HashTagActivity extends AppCompatActivity implements OnRetrieveFeed
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) {
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
|
|
|
@ -525,7 +525,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) {
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = getApplicationContext().getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
|
|
|
@ -216,7 +216,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) {
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
|
|
|
@ -37,7 +37,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private String tag;
|
||||
private boolean showMediaOnly = false;
|
||||
private boolean showPinned = false;
|
||||
private boolean refreshData;
|
||||
|
||||
public enum Type{
|
||||
HOME,
|
||||
|
@ -56,7 +55,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.action = action;
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.refreshData = true;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
|
||||
|
@ -66,7 +64,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.listener = onRetrieveFeedsInterface;
|
||||
this.targetedID = targetedID;
|
||||
this.showMediaOnly = showMediaOnly;
|
||||
this.refreshData = true;
|
||||
this.showPinned = showPinned;
|
||||
}
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String tag, String targetedID, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
|
||||
|
@ -76,7 +73,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.listener = onRetrieveFeedsInterface;
|
||||
this.targetedID = targetedID;
|
||||
this.tag = tag;
|
||||
this.refreshData = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,6 +114,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveFeeds(apiResponse, refreshData);
|
||||
listener.onRetrieveFeeds(apiResponse);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1027,7 +1027,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) {
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
|
|
|
@ -34,7 +34,10 @@ import android.widget.ListView;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask;
|
||||
|
@ -80,6 +83,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
private String instanceValue;
|
||||
private String lastReadStatus;
|
||||
private Intent streamingFederatedIntent;
|
||||
private Date lastRefreshPublic;
|
||||
|
||||
public DisplayStatusFragment(){
|
||||
}
|
||||
|
@ -166,6 +170,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
}
|
||||
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
||||
if(!flag_loading ) {
|
||||
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC)
|
||||
lastRefreshPublic = new Date();
|
||||
flag_loading = true;
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
@ -192,6 +198,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
flag_loading = true;
|
||||
swiped = true;
|
||||
MainActivity.countNewStatus = 0;
|
||||
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC)
|
||||
lastRefreshPublic = new Date();
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
|
@ -203,13 +211,15 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
|
||||
R.color.mastodonC2,
|
||||
R.color.mastodonC3);
|
||||
|
||||
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC)
|
||||
lastRefreshPublic = new Date();
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
else {
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}else {
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
|
@ -246,7 +256,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) {
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
//Discards 404 - error which can often happen due to toots which have been deleted
|
||||
|
@ -371,6 +381,25 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC){
|
||||
Calendar date = Calendar.getInstance();
|
||||
long t = date.getTimeInMillis();
|
||||
Date newDate = new Date(t - TimeUnit.SECONDS.toMillis(20));
|
||||
if( lastRefreshPublic.before(newDate)){
|
||||
lastRefreshPublic = new Date();
|
||||
max_id = null;
|
||||
statuses = new ArrayList<>();
|
||||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
swiped = true;
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from main activity in onResume to retrieve missing toots (home timeline)
|
||||
|
|
|
@ -21,5 +21,5 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
|
|||
* Interface when status have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveFeedsInterface {
|
||||
void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData);
|
||||
void onRetrieveFeeds(APIResponse apiResponse);
|
||||
}
|
||||
|
|
|
@ -92,7 +92,6 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
|||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface;
|
||||
import fr.gouv.etalab.mastodon.services.StreamingFederatedTimelineService;
|
||||
import fr.gouv.etalab.mastodon.services.StreamingService;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
|
||||
|
@ -916,10 +915,8 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
};
|
||||
StreamingService.shouldContinue = true;
|
||||
streamingIntent = new Intent(this, StreamingService.class);
|
||||
startService(streamingIntent);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(receive_federated_data, new IntentFilter(Helper.RECEIVE_FEDERATED_DATA));
|
||||
}
|
||||
|
@ -927,8 +924,13 @@ public class MainActivity extends AppCompatActivity
|
|||
@Override
|
||||
public void onStop(){
|
||||
super.onStop();
|
||||
if( streamingIntent != null)
|
||||
StreamingService.shouldContinue = false;
|
||||
if( streamingIntent != null) {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
|
||||
editor.apply();
|
||||
}
|
||||
if( receive_data != null)
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
||||
if( receive_federated_data != null)
|
||||
|
|
Loading…
Reference in New Issue