Search in sources :

Example 1 with FabOverlapTextView

use of io.plaidapp.ui.widget.FabOverlapTextView in project sbt-android by scala-android.

the class DribbbleShot method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dribbble_shot);
    shot = getIntent().getParcelableExtra(EXTRA_SHOT);
    setupDribbble();
    setExitSharedElementCallback(fabLoginSharedElementCallback);
    getWindow().getSharedElementReturnTransition().addListener(shotReturnHomeListener);
    Resources res = getResources();
    ButterKnife.bind(this);
    View shotDescription = getLayoutInflater().inflate(R.layout.dribbble_shot_description, commentsList, false);
    shotSpacer = shotDescription.findViewById(R.id.shot_spacer);
    title = shotDescription.findViewById(R.id.shot_title);
    description = (TextView) shotDescription.findViewById(R.id.shot_description);
    shotActions = (LinearLayout) shotDescription.findViewById(R.id.shot_actions);
    likeCount = (Button) shotDescription.findViewById(R.id.shot_like_count);
    viewCount = (Button) shotDescription.findViewById(R.id.shot_view_count);
    share = (Button) shotDescription.findViewById(R.id.shot_share_action);
    playerName = (TextView) shotDescription.findViewById(R.id.player_name);
    playerAvatar = (ImageView) shotDescription.findViewById(R.id.player_avatar);
    shotTimeAgo = (TextView) shotDescription.findViewById(R.id.shot_time_ago);
    commentsList = (ListView) findViewById(R.id.dribbble_comments);
    commentsList.addHeaderView(shotDescription);
    View enterCommentView = getLayoutInflater().inflate(R.layout.dribbble_enter_comment, commentsList, false);
    userAvatar = (ForegroundImageView) enterCommentView.findViewById(R.id.avatar);
    enterComment = (EditText) enterCommentView.findViewById(R.id.comment);
    postComment = (ImageButton) enterCommentView.findViewById(R.id.post_comment);
    enterComment.setOnFocusChangeListener(enterCommentFocus);
    commentsList.addFooterView(enterCommentView);
    commentsList.setOnScrollListener(scrollListener);
    back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            expandImageAndFinish();
        }
    });
    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(getWindow()) {

        @Override
        public void onDragDismissed() {
            expandImageAndFinish();
        }
    };
    circleTransform = new CircleTransform(this);
    // load the main image
    Glide.with(this).load(shot.images.best()).listener(shotLoadListener).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.IMMEDIATE).into(imageView);
    imageView.setOnClickListener(shotClick);
    shotSpacer.setOnClickListener(shotClick);
    postponeEnterTransition();
    imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            imageView.getViewTreeObserver().removeOnPreDrawListener(this);
            calculateFabPosition();
            enterAnimation();
            startPostponedEnterTransition();
            return true;
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        ((FabOverlapTextView) title).setText(shot.title);
    } else {
        ((TextView) title).setText(shot.title);
    }
    if (!TextUtils.isEmpty(shot.description)) {
        HtmlUtils.setTextWithNiceLinks(description, shot.getParsedDescription(description));
    } else {
        description.setVisibility(View.GONE);
    }
    NumberFormat nf = NumberFormat.getInstance();
    likeCount.setText(res.getQuantityString(R.plurals.likes, (int) shot.likes_count, nf.format(shot.likes_count)));
    // TODO onClick show likes
    viewCount.setText(res.getQuantityString(R.plurals.views, (int) shot.views_count, nf.format(shot.views_count)));
    share.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new ShareDribbbleImageTask(DribbbleShot.this, shot).execute();
        }
    });
    if (shot.user != null) {
        playerName.setText("–" + shot.user.name);
        Glide.with(this).load(shot.user.avatar_url).transform(circleTransform).placeholder(R.drawable.avatar_placeholder).into(playerAvatar);
        playerAvatar.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                DribbbleShot.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(shot.user.html_url)));
            }
        });
        if (shot.created_at != null) {
            shotTimeAgo.setText(DateUtils.getRelativeTimeSpanString(shot.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS));
        }
    } else {
        playerName.setVisibility(View.GONE);
        playerAvatar.setVisibility(View.GONE);
        shotTimeAgo.setVisibility(View.GONE);
    }
    if (shot.comments_count > 0) {
        loadComments();
    } else {
        commentsList.setAdapter(getNoCommentsAdapter());
    }
    if (dribbblePrefs.isLoggedIn() && !TextUtils.isEmpty(dribbblePrefs.getUserAvatar())) {
        Glide.with(this).load(dribbblePrefs.getUserAvatar()).transform(circleTransform).placeholder(R.drawable.ic_player).into(userAvatar);
    }
}
Also used : CircleTransform(io.plaidapp.util.glide.CircleTransform) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) FabOverlapTextView(io.plaidapp.ui.widget.FabOverlapTextView) ImageView(android.widget.ImageView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) ForegroundImageView(io.plaidapp.ui.widget.ForegroundImageView) TextView(android.widget.TextView) ListView(android.widget.ListView) FabOverlapTextView(io.plaidapp.ui.widget.FabOverlapTextView) ParallaxScrimageView(io.plaidapp.ui.widget.ParallaxScrimageView) AbsListView(android.widget.AbsListView) ElasticDragDismissFrameLayout(io.plaidapp.ui.widget.ElasticDragDismissFrameLayout) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) FabOverlapTextView(io.plaidapp.ui.widget.FabOverlapTextView) Resources(android.content.res.Resources) ViewTreeObserver(android.view.ViewTreeObserver) NumberFormat(java.text.NumberFormat)

Example 2 with FabOverlapTextView

use of io.plaidapp.ui.widget.FabOverlapTextView in project plaid by nickbutcher.

the class DribbbleShot method bindShot.

void bindShot(final boolean postponeEnterTransition) {
    final Resources res = getResources();
    // load the main image
    final int[] imageSize = shot.images.bestSize();
    Glide.with(this).load(shot.images.best()).listener(shotLoadListener).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.IMMEDIATE).override(imageSize[0], imageSize[1]).into(imageView);
    imageView.setOnClickListener(shotClick);
    shotSpacer.setOnClickListener(shotClick);
    if (postponeEnterTransition)
        postponeEnterTransition();
    imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            imageView.getViewTreeObserver().removeOnPreDrawListener(this);
            calculateFabPosition();
            if (postponeEnterTransition)
                startPostponedEnterTransition();
            return true;
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        ((FabOverlapTextView) title).setText(shot.title);
    } else {
        ((TextView) title).setText(shot.title);
    }
    if (!TextUtils.isEmpty(shot.description)) {
        final Spanned descText = shot.getParsedDescription(ContextCompat.getColorStateList(this, R.color.dribbble_links), ContextCompat.getColor(this, R.color.dribbble_link_highlight));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            ((FabOverlapTextView) description).setText(descText);
        } else {
            HtmlUtils.setTextWithNiceLinks((TextView) description, descText);
        }
    } else {
        description.setVisibility(View.GONE);
    }
    NumberFormat nf = NumberFormat.getInstance();
    likeCount.setText(res.getQuantityString(R.plurals.likes, (int) shot.likes_count, nf.format(shot.likes_count)));
    likeCount.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) likeCount.getCompoundDrawables()[1]).start();
            if (shot.likes_count > 0) {
                PlayerSheet.start(DribbbleShot.this, shot);
            }
        }
    });
    if (shot.likes_count == 0) {
        // clear touch ripple if doesn't do anything
        likeCount.setBackground(null);
    }
    viewCount.setText(res.getQuantityString(R.plurals.views, (int) shot.views_count, nf.format(shot.views_count)));
    viewCount.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) viewCount.getCompoundDrawables()[1]).start();
        }
    });
    share.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
            new ShareDribbbleImageTask(DribbbleShot.this, shot).execute();
        }
    });
    if (shot.user != null) {
        playerName.setText(shot.user.name.toLowerCase());
        Glide.with(this).load(shot.user.getHighQualityAvatarUrl()).transform(circleTransform).placeholder(R.drawable.avatar_placeholder).override(largeAvatarSize, largeAvatarSize).into(playerAvatar);
        View.OnClickListener playerClick = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent player = new Intent(DribbbleShot.this, PlayerActivity.class);
                if (shot.user.shots_count > 0) {
                    // legit user object
                    player.putExtra(PlayerActivity.EXTRA_PLAYER, shot.user);
                } else {
                    // search doesn't fully populate the user object,
                    // in this case send the ID not the full user
                    player.putExtra(PlayerActivity.EXTRA_PLAYER_NAME, shot.user.username);
                    player.putExtra(PlayerActivity.EXTRA_PLAYER_ID, shot.user.id);
                }
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this, playerAvatar, getString(R.string.transition_player_avatar));
                startActivity(player, options.toBundle());
            }
        };
        playerAvatar.setOnClickListener(playerClick);
        playerName.setOnClickListener(playerClick);
        if (shot.created_at != null) {
            shotTimeAgo.setText(DateUtils.getRelativeTimeSpanString(shot.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase());
        }
    } else {
        playerName.setVisibility(View.GONE);
        playerAvatar.setVisibility(View.GONE);
        shotTimeAgo.setVisibility(View.GONE);
    }
    commentAnimator = new CommentAnimator();
    commentsList.setItemAnimator(commentAnimator);
    adapter = new CommentsAdapter(shotDescription, commentFooter, shot.comments_count, getResources().getInteger(R.integer.comment_expand_collapse_duration));
    commentsList.setAdapter(adapter);
    commentsList.addItemDecoration(new InsetDividerDecoration(CommentViewHolder.class, res.getDimensionPixelSize(R.dimen.divider_height), res.getDimensionPixelSize(R.dimen.keyline_1), ContextCompat.getColor(this, R.color.divider)));
    if (shot.comments_count != 0) {
        loadComments();
    }
    checkLiked();
}
Also used : InsetDividerDecoration(io.plaidapp.ui.recyclerview.InsetDividerDecoration) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) FabOverlapTextView(io.plaidapp.ui.widget.FabOverlapTextView) Spanned(android.text.Spanned) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) ForegroundImageView(io.plaidapp.ui.widget.ForegroundImageView) TextView(android.widget.TextView) FabOverlapTextView(io.plaidapp.ui.widget.FabOverlapTextView) ParallaxScrimageView(io.plaidapp.ui.widget.ParallaxScrimageView) RecyclerView(android.support.v7.widget.RecyclerView) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) FabOverlapTextView(io.plaidapp.ui.widget.FabOverlapTextView) Resources(android.content.res.Resources) ViewTreeObserver(android.view.ViewTreeObserver) NumberFormat(java.text.NumberFormat) ActivityOptions(android.app.ActivityOptions)

Aggregations

Intent (android.content.Intent)2 Resources (android.content.res.Resources)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 View (android.view.View)2 ViewTreeObserver (android.view.ViewTreeObserver)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AuthorTextView (io.plaidapp.ui.widget.AuthorTextView)2 FabOverlapTextView (io.plaidapp.ui.widget.FabOverlapTextView)2 ForegroundImageView (io.plaidapp.ui.widget.ForegroundImageView)2 ParallaxScrimageView (io.plaidapp.ui.widget.ParallaxScrimageView)2 NumberFormat (java.text.NumberFormat)2 ActivityOptions (android.app.ActivityOptions)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Spanned (android.text.Spanned)1 AbsListView (android.widget.AbsListView)1 ListView (android.widget.ListView)1 BindView (butterknife.BindView)1 InsetDividerDecoration (io.plaidapp.ui.recyclerview.InsetDividerDecoration)1 ElasticDragDismissFrameLayout (io.plaidapp.ui.widget.ElasticDragDismissFrameLayout)1