From ac4bdde1b90a07a76a0a5ed45ab6ce7831f3d593 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Sat, 28 May 2022 21:51:14 +0800 Subject: [PATCH] fix search --- .../ui/activity/SearchBookActivity.java | 43 +++++++++---------- .../fycz/myreader/ui/adapter/SearchAdapter.kt | 31 ++++++------- build.gradle | 3 ++ 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java index 18cb0de..44d5d96 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchBookActivity.java @@ -156,6 +156,25 @@ public class SearchBookActivity extends BaseActivity } } + @Override + protected void onStop() { + if (mSearchBookAdapter != null) { + mSearchBookAdapter.setStop(true); + } + super.onStop(); + } + + @Override + protected void onStart() { + super.onStart(); + if (mSearchBookAdapter != null) { + mSearchBookAdapter.setStop(false); + if (showBooks) { + mSearchBookAdapter.addAll(new ArrayList<>(), searchKey); + } + } + } + @Override protected void initData(Bundle savedInstanceState) { super.initData(savedInstanceState); @@ -757,28 +776,8 @@ public class SearchBookActivity extends BaseActivity /*for (ReadCrawler readCrawler : readCrawlers) { searchBookByCrawler(readCrawler, readCrawler.getSearchCharset()); }*/ - if (readCrawlers.size() > 2000 && !SharedPreUtils.getInstance().getBoolean("searchBookWarning")) { - DialogCreator.createThreeButtonDialog(this, "书源过多警告", - "当前搜索书源数量超过2000(建议1000以内),继续搜索可能会导致软件异常(如搜索时前往阅读页返回后将会导致卡死黑屏),确定要继续搜索吗?", - true, "继续搜索并不再提示", "书源管理", "继续搜索", - (dialog, which) -> { - SharedPreUtils.getInstance().putBoolean("searchBookWarning", true); - searchEngine.initSearchEngine(readCrawlers); - searchEngine.search(searchKey); - }, (dialog, which) -> { - startActivityForResult(new Intent(this, BookSourceActivity.class), - APPCONST.REQUEST_BOOK_SOURCE); - }, - (dialog, which) -> { - searchEngine.initSearchEngine(readCrawlers); - searchEngine.search(searchKey); - } - ); - } else { - searchEngine.initSearchEngine(readCrawlers); - searchEngine.search(searchKey); - } - + searchEngine.initSearchEngine(readCrawlers); + searchEngine.search(searchKey); } /** diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchAdapter.kt b/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchAdapter.kt index 6b6db5f..d081a45 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchAdapter.kt +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/SearchAdapter.kt @@ -52,11 +52,12 @@ class SearchAdapter( val keyword: String ) : DiffRecyclerAdapter(context) { private val mBooks: ConMVMap = ConMVMap() - private lateinit var mList: List + private var mList: MutableList = ArrayList() private val tagList: MutableList = ArrayList() private val handler = Handler(Looper.getMainLooper()) private var postTime = 0L private val sendRunnable = Runnable { upAdapter() } + var isStop = false override val diffItemCallback: DiffUtil.ItemCallback get() = object : DiffUtil.ItemCallback() { @@ -300,7 +301,7 @@ class SearchAdapter( } fun addAll(newDataS: List, keyWord: String?) { - val copyDataS: MutableList = ArrayList(getItems()) + val copyData: MutableList = ArrayList(mList) val filterDataS: MutableList = ArrayList() when (SysManager.getSetting().searchFilter) { 0 -> filterDataS.addAll(newDataS) @@ -328,16 +329,16 @@ class SearchAdapter( } if (filterDataS.size > 0) { val searchBookBeansAdd: MutableList = ArrayList() - if (copyDataS.size == 0) { - copyDataS.addAll(filterDataS) + if (mList.size == 0) { + mList.addAll(filterDataS) } else { //存在 for (temp in filterDataS) { var hasSame = false var i = 0 - val size = copyDataS.size + val size = copyData.size while (i < size) { - val searchBook = copyDataS[i] + val searchBook = copyData[i] if (TextUtils.equals(temp.name, searchBook.name) && TextUtils.equals(temp.author, searchBook.author) ) { @@ -353,30 +354,30 @@ class SearchAdapter( //添加 for (temp in searchBookBeansAdd) { if (TextUtils.equals(keyWord, temp.name)) { - for (i in copyDataS.indices) { - val searchBook = copyDataS[i] + for (i in copyData.indices) { + val searchBook = copyData[i] if (!TextUtils.equals(keyWord, searchBook.name)) { - copyDataS.add(i, temp) + mList.add(i, temp) break } } } else if (TextUtils.equals(keyWord, temp.author)) { - for (i in copyDataS.indices) { - val searchBook = copyDataS[i] + for (i in copyData.indices) { + val searchBook = copyData[i] if (!TextUtils.equals(keyWord, searchBook.name) && !TextUtils.equals(keyWord, searchBook.author) ) { - copyDataS.add(i, temp) + mList.add(i, temp) break } } } else { - copyDataS.add(temp) + mList.add(temp) } } } - mList = copyDataS - upAdapter() + if (!isStop) + upAdapter() } } diff --git a/build.gradle b/build.gradle index c0a5b9e..bc8b29f 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,7 @@ buildscript { maven { url 'https://s3.amazonaws.com/fabric-artifacts/public' } maven { url 'https://plugins.gradle.org/m2/' } maven { url "https://maven.java.net/content/groups/public/" } + maven { url 'https://jitpack.io' } } dependencies { classpath 'com.android.tools.build:gradle:4.1.3' @@ -38,6 +39,8 @@ buildscript { classpath 'com.github.megatronking.stringfog:gradle-plugin:3.0.0' // 选用加解密算法库,默认实现了xor算法,也可以使用自己的加解密库。 classpath 'com.github.megatronking.stringfog:xor:3.0.0' + + classpath "com.github.CodingGay:BlackObfuscator-ASPlugin:3.7" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }