Search in sources :

Example 21 with TimeLinePosition

use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.

the class FriendsTimeLineDBTask method getRecentGroupData.

public static MessageTimeLineData getRecentGroupData(String accountId) {
    String groupId = getRecentGroupId(accountId);
    MessageListBean msgList;
    TimeLinePosition position;
    if (groupId.equals("0")) {
        position = getPosition(accountId);
        msgList = getHomeLineMsgList(accountId, position.position + AppConfig.DB_CACHE_COUNT_OFFSET);
    } else {
        position = HomeOtherGroupTimeLineDBTask.getPosition(accountId, groupId);
        msgList = HomeOtherGroupTimeLineDBTask.get(accountId, groupId, position.position + AppConfig.DB_CACHE_COUNT_OFFSET);
    }
    return new MessageTimeLineData(groupId, msgList, position);
}
Also used : MessageListBean(org.qii.weiciyuan.bean.MessageListBean) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) MessageTimeLineData(org.qii.weiciyuan.bean.android.MessageTimeLineData)

Example 22 with TimeLinePosition

use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.

the class HomeOtherGroupTimeLineDBTask method getTimeLineData.

static MessageTimeLineData getTimeLineData(String accountId, String groupId) {
    TimeLinePosition position = getPosition(accountId, groupId);
    MessageListBean msgList = get(accountId, groupId, position.position + AppConfig.DB_CACHE_COUNT_OFFSET);
    return new MessageTimeLineData(groupId, msgList, position);
}
Also used : MessageListBean(org.qii.weiciyuan.bean.MessageListBean) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) MessageTimeLineData(org.qii.weiciyuan.bean.android.MessageTimeLineData)

Example 23 with TimeLinePosition

use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.

the class MentionsCommentTimeLineFragment method addNewDataAndRememberPosition.

private void addNewDataAndRememberPosition(final CommentListBean 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<CommentBean> unreadData = newValue.getItemList();
        for (CommentBean comment : unreadData) {
            if (comment != null) {
                MentionsCommentTimeLineFragment.this.timeLinePosition.newMsgIds.add(comment.getIdLong());
            }
        }
        newMsgTipBar.setValue(MentionsCommentTimeLineFragment.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(MentionsCommentTimeLineFragment.this.timeLinePosition.newMsgIds.size());
    MentionCommentsTimeLineDBTask.asyncReplace(getList(), accountBean.getUid());
}
Also used : TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) CommentBean(org.qii.weiciyuan.bean.CommentBean) ViewTreeObserver(android.view.ViewTreeObserver)

Example 24 with TimeLinePosition

use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.

the class MentionsCommentTimeLineFragment method saveTimeLinePositionToDB.

private void saveTimeLinePositionToDB() {
    TimeLinePosition current = Utility.getCurrentPositionFromListView(getListView());
    if (!current.isEmpty()) {
        timeLinePosition = current;
        timeLinePosition.newMsgIds = newMsgTipBar.getValues();
    }
    if (timeLinePosition != null) {
        MentionCommentsTimeLineDBTask.asyncUpdatePosition(timeLinePosition, accountBean.getUid());
    }
}
Also used : TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition)

Example 25 with TimeLinePosition

use of org.qii.weiciyuan.bean.android.TimeLinePosition in project weiciyuan by qii.

the class MentionsWeiboTimeLineFragment method saveTimeLinePositionToDB.

private void saveTimeLinePositionToDB() {
    TimeLinePosition current = Utility.getCurrentPositionFromListView(getListView());
    if (!current.isEmpty()) {
        timeLinePosition = current;
        timeLinePosition.newMsgIds = newMsgTipBar.getValues();
    }
    if (timeLinePosition != null) {
        MentionWeiboTimeLineDBTask.asyncUpdatePosition(timeLinePosition, accountBean.getUid());
    }
}
Also used : TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition)

Aggregations

TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)30 Cursor (android.database.Cursor)12 Gson (com.google.gson.Gson)12 JsonSyntaxException (com.google.gson.JsonSyntaxException)12 CommentBean (org.qii.weiciyuan.bean.CommentBean)7 ArrayList (java.util.ArrayList)5 CommentTimeLineData (org.qii.weiciyuan.bean.android.CommentTimeLineData)5 MessageListBean (org.qii.weiciyuan.bean.MessageListBean)4 ViewTreeObserver (android.view.ViewTreeObserver)3 HashMap (java.util.HashMap)3 CommentListBean (org.qii.weiciyuan.bean.CommentListBean)3 MessageBean (org.qii.weiciyuan.bean.MessageBean)3 MessageTimeLineData (org.qii.weiciyuan.bean.android.MessageTimeLineData)3 MentionTimeLineData (org.qii.weiciyuan.bean.android.MentionTimeLineData)2 View (android.view.View)1 WebView (android.webkit.WebView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 GroupBean (org.qii.weiciyuan.bean.GroupBean)1