/**
  * true = zoom in (bigger), else zoom out (smaller)
  *
  * @param bZoomIn
  */
 protected void changeTextZoom(boolean bZoomIn) {
   FragmentManager fm = getSupportFragmentManager();
   VideoStoryDetailFragment frag =
       (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
   if (frag != null) {
     frag.changeTextZoom(bZoomIn);
   }
 }
 private void updateFragmentTextZoommode() {
   FragmentManager fm = getSupportFragmentManager();
   VideoStoryDetailFragment frag =
       (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
   if (frag != null) {
     frag.resizeFontWebView();
   }
 }
  protected void socialLike() {
    // Collect story's information
    String[] data = null;
    FragmentManager fm = getSupportFragmentManager();
    VideoStoryDetailFragment frag =
        (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
    if (frag != null) {
      data = frag.getShareContent().split("%2C");
      GKIMLog.lf(null, 0, TAG + "=>socialLike: " + data.length);
    }

    if (data != null && data.length >= 4) {
      SocialHelper helper = SocialHelper.getInstance(this, 1);
      helper.like(data[3], data);
    }
  }
  protected void showCommentDialog() {
    if (mCommentDialog != null) {
      mCommentDialog = null;
    }
    if (mShareDialog != null && mShareDialog.isShowing()) {
      mShareDialog.dismiss();
    }
    FragmentManager fm = getSupportFragmentManager();
    VideoStoryDetailFragment frag =
        (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));

    mCommentDialog = new GUIStoryCommentDialog(this);
    mCommentDialog.setStoryId(mStoryId);
    mCommentDialog.setStoryTitle(frag.getStoryTitle());
    // FIXME: refresh story comment on Dialog's dismiss.
    mCommentDialog.setOnDismissListener(mOnDialogDismissListener);
    mCommentDialog.show();
  }
 private void updateFragmentTextmode(boolean bChecked) {
   FragmentManager fm = getSupportFragmentManager();
   VideoStoryDetailFragment frag =
       (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
   if (frag != null) {
     GKIMLog.lf(
         null,
         0,
         TAG
             + "=> update text mode: "
             + bChecked
             + " for fragment: "
             + frag.getStoryId()
             + " =>: "
             + frag.getStoryTitle());
     frag.changeTextMode(bChecked);
   }
 }
  protected void startCommentActivity(String storyId) {
    if (mIntentComment == null) {
      mIntentComment = new Intent(this, StoryDetailCommentActivity.class);
      mIntentComment.setFlags(
          Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
    }
    FragmentManager fm = getSupportFragmentManager();
    VideoStoryDetailFragment frag =
        (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));

    mIntentComment.putExtra(StoryDetailCommentActivity.EXTRA_STORY_TITLE, frag.getStoryTitle());
    mIntentComment.putExtra(StoryDetailCommentActivity.EXTRA_STORYID, storyId);
    int count = 0;
    if (mHashStoryCommentCount.containsKey(storyId)) {
      count = mHashStoryCommentCount.get(storyId);
    }
    mIntentComment.putExtra(StoryDetailCommentActivity.EXTRA_COMMENT_COUNT, count);
    startActivityForResult(mIntentComment, TNPreferenceManager.REQ_CODE_STORYDETAIL_COMMENT);
  }
  protected void socialShare(int networkId, int isstatus) {
    if (mShareDialog != null && mShareDialog.isShowing()) {
      mShareDialog.dismiss();
    }

    // Collect story's information
    String[] data = null;
    FragmentManager fm = getSupportFragmentManager();
    VideoStoryDetailFragment frag =
        (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
    if (frag != null) {
      data = frag.getShareContent().split("%2C");
      GKIMLog.lf(null, 0, TAG + "=>socialShare: " + data.length);
    }

    if (data != null && data.length >= 3) {
      // Progress SNS's strategy
      SocialHelper helper = SocialHelper.getInstance(this, networkId);
      // FIXME: add callback for listening result.
      helper.post(data, isstatus);
    }
  }
 private void onSessionStateChange(Session session, SessionState state, Exception exception) {
   GKIMLog.lf(this, 1, TAG + "=>onSessionStateChange.Actity");
   GKIMLog.l(4, "onSessionStateChange");
   if (session != null && session.isOpened()) {
     if (checksharelikefb == 1) {
       checksharelikefb = 0;
       socialShare(1, 0);
     } else if (checksharelikefb == 2) {
       checksharelikefb = 0;
       if (!mTabletVersion) {
         socialLike();
       } else {
         FragmentManager fm = getSupportFragmentManager();
         VideoStoryDetailFragment frag =
             (VideoStoryDetailFragment)
                 fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
         if (frag != null) {
           frag.socialLike();
         }
       }
     }
   }
 }
 @Override
 public void destroyItem(ViewGroup container, int position, Object object) {
   GKIMLog.lf(
       null,
       1,
       TAG
           + "=>destroyItem: "
           + position
           + ": "
           + mArrayStories[position]
           + ": "
           + ((VideoStoryDetailFragment) object).getStoryTitle());
   ((VideoStoryDetailFragment) object).MyDestroy();
   super.destroyItem(container, position, object);
 }
 @Override
 public boolean handleMessage(Message msg) {
   switch (msg.what) {
     case TNPreferenceManager.HANDLER_MSG_HAS_LOGGIN_CHANGED:
       GKIMLog.lf(null, 0, TAG + "=>login has changed.");
       // XXX: not correct on the UID from logout to login state.
       // boolean bLoggedIn = TNPreferenceManager.checkLoggedIn();
       if (mTabletVersion) {
         FragmentManager fm = getSupportFragmentManager();
         VideoStoryDetailFragment frag =
             (VideoStoryDetailFragment)
                 fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
         // if (bLoggedIn) {
         frag.setCheckSave(TNPreferenceManager.hasSavedStory(mStoryId));
         // } else {
         // frag.setCheckSave(false);
         // }
       } else {
         // if (bLoggedIn) {
         GKIMLog.l(1, TAG + " handleMessage call setSavedStory");
         setSavedStory(TNPreferenceManager.hasSavedStory(mStoryId));
         // } else {
         // setSavedStory(false);
         // }
       }
       hideGUIListMenu();
       return true;
     case TNPreferenceManager.HANDLER_MSG_HAS_STORYDETAIL_LOAD_COMPLETED:
       // Story activity will receive this event when a
       // StoryDetail is completely loaded in fragment.
       StoryDetail sd = (StoryDetail) msg.obj;
       if (sd == null || TextUtils.isEmpty(sd.getSectionid())) {
         return false;
       }
       String sectionid = sd.getSectionid();
       String storyid = String.valueOf(sd.getStoryid());
       try {
         if (mStoryId == null || storyid.equals(mStoryId)) {
           GKIMLog.lf(
               VideoStoryDetailFragmentActivity.this,
               0,
               TAG
                   + "=>myOnPageSelectedLogic, update section code from current story: "
                   + storyid
                   + ", section: "
                   + sectionid);
           TNPreferenceManager.updateCurrentStandingSectionId(sectionid);
         }
       } catch (Exception e) {
         GKIMLog.lf(
             VideoStoryDetailFragmentActivity.this,
             0,
             TAG
                 + "=> failed to get current section code from story: "
                 + sectionid
                 + ", "
                 + e.getMessage());
       }
       break;
     default:
       break;
   }
   return false;
 }
 protected void updateStoryComment(VideoStoryDetailFragment frag, String storyid) {
   if (frag != null) {
     frag.updateStoryComment();
   }
 }
  private void myOnPageSelectedLogic(int position) {
    // if(TNPreferenceManager.isConnectionAvailable()) {
    mStoryId = mPagerAdapter.getPageStoryId(position);
    GKIMLog.lf(null, 1, TAG + "=>onPageSelected: " + position + " story: " + mStoryId);
    TNPreferenceManager.putReadStory(mStoryId);

    String storyName = "";
    try {
      FragmentManager fm = getSupportFragmentManager();
      VideoStoryDetailFragment frag =
          (VideoStoryDetailFragment) fm.findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
      if (frag != null) {
        StoryDetail sd = frag.getStoryDetail();
        String sectionid = "";
        if (sd != null) {
          sectionid = sd.getSectionid();
          storyName = sd.getStorytitle();
        }
        GKIMLog.lf(this, 0, TAG + "=>myOnPageSelectedLogic, saving section code: " + sectionid);
        TNPreferenceManager.updateCurrentStandingSectionId(sectionid);
      }
    } catch (Exception e) {
      GKIMLog.lf(
          this,
          0,
          TAG
              + "=> failed to get current section code from story: "
              + mStoryId
              + ", "
              + e.getMessage());
    }
    HashMap<String, String> map = new HashMap<String, String>();
    map.put(TNPreferenceManager.EVENT_KEY_STORY_NAME, storyName);
    map.put(TNPreferenceManager.EVENT_KEY_STORY_ID, mStoryId);
    Tracking.sendEvent(TNPreferenceManager.EVENT_STORY_VIEW, map);

    updateFragmentTextmode(TNPreferenceManager.isNightMode());
    updateFragmentTextZoommode();
    if (!mTabletVersion) {
      int count = 0;
      if (mHashStoryCommentCount != null
          && mHashStoryCommentCount.containsKey(mStoryId)
          && mGuiFooter != null) {
        count = mHashStoryCommentCount.get(mStoryId);
      }
      mGuiFooter.setCommentCountView(count);
      count = 0;
      if (mHashStoryFBLikeCount != null && mHashStoryFBLikeCount.containsKey(mStoryId)) {
        count = mHashStoryFBLikeCount.get(mStoryId);
      }
      mGuiFooter.setFbLikeCountView(count);
    }
    // boolean bLoggedIn = TNPreferenceManager.checkLoggedIn();
    // if (bLoggedIn) {
    GKIMLog.l(1, TAG + " myOnPageSelectedLogic call setSavedStory");
    setSavedStory(TNPreferenceManager.hasSavedStory(mStoryId));
    // } else {
    // setSavedStory(false);
    // }

    if (mGuiFooter != null && !mTabletVersion) {
      int mFbLikeCount =
          getSharedPreferences(mStoryId + "_", Context.MODE_PRIVATE).getInt(mStoryId + "_", 0);
      boolean is = getSharedPreferences(mStoryId, Context.MODE_PRIVATE).getBoolean(mStoryId, false);
      TextView tvlikefb = (TextView) mGuiFooter.findViewById(R.id.tv_storydetail_fblike_count);
      tvlikefb.setText(mFbLikeCount + "");
      if (is) {
        tvlikefb.setBackgroundResource(R.drawable.ic_storyfooter_fblike_over);
      } else {
        tvlikefb.setBackgroundResource(R.drawable.ic_storyfooter_fblike);
      }
    }
  }
 /*
  * (non-Javadoc)
  *
  * @see android.support.v4.app.FragmentPagerAdapter#getItem(int)
  */
 @Override
 public Fragment getItem(int position) {
   GKIMLog.lf(null, 1, TAG + "=>getItem: " + position + ": " + mArrayStories[position]);
   return VideoStoryDetailFragment.create(mArrayStories[position]);
 }