From a794cdaf7557b08a5650d307920db6c785d42fb8 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Sat, 24 Jul 2021 21:16:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyz/fycz/myreader/base/LazyFragment.kt | 21 ++++++++++++++++++ .../base/adapter/BaseListAdapter.java | 10 ++++++++- .../ui/adapter/LocalSourceAdapter.java | 2 +- .../ui/adapter/ReplaceRuleAdapter.java | 2 +- .../ui/adapter/SearchBookAdapter.java | 22 +++++++++++++++++-- .../ui/adapter/SourceExchangeAdapter.java | 2 +- .../ui/fragment/FindBook1Fragment.java | 2 +- .../ui/fragment/FindBook2Fragment.java | 3 ++- .../ui/presenter/BookcasePresenter.java | 3 +++ 9 files changed, 59 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/base/LazyFragment.kt b/app/src/main/java/xyz/fycz/myreader/base/LazyFragment.kt index 6af8dfa..8f4c625 100644 --- a/app/src/main/java/xyz/fycz/myreader/base/LazyFragment.kt +++ b/app/src/main/java/xyz/fycz/myreader/base/LazyFragment.kt @@ -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() } \ No newline at end of file diff --git a/app/src/main/java/xyz/fycz/myreader/base/adapter/BaseListAdapter.java b/app/src/main/java/xyz/fycz/myreader/base/adapter/BaseListAdapter.java index 6631a4e..670164b 100644 --- a/app/src/main/java/xyz/fycz/myreader/base/adapter/BaseListAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/base/adapter/BaseListAdapter.java @@ -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 extends RecyclerView.Adapter{ +public abstract class BaseListAdapter extends RecyclerView.Adapter implements Filterable { private static final String TAG = "BaseListAdapter"; /*common statement*/ @@ -73,6 +76,11 @@ public abstract class BaseListAdapter extends RecyclerView.Adapter sources; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/ReplaceRuleAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/ReplaceRuleAdapter.java index 22224d6..a796803 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/ReplaceRuleAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/ReplaceRuleAdapter.java @@ -18,7 +18,7 @@ import xyz.fycz.myreader.util.help.StringHelper; * @author fengyue * @date 2021/1/19 9:51 */ -public class ReplaceRuleAdapter extends BaseListAdapter implements Filterable { +public class ReplaceRuleAdapter extends BaseListAdapter { private AppCompatActivity activity; private List beans; private OnSwipeListener onSwipeListener; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchBookAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchBookAdapter.java index 940a575..ecb7fe8 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchBookAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchBookAdapter.java @@ -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 { private ConMVMap 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 mBooks, SearchEngine searchEngine, String keyWord) { this.activity = activity; @@ -110,12 +115,25 @@ public class SearchBookAdapter extends BaseListAdapter { } } } - 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); } } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/SourceExchangeAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/SourceExchangeAdapter.java index ebccd48..e3bfb6b 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/SourceExchangeAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/SourceExchangeAdapter.java @@ -19,7 +19,7 @@ import java.util.List; * @author fengyue * @date 2020/9/30 18:42 */ -public class SourceExchangeAdapter extends BaseListAdapter implements Filterable { +public class SourceExchangeAdapter extends BaseListAdapter { private SourceExchangeDialog dialog; private List beans; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook1Fragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook1Fragment.java index 31f0b4d..896d64b 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook1Fragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook1Fragment.java @@ -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(); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook2Fragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook2Fragment.java index fc6f7a9..cec9263 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook2Fragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/FindBook2Fragment.java @@ -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); } + } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java b/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java index e673ffb..6c9623c 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java @@ -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)) {