Search in sources :

Example 1 with Favorite

use of com.xinshang.audient.model.entities.Favorite in project Audient by komamj.

the class MyFavoritesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyFavoritesVH holder, int position) {
    Favorite favorite = mData.get(position);
    mGlideRequest.load(favorite.coverImageUrl).into(holder.mImage);
    holder.mName.setText(favorite.favoriteName);
    holder.mCount.setText(mContext.getResources().getQuantityString(R.plurals.song_count, favorite.itemCount, favorite.itemCount));
}
Also used : Favorite(com.xinshang.audient.model.entities.Favorite)

Example 2 with Favorite

use of com.xinshang.audient.model.entities.Favorite in project Audient by komamj.

the class MyFavoritesFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    LogUtils.i(TAG, "onViewCreated");
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (mPresenter != null) {
                mPresenter.loadMyFavorites();
            }
        }
    });
    mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimaryDark, R.color.colorPrimary);
    setLoadingIndicator(true);
    mAdapter = new MyFavoritesAdapter(mContext);
    mAdapter.setListener(new MyFavoritesAdapter.EventListener() {

        @Override
        public void onItemClick(Favorite favorite) {
            if (mPresenter != null) {
                mPresenter.addToFavorite(favorite.favoritesId, mAudient);
            }
        }
    });
    LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.addItemDecoration(new AudientItemDecoration(mContext));
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(mAdapter);
    if (mPresenter != null) {
        mPresenter.loadMyFavorites();
    }
}
Also used : Favorite(com.xinshang.audient.model.entities.Favorite) AudientItemDecoration(com.xinshang.audient.widget.AudientItemDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 3 with Favorite

use of com.xinshang.audient.model.entities.Favorite in project Audient by komamj.

the class FavoriteAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(FavoriteViewHolder holder, int position) {
    Favorite favorite = mData.get(position);
    mGlideRequest.load(favorite.coverImageUrl).into(holder.mFavoriteImage);
    holder.mFavoriteName.setText(favorite.favoriteName);
}
Also used : Favorite(com.xinshang.audient.model.entities.Favorite)

Example 4 with Favorite

use of com.xinshang.audient.model.entities.Favorite in project Audient by komamj.

the class MinePresenter method loadFavorites.

@Override
public void loadFavorites() {
    LogUtils.i(TAG, "loadFavorites");
    Disposable disposable = mRepository.getFavoriteResult().map(new Function<FavoritesResult, List<Favorite>>() {

        @Override
        public List<Favorite> apply(FavoritesResult favoriteResult) throws Exception {
            return favoriteResult.favorites;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Favorite>>() {

        @Override
        public void onNext(List<Favorite> favorites) {
            LogUtils.i(TAG, "loadfavorites " + favorites.toString());
            if (mView.isActive()) {
                mView.showFavorites(favorites);
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadFavorites error " + t.toString());
            if (mView.isActive()) {
                mView.showFavoriteProgressBar(false);
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.showFavoriteProgressBar(false);
            }
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Favorite(com.xinshang.audient.model.entities.Favorite) Function(io.reactivex.functions.Function) FavoritesResult(com.xinshang.audient.model.entities.FavoritesResult) List(java.util.List)

Example 5 with Favorite

use of com.xinshang.audient.model.entities.Favorite in project Audient by komamj.

the class MyFavoritesPresenter method loadMyFavorites.

@Override
public void loadMyFavorites() {
    Disposable disposable = mRepository.getFavoriteResult().map(new Function<FavoritesResult, List<Favorite>>() {

        @Override
        public List<Favorite> apply(FavoritesResult favoriteResult) throws Exception {
            return favoriteResult.favorites;
        }
    }).doOnNext(new Consumer<List<Favorite>>() {

        @Override
        public void accept(List<Favorite> favorites) throws Exception {
            LogUtils.i(TAG, "loadFavorites thread name :" + Thread.currentThread().getName() + "," + favorites.isEmpty());
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Favorite>>() {

        @Override
        public void onNext(List<Favorite> favorites) {
            LogUtils.i(TAG, "loadfavorites " + favorites.toString());
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
                mView.showFavorites(favorites);
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadFavorites error " + t.toString());
        }

        @Override
        public void onComplete() {
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Favorite(com.xinshang.audient.model.entities.Favorite) Consumer(io.reactivex.functions.Consumer) FavoritesResult(com.xinshang.audient.model.entities.FavoritesResult) List(java.util.List)

Aggregations

Favorite (com.xinshang.audient.model.entities.Favorite)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 FavoritesResult (com.xinshang.audient.model.entities.FavoritesResult)2 AudientItemDecoration (com.xinshang.audient.widget.AudientItemDecoration)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 List (java.util.List)2 Intent (android.content.Intent)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 BitmapTransitionOptions (com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions)1 AudientApplication (com.xinshang.audient.AudientApplication)1 AudientAdapter (com.xinshang.audient.base.AudientAdapter)1 MyFavoritesActivity (com.xinshang.audient.favorite.MyFavoritesActivity)1 Audient (com.xinshang.audient.model.entities.Audient)1 Consumer (io.reactivex.functions.Consumer)1 Function (io.reactivex.functions.Function)1