|
|
|
@ -2,6 +2,7 @@ package xyz.fycz.myreader.ui.fragment; |
|
|
|
|
|
|
|
|
|
import android.content.Intent; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.util.Log; |
|
|
|
|
import android.view.LayoutInflater; |
|
|
|
|
import android.view.View; |
|
|
|
|
import android.view.ViewGroup; |
|
|
|
@ -21,17 +22,21 @@ import xyz.fycz.myreader.base.LazyFragment; |
|
|
|
|
import xyz.fycz.myreader.base.adapter.BaseListAdapter; |
|
|
|
|
import xyz.fycz.myreader.base.adapter.IViewHolder; |
|
|
|
|
import xyz.fycz.myreader.base.observer.MyObserver; |
|
|
|
|
import xyz.fycz.myreader.base.observer.MySingleObserver; |
|
|
|
|
import xyz.fycz.myreader.common.APPCONST; |
|
|
|
|
import xyz.fycz.myreader.databinding.FragmentFindBook2Binding; |
|
|
|
|
import xyz.fycz.myreader.entity.FindKind; |
|
|
|
|
import xyz.fycz.myreader.entity.ad.AdBean; |
|
|
|
|
import xyz.fycz.myreader.greendao.entity.Book; |
|
|
|
|
import xyz.fycz.myreader.greendao.service.BookService; |
|
|
|
|
import xyz.fycz.myreader.ui.activity.BookDetailedActivity; |
|
|
|
|
import xyz.fycz.myreader.ui.activity.BookstoreActivity; |
|
|
|
|
import xyz.fycz.myreader.ui.activity.ReadActivity; |
|
|
|
|
import xyz.fycz.myreader.ui.adapter.holder.FindBookHolder; |
|
|
|
|
import xyz.fycz.myreader.ui.dialog.SourceExchangeDialog; |
|
|
|
|
import xyz.fycz.myreader.util.ToastUtils; |
|
|
|
|
import xyz.fycz.myreader.util.help.StringHelper; |
|
|
|
|
import xyz.fycz.myreader.util.utils.AdUtils; |
|
|
|
|
import xyz.fycz.myreader.util.utils.RxUtils; |
|
|
|
|
import xyz.fycz.myreader.webapi.BookApi; |
|
|
|
|
import xyz.fycz.myreader.webapi.crawler.base.FindCrawler; |
|
|
|
@ -51,6 +56,8 @@ public class FindBook2Fragment extends LazyFragment { |
|
|
|
|
|
|
|
|
|
private static final String KIND = "kind"; |
|
|
|
|
private static final String FIND_CRAWLER = "findCrawler"; |
|
|
|
|
private AdBean adBean; |
|
|
|
|
private View flow; |
|
|
|
|
|
|
|
|
|
public FindBook2Fragment() { |
|
|
|
|
} |
|
|
|
@ -78,6 +85,7 @@ public class FindBook2Fragment extends LazyFragment { |
|
|
|
|
outState.putString(APPCONST.DATA_KEY, dataKey); |
|
|
|
|
super.onSaveInstanceState(outState); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void lazyInit() { |
|
|
|
|
initData(); |
|
|
|
@ -92,6 +100,8 @@ public class FindBook2Fragment extends LazyFragment { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initData() { |
|
|
|
|
adBean = AdUtils.getAdConfig().getFind(); |
|
|
|
|
getFlow(); |
|
|
|
|
findBookAdapter = new BaseListAdapter<Book>() { |
|
|
|
|
@Override |
|
|
|
|
protected IViewHolder<Book> createViewHolder(int viewType) { |
|
|
|
@ -104,6 +114,19 @@ public class FindBook2Fragment extends LazyFragment { |
|
|
|
|
loadBooks(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void getFlow() { |
|
|
|
|
AdUtils.checkHasAd().subscribe(new MySingleObserver<Boolean>() { |
|
|
|
|
@Override |
|
|
|
|
public void onSuccess(@NonNull Boolean aBoolean) { |
|
|
|
|
if (aBoolean && AdUtils.adTime("find", adBean)) { |
|
|
|
|
if (adBean.getStatus() > 0) { |
|
|
|
|
AdUtils.getFlowAd(getActivity(), 1, view -> flow = view, "find"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initWidget() { |
|
|
|
|
binding.loading.setOnReloadingListener(() -> { |
|
|
|
|
page = 1; |
|
|
|
@ -156,6 +179,13 @@ public class FindBook2Fragment extends LazyFragment { |
|
|
|
|
} else { |
|
|
|
|
findBookAdapter.refreshItems(books); |
|
|
|
|
binding.srlFindBooks.finishRefresh(); |
|
|
|
|
if (flow != null) { |
|
|
|
|
int index = findBookAdapter.getItemCount() - books.size() + 2; |
|
|
|
|
index = Math.min(findBookAdapter.getItemCount() - 1, index); |
|
|
|
|
findBookAdapter.addOther(index, flow); |
|
|
|
|
flow = null; |
|
|
|
|
getFlow(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (books.size() == 0) { |
|
|
|
@ -163,6 +193,13 @@ public class FindBook2Fragment extends LazyFragment { |
|
|
|
|
} else { |
|
|
|
|
findBookAdapter.addItems(books); |
|
|
|
|
binding.srlFindBooks.finishLoadMore(); |
|
|
|
|
if (flow != null) { |
|
|
|
|
int index = findBookAdapter.getItemCount() - books.size() + 2; |
|
|
|
|
index = Math.min(findBookAdapter.getItemCount() - 1, index); |
|
|
|
|
findBookAdapter.addOther(index, flow); |
|
|
|
|
flow = null; |
|
|
|
|
getFlow(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
page++; |
|
|
|
|