@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); ButterKnife.bind(this); mCustomTabsHelperFragment = CustomTabsHelperFragment.attachTo(this); mCustomTabsIntent = new CustomTabsIntent.Builder() .enableUrlBarHiding() .setToolbarColor(mColorPrimary) .setShowTitle(true) .build(); mCustomTabsHelperFragment.setConnectionCallback( new CustomTabsActivityHelper.ConnectionCallback() { @Override public void onCustomTabsConnected() { mCustomTabsHelperFragment.mayLaunchUrl(PROJECT_URI, null, null); } @Override public void onCustomTabsDisconnected() {} }); mViewOnGitHubButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { CustomTabsHelperFragment.open( MainActivity.this, mCustomTabsIntent, PROJECT_URI, mCustomTabsFallback); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { TransitionUtils.setupTransitionBeforeDecorate(this); super.onCreate(savedInstanceState); setContentView(R.layout.broadcast_activity); TransitionUtils.setEnterReturnExplode(this); TransitionUtils.setupTransitionAfterSetContentView(this); ButterKnife.bind(this); CustomTabsHelperFragment.attachTo(this); mRetainDataFragment = RetainDataFragment.attachTo(this); mContentLayout.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { supportFinishAfterTransition(); } }); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mSwipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { loadBroadcast(true); } }); mBroadcastCommentList.setHasFixedSize(true); mBroadcastCommentList.setItemAnimator(new NoChangeAnimationItemAnimator()); mBroadcastCommentList.setLayoutManager(new LinearLayoutManager(this)); Broadcast broadcast = mRetainDataFragment.remove(RETAIN_DATA_KEY_BROADCAST); Intent intent = getIntent(); // Be consistent with what the user will see first. if (broadcast == null) { broadcast = intent.getParcelableExtra(EXTRA_BROADCAST); } if (broadcast == null) { if (intent.hasExtra(EXTRA_BROADCAST_ID)) { mBroadcastId = intent.getLongExtra(EXTRA_BROADCAST_ID, -1); } else { // TODO: Read from uri. // broadcastId = intent.getData(); } } else { mBroadcastId = broadcast.id; } mBroadcastAdapter = new SingleBroadcastAdapter(null, this); setBroadcast(broadcast); List<Comment> commentList = mRetainDataFragment.remove(RETAIN_DATA_KEY_COMMENT_LIST); mCommentAdapter = new CommentAdapter( commentList, new ClickableSimpleAdapter.OnItemClickListener<Comment, CommentAdapter.ViewHolder>() { @Override public void onItemClick( RecyclerView parent, Comment item, CommentAdapter.ViewHolder holder) { onShowCommentAction(item); } }); mAdapter = new LoadMoreAdapter(R.layout.load_more_item, mBroadcastAdapter, mCommentAdapter); mBroadcastCommentList.setAdapter(mAdapter); mBroadcastCommentList.addOnScrollListener( new OnVerticalScrollListener() { public void onScrolledToBottom() { loadCommentList(true); } }); mCanLoadMoreComments = mRetainDataFragment.removeBoolean(RETAIN_DATA_KEY_CAN_LOAD_MORE_COMMENTS, true); CheatSheetUtils.setup(mSendButton); mSendButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { onSendComment(); } }); mLoadingBroadcastOrCommentList = mRetainDataFragment.removeBoolean(RETAIN_DATA_KEY_LOADING_BROADCAST_OR_COMMENT_LIST, false); Boolean sendingComment = mRetainDataFragment.remove(RETAIN_DATA_KEY_SENDING_COMMENT); if (sendingComment != null) { setSendingComment(sendingComment); } // View only saves state influenced by user action, so we have to do this ourselves. ViewState viewState = mRetainDataFragment.remove(RETAIN_DATA_KEY_VIEW_STATE); if (viewState != null) { onRestoreViewState(viewState); } if (savedInstanceState == null) { boolean comment = getIntent().getBooleanExtra(EXTRA_COMMENT, false); if (comment) { TransitionUtils.postAfterTransition( this, new Runnable() { @Override public void run() { onComment(); } }); } } }