Search in sources :

Example 1 with NewsBean

use of com.looklook.xinghongfei.looklook.bean.news.NewsBean in project LookLook by xinghongfei.

the class TopNewsAdapter method bindViewHolderNormal.

private void bindViewHolderNormal(final TopNewsViewHolder holder, final int position) {
    final NewsBean newsBeanItem = topNewitems.get(holder.getAdapterPosition());
    if (DBUtils.getDB(mContext).isRead(Config.TOPNEWS, newsBeanItem.getTitle(), 1)) {
        holder.textView.setTextColor(Color.GRAY);
        holder.sourceTextview.setTextColor(Color.GRAY);
    } else {
        holder.textView.setTextColor(Color.BLACK);
        holder.sourceTextview.setTextColor(Color.BLACK);
    }
    holder.imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            DBUtils.getDB(mContext).insertHasRead(Config.ZHIHU, newsBeanItem.getTitle(), 1);
            holder.textView.setTextColor(Color.GRAY);
            holder.sourceTextview.setTextColor(Color.GRAY);
            startTopnewsActivity(newsBeanItem, holder);
        }
    });
    holder.textView.setText(newsBeanItem.getTitle());
    holder.sourceTextview.setText(newsBeanItem.getSource());
    holder.linearLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startTopnewsActivity(newsBeanItem, holder);
        }
    });
    Glide.with(mContext).load(newsBeanItem.getImgsrc()).listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            if (!newsBeanItem.hasFadedIn) {
                holder.imageView.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final ObjectAnimator animator = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        holder.imageView.setColorFilter(new ColorMatrixColorFilter(cm));
                    }
                });
                animator.setDuration(2000L);
                animator.setInterpolator(new AccelerateInterpolator());
                animator.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        holder.imageView.clearColorFilter();
                        holder.imageView.setHasTransientState(false);
                        animator.start();
                        newsBeanItem.hasFadedIn = true;
                    }
                });
            }
            return false;
        }
    }).diskCacheStrategy(DiskCacheStrategy.SOURCE).centerCrop().override(widthPx, heighPx).into(new DribbbleTarget(holder.imageView, false));
}
Also used : DribbbleTarget(com.looklook.xinghongfei.looklook.util.DribbbleTarget) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) BadgedFourThreeImageView(com.looklook.xinghongfei.looklook.widget.BadgedFourThreeImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ObservableColorMatrix(com.looklook.xinghongfei.looklook.util.ObservableColorMatrix) NewsBean(com.looklook.xinghongfei.looklook.bean.news.NewsBean) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 2 with NewsBean

use of com.looklook.xinghongfei.looklook.bean.news.NewsBean in project LookLook by xinghongfei.

the class NewsJsonUtils method readJsonNewsBeans.

/**
     * 将获取到的json转换为新闻列表对象
     * @param res
     * @param value
     * @return
     */
public static List<NewsBean> readJsonNewsBeans(String res, String value) {
    List<NewsBean> beans = new ArrayList<NewsBean>();
    try {
        JsonParser parser = new JsonParser();
        JsonObject jsonObj = parser.parse(res).getAsJsonObject();
        JsonElement jsonElement = jsonObj.get(value);
        if (jsonElement == null) {
            return null;
        }
        JsonArray jsonArray = jsonElement.getAsJsonArray();
        for (int i = 1; i < jsonArray.size(); i++) {
            JsonObject jo = jsonArray.get(i).getAsJsonObject();
            if (jo.has("skipType") && "special".equals(jo.get("skipType").getAsString())) {
                continue;
            }
            if (jo.has("TAGS") && !jo.has("TAG")) {
                continue;
            }
            if (!jo.has("imgextra")) {
                NewsBean news = JsonUtils.deserialize(jo, NewsBean.class);
                beans.add(news);
            }
        }
    } catch (Exception e) {
    }
    return beans;
}
Also used : JsonArray(com.google.gson.JsonArray) NewsBean(com.looklook.xinghongfei.looklook.bean.news.NewsBean) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Aggregations

NewsBean (com.looklook.xinghongfei.looklook.bean.news.NewsBean)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 TextView (android.widget.TextView)1 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 DribbbleTarget (com.looklook.xinghongfei.looklook.util.DribbbleTarget)1 ObservableColorMatrix (com.looklook.xinghongfei.looklook.util.ObservableColorMatrix)1 BadgedFourThreeImageView (com.looklook.xinghongfei.looklook.widget.BadgedFourThreeImageView)1 ArrayList (java.util.ArrayList)1