Search in sources :

Example 21 with CommentBean

use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.

the class CommentByMeTimeLineDBTask method addCommentLineMsg.

public static void addCommentLineMsg(CommentListBean list, String accountId) {
    Gson gson = new Gson();
    List<CommentBean> msgList = list.getItemList();
    DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), CommentByMeTable.CommentByMeDataTable.TABLE_NAME);
    final int mblogidColumn = ih.getColumnIndex(CommentByMeTable.CommentByMeDataTable.MBLOGID);
    final int accountidColumn = ih.getColumnIndex(CommentByMeTable.CommentByMeDataTable.ACCOUNTID);
    final int jsondataColumn = ih.getColumnIndex(CommentByMeTable.CommentByMeDataTable.JSONDATA);
    try {
        getWsd().beginTransaction();
        for (CommentBean msg : msgList) {
            ih.prepareForInsert();
            if (msg != null) {
                ih.bind(mblogidColumn, msg.getId());
                ih.bind(accountidColumn, accountId);
                String json = gson.toJson(msg);
                ih.bind(jsondataColumn, json);
            } else {
                ih.bind(mblogidColumn, "-1");
                ih.bind(accountidColumn, accountId);
                ih.bind(jsondataColumn, "");
            }
            ih.execute();
        }
        getWsd().setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        getWsd().endTransaction();
        ih.close();
    }
    reduceCommentTable(accountId);
}
Also used : SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 22 with CommentBean

use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.

the class CommentToMeTimeLineDBTask method addCommentLineMsg.

public static void addCommentLineMsg(CommentListBean list, String accountId) {
    Gson gson = new Gson();
    List<CommentBean> msgList = list.getItemList();
    DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), CommentsTable.CommentsDataTable.TABLE_NAME);
    final int mblogidColumn = ih.getColumnIndex(CommentsTable.CommentsDataTable.MBLOGID);
    final int accountidColumn = ih.getColumnIndex(CommentsTable.CommentsDataTable.ACCOUNTID);
    final int jsondataColumn = ih.getColumnIndex(CommentsTable.CommentsDataTable.JSONDATA);
    try {
        getWsd().beginTransaction();
        for (CommentBean msg : msgList) {
            ih.prepareForInsert();
            if (msg != null) {
                ih.bind(mblogidColumn, msg.getId());
                ih.bind(accountidColumn, accountId);
                String json = gson.toJson(msg);
                ih.bind(jsondataColumn, json);
            } else {
                ih.bind(mblogidColumn, "-1");
                ih.bind(accountidColumn, accountId);
                ih.bind(jsondataColumn, "");
            }
            ih.execute();
        }
        getWsd().setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        getWsd().endTransaction();
        ih.close();
    }
    reduceCommentTable(accountId);
}
Also used : SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 23 with CommentBean

use of org.qii.weiciyuan.bean.CommentBean 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 CommentBean

use of org.qii.weiciyuan.bean.CommentBean 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());
}
Also used : TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) CommentBean(org.qii.weiciyuan.bean.CommentBean) ViewTreeObserver(android.view.ViewTreeObserver)

Example 25 with CommentBean

use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.

the class DestroyCommentDao method destroy.

public boolean destroy() throws WeiboException {
    String url = URLHelper.COMMENT_DESTROY;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("cid", cid);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Post, url, map);
    Gson gson = new Gson();
    try {
        CommentBean value = gson.fromJson(jsonData, CommentBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
        return false;
    }
    return true;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Aggregations

CommentBean (org.qii.weiciyuan.bean.CommentBean)30 Gson (com.google.gson.Gson)13 JsonSyntaxException (com.google.gson.JsonSyntaxException)9 Intent (android.content.Intent)8 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 CommentListBean (org.qii.weiciyuan.bean.CommentListBean)7 TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)7 MessageBean (org.qii.weiciyuan.bean.MessageBean)6 CommentTimeLineData (org.qii.weiciyuan.bean.android.CommentTimeLineData)5 PendingIntent (android.app.PendingIntent)4 Cursor (android.database.Cursor)4 Notification (android.app.Notification)3 NotificationManager (android.app.NotificationManager)3 Context (android.content.Context)3 IntentFilter (android.content.IntentFilter)3 DatabaseUtils (android.database.DatabaseUtils)3 SQLException (android.database.SQLException)3 View (android.view.View)3 ListView (android.widget.ListView)3