Fixes scroll

This commit is contained in:
tom79 2017-10-06 07:16:12 +02:00
parent 1a7e93c8cc
commit becae0157a
1 changed files with 14 additions and 36 deletions

View File

@ -84,7 +84,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
private String instanceValue;
private String lastReadStatus;
private Intent streamingFederatedIntent, streamingLocalIntent;
private Date lastRefreshPublic, lastRefreshLocal;
public DisplayStatusFragment(){
}
@ -171,10 +170,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
if(!flag_loading ) {
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC)
lastRefreshPublic = new Date();
if( type == RetrieveFeedsAsyncTask.Type.LOCAL)
lastRefreshLocal = 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);
@ -201,8 +196,6 @@ 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)
@ -214,10 +207,6 @@ 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.LOCAL)
lastRefreshLocal = 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)
@ -395,18 +384,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
context.startService(streamingFederatedIntent);
}
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);
}
if( statuses != null && statuses.size() > 0)
retrieveMissingToots(statuses.get(0).getId());
}else if (type == RetrieveFeedsAsyncTask.Type.LOCAL){
@ -419,18 +398,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
context.startService(streamingLocalIntent);
}
Calendar date = Calendar.getInstance();
long t = date.getTimeInMillis();
Date newDate = new Date(t - TimeUnit.SECONDS.toMillis(20));
if( lastRefreshLocal.before(newDate)){
lastRefreshLocal = 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);
}
if( statuses != null && statuses.size() > 0)
retrieveMissingToots(statuses.get(0).getId());
}
}
@ -562,14 +531,23 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
for (Status st : this.statuses) {
knownId.add(st.getId());
}
int index = lv_status.getFirstVisiblePosition() + 1;
View v = lv_status.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
for (int i = statuses.size()-1 ; i >= 0 ; i--) {
if (!knownId.contains(statuses.get(i).getId())) {
statuses.get(i).setNew(true);
MainActivity.countNewStatus++;
statuses.get(i).setReplies(new ArrayList<Status>());
this.statuses.add(0, statuses.get(i));
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
if( !statuses.get(i).getAccount().getId().equals(userId))
MainActivity.countNewStatus++;
}
}
statusListAdapter.notifyDataSetChanged();
lv_status.setSelectionFromTop(index, top);
try {
((MainActivity) context).updateHomeCounter();
}catch (Exception ignored){}