Search in sources :

Example 1 with CustomTabActivityHelper

use of io.plaidapp.core.util.customtabs.CustomTabActivityHelper in project plaid by nickbutcher.

the class StoryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_designer_news_story);
    long storyId = getIntent().getLongExtra(Activities.DesignerNews.Story.EXTRA_STORY_ID, -1);
    if (storyId == -1) {
        finishAfterTransition();
    }
    Injector.inject(storyId, this);
    bindResources();
    story = viewModel.getStory();
    viewModel.getUiModel().observe(this, storyUiModel -> setupComments(storyUiModel.getComments()));
    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);
    layoutManager = new LinearLayoutManager(this);
    commentsList.setLayoutManager(layoutManager);
    commentsList.setItemAnimator(new CommentAnimator(getResources().getInteger(io.plaidapp.R.integer.comment_expand_collapse_duration)));
    header = getLayoutInflater().inflate(R.layout.designer_news_story_description, commentsList, false);
    bindDescription();
    // setup title/toolbar
    if (collapsingToolbar != null) {
        // narrow device: collapsing toolbar
        collapsingToolbar.addOnLayoutChangeListener(titlebarLayout);
        collapsingToolbar.setTitle(story.getTitle());
        final Toolbar toolbar = findViewById(R.id.story_toolbar);
        toolbar.setNavigationOnClickListener(backClick);
        commentsList.addOnScrollListener(headerScrollListener);
        setEnterSharedElementCallback(new SharedElementCallback() {

            @Override
            public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(getIntent(), collapsingToolbar);
            }

            @Override
            public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(collapsingToolbar);
            }
        });
    } else {
        // w600dp configuration: content card scrolls over title bar
        final TextView title = findViewById(R.id.story_title);
        title.setText(story.getTitle());
        findViewById(R.id.back).setOnClickListener(backClick);
    }
    enterCommentView = setupCommentField();
    commentsAdapter = new DesignerNewsCommentsAdapter(header, new ArrayList<>(0), enterCommentView);
    commentsList.setAdapter(commentsAdapter);
    draggableFrame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    final int stableListPaddingBottom = commentsList.getPaddingBottom();
    final int stableListPaddingLeft = commentsList.getPaddingLeft();
    final int stableListPaddingRight = commentsList.getPaddingRight();
    final int stableFabMarginBottom = ((MarginLayoutParams) fab.getLayoutParams()).bottomMargin;
    final int stableFabMarginRight = ((MarginLayoutParams) fab.getLayoutParams()).rightMargin;
    final View back = findViewById(R.id.back);
    final int stableBackMarginLeft = back == null ? 0 : ((MarginLayoutParams) back.getLayoutParams()).leftMargin;
    draggableFrame.setOnApplyWindowInsetsListener((v, insets) -> {
        final MarginLayoutParams listLp = (MarginLayoutParams) v.getLayoutParams();
        listLp.topMargin = insets.getSystemWindowInsetTop();
        v.setLayoutParams(listLp);
        commentsList.setPadding(stableListPaddingLeft + commentsList.getPaddingLeft(), commentsList.getPaddingTop(), stableListPaddingRight + insets.getSystemWindowInsetRight(), stableListPaddingBottom + insets.getSystemWindowInsetBottom());
        final MarginLayoutParams fabLp = (MarginLayoutParams) fab.getLayoutParams();
        fabLp.rightMargin = stableFabMarginRight + insets.getSystemWindowInsetRight();
        fabLp.bottomMargin = stableFabMarginBottom + insets.getSystemWindowInsetBottom();
        fab.setLayoutParams(fabLp);
        if (back != null) {
            final MarginLayoutParams backLp = (MarginLayoutParams) back.getLayoutParams();
            backLp.leftMargin = stableBackMarginLeft + insets.getSystemWindowInsetLeft();
        }
        return insets;
    });
    customTab = new CustomTabActivityHelper();
    customTab.setConnectionCallback(customTabConnect);
}
Also used : ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) ElasticDragDismissFrameLayout(io.plaidapp.core.ui.widget.ElasticDragDismissFrameLayout) CustomTabActivityHelper(io.plaidapp.core.util.customtabs.CustomTabActivityHelper) TextView(android.widget.TextView) SharedElementCallback(android.app.SharedElementCallback) Toolbar(android.widget.Toolbar)

Aggregations

SharedElementCallback (android.app.SharedElementCallback)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Toolbar (android.widget.Toolbar)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ElasticDragDismissFrameLayout (io.plaidapp.core.ui.widget.ElasticDragDismissFrameLayout)1 CustomTabActivityHelper (io.plaidapp.core.util.customtabs.CustomTabActivityHelper)1 PinnedOffsetView (io.plaidapp.ui.widget.PinnedOffsetView)1 ArrayList (java.util.ArrayList)1