use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.
the class MentionsWeiboTimeLineFragment method addNewDataAndRememberPosition.
private void addNewDataAndRememberPosition(final MessageListBean newValue) {
AppLogger.i("Add new unread data to memory cache");
if (getActivity() == null || newValue.getSize() == 0) {
AppLogger.i("Activity is destroyed or new data count is zero, give up");
return;
}
final boolean isDataSourceEmpty = getList().getSize() == 0;
TimeLinePosition previousPosition = Utility.getCurrentPositionFromListView(getListView());
getList().addNewData(newValue);
if (isDataSourceEmpty) {
newMsgTipBar.setValue(newValue, true);
newMsgTipBar.clearAndReset();
getAdapter().notifyDataSetChanged();
AppLogger.i("Init data source is empty, ListView jump to zero position after refresh, first time open app? ");
getListView().setSelection(0);
saveTimeLinePositionToDB();
} else {
if (previousPosition.isEmpty() && timeLinePosition != null) {
previousPosition = timeLinePosition;
}
AppLogger.i("Previous first visible item id " + previousPosition.firstItemId);
getAdapter().notifyDataSetChanged();
List<MessageBean> unreadData = newValue.getItemList();
for (MessageBean message : unreadData) {
if (message != null) {
MentionsWeiboTimeLineFragment.this.timeLinePosition.newMsgIds.add(message.getIdLong());
}
}
newMsgTipBar.setValue(MentionsWeiboTimeLineFragment.this.timeLinePosition.newMsgIds);
int positionInAdapter = Utility.getAdapterPositionFromItemId(getAdapter(), previousPosition.firstItemId);
//use 1 px to show newMsgTipBar
AppLogger.i("ListView restore to previous position " + positionInAdapter);
getListView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getListView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
AppLogger.i("Save ListView position to database");
saveTimeLinePositionToDB();
}
});
Utility.setListViewAdapterPosition(getListView(), positionInAdapter, previousPosition.top - 1, null);
}
showUIUnreadCount(MentionsWeiboTimeLineFragment.this.timeLinePosition.newMsgIds.size());
MentionWeiboTimeLineDBTask.asyncReplace(getList(), accountBean.getUid());
}
use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.
the class FriendsTimeLineFragment method savePositionToPositionsCache.
private void savePositionToPositionsCache() {
TimeLinePosition current = Utility.getCurrentPositionFromListView(getListView());
if (!current.isEmpty()) {
positionCache.put(currentGroupId, current);
AppLogger.i("Current ListView position first visible item id " + current.firstItemId + " , save to memory cache");
} else {
AppLogger.i("Cant get correct current ListView position, so use previous database data");
}
}
use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.
the class MentionWeiboTimeLineDBTask method getRepostLineMsgList.
public static MentionTimeLineData getRepostLineMsgList(String accountId) {
TimeLinePosition position = getPosition(accountId);
Gson gson = new Gson();
MessageListBean result = new MessageListBean();
int limit = position.position + AppConfig.DB_CACHE_COUNT_OFFSET > AppConfig.DEFAULT_MSG_COUNT_50 ? position.position + AppConfig.DB_CACHE_COUNT_OFFSET : AppConfig.DEFAULT_MSG_COUNT_50;
List<MessageBean> msgList = new ArrayList<MessageBean>();
String sql = "select * from " + RepostsTable.RepostDataTable.TABLE_NAME + " where " + RepostsTable.RepostDataTable.ACCOUNTID + " = " + accountId + " order by " + RepostsTable.RepostDataTable.MBLOGID + " desc limit " + limit;
Cursor c = getRsd().rawQuery(sql, null);
while (c.moveToNext()) {
String json = c.getString(c.getColumnIndex(RepostsTable.RepostDataTable.JSONDATA));
if (!TextUtils.isEmpty(json)) {
try {
MessageBean value = gson.fromJson(json, MessageBean.class);
if (!value.isMiddleUnreadItem()) {
value.getListViewSpannableString();
}
msgList.add(value);
} catch (JsonSyntaxException e) {
AppLogger.e(e.getMessage());
}
} else {
msgList.add(null);
}
}
result.setStatuses(msgList);
c.close();
MentionTimeLineData mentionTimeLineData = new MentionTimeLineData(result, position);
return mentionTimeLineData;
}
use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.
the class CommentsToMeTimeLineFragment method addNewDataAndRememberPosition.
private void addNewDataAndRememberPosition(final CommentListBean newValue, boolean ignored) /**unused**/
{
AppLogger.i("Add new unread data to memory cache");
if (getActivity() == null || newValue.getSize() == 0) {
AppLogger.i("Activity is destroyed or new data count is zero, give up");
return;
}
final boolean isDataSourceEmpty = getList().getSize() == 0;
TimeLinePosition previousPosition = Utility.getCurrentPositionFromListView(getListView());
getList().addNewData(newValue);
if (isDataSourceEmpty) {
newMsgTipBar.setValue(newValue, true);
newMsgTipBar.clearAndReset();
getAdapter().notifyDataSetChanged();
AppLogger.i("Init data source is empty, ListView jump to zero position after refresh, first time open app? ");
getListView().setSelection(0);
saveTimeLinePositionToDB();
} else {
if (previousPosition.isEmpty() && timeLinePosition != null) {
previousPosition = timeLinePosition;
}
AppLogger.i("Previous first visible item id " + previousPosition.firstItemId);
getAdapter().notifyDataSetChanged();
List<CommentBean> unreadData = newValue.getItemList();
for (CommentBean comment : unreadData) {
if (comment != null) {
CommentsToMeTimeLineFragment.this.timeLinePosition.newMsgIds.add(comment.getIdLong());
}
}
newMsgTipBar.setValue(CommentsToMeTimeLineFragment.this.timeLinePosition.newMsgIds);
int positionInAdapter = Utility.getAdapterPositionFromItemId(getAdapter(), previousPosition.firstItemId);
//use 1 px to show newMsgTipBar
AppLogger.i("ListView restore to previous position " + positionInAdapter);
getListView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getListView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
AppLogger.i("Save ListView position to database");
saveTimeLinePositionToDB();
}
});
Utility.setListViewAdapterPosition(getListView(), positionInAdapter, previousPosition.top - 1, null);
}
showUIUnreadCount(CommentsToMeTimeLineFragment.this.timeLinePosition.newMsgIds.size());
CommentToMeTimeLineDBTask.asyncReplace(getList(), accountBean.getUid());
}
use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.
the class Utility method getCurrentPositionFromListView.
public static TimeLinePosition getCurrentPositionFromListView(ListView listView) {
if (listView.getChildCount() == 0) {
AppLogger.i("ListView child count is empty, maybe this ListView have not be visible to user");
return TimeLinePosition.empty();
}
AppLogger.i("ListView child count " + listView.getChildCount());
View view = listView.getChildAt(0);
int top = (view != null ? view.getTop() : 0);
/**
* warning: listView.getFirstVisiblePosition() return position include headerview count (HeaderAdapter) and use java
* reflection to set mFirstPosition when call setSelectionFromTop/setSelectionAfterHeaderView/setSelection
* see HeaderListView.java
*
*/
int firstVisiblePosition = listView.getFirstVisiblePosition();
if (firstVisiblePosition < listView.getHeaderViewsCount()) {
/**
* for example, if header view count is 2, firstVisiblePosition is 1, then listView getItemIdAtPosition(1)
* will return the second header view id -1, so we have to set firstVisiblePosition to 2 to get your
* actual adapter's first item id
*/
AppLogger.i("ListView first visible position is " + firstVisiblePosition + " it below header view count " + listView.getHeaderViewsCount() + " so set header view count to it");
firstVisiblePosition = listView.getHeaderViewsCount();
}
AppLogger.i("ListView first visible position " + firstVisiblePosition);
long firstVisibleId = listView.getItemIdAtPosition(firstVisiblePosition);
AppLogger.i("ListView first visible id " + firstVisibleId);
return new TimeLinePosition(firstVisibleId, top, listView.getFirstVisiblePosition());
}
Aggregations