/** * 用户博客列表 * * @param authoruid * @param pageIndex * @return * @throws AppException */ public BlogList getUserBlogList( int authoruid, String authorname, int pageIndex, boolean isRefresh) throws AppException { BlogList list = null; String key = "userbloglist_" + authoruid + "_" + (URLEncoder.encode(authorname)) + "_" + loginUid + "_" + pageIndex + "_" + PAGE_SIZE; if (isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) { try { list = ApiClient.getUserBlogList(this, authoruid, authorname, loginUid, pageIndex, PAGE_SIZE); if (list != null && pageIndex == 0) { Notice notice = list.getNotice(); list.setNotice(null); list.setCacheKey(key); saveObject(list, key); list.setNotice(notice); } } catch (AppException e) { list = (BlogList) readObject(key); if (list == null) throw e; } } else { list = (BlogList) readObject(key); if (list == null) list = new BlogList(); } return list; }
/** * 博客列表 * * @param type 推荐:recommend 最新:latest * @param pageIndex * @return * @throws AppException */ public BlogList getBlogList(String type, int pageIndex, boolean isRefresh) throws AppException { BlogList list = null; String key = "bloglist_" + type + "_" + pageIndex + "_" + PAGE_SIZE; if (isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) { try { list = ApiClient.getBlogList(this, type, pageIndex, PAGE_SIZE); if (list != null && pageIndex == 0) { Notice notice = list.getNotice(); list.setNotice(null); list.setCacheKey(key); saveObject(list, key); list.setNotice(notice); } } catch (AppException e) { list = (BlogList) readObject(key); if (list == null) throw e; } } else { list = (BlogList) readObject(key); if (list == null) list = new BlogList(); } return list; }
private void lvBlogHandleMessage(Message msg) { if (msg.what >= 0) { BlogList bloglist = (BlogList) msg.obj; Notice notice = bloglist.getNotice(); // 显示用户博客数量 String tabBlogText = String.format("博客(%d)", bloglist.getBlogsCount()); mTabBlog.setText(tabBlogText); // 处理listview数据 switch (msg.arg1) { case UIHelper.LISTVIEW_ACTION_INIT: case UIHelper.LISTVIEW_ACTION_REFRESH: case UIHelper.LISTVIEW_ACTION_CHANGE_CATALOG: lvBlogSumData = msg.what; lvBlogData.clear(); // 先清除原有数据 lvBlogData.addAll(bloglist.getBloglist()); break; case UIHelper.LISTVIEW_ACTION_SCROLL: lvBlogSumData += msg.what; if (lvBlogData.size() > 0) { for (Blog blog1 : bloglist.getBloglist()) { boolean b = false; for (Blog blog2 : lvBlogData) { if (blog1.getId() == blog2.getId()) { b = true; break; } } if (!b) lvBlogData.add(blog1); } } else { lvBlogData.addAll(bloglist.getBloglist()); } break; } if (msg.what < _pageSize) { curLvBlogDataState = UIHelper.LISTVIEW_DATA_FULL; lvBlogAdapter.notifyDataSetChanged(); lvBlog_foot_more.setText(R.string.load_full); } else if (msg.what == _pageSize) { curLvBlogDataState = UIHelper.LISTVIEW_DATA_MORE; lvBlogAdapter.notifyDataSetChanged(); lvBlog_foot_more.setText(R.string.load_more); } // 发送通知广播 if (msg.obj != null) { UIHelper.sendBroadCast(UserCenter.this, notice); } } else if (msg.what == -1) { // 有异常--显示加载出错 & 弹出错误消息 curLvBlogDataState = UIHelper.LISTVIEW_DATA_MORE; lvBlog_foot_more.setText(R.string.load_error); ((AppException) msg.obj).makeToast(UserCenter.this); } if (lvBlogData.size() == 0) { curLvBlogDataState = UIHelper.LISTVIEW_DATA_EMPTY; lvBlog_foot_more.setText(R.string.load_empty); } lvBlog_foot_progress.setVisibility(View.GONE); if (msg.arg1 == UIHelper.LISTVIEW_ACTION_REFRESH) { mLvBlog.onRefreshComplete( getString(R.string.pull_to_refresh_update) + new Date().toLocaleString()); mLvBlog.setSelection(0); } else if (msg.arg1 == UIHelper.LISTVIEW_ACTION_CHANGE_CATALOG) { mLvBlog.setSelection(0); } }