Search in sources :

Example 1 with TimeLinePosition

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

the class AppNotificationCenter method addDatabaseUnreadCommentsToMe.

private void addDatabaseUnreadCommentsToMe(String accountId, CommentListBean mentions) {
    CommentTimeLineData dbData = CommentToMeTimeLineDBTask.getCommentLineMsgList(accountId);
    List<CommentBean> itemList = dbData.cmtList.getItemList();
    TimeLinePosition position = dbData.position;
    TreeSet<Long> newMsgIds = position.newMsgIds;
    HashMap<Long, CommentBean> map = new HashMap<>();
    for (CommentBean msg : itemList) {
        map.put(msg.getIdLong(), msg);
    }
    for (Object object : newMsgIds) {
        long id;
        if (object instanceof Double) {
            Double value = (Double) object;
            id = value.longValue();
        } else {
            id = (Long) object;
        }
        CommentBean msg = map.get(id);
        if (msg != null) {
            mentions.getItemList().add(msg);
        }
    }
}
Also used : HashMap(java.util.HashMap) CommentTimeLineData(org.qii.weiciyuan.bean.android.CommentTimeLineData) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 2 with TimeLinePosition

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

the class CommentByMeTimeLineDBTask method getCommentLineMsgList.

public static CommentTimeLineData getCommentLineMsgList(String accountId) {
    TimeLinePosition position = getPosition(accountId);
    CommentListBean result = new CommentListBean();
    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<CommentBean> msgList = new ArrayList<CommentBean>();
    String sql = "select * from " + CommentByMeTable.CommentByMeDataTable.TABLE_NAME + " where " + CommentByMeTable.CommentByMeDataTable.ACCOUNTID + "  = " + accountId + " order by " + CommentByMeTable.CommentByMeDataTable.MBLOGID + " desc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(CommentByMeTable.CommentByMeDataTable.JSONDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                CommentBean value = gson.fromJson(json, CommentBean.class);
                if (!value.isMiddleUnreadItem()) {
                    value.getListViewSpannableString();
                }
                msgList.add(value);
            } catch (JsonSyntaxException e) {
                AppLogger.e(e.getMessage());
            }
        } else {
            msgList.add(null);
        }
    }
    result.setComments(msgList);
    c.close();
    return new CommentTimeLineData(result, position);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) CommentTimeLineData(org.qii.weiciyuan.bean.android.CommentTimeLineData) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) CommentListBean(org.qii.weiciyuan.bean.CommentListBean) Cursor(android.database.Cursor) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 3 with TimeLinePosition

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

the class CommentByMeTimeLineDBTask method getPosition.

private static TimeLinePosition getPosition(String accountId) {
    String sql = "select * from " + CommentByMeTable.TABLE_NAME + " where " + CommentByMeTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(CommentByMeTable.TIMELINEDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
                c.close();
                return value;
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    c.close();
    return TimeLinePosition.empty();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Example 4 with TimeLinePosition

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

the class CommentToMeTimeLineDBTask method getPosition.

public static TimeLinePosition getPosition(String accountId) {
    String sql = "select * from " + CommentsTable.TABLE_NAME + " where " + CommentsTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(CommentsTable.TIMELINEDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
                c.close();
                return value;
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    c.close();
    return TimeLinePosition.empty();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Example 5 with TimeLinePosition

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

the class CommentToMeTimeLineDBTask method getCommentLineMsgList.

public static CommentTimeLineData getCommentLineMsgList(String accountId) {
    TimeLinePosition position = getPosition(accountId);
    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;
    CommentListBean result = new CommentListBean();
    List<CommentBean> msgList = new ArrayList<CommentBean>();
    String sql = "select * from " + CommentsTable.CommentsDataTable.TABLE_NAME + " where " + CommentsTable.CommentsDataTable.ACCOUNTID + "  = " + accountId + " order by " + CommentsTable.CommentsDataTable.MBLOGID + " desc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(CommentsTable.CommentsDataTable.JSONDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                CommentBean value = gson.fromJson(json, CommentBean.class);
                if (!value.isMiddleUnreadItem()) {
                    value.getListViewSpannableString();
                }
                msgList.add(value);
            } catch (JsonSyntaxException e) {
                AppLogger.e(e.getMessage());
            }
        } else {
            msgList.add(null);
        }
    }
    result.setComments(msgList);
    c.close();
    return new CommentTimeLineData(result, position);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) CommentTimeLineData(org.qii.weiciyuan.bean.android.CommentTimeLineData) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) CommentListBean(org.qii.weiciyuan.bean.CommentListBean) Cursor(android.database.Cursor) CommentBean(org.qii.weiciyuan.bean.CommentBean)

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