|
|
@ -7,7 +7,6 @@ import android.view.inputmethod.EditorInfo |
|
|
|
import android.view.inputmethod.InputMethodManager |
|
|
|
import android.view.inputmethod.InputMethodManager |
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import org.jetbrains.anko.contentView |
|
|
|
|
|
|
|
import xyz.fycz.myreader.R |
|
|
|
import xyz.fycz.myreader.R |
|
|
|
import xyz.fycz.myreader.application.App |
|
|
|
import xyz.fycz.myreader.application.App |
|
|
|
import xyz.fycz.myreader.base.BaseActivity |
|
|
|
import xyz.fycz.myreader.base.BaseActivity |
|
|
@ -17,15 +16,14 @@ import xyz.fycz.myreader.base.adapter.IViewHolder |
|
|
|
import xyz.fycz.myreader.base.adapter2.onClick |
|
|
|
import xyz.fycz.myreader.base.adapter2.onClick |
|
|
|
import xyz.fycz.myreader.common.APPCONST |
|
|
|
import xyz.fycz.myreader.common.APPCONST |
|
|
|
import xyz.fycz.myreader.databinding.ActivitySearchWordBinding |
|
|
|
import xyz.fycz.myreader.databinding.ActivitySearchWordBinding |
|
|
|
import xyz.fycz.myreader.entity.SearchWord1 |
|
|
|
import xyz.fycz.myreader.greendao.DbManager |
|
|
|
|
|
|
|
import xyz.fycz.myreader.greendao.entity.search.SearchWord1 |
|
|
|
import xyz.fycz.myreader.greendao.entity.Book |
|
|
|
import xyz.fycz.myreader.greendao.entity.Book |
|
|
|
import xyz.fycz.myreader.greendao.entity.Chapter |
|
|
|
import xyz.fycz.myreader.greendao.entity.Chapter |
|
|
|
|
|
|
|
import xyz.fycz.myreader.greendao.entity.search.SearchWord |
|
|
|
import xyz.fycz.myreader.model.SearchWordEngine |
|
|
|
import xyz.fycz.myreader.model.SearchWordEngine |
|
|
|
import xyz.fycz.myreader.ui.adapter.holder.SearchWord1Holder |
|
|
|
import xyz.fycz.myreader.ui.adapter.holder.SearchWord1Holder |
|
|
|
import xyz.fycz.myreader.ui.adapter.holder.SearchWord2Holder |
|
|
|
|
|
|
|
import xyz.fycz.myreader.util.ToastUtils |
|
|
|
|
|
|
|
import xyz.fycz.myreader.widget.page.PageLoader |
|
|
|
import xyz.fycz.myreader.widget.page.PageLoader |
|
|
|
import xyz.fycz.myreader.widget.page.PageView |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author fengyue |
|
|
|
* @author fengyue |
|
|
@ -39,6 +37,8 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
private lateinit var pageLoader: PageLoader |
|
|
|
private lateinit var pageLoader: PageLoader |
|
|
|
private lateinit var searchWordEngine: SearchWordEngine |
|
|
|
private lateinit var searchWordEngine: SearchWordEngine |
|
|
|
private lateinit var adapter: BaseListAdapter<SearchWord1> |
|
|
|
private lateinit var adapter: BaseListAdapter<SearchWord1> |
|
|
|
|
|
|
|
private var searchWord: SearchWord? = null |
|
|
|
|
|
|
|
private var keyword: String? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun bindView() { |
|
|
|
override fun bindView() { |
|
|
|
binding = ActivitySearchWordBinding.inflate(layoutInflater) |
|
|
|
binding = ActivitySearchWordBinding.inflate(layoutInflater) |
|
|
@ -48,7 +48,21 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
override fun setUpToolbar(toolbar: Toolbar?) { |
|
|
|
override fun setUpToolbar(toolbar: Toolbar?) { |
|
|
|
super.setUpToolbar(toolbar) |
|
|
|
super.setUpToolbar(toolbar) |
|
|
|
setStatusBarColor(R.color.colorPrimary, true) |
|
|
|
setStatusBarColor(R.color.colorPrimary, true) |
|
|
|
|
|
|
|
setUpToolbarTitle() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun setUpToolbarTitle() { |
|
|
|
|
|
|
|
if (searchWord == null) { |
|
|
|
supportActionBar?.title = getString(R.string.search_word) |
|
|
|
supportActionBar?.title = getString(R.string.search_word) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var sum = 0 |
|
|
|
|
|
|
|
searchWord?.searchWords?.forEach { |
|
|
|
|
|
|
|
sum += it.searchWord2List.size |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
supportActionBar?.title = |
|
|
|
|
|
|
|
getString(R.string.search_word) + "(共" + searchWord?.searchWords?.size + |
|
|
|
|
|
|
|
"个章节," + sum + "条结果)" |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(outState: Bundle) { |
|
|
|
override fun onSaveInstanceState(outState: Bundle) { |
|
|
@ -60,7 +74,7 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
|
|
|
|
|
|
|
|
override fun onWindowFocusChanged(hasFocus: Boolean) { |
|
|
|
override fun onWindowFocusChanged(hasFocus: Boolean) { |
|
|
|
super.onWindowFocusChanged(hasFocus) |
|
|
|
super.onWindowFocusChanged(hasFocus) |
|
|
|
if (hasFocus) { |
|
|
|
if (hasFocus && binding.etSearchKey.text?.isEmpty() == true) { |
|
|
|
App.getHandler().postDelayed({ |
|
|
|
App.getHandler().postDelayed({ |
|
|
|
binding.etSearchKey.requestFocus() |
|
|
|
binding.etSearchKey.requestFocus() |
|
|
|
val imm = |
|
|
|
val imm = |
|
|
@ -81,6 +95,7 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
pageLoader = |
|
|
|
pageLoader = |
|
|
|
BitIntentDataManager.getInstance().getData(APPCONST.PAGE_LOADER_KEY) as PageLoader |
|
|
|
BitIntentDataManager.getInstance().getData(APPCONST.PAGE_LOADER_KEY) as PageLoader |
|
|
|
searchWordEngine = SearchWordEngine(book, chapters, pageLoader) |
|
|
|
searchWordEngine = SearchWordEngine(book, chapters, pageLoader) |
|
|
|
|
|
|
|
searchWord = DbManager.getDaoSession().searchWordDao.load(book.id) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun initWidget() { |
|
|
|
override fun initWidget() { |
|
|
@ -96,12 +111,11 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
override fun loadFinish(isEmpty: Boolean) { |
|
|
|
override fun loadFinish(isEmpty: Boolean) { |
|
|
|
binding.fabSearchStop.visibility = View.GONE |
|
|
|
binding.fabSearchStop.visibility = View.GONE |
|
|
|
binding.rpb.isAutoLoading = false |
|
|
|
binding.rpb.isAutoLoading = false |
|
|
|
var sum = 0 |
|
|
|
if (adapter.itemSize > 0) { |
|
|
|
adapter.items.forEach { |
|
|
|
searchWord = SearchWord(book.id, keyword, adapter.items) |
|
|
|
sum += it.searchWord2List.size |
|
|
|
setUpToolbarTitle() |
|
|
|
|
|
|
|
DbManager.getDaoSession().searchWordDao.insertOrReplace(searchWord) |
|
|
|
} |
|
|
|
} |
|
|
|
supportActionBar?.title = getString(R.string.search_word) + "(共" + adapter.itemSize + |
|
|
|
|
|
|
|
"个章节," + sum + "条结果)" |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
@ -135,6 +149,11 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
} |
|
|
|
} |
|
|
|
binding.rvSearchWord1.layoutManager = LinearLayoutManager(this) |
|
|
|
binding.rvSearchWord1.layoutManager = LinearLayoutManager(this) |
|
|
|
binding.rvSearchWord1.adapter = adapter |
|
|
|
binding.rvSearchWord1.adapter = adapter |
|
|
|
|
|
|
|
searchWord?.let { |
|
|
|
|
|
|
|
binding.etSearchKey.setText(it.keyword) |
|
|
|
|
|
|
|
keyword = it.keyword |
|
|
|
|
|
|
|
adapter.refreshItems(it.searchWords) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun initClick() { |
|
|
|
override fun initClick() { |
|
|
@ -144,8 +163,8 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
|
|
|
|
|
|
|
|
private fun search() { |
|
|
|
private fun search() { |
|
|
|
val keyword = binding.etSearchKey.text.toString() |
|
|
|
val keyword = binding.etSearchKey.text.toString() |
|
|
|
if (keyword.isNotEmpty()) { |
|
|
|
if (keyword.isNotEmpty() && this.keyword != keyword) { |
|
|
|
supportActionBar?.title = getString(R.string.search_word) |
|
|
|
this.keyword = keyword |
|
|
|
adapter.clear() |
|
|
|
adapter.clear() |
|
|
|
binding.fabSearchStop.visibility = View.VISIBLE |
|
|
|
binding.fabSearchStop.visibility = View.VISIBLE |
|
|
|
binding.rpb.isAutoLoading = true |
|
|
|
binding.rpb.isAutoLoading = true |
|
|
@ -156,6 +175,9 @@ class SearchWordActivity : BaseActivity() { |
|
|
|
binding.etSearchKey.windowToken, |
|
|
|
binding.etSearchKey.windowToken, |
|
|
|
InputMethodManager.HIDE_NOT_ALWAYS |
|
|
|
InputMethodManager.HIDE_NOT_ALWAYS |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
DbManager.getDaoSession().searchWordDao.deleteByKey(book.id) |
|
|
|
|
|
|
|
searchWord = null |
|
|
|
|
|
|
|
setUpToolbarTitle() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|