/** Show {@link android.app.AlertDialog} when reply content is not empty. */ @Override public void onBackPressed() { if (mReplyFragment.isEmoticonKeyboardShowing()) { mReplyFragment.hideEmoticonKeyboard(); } else if (mReplyFragment.isReplyEmpty()) { super.onBackPressed(); } else { new ReplyDiscardPromptDialogFragment() .show(getSupportFragmentManager(), ReplyDiscardPromptDialogFragment.TAG); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base_without_drawer); setupNavCrossIcon(); Intent intent = getIntent(); String quotePostId = intent.getStringExtra(ARG_QUOTE_POST_ID); String titlePrefix = TextUtils.isEmpty(quotePostId) ? getString(R.string.reply_activity_title_prefix) : getString( R.string.reply_activity_quote_title_prefix, intent.getStringExtra(ARG_QUOTE_POST_COUNT)); setTitle( titlePrefix + StringUtils.defaultString( intent.getStringExtra(ARG_THREAD_TITLE), StringUtils.EMPTY)); FragmentManager fragmentManager = getSupportFragmentManager(); Fragment fragment = fragmentManager.findFragmentByTag(ReplyFragment.TAG); if (fragment == null) { mReplyFragment = ReplyFragment.newInstance(intent.getStringExtra(ARG_THREAD_ID), quotePostId); fragmentManager .beginTransaction() .add(R.id.frame_layout, mReplyFragment, ReplyFragment.TAG) .commit(); } else { mReplyFragment = (ReplyFragment) fragment; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (mReplyFragment.isReplyEmpty()) { finish(); } else { new ReplyDiscardPromptDialogFragment() .show(getSupportFragmentManager(), ReplyDiscardPromptDialogFragment.TAG); } return true; } return super.onOptionsItemSelected(item); }