This commit is contained in:
chenjuntao
2019-05-05 17:53:22 +08:00
parent 7f5dd97359
commit 3cd248a2c5
33 changed files with 679 additions and 77 deletions

View File

@ -4,6 +4,7 @@ import android.app.Application;
import android.arch.lifecycle.LiveData;
import android.support.annotation.NonNull;
import com.gh.common.history.HistoryDatabase;
import com.gh.gamecenter.baselist.ListViewModel;
import com.gh.gamecenter.entity.NewsEntity;
import com.gh.gamecenter.entity.ViewsEntity;
@ -14,6 +15,7 @@ import com.gh.gamecenter.retrofit.RetrofitManager;
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.Single;
/**
* Created by khy on 30/03/18.
@ -21,6 +23,7 @@ import io.reactivex.Observable;
public class ArticleViewModel extends ListViewModel<NewsEntity, NewsEntity> {
public ArticleFragment.Type type;
NewsViewsRepository<ViewsEntity> mNewsViewsRepository = new NewsViewsRepository<>();
@ -66,8 +69,17 @@ public class ArticleViewModel extends ListViewModel<NewsEntity, NewsEntity> {
}
@Override
public Single<List<NewsEntity>> provideDataSingle(int page) {
if (type == ArticleFragment.Type.COLLECTION) {
return Single.fromObservable(RetrofitManager.getInstance(getApplication()).getApi().getCollectionArticle(UserManager.getInstance().getUserId(), page));
} else {
return HistoryDatabase.Companion.getInstance().newsDao().getNewsWithOffset(20, (page - 1) * 20);
}
}
@Override
public Observable<List<NewsEntity>> provideDataObservable(int page) {
return RetrofitManager.getInstance(getApplication()).getApi().getCollectionArticle(UserManager.getInstance().getUserId(), page);
return null;
}
}