コード例 #1
0
    public LongPressMenuListAdapter(HNPost post, int position) {
      pos = position;
      mPost = post;
      mIsLoggedIn = Settings.isUserLoggedIn(MainActivity.this);
      mUpVotingEnabled =
          !mIsLoggedIn
              || (mPost.getUpvoteURL(Settings.getUserName(MainActivity.this)) != null
                  && !mUpvotedPosts.contains(mPost));

      mItems = new ArrayList<CharSequence>();
      if (mUpVotingEnabled) mItems.add(getString(R.string.upvote));
      else mItems.add(getString(R.string.already_upvoted));
      mItems.addAll(
          Arrays.asList(
              getString(R.string.pref_htmlprovider_original_url),
              getString(R.string.pref_htmlprovider_viewtext),
              getString(R.string.pref_htmlprovider_google),
              getString(R.string.pref_htmlprovider_instapaper),
              getString(R.string.external_browser)));
    }
コード例 #2
0
 @Override
 public void onClick(DialogInterface dialog, int item) {
   switch (item) {
     case 0:
       if (!mIsLoggedIn)
         Toast.makeText(MainActivity.this, R.string.please_log_in, Toast.LENGTH_LONG).show();
       else if (mUpVotingEnabled)
         vote(mPost.getUpvoteURL(Settings.getUserName(MainActivity.this)), mPost);
       break;
     case 1:
     case 2:
     case 3:
     case 4:
       openPostInApp(pos, mPost, getItem(item).toString(), MainActivity.this);
       break;
     case 5:
       openURLInBrowser(getArticleViewURL(mPost), MainActivity.this);
       break;
     default:
       break;
   }
 }