Search in sources :

Example 1 with Comment

use of io.plaidapp.data.api.designernews.model.Comment in project plaid by nickbutcher.

the class DesignerNewsStory method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_designer_news_story);
    ButterKnife.bind(this);
    story = getIntent().getParcelableExtra(EXTRA_STORY);
    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);
    markdown = new Bypass(this, new Bypass.Options().setBlockQuoteLineColor(ContextCompat.getColor(this, R.color.designer_news_quote_line)).setBlockQuoteLineWidth(// dps
    2).setBlockQuoteLineIndent(// dps
    8).setPreImageLinebreakHeight(//dps
    4).setBlockQuoteIndentSize(TypedValue.COMPLEX_UNIT_DIP, 2f).setBlockQuoteTextColor(ContextCompat.getColor(this, R.color.designer_news_quote)));
    circleTransform = new CircleTransform(this);
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    layoutManager = new LinearLayoutManager(this);
    commentsList.setLayoutManager(layoutManager);
    commentsList.setItemAnimator(new CommentAnimator(getResources().getInteger(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.title);
        final Toolbar 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 = (TextView) findViewById(R.id.story_title);
        title.setText(story.title);
        findViewById(R.id.back).setOnClickListener(backClick);
    }
    final View enterCommentView = setupCommentField();
    if (story.comment_count > 0) {
        // flatten the comments from a nested structure {@see Comment#comments} to a
        // list appropriate for our adapter (using the depth attribute).
        List<Comment> flattened = new ArrayList<>(story.comment_count);
        unnestComments(story.comments, flattened);
        commentsAdapter = new DesignerNewsCommentsAdapter(header, flattened, enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    } else {
        commentsAdapter = new DesignerNewsCommentsAdapter(header, new ArrayList<Comment>(0), enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    }
    customTab = new CustomTabActivityHelper();
    customTab.setConnectionCallback(customTabConnect);
}
Also used : ActivityOptions(android.app.ActivityOptions) Comment(io.plaidapp.data.api.designernews.model.Comment) ArrayList(java.util.ArrayList) CircleTransform(io.plaidapp.util.glide.CircleTransform) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) RecyclerView(android.support.v7.widget.RecyclerView) ElasticDragDismissFrameLayout(io.plaidapp.ui.widget.ElasticDragDismissFrameLayout) CustomTabActivityHelper(io.plaidapp.util.customtabs.CustomTabActivityHelper) Bypass(in.uncod.android.bypass.Bypass) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) SharedElementCallback(android.app.SharedElementCallback) Toolbar(android.widget.Toolbar)

Example 2 with Comment

use of io.plaidapp.data.api.designernews.model.Comment in project sbt-android by scala-android.

the class DesignerNewsStory method setupCommentField.

@NonNull
private View setupCommentField() {
    View enterCommentView = getLayoutInflater().inflate(R.layout.designer_news_enter_comment, commentsList, false);
    enterComment = (EditText) enterCommentView.findViewById(R.id.comment);
    postComment = (ImageButton) enterCommentView.findViewById(R.id.post_comment);
    postComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (designerNewsPrefs.isLoggedIn()) {
                if (TextUtils.isEmpty(enterComment.getText()))
                    return;
                enterComment.setEnabled(false);
                postComment.setEnabled(false);
                designerNewsApi.comment(story.id, enterComment.getText().toString(), new Callback<Comment>() {

                    @Override
                    public void success(Comment comment, Response response) {
                        enterComment.getText().clear();
                        enterComment.setEnabled(true);
                        postComment.setEnabled(true);
                        ((DesignerNewsCommentsAdapter) commentsList.getAdapter()).addComment(new ThreadedComment(0, comment));
                    }

                    @Override
                    public void failure(RetrofitError error) {
                        Toast.makeText(getApplicationContext(), "Failed to post comment :(", Toast.LENGTH_SHORT).show();
                        enterComment.setEnabled(true);
                        postComment.setEnabled(true);
                    }
                });
            } else {
                needsLogin(postComment, 0);
            }
            enterComment.clearFocus();
        }
    });
    enterComment.setOnFocusChangeListener(enterCommentFocus);
    return enterCommentView;
}
Also used : StoryResponse(io.plaidapp.data.api.designernews.model.StoryResponse) Response(retrofit.client.Response) Comment(io.plaidapp.data.api.designernews.model.Comment) Callback(retrofit.Callback) SharedElementCallback(android.app.SharedElementCallback) ImageView(android.widget.ImageView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) FontTextView(io.plaidapp.ui.widget.FontTextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) RecyclerView(android.support.v7.widget.RecyclerView) RetrofitError(retrofit.RetrofitError) NonNull(android.support.annotation.NonNull)

Aggregations

SharedElementCallback (android.app.SharedElementCallback)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Comment (io.plaidapp.data.api.designernews.model.Comment)2 AuthorTextView (io.plaidapp.ui.widget.AuthorTextView)2 PinnedOffsetView (io.plaidapp.ui.widget.PinnedOffsetView)2 ActivityOptions (android.app.ActivityOptions)1 NonNull (android.support.annotation.NonNull)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 SpannableString (android.text.SpannableString)1 Toolbar (android.widget.Toolbar)1 BindView (butterknife.BindView)1 Bypass (in.uncod.android.bypass.Bypass)1 StoryResponse (io.plaidapp.data.api.designernews.model.StoryResponse)1 ElasticDragDismissFrameLayout (io.plaidapp.ui.widget.ElasticDragDismissFrameLayout)1 FontTextView (io.plaidapp.ui.widget.FontTextView)1 CustomTabActivityHelper (io.plaidapp.util.customtabs.CustomTabActivityHelper)1 CircleTransform (io.plaidapp.util.glide.CircleTransform)1