优化搜索

master
fengyuecanzhu 3 years ago
parent 463487f161
commit a794cdaf75
  1. 21
      app/src/main/java/xyz/fycz/myreader/base/LazyFragment.kt
  2. 10
      app/src/main/java/xyz/fycz/myreader/base/adapter/BaseListAdapter.java
  3. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/LocalSourceAdapter.java
  4. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/ReplaceRuleAdapter.java
  5. 22
      app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchBookAdapter.java
  6. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/SourceExchangeAdapter.java
  7. 2
      app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook1Fragment.java
  8. 3
      app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook2Fragment.java
  9. 3
      app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java

@ -1,5 +1,9 @@
package xyz.fycz.myreader.base
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
@ -10,6 +14,8 @@ import io.reactivex.disposables.Disposable
*/
abstract class LazyFragment : Fragment() {
protected var mDisposable: CompositeDisposable? = null
private var root: View? = null
/**
* 是否执行懒加载
*/
@ -76,11 +82,26 @@ abstract class LazyFragment : Fragment() {
judgeLazyInit()
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
root = bindView(inflater, container)
return root
}
override fun onDetach() {
super.onDetach()
if (mDisposable != null) {
mDisposable!!.clear()
}
}
/**
* 绑定视图
*/
protected abstract fun bindView(inflater: LayoutInflater, container: ViewGroup?): View?
abstract fun lazyInit()
}

@ -3,6 +3,9 @@ package xyz.fycz.myreader.base.adapter;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
@ -14,7 +17,7 @@ import java.util.List;
* @date 2020/8/12 20:02
*/
public abstract class BaseListAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
public abstract class BaseListAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements Filterable {
private static final String TAG = "BaseListAdapter";
/*common statement*/
@ -73,6 +76,11 @@ public abstract class BaseListAdapter<T> extends RecyclerView.Adapter<RecyclerVi
return mList.size();
}
@Override
public Filter getFilter() {
return null;
}
protected void onItemClick(View v, int pos){
}

@ -14,7 +14,7 @@ import xyz.fycz.myreader.ui.adapter.holder.LocalSourceHolder;
* @author fengyue
* @date 2021/2/10 18:27
*/
public class LocalSourceAdapter extends BaseSourceAdapter implements Filterable {
public class LocalSourceAdapter extends BaseSourceAdapter {
private List<BookSource> sources;

@ -18,7 +18,7 @@ import xyz.fycz.myreader.util.help.StringHelper;
* @author fengyue
* @date 2021/1/19 9:51
*/
public class ReplaceRuleAdapter extends BaseListAdapter<ReplaceRuleBean> implements Filterable {
public class ReplaceRuleAdapter extends BaseListAdapter<ReplaceRuleBean> {
private AppCompatActivity activity;
private List<ReplaceRuleBean> beans;
private OnSwipeListener onSwipeListener;

@ -1,6 +1,8 @@
package xyz.fycz.myreader.ui.adapter;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import xyz.fycz.myreader.application.App;
@ -27,6 +29,9 @@ public class SearchBookAdapter extends BaseListAdapter<SearchBookBean> {
private ConMVMap<SearchBookBean, Book> mBooks;
private SearchEngine searchEngine;
private String keyWord;
private Handler handler = new Handler(Looper.getMainLooper());
private long postTime = 0L;
private Runnable sendRunnable = this::upAdapter;
public SearchBookAdapter(Activity activity, ConMVMap<SearchBookBean, Book> mBooks, SearchEngine searchEngine, String keyWord) {
this.activity = activity;
@ -110,12 +115,25 @@ public class SearchBookAdapter extends BaseListAdapter<SearchBookBean> {
}
}
}
synchronized (this) {
mList = copyDataS;
upAdapter();
/*synchronized (this) {
App.runOnUiThread(() -> {
mList = copyDataS;
notifyDataSetChanged();
});
}
}*/
}
}
private synchronized void upAdapter(){
if (System.currentTimeMillis() >= postTime + 500) {
handler.removeCallbacks(sendRunnable);
postTime = System.currentTimeMillis();
notifyDataSetChanged();
} else {
handler.removeCallbacks(sendRunnable);
handler.postDelayed(sendRunnable, 500 - System.currentTimeMillis() + postTime);
}
}

@ -19,7 +19,7 @@ import java.util.List;
* @author fengyue
* @date 2020/9/30 18:42
*/
public class SourceExchangeAdapter extends BaseListAdapter<Book> implements Filterable {
public class SourceExchangeAdapter extends BaseListAdapter<Book> {
private SourceExchangeDialog dialog;
private List<Book> beans;

@ -59,7 +59,7 @@ public class FindBook1Fragment extends LazyFragment {
@Nullable
@Override
public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
public View bindView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container) {
binding = FragmentFindBook1Binding.inflate(inflater, container, false);
return binding.getRoot();
}

@ -62,7 +62,7 @@ public class FindBook2Fragment extends LazyFragment {
@Nullable
@Override
public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
public View bindView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container) {
binding = FragmentFindBook2Binding.inflate(inflater, container, false);
return binding.getRoot();
}
@ -174,4 +174,5 @@ public class FindBook2Fragment extends LazyFragment {
getActivity().startActivity(intent);
}
}

@ -368,6 +368,9 @@ public class BookcasePresenter implements BasePresenter {
book.setNoReadNum(Math.max(noReadNum, 0));
book.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle());
mChapterService.updateAllOldChapterData(mChapters, chapters, book.getId());
if (book.getHisttoryChapterNum() + 1 > chapters.size()){
book.setHisttoryChapterNum(chapters.size() - 1);
}
mBookService.updateEntity(book);
if (isChangeSource) {
if (mBookService.matchHistoryChapterPos(book, chapters)) {

Loading…
Cancel
Save