Ejemplo n.º 1
0
  private void showAndLoadAuthorOnly() {
    while (mCache.get(mCurrentPage) != null && mCurrentPage <= mMaxPage) {
      addAuthorPosts(mCache.get(mCurrentPage));
      mCurrentPage++;
    }

    if (mCurrentPage <= mMaxPage) {
      Bundle b = new Bundle();
      b.putInt(LOADER_PAGE_KEY, mCurrentPage);
      getLoaderManager().restartLoader(0, b, mLoaderCallbacks).forceLoad();
    }
  }
Ejemplo n.º 2
0
  @Override
  public void onPostDone(int mode, int status, String message, PostBean postBean) {
    if (status == Constants.STATUS_SUCCESS) {
      if (postProgressDialog != null) {
        postProgressDialog.dismiss(message);
      } else {
        Toast.makeText(mCtx, message, Toast.LENGTH_SHORT).show();
      }

      if (!mAuthorOnly) {
        if (mode != PostAsyncTask.MODE_EDIT_POST) mCurrentPage = mMaxPage;

        int floor = LAST_FLOOR;
        if (!TextUtils.isEmpty(postBean.getFloor()) && TextUtils.isDigitsOnly(postBean.getFloor()))
          floor = Integer.parseInt(postBean.getFloor());
        if (floor == LAST_FLOOR || floor > 0) mFloorOfPage = floor;

        mCache.remove(mCurrentPage);
        showOrLoadPage();
      }

    } else {
      if (postProgressDialog != null) {
        postProgressDialog.dismissError(message);
      } else {
        Toast.makeText(mCtx, message, Toast.LENGTH_LONG).show();
      }
    }
  }
Ejemplo n.º 3
0
 private void addAuthorPosts(DetailListBean details) {
   for (DetailBean detail : details.getAll()) {
     if (detail.getAuthor().equals(mCache.get(1).getAll().get(0).getAuthor())) {
       mDetailBeans.add(detail);
     }
   }
   mDetailAdapter.setBeans(mDetailBeans);
 }
Ejemplo n.º 4
0
 private void prefetchNextPage(int pageOffset) {
   if (!mPrefetching && !mAuthorOnly && mCache.get(mCurrentPage + pageOffset) == null) {
     int page = mCurrentPage + pageOffset;
     if (page < 1 || page > mMaxPage) return;
     mPrefetching = true;
     Logger.v("prefetch page " + page);
     Bundle b = new Bundle();
     b.putInt(LOADER_PAGE_KEY, page);
     getLoaderManager().restartLoader(0, b, mLoaderCallbacks).forceLoad();
   }
 }
Ejemplo n.º 5
0
  private void showOrLoadPage() {

    setActionBarTitle(
        "("
            + (mCurrentPage > 0
                ? String.valueOf(mCurrentPage) + "/" + String.valueOf(mMaxPage) + ")"
                : "")
            + mTitle);

    if (mCache.get(mCurrentPage) != null) {
      mDetailBeans.clear();
      mDetailBeans.addAll(mCache.get(mCurrentPage).getAll());
      mDetailAdapter.setBeans(mDetailBeans);

      if (mFloorOfPage == LAST_FLOOR) {
        mDetailListView.setSelection(
            mDetailAdapter.getCount() - 1 + mDetailListView.getHeaderViewsCount());
      } else if (mFloorOfPage >= 0) {
        mDetailListView.setSelection(mFloorOfPage + mDetailListView.getHeaderViewsCount() - 1);
      } else {
        mDetailListView.setSelection(0);
      }

      mFloorOfPage = -1;
      mGotoPostId = null;

      // if current page loaded from cache, set prefetch flag for next page
      mPrefetching = false;

      setPullLoadStatus();

    } else {
      Bundle b = new Bundle();
      b.putInt(LOADER_PAGE_KEY, mCurrentPage);
      getLoaderManager().restartLoader(0, b, mLoaderCallbacks).forceLoad();
    }
  }
Ejemplo n.º 6
0
 public void startImageGallery(int imageIndex) {
   if (mAuthorOnly) {
     Toast.makeText(getActivity(), "请先退出只看楼主模式", Toast.LENGTH_LONG).show();
     return;
   }
   DetailListBean detailListBean = mCache.get(mCurrentPage);
   if (detailListBean == null) {
     Toast.makeText(getActivity(), "帖子还未加载完成", Toast.LENGTH_LONG).show();
     return;
   }
   if (detailListBean.getContentImages().size() > 0) {
     PopupImageDialog popupImageDialog = new PopupImageDialog();
     popupImageDialog.init(detailListBean, imageIndex);
     popupImageDialog.show(getFragmentManager(), PopupImageDialog.class.getName());
   } else {
     Toast.makeText(mCtx, "本页没有图片", Toast.LENGTH_SHORT).show();
   }
 }
Ejemplo n.º 7
0
 public DetailBean getCachedPost(String postId) {
   return mCache.getPostByPostId(postId);
 }
Ejemplo n.º 8
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    Logger.v("onOptionsItemSelected");
    switch (item.getItemId()) {
      case android.R.id.home:
        // Implemented in activity
        return false;
      case R.id.action_open_url:
        String url = HiUtils.DetailListUrl + mTid;
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
        return true;
      case R.id.action_copy_url:
        ClipboardManager clipboard =
            (ClipboardManager) mCtx.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip =
            ClipData.newPlainText("THREAD URL FROM HiPDA", HiUtils.DetailListUrl + mTid);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(mCtx, "帖子地址已经复制到粘贴板", Toast.LENGTH_SHORT).show();
        return true;
      case R.id.action_share_thread:
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = HiUtils.DetailListUrl + mTid + "\n" + "主题:" + mTitle + "\n";
        if (mCache.get(1) != null && mCache.get(1).getAll().size() > 0)
          shareBody += ("作者:" + mCache.get(1).getAll().get(0).getAuthor());
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, "分享帖子"));
        return true;
      case R.id.action_reply:
        setHasOptionsMenu(false);
        Bundle arguments = new Bundle();
        arguments.putString(PostFragment.ARG_TID_KEY, mTid);
        arguments.putInt(PostFragment.ARG_MODE_KEY, PostAsyncTask.MODE_REPLY_THREAD);
        PostFragment fragment = new PostFragment();
        fragment.setArguments(arguments);
        fragment.setPostListener(this);
        if (HiSettingsHelper.getInstance().getIsLandscape()) {
          getFragmentManager()
              .beginTransaction()
              .add(R.id.main_frame_container, fragment, PostFragment.class.getName())
              .addToBackStack(PostFragment.class.getName())
              .commit();
        } else {
          getFragmentManager()
              .beginTransaction()
              .add(R.id.main_frame_container, fragment, PostFragment.class.getName())
              .addToBackStack(PostFragment.class.getName())
              .commit();
        }

        return true;
      case R.id.action_refresh_detail:
        refresh();
        return true;
      case R.id.action_image_gallery:
        startImageGallery(0);
        return true;
        //            case R.id.action_goto:
        //                showGotoPageDialog();
        //                return true;
      case R.id.action_only_author:
        mAuthorOnly = !mAuthorOnly;
        mDetailBeans.clear();
        mDetailAdapter.setBeans(mDetailBeans);
        mCurrentPage = 1;
        if (mAuthorOnly) {
          mDetailListView.setPullLoadEnable(false);
          mDetailListView.setPullRefreshEnable(false);
          setActionBarTitle("(只看楼主)" + mTitle);
          showAndLoadAuthorOnly();
        } else {
          showOrLoadPage();
        }
        return true;
      case R.id.action_add_favorite:
        FavoriteHelper.getInstance().addFavorite(mCtx, mTid, mTitle);
        return true;
      case R.id.action_remove_favorite:
        FavoriteHelper.getInstance().removeFavorite(mCtx, mTid, mTitle);
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }