Set UPDATE event as default event to catch 2 stuck elements

This commit is contained in:
tom79 2017-09-10 08:52:41 +02:00
parent 8d1b4a79de
commit d71e205999
3 changed files with 55 additions and 48 deletions

View File

@ -38,6 +38,7 @@ import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.SwitchCompat;
import android.util.Log;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
@ -706,7 +707,7 @@ public class MainActivity extends AppCompatActivity
unCheckAllMenuItems(navigationView);
toot.setVisibility(View.VISIBLE);
//Manages theme for icon colors
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_DARK){
changeDrawableColor(getApplicationContext(), R.drawable.ic_reply,R.color.dark_text);
@ -1162,5 +1163,4 @@ public class MainActivity extends AppCompatActivity
}
private static boolean activityVisible;
}

View File

@ -25,6 +25,7 @@ import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -258,27 +259,29 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
@Override
public void onResume() {
super.onResume();
//New data are available
statusesTmp = Helper.getTempStatus(context, null);
if (getUserVisibleHint() && statusesTmp != null && statusesTmp.size() > 0 && statuses.size() > 0) {
ArrayList<String> added = new ArrayList<>();
for(Status status : statuses){
added.add(status.getId());
}
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isOnWifi = Helper.isOnWIFI(context);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
for(int i = statusesTmp.size() -1 ; i >= 0 ; i--){
if( !added.contains(statusesTmp.get(i).getId())) {
this.statuses.add(0, statusesTmp.get(i));
added.add(statusesTmp.get(i).getId());
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
//New data are available
statusesTmp = Helper.getTempStatus(context, null);
if (getUserVisibleHint() && statusesTmp != null && statusesTmp.size() > 0 && statuses.size() > 0) {
ArrayList<String> added = new ArrayList<>();
for (Status status : statuses) {
added.add(status.getId());
}
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isOnWifi = Helper.isOnWIFI(context);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
for (int i = statusesTmp.size() - 1; i >= 0; i--) {
if (!added.contains(statusesTmp.get(i).getId())) {
this.statuses.add(0, statusesTmp.get(i));
added.add(statusesTmp.get(i).getId());
}
}
if (this.statuses.size() > 0)
max_id = this.statuses.get(this.statuses.size() - 1).getId();
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
lv_status.setAdapter(statusListAdapter);
}
if( this.statuses.size() > 0 )
max_id = this.statuses.get(this.statuses.size()-1).getId();
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
lv_status.setAdapter(statusListAdapter);
}
}
@ -382,35 +385,37 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
public void refresh(){
//New data are available
if( context == null)
return;
statusesTmp = Helper.getTempStatus(context, null);
if( statusesTmp.size() > 0){
ArrayList<String> added = new ArrayList<>();
for(Status status : statuses){
added.add(status.getId());
}
for(int i = statusesTmp.size() -1 ; i >= 0 ; i--){
if( !added.contains(statusesTmp.get(i).getId())) {
this.statuses.add(0, statusesTmp.get(i));
added.add(statusesTmp.get(i).getId());
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
if (context == null)
return;
statusesTmp = Helper.getTempStatus(context, null);
if (statusesTmp.size() > 0) {
ArrayList<String> added = new ArrayList<>();
for (Status status : statuses) {
added.add(status.getId());
}
for (int i = statusesTmp.size() - 1; i >= 0; i--) {
if (!added.contains(statusesTmp.get(i).getId())) {
this.statuses.add(0, statusesTmp.get(i));
added.add(statusesTmp.get(i).getId());
}
}
if (this.statuses.size() > 0)
max_id = this.statuses.get(this.statuses.size() - 1).getId();
boolean isOnWifi = Helper.isOnWIFI(context);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statusesTmp.get(0).getId());
editor.apply();
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
lv_status.setAdapter(statusListAdapter);
if (textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
}
if( this.statuses.size() > 0 )
max_id = this.statuses.get(this.statuses.size()-1).getId();
boolean isOnWifi = Helper.isOnWIFI(context);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statusesTmp.get(0).getId());
editor.apply();
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
lv_status.setAdapter(statusListAdapter);
if( textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
new_data.setVisibility(View.GONE);
}
new_data.setVisibility(View.GONE);
}
public void scrollToTop(){

View File

@ -219,7 +219,7 @@ public class StreamingService extends Service {
break;
}
if (event !=null){
if( lastEvent == EventStreaming.NONE || lastEvent == null) {
if( (lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
switch (event.trim()) {
case "event: update":
@ -247,6 +247,8 @@ public class StreamingService extends Service {
}else if( lastEvent == EventStreaming.DELETE) {
eventStreaming = EventStreaming.DELETE;
event = "{id:" + event + "}";
}else {
eventStreaming = EventStreaming.UPDATE;
}
lastEvent = EventStreaming.NONE;
try {