gt:         if ((position + 1) == MainActivity.posts.size()) {
context: /******************************************************************************
   *
   *  Copyright 2014 Paphus Solutions Inc.
   *
   *  Licensed under the Eclipse Public License, Version 1.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.eclipse.org/legal/epl-v10.html
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   ******************************************************************************/
  
  package org.botlibre.sdk.activity.forum;
  
  import org.botlibre.sdk.activity.LibreActivity;
  import org.botlibre.sdk.activity.MainActivity;
  import org.botlibre.sdk.activity.actions.HttpAction;
  import org.botlibre.sdk.activity.actions.HttpDeleteForumPostAction;
  import org.botlibre.sdk.activity.actions.HttpFetchForumPostAction;
  import org.botlibre.sdk.activity.actions.HttpFetchUserAction;
  import org.botlibre.sdk.activity.actions.HttpFlagForumPostAction;
  import org.botlibre.sdk.activity.actions.HttpGetImageAction;
  import org.botlibre.sdk.activity.actions.HttpStarPostAction;
  import org.botlibre.sdk.activity.actions.HttpSubscribeAction;
  import org.botlibre.sdk.activity.actions.HttpThumbsDownPostAction;
  import org.botlibre.sdk.activity.actions.HttpThumbsUpPostAction;
  import org.botlibre.sdk.activity.actions.HttpUnsubscribeAction;
  import org.botlibre.sdk.config.ForumPostConfig;
  import org.botlibre.sdk.config.UserConfig;
  import org.botlibre.sdk.util.Utils;
  
  import org.botlibre.sdk.R;
  
  import android.annotation.SuppressLint;
  import android.app.Dialog;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.view.GestureDetector;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.ListView;
  import android.widget.TextView;
  
  /**
   * Activity for viewing a forum post.
   */
  @SuppressLint("DefaultLocale")
  public class ForumPostActivity extends LibreActivity {
  	Menu menu;
  	ForumPostConfig instance;
  	
  	@Override
  	public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  		resetView();
  	}
  	
  	@Override
  	public void onResume() {
  		if (MainActivity.post != null && MainActivity.post.id.equals(this.instance.id)) {
  			this.instance = MainActivity.post;
  		} else {
  			MainActivity.post = this.instance;
  		}
  		resetView();
  		resetMenu();
  		super.onResume();
  	}
  	
  	@Override
      public boolean onCreateOptionsMenu(Menu menu)
      {
          MenuInflater menuInflater = getMenuInflater();
          menuInflater.inflate(R.layout.menu_post, menu);
          return true;
      }
  	
  	public void resetMenu() {
  		if (this.menu == null) {
  			return;
  		}
          for (int index = 0; index < menu.size(); index++) {
      	    menu.getItem(index).setEnabled(true);        	
          }
          
          boolean isAdmin = (MainActivity.user != null) && instance.isAdmin;
          if (!isAdmin) {
          	menu.findItem(R.id.menuEdit).setEnabled(false);
          	menu.findItem(R.id.menuDelete).setEnabled(false);
          }
          if (instance.isFlagged) {
          	menu.findItem(R.id.menuFlag).setEnabled(false);
          }
          if (instance.parent == null || instance.parent.length() == 0) {
          	menu.findItem(R.id.menuViewParent).setEnabled(false);        	
          }
          if (instance.replies == null || instance.replies.isEmpty()) {
          	menu.findItem(R.id.menuViewReply).setEnabled(false);
          }
          int position = MainActivity.posts.indexOf(this.instance);
          if (position < 0) {
          	menu.findItem(R.id.menuViewNext).setEnabled(false);
          	menu.findItem(R.id.menuViewPrevious).setEnabled(false);
          } else if (position == 0) {
          	menu.findItem(R.id.menuViewNext).setEnabled(false);        	
          }
          if ((position + 1) == MainActivity.posts.size()) {
          	menu.findItem(R.id.menuViewPrevious).setEnabled(false);
          }
  	}
  	
  	@Override
  	public boolean onPrepareOptionsMenu(Menu menu) {
  		this.menu = menu;
          resetMenu();
  	    return true;
  	}
  	
      @Override
      public boolean onOptionsItemSelected(MenuItem item)
      {
           
          switch (item.getItemId())
          {
          case R.id.menuViewReply:
          	viewReply();
              return true;
          case R.id.menuViewParent:
          	viewParent();
              return true;
          case R.id.menuViewNext:
          	viewNext();
              return true;
          case R.id.menuViewPrevious:
          	viewPrevious();
              return true;
          case R.id.menuViewUser:
          	viewUser();
              return true;
          case R.id.menuReply:
          	reply();
              return true;
          case R.id.menuEdit:
          	editPost();
              return true;
          case R.id.menuDelete:
          	deletePost();
              return true;
          case R.id.menuFlag:
          	flag();
              return true;
          case R.id.menuThumbsUp:
          	thumbsUp();
              return true;
          case R.id.menuThumbsDown:
          	thumbsDown();
              return true;
          case R.id.menuSubscribe:
          	subscribe();
              return true;
          case R.id.menuUnsubscribe:
          	unsubscribe();
              return true;
          case R.id.menuStar:
          	star();
              return true;
          default:
              return super.onOptionsItemSelected(item);
          }
      }
  
  	public void resetView() {
          this.instance = MainActivity.post;
          setContentView(R.layout.activity_forumpost);
  	
          ForumPostConfig instance = MainActivity.post;
          
          if (!instance.isFlagged) {
  	        findViewById(R.id.flaggedLabel).setVisibility(View.GONE);
          }
          
  		((TextView) findViewById(R.id.title)).setText(Utils.stripTags(instance.topic));
          
          TextView textView = (TextView) findViewById(R.id.tagsLabel);
          textView.setText(instance.tags);
          if (instance.tags == null || instance.tags.isEmpty()) {
          	textView.setVisibility(View.GONE);
          }
          textView = (TextView) findViewById(R.id.creationDateLabel);
          textView.setText("by " + instance.creator + " posted " + instance.displayCreationDate());
  
          textView = (TextView) findViewById(R.id.thumbsupLabel);
          textView.setText(String.valueOf(this.instance.thumbsUp));
          textView = (TextView) findViewById(R.id.thumbsdownLabel);
          textView.setText(String.valueOf(this.instance.thumbsDown));
          textView = (TextView) findViewById(R.id.starsLabel);
          textView.setText(String.valueOf(this.instance.stars));
          
          int position = MainActivity.posts.indexOf(this.instance);
          if (position < 0) {
          	findViewById(R.id.nextButton).setEnabled(false);
          	findViewById(R.id.nextButton).setAlpha(0.5f);
          	findViewById(R.id.previousButton).setEnabled(false);
          	findViewById(R.id.previousButton).setAlpha(0.5f);
          } else if (position == 0) {
          	findViewById(R.id.nextButton).setEnabled(false);
          	findViewById(R.id.nextButton).setAlpha(0.5f);
          }
  