Example #1
0
 /**
  * 博客详情
  *
  * @param blog_id
  * @return
  * @throws AppException
  */
 public Blog getBlog(int blog_id, boolean isRefresh) throws AppException {
   Blog blog = null;
   String key = "blog_" + blog_id;
   if (isNetworkConnected() && (!isReadDataCache(key) || isRefresh)) {
     try {
       blog = ApiClient.getBlogDetail(this, blog_id);
       if (blog != null) {
         Notice notice = blog.getNotice();
         blog.setNotice(null);
         blog.setCacheKey(key);
         saveObject(blog, key);
         blog.setNotice(notice);
       }
     } catch (AppException e) {
       blog = (Blog) readObject(key);
       if (blog == null) throw e;
     }
   } else {
     blog = (Blog) readObject(key);
     if (blog == null) blog = new Blog();
   }
   return blog;
 }
 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);
   }
 }