@Override
  public void onActivityCreated(Bundle aSavedState) {
    super.onActivityCreated(aSavedState);

    setRetainInstance(true);

    mMessage.setBackgroundColor(mPrefs.postBackgroundColor);
    mMessage.setTextColor(mPrefs.postFontColor);

    mExtras = getExtras();
    mReplyType = mExtras.getInt(Constants.EDITING, getArguments().getInt(Constants.EDITING, -1));
    mPostId = mExtras.getInt(Constants.POST_ID, getArguments().getInt(Constants.POST_ID, -1));
    mThreadId = mExtras.getInt(Constants.THREAD_ID, getArguments().getInt(Constants.THREAD_ID, -1));
    if (mReplyType < 0
        || mThreadId < 0
        || (mReplyType != AwfulMessage.TYPE_NEW_REPLY && mPostId < 0)) {
      Log.e(TAG, "MISSING ARGUMENTS!");
      getActivity().finish();
    }

    ((AwfulActivity) getActivity()).registerSyncService(mMessenger, mThreadId);
    getActivity()
        .getSupportLoaderManager()
        .restartLoader(Constants.REPLY_LOADER_ID, null, mReplyDataCallback);
    getActivity()
        .getContentResolver()
        .registerContentObserver(AwfulMessage.CONTENT_URI_REPLY, true, mReplyDataCallback);

    if (((AwfulActivity) getActivity()).isTV()) {
      mTitle.setText(getString(R.string.post_reply));
      mSubmit.setOnClickListener(onSubmitClick);
    }
  }
 @Override
 public void onDestroyView() {
   super.onDestroyView();
   // ((AwfulActivity) getActivity()).unregisterSyncService(mMessenger, mThreadId);//this is
   // causing the threadview to lose its sync
   getActivity().getSupportLoaderManager().destroyLoader(mThreadId);
   getActivity().getContentResolver().unregisterContentObserver(mReplyDataCallback);
 }
 @Override
 public void onDestroy() {
   super.onDestroy();
   cleanupTasks();
   if (getActivity() != null) {
     if (getActivity() instanceof PostReplyActivity) {
     } else {
       ((ThreadDisplayActivity) getActivity()).refreshInfo();
       ((ThreadDisplayActivity) getActivity()).refreshThread();
     }
   }
 }
  @Override
  public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedState) {
    super.onCreateView(aInflater, aContainer, aSavedState);

    View result = aInflater.inflate(R.layout.post_reply, aContainer, false);

    mMessage = (EditText) result.findViewById(R.id.post_message);
    result.findViewById(R.id.bbcode).setOnClickListener(this);
    result.findViewById(R.id.emotes).setOnClickListener(this);
    mPrefs = new AwfulPreferences(getActivity());

    return result;
  }
 @Override
 public void handleMessage(Message aMsg) {
   Log.i(TAG, "Received Message:" + aMsg.what + " " + aMsg.arg1 + " " + aMsg.arg2);
   switch (aMsg.arg1) {
     case AwfulSyncService.Status.OKAY:
       loadingSucceeded();
       if (mDialog != null) {
         mDialog.dismiss();
         mDialog = null;
       }
       if (aMsg.what == AwfulSyncService.MSG_FETCH_POST_REPLY) {
         refreshLoader();
       }
       if (aMsg.what == AwfulSyncService.MSG_SEND_POST) {
         sendSuccessful = true;
         if (getActivity() != null) {
           Toast.makeText(
                   getActivity(),
                   getActivity().getString(R.string.post_sent),
                   Toast.LENGTH_LONG)
               .show();
           leave();
         }
       }
       break;
     case AwfulSyncService.Status.WORKING:
       loadingStarted();
       break;
     case AwfulSyncService.Status.ERROR:
       loadingFailed();
       if (mDialog != null) {
         mDialog.dismiss();
         mDialog = null;
       }
       if (aMsg.what == AwfulSyncService.MSG_SEND_POST) {
         saveReply();
         if (getActivity() != null) {
           Toast.makeText(
                   getActivity(), "Post Failed to Send! Message Saved...", Toast.LENGTH_LONG)
               .show();
         }
       }
       if (aMsg.what == AwfulSyncService.MSG_FETCH_POST_REPLY && getActivity() != null) {
         Toast.makeText(getActivity(), "Reply Load Failed!", Toast.LENGTH_LONG).show();
       }
       break;
     default:
       super.handleMessage(aMsg);
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    new Thread(
            new Runnable() {
              public void run() {
                GoogleAnalyticsTracker.getInstance().trackPageView("/PostReplyFragment");
                GoogleAnalyticsTracker.getInstance().dispatch();
              }
            })
        .start();

    if (!((AwfulActivity) getActivity()).isTV()) {
      setHasOptionsMenu(true);
    }
  }
 @Override
 public void onStop() {
   super.onStop();
   if (!sendSuccessful) {
     if (mMessage
         .getText()
         .toString()
         .replaceAll("\\s", "")
         .equalsIgnoreCase(originalReplyData.replaceAll("\\s", ""))) {
       Log.i(TAG, "Message unchanged, discarding.");
       deleteReply(); // if the reply is unchanged, throw it out.
     } else {
       Log.i(TAG, "Message Unsent, saving.");
       saveReply();
     }
   }
   cleanupTasks();
 }
 @Override
 public void onDetach() {
   super.onDetach();
   mSelection = mMessage.getSelectionStart();
 }
  @Override
  public void onPause() {
    super.onPause();

    cleanupTasks();
  }
 @Override
 public void onResume() {
   super.onResume();
 }