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