|
|
@ -34,7 +34,6 @@ import org.jetbrains.anko.startActivity |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_search), |
|
|
|
class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_search), |
|
|
|
SearchViewModel.CallBack, |
|
|
|
|
|
|
|
BookAdapter.CallBack, |
|
|
|
BookAdapter.CallBack, |
|
|
|
HistoryKeyAdapter.CallBack, |
|
|
|
HistoryKeyAdapter.CallBack, |
|
|
|
SearchAdapter.CallBack { |
|
|
|
SearchAdapter.CallBack { |
|
|
@ -53,7 +52,6 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se |
|
|
|
private var groups = hashSetOf<String>() |
|
|
|
private var groups = hashSetOf<String>() |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
viewModel.callBack = this |
|
|
|
|
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
|
initSearchView() |
|
|
|
initSearchView() |
|
|
|
initOtherView() |
|
|
|
initOtherView() |
|
|
@ -181,6 +179,13 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se |
|
|
|
viewModel.searchBookLiveData.observe(this, Observer { |
|
|
|
viewModel.searchBookLiveData.observe(this, Observer { |
|
|
|
setSearchItems(it) |
|
|
|
setSearchItems(it) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
viewModel.isSearchLiveData.observe(this, Observer { |
|
|
|
|
|
|
|
if (it) { |
|
|
|
|
|
|
|
startSearch() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
searchFinally() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initIntent() { |
|
|
|
private fun initIntent() { |
|
|
@ -256,18 +261,19 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
private fun setSearchItems(items: List<SearchBook>) { |
|
|
|
private fun setSearchItems(items: List<SearchBook>) { |
|
|
|
val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), items)) |
|
|
|
val diffResult = DiffUtil.calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), items)) |
|
|
|
adapter.setItems(items, false) |
|
|
|
adapter.setItems(items, false) |
|
|
|
diffResult.dispatchUpdatesTo(adapter) |
|
|
|
diffResult.dispatchUpdatesTo(adapter) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun startSearch() { |
|
|
|
fun startSearch() { |
|
|
|
refresh_progress_bar.isAutoLoading = true |
|
|
|
refresh_progress_bar.isAutoLoading = true |
|
|
|
fb_stop.visible() |
|
|
|
fb_stop.visible() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun searchFinally() { |
|
|
|
fun searchFinally() { |
|
|
|
refresh_progress_bar.isAutoLoading = false |
|
|
|
refresh_progress_bar.isAutoLoading = false |
|
|
|
loadMoreView.startLoad() |
|
|
|
loadMoreView.startLoad() |
|
|
|
fb_stop.invisible() |
|
|
|
fb_stop.invisible() |
|
|
|