Search in sources :

Example 1 with ZhihuDailyItem

use of com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem in project LookLook by xinghongfei.

the class ZhihuPresenterImpl method getLastZhihuNews.

@Override
public void getLastZhihuNews() {
    mZhihuFragment.showProgressDialog();
    Subscription subscription = ApiManage.getInstence().getZhihuApiService().getLastDaily().map(new Func1<ZhihuDaily, ZhihuDaily>() {

        @Override
        public ZhihuDaily call(ZhihuDaily zhihuDaily) {
            String date = zhihuDaily.getDate();
            for (ZhihuDailyItem zhihuDailyItem : zhihuDaily.getStories()) {
                zhihuDailyItem.setDate(date);
            }
            return zhihuDaily;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ZhihuDaily>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            mZhihuFragment.hidProgressDialog();
            mZhihuFragment.showError(e.getMessage());
        }

        @Override
        public void onNext(ZhihuDaily zhihuDaily) {
            mZhihuFragment.hidProgressDialog();
            mCacheUtil.put(Config.ZHIHU, gson.toJson(zhihuDaily));
            mZhihuFragment.updateList(zhihuDaily);
        }
    });
    addSubscription(subscription);
}
Also used : ZhihuDaily(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily) ZhihuDailyItem(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 2 with ZhihuDailyItem

use of com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem in project LookLook by xinghongfei.

the class ZhihuPresenterImpl method getTheDaily.

@Override
public void getTheDaily(String date) {
    Subscription subscription = ApiManage.getInstence().getZhihuApiService().getTheDaily(date).map(new Func1<ZhihuDaily, ZhihuDaily>() {

        @Override
        public ZhihuDaily call(ZhihuDaily zhihuDaily) {
            String date = zhihuDaily.getDate();
            for (ZhihuDailyItem zhihuDailyItem : zhihuDaily.getStories()) {
                zhihuDailyItem.setDate(date);
            }
            return zhihuDaily;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ZhihuDaily>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            e.printStackTrace();
            mZhihuFragment.hidProgressDialog();
            mZhihuFragment.showError(e.getMessage());
        }

        @Override
        public void onNext(ZhihuDaily zhihuDaily) {
            mZhihuFragment.hidProgressDialog();
            mZhihuFragment.updateList(zhihuDaily);
        }
    });
    addSubscription(subscription);
}
Also used : ZhihuDaily(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily) ZhihuDailyItem(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 3 with ZhihuDailyItem

use of com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem in project LookLook by xinghongfei.

the class ZhihuAdapter method bindViewHolderNormal.

private void bindViewHolderNormal(final ZhihuViewHolder holder, final int position) {
    final ZhihuDailyItem zhihuDailyItem = zhihuDailyItems.get(holder.getAdapterPosition());
    if (DBUtils.getDB(mContext).isRead(Config.ZHIHU, zhihuDailyItem.getId(), 1))
        holder.textView.setTextColor(Color.GRAY);
    else
        holder.textView.setTextColor(Color.BLACK);
    holder.imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            goDescribeActivity(holder, zhihuDailyItem);
        }
    });
    holder.textView.setText(zhihuDailyItem.getTitle());
    holder.linearLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            goDescribeActivity(holder, zhihuDailyItem);
        }
    });
    Glide.with(mContext).load(zhihuDailyItems.get(position).getImages()[0]).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 (!zhihuDailyItem.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();
                        zhihuDailyItem.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) ZhihuDailyItem(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem) 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) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Aggregations

ZhihuDailyItem (com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem)3 ZhihuDaily (com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily)2 Subscription (rx.Subscription)2 Func1 (rx.functions.Func1)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 DribbbleTarget (com.looklook.xinghongfei.looklook.util.DribbbleTarget)1 ObservableColorMatrix (com.looklook.xinghongfei.looklook.util.ObservableColorMatrix)1 BadgedFourThreeImageView (com.looklook.xinghongfei.looklook.widget.BadgedFourThreeImageView)1