Search in sources :

Example 6 with Shot

use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.

the class FeedAdapter method createDribbbleShotHolder.

@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
    final DribbbleShotHolder holder = new DribbbleShotHolder(layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
    holder.image.setBadgeColor(initialGifBadgeColor);
    holder.image.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, (Shot) getItem(holder.getAdapterPosition()));
            setGridItemContentTransitions(holder.image);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(view, host.getString(R.string.transition_shot)), Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivityForResult(intent, REQUEST_CODE_VIEW_SHOT, options.toBundle());
        }
    });
    // play animated GIFs whilst touched
    holder.image.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // check if it's an event we care about, else bail fast
            final int action = event.getAction();
            if (!(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL))
                return false;
            // get the image and check if it's an animated GIF
            final Drawable drawable = holder.image.getDrawable();
            if (drawable == null)
                return false;
            GifDrawable gif = null;
            if (drawable instanceof GifDrawable) {
                gif = (GifDrawable) drawable;
            } else if (drawable instanceof TransitionDrawable) {
                // we fade in images on load which uses a TransitionDrawable; check its layers
                TransitionDrawable fadingIn = (TransitionDrawable) drawable;
                for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
                    if (fadingIn.getDrawable(i) instanceof GifDrawable) {
                        gif = (GifDrawable) fadingIn.getDrawable(i);
                        break;
                    }
                }
            }
            if (gif == null)
                return false;
            // GIF found, start/stop it on press/lift
            switch(action) {
                case MotionEvent.ACTION_DOWN:
                    gif.start();
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    gif.stop();
                    break;
            }
            return false;
        }
    });
    return holder;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) BadgedFourThreeImageView(io.plaidapp.ui.widget.BadgedFourThreeImageView) RecyclerView(android.support.v7.widget.RecyclerView) MotionEvent(android.view.MotionEvent) Shot(io.plaidapp.data.api.dribbble.model.Shot) ActivityOptions(android.app.ActivityOptions) NonNull(android.support.annotation.NonNull)

Example 7 with Shot

use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.

the class FeedAdapter method weighItems.

/**
     * Calculate a 'weight' [0, 1] for each data type for sorting. Each data type/source has a
     * different metric for weighing it e.g. Dribbble uses likes etc. but some sources should keep
     * the order returned by the API. Weights are 'scoped' to the page they belong to and lower
     * weights are sorted earlier in the grid (i.e. in ascending weight).
     */
private void weighItems(List<? extends PlaidItem> items) {
    if (items == null || items.isEmpty())
        return;
    PlaidItemSorting.PlaidItemGroupWeigher weigher = null;
    switch(items.get(0).dataSource) {
        // have an expectation about the order they appear in
        case SourceManager.SOURCE_DRIBBBLE_USER_SHOTS:
        case SourceManager.SOURCE_DRIBBBLE_USER_LIKES:
        case SourceManager.SOURCE_PRODUCT_HUNT:
        case PlayerShotsDataManager.SOURCE_PLAYER_SHOTS:
        case PlayerShotsDataManager.SOURCE_TEAM_SHOTS:
            if (naturalOrderWeigher == null) {
                naturalOrderWeigher = new PlaidItemSorting.NaturalOrderWeigher();
            }
            weigher = naturalOrderWeigher;
            break;
        default:
            // regular pattern of items in the grid
            if (items.get(0) instanceof Shot) {
                if (shotWeigher == null)
                    shotWeigher = new ShotWeigher();
                weigher = shotWeigher;
            } else if (items.get(0) instanceof Story) {
                if (storyWeigher == null)
                    storyWeigher = new StoryWeigher();
                weigher = storyWeigher;
            } else if (items.get(0) instanceof Post) {
                if (postWeigher == null)
                    postWeigher = new PostWeigher();
                weigher = postWeigher;
            }
    }
    weigher.weigh(items);
}
Also used : Post(io.plaidapp.data.api.producthunt.model.Post) PlaidItemSorting(io.plaidapp.data.PlaidItemSorting) StoryWeigher(io.plaidapp.data.api.designernews.StoryWeigher) PostWeigher(io.plaidapp.data.api.producthunt.PostWeigher) Shot(io.plaidapp.data.api.dribbble.model.Shot) Story(io.plaidapp.data.api.designernews.model.Story) ShotWeigher(io.plaidapp.data.api.dribbble.ShotWeigher)

Example 8 with Shot

use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.

the class FeedAdapter method expandPopularItems.

private void expandPopularItems() {
    // for now just expand the first dribbble image per page which should be
    // the most popular according to our weighing & sorting
    List<Integer> expandedPositions = new ArrayList<>();
    int page = -1;
    final int count = items.size();
    for (int i = 0; i < count; i++) {
        PlaidItem item = getItem(i);
        if (item instanceof Shot && item.page > page) {
            item.colspan = columns;
            page = item.page;
            expandedPositions.add(i);
        } else {
            item.colspan = 1;
        }
    }
    // so that we don't leave any gaps in the grid
    for (int expandedPos = 0; expandedPos < expandedPositions.size(); expandedPos++) {
        int pos = expandedPositions.get(expandedPos);
        int extraSpannedSpaces = expandedPos * (columns - 1);
        int rowPosition = (pos + extraSpannedSpaces) % columns;
        if (rowPosition != 0) {
            int swapWith = pos + (columns - rowPosition);
            if (swapWith < items.size()) {
                Collections.swap(items, pos, swapWith);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PlaidItem(io.plaidapp.data.PlaidItem) Shot(io.plaidapp.data.api.dribbble.model.Shot)

Example 9 with Shot

use of io.plaidapp.data.api.dribbble.model.Shot in project sbt-android by scala-android.

the class FeedAdapter method expandPopularItems.

private void expandPopularItems() {
    // for now just expand the first dribbble image per page which should be
    // the most popular according to #sort.
    // TODO make this smarter & handle other item types
    List<Integer> expandedPositions = new ArrayList<>();
    int page = -1;
    final int count = items.size();
    for (int i = 0; i < count; i++) {
        PlaidItem item = getItem(i);
        if (item instanceof Shot && item.page > page) {
            item.colspan = columns;
            page = item.page;
            expandedPositions.add(i);
        } else {
            item.colspan = 1;
        }
    }
    // so that we don't leave any gaps in the grid
    for (int expandedPos = 0; expandedPos < expandedPositions.size(); expandedPos++) {
        int pos = expandedPositions.get(expandedPos);
        int extraSpannedSpaces = expandedPos * (columns - 1);
        int rowPosition = (pos + extraSpannedSpaces) % columns;
        if (rowPosition != 0) {
            int swapWith = pos + (columns - rowPosition);
            Collections.swap(items, pos, swapWith);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PlaidItem(io.plaidapp.data.PlaidItem) Shot(io.plaidapp.data.api.dribbble.model.Shot)

Example 10 with Shot

use of io.plaidapp.data.api.dribbble.model.Shot in project sbt-android by scala-android.

the class DribbbleSearch method parseShot.

private static Shot parseShot(Element element, SimpleDateFormat dateFormat) {
    Element descriptionBlock = element.select("a.dribbble-over").first();
    // API responses wrap description in a <p> tag. Do the same for consistent display.
    String description = descriptionBlock.select("span.comment").text().trim();
    if (!TextUtils.isEmpty(description)) {
        description = "<p>" + description + "</p>";
    }
    String imgUrl = element.select("img").first().attr("src");
    if (imgUrl.contains("_teaser.")) {
        imgUrl = imgUrl.replace("_teaser.", ".");
    }
    Date createdAt = null;
    try {
        createdAt = dateFormat.parse(descriptionBlock.select("em.timestamp").first().text());
    } catch (ParseException e) {
    }
    return new Shot.Builder().setId(Long.parseLong(element.id().replace("screenshot-", ""))).setHtmlUrl(HOST + element.select("a.dribbble-link").first().attr("href")).setTitle(descriptionBlock.select("strong").first().text()).setDescription(description).setImages(new Images(null, imgUrl, null)).setCreatedAt(createdAt).setLikesCount(Long.parseLong(element.select("li.fav").first().child(0).text().replaceAll(",", ""))).setCommentsCount(Long.parseLong(element.select("li.cmnt").first().child(0).text().replaceAll(",", ""))).setViewsCount(Long.parseLong(element.select("li.views").first().child(0).text().replaceAll(",", ""))).setUser(parsePlayer(element.select("h2").first())).build();
}
Also used : Element(org.jsoup.nodes.Element) Images(io.plaidapp.data.api.dribbble.model.Images) ParseException(java.text.ParseException) Shot(io.plaidapp.data.api.dribbble.model.Shot) Date(java.util.Date)

Aggregations

Shot (io.plaidapp.data.api.dribbble.model.Shot)10 ArrayList (java.util.ArrayList)4 PlaidItem (io.plaidapp.data.PlaidItem)3 Element (org.jsoup.nodes.Element)3 RecyclerView (android.support.v7.widget.RecyclerView)2 MotionEvent (android.view.MotionEvent)2 View (android.view.View)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 Story (io.plaidapp.data.api.designernews.model.Story)2 Post (io.plaidapp.data.api.producthunt.model.Post)2 Elements (org.jsoup.select.Elements)2 ActivityOptions (android.app.ActivityOptions)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 NonNull (android.support.annotation.NonNull)1 WorkerThread (android.support.annotation.WorkerThread)1