use of com.abewy.android.apps.klyph.adapter.animation.KlyphAnimationAdapter in project Klyph by jonathangerbaud.
the class StreamListFragment method populateNewest.
@Override
protected void populateNewest(List<GraphObject> data) {
int n = data.size();
if (n > 0) {
int index = getListView().getFirstVisiblePosition();
View v = getListView().getChildAt(index);
int top = v == null ? 0 : v.getTop();
int lastIndex = -1;
if (KlyphPreferences.getNewsfeedGoToTop() == false) {
List<GraphObject> list = new ArrayList<GraphObject>();
list.addAll(getAdapter().getItems());
// Looking for a matching post
outer: for (int i = 0; i < n; i++) {
Stream stream = (Stream) data.get(i);
for (int j = 0, m = list.size(); j < m; j++) {
if (list.get(j) instanceof Stream) {
Stream s = (Stream) list.get(j);
Log.d("StreamListFragment", "populateNewest: " + stream.getPost_id() + " " + s.getPost_id());
if (stream.getPost_id().equals(s.getPost_id())) {
lastIndex = i;
// list.add(stream);
break outer;
}
}
}
}
Log.d("StreamListFragment", "populateNewest: " + lastIndex);
// If no match, then insert all the data
if (lastIndex == -1)
lastIndex = data.size();
// Insert filtered data
for (int i = lastIndex - 1; i >= 0; i--) {
list.add(0, data.get(i));
}
getAdapter().clear(false);
getAdapter().addAll(list);
} else {
getAdapter().clear(false);
getAdapter().addAll(data);
setOffset(((Stream) data.get(data.size() - 1)).getCreated_time());
}
if (getListAdapter() instanceof KlyphAnimationAdapter) {
int firstVisiblePosition = getListView().getFirstVisiblePosition();
int lastVisiblePosition = getListView().getLastVisiblePosition();
if (firstVisiblePosition != lastVisiblePosition)
((KlyphAnimationAdapter) getListAdapter()).deactivateNext(lastVisiblePosition - firstVisiblePosition);
else
((KlyphAnimationAdapter) getListAdapter()).deactivateNext(1);
}
getAdapter().notifyDataSetChanged();
if (KlyphPreferences.getNewsfeedGoToTop() == false) {
getListView().setSelectionFromTop(lastIndex, top);
}
}
setNewestLoading(false);
setPullToRefreshRefreshing(false);
if (data.size() > 0) {
storeSessionStreams();
storeData();
}
}
Aggregations