@Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); if (isVisibleToUser && adapter.getItemCount() == 0) { QueryBuilder<ChapterEntity> queryBuilder = chapterDao.queryBuilder(); if (type.getId() != 1) { queryBuilder.where(ChapterEntityDao.Properties.TypeId.eq(type.getId())); } Query<ChapterEntity> query = queryBuilder.limit(20).orderDesc(ChapterEntityDao.Properties.SendDate).build(); adapter.addAll(query.list()); } }
@Override public void onResponse(Response<ChapterResult> response, Retrofit retrofit) { refresh.setRefreshing(false); List<ChapterEntity> chapterList = response.body().getChapterList(); adapter.addAll(chapterList); chapterDao.insertOrReplaceInTx(chapterList); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); RecyclerView recycler = (RecyclerView) view.findViewById(R.id.chapter_list_recycler); recycler.setAdapter(adapter); refresh = ((SwipeRefreshLayout) view); refresh.setOnRefreshListener( () -> { adapter.clear(); HttpUtils.getService().getChapterList(20, 1, type.getId()).enqueue(this); }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); long typeId = getArguments().getLong(TYPE_ID); DaoSession session = DaoUtils.getSession(); TypeEntityDao typeDao = session.getTypeEntityDao(); chapterDao = session.getChapterEntityDao(); type = typeDao.load(typeId); adapter = new BindingAdapter<>(new ArrayList<ChapterEntity>(), R.layout.chapter_item, BR.chapter); adapter.setOnClickListener(this); }