properly handle item refreshing at the search screen

This commit is contained in:
tibbi 2019-06-26 23:15:04 +02:00
parent 49510884b7
commit b2cd19109f

View file

@ -30,6 +30,8 @@ import kotlinx.android.synthetic.main.activity_search.*
class SearchActivity : SimpleActivity(), MediaOperationsListener { class SearchActivity : SimpleActivity(), MediaOperationsListener {
private var mIsSearchOpen = false private var mIsSearchOpen = false
private var mLastSearchedText = ""
private var mSearchMenuItem: MenuItem? = null private var mSearchMenuItem: MenuItem? = null
private var mCurrAsyncTask: GetMediaAsynctask? = null private var mCurrAsyncTask: GetMediaAsynctask? = null
private var mAllMedia = ArrayList<ThumbnailItem>() private var mAllMedia = ArrayList<ThumbnailItem>()
@ -63,6 +65,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
override fun onQueryTextChange(newText: String): Boolean { override fun onQueryTextChange(newText: String): Boolean {
if (mIsSearchOpen) { if (mIsSearchOpen) {
mLastSearchedText = newText
textChanged(newText) textChanged(newText)
} }
return true return true
@ -80,6 +83,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
if (mIsSearchOpen) { if (mIsSearchOpen) {
mIsSearchOpen = false mIsSearchOpen = false
mLastSearchedText = ""
} }
return true return true
} }
@ -267,20 +271,24 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
runOnUiThread { runOnUiThread {
setupAdapter() setupAdapter()
} }
startAsyncTask() startAsyncTask(false)
} }
} }
private fun startAsyncTask() { private fun startAsyncTask(updateItems: Boolean) {
mCurrAsyncTask?.stopFetching() mCurrAsyncTask?.stopFetching()
mCurrAsyncTask = GetMediaAsynctask(applicationContext, "", showAll = true) { mCurrAsyncTask = GetMediaAsynctask(applicationContext, "", showAll = true) {
mAllMedia = it.clone() as ArrayList<ThumbnailItem> mAllMedia = it.clone() as ArrayList<ThumbnailItem>
if (updateItems) {
textChanged(mLastSearchedText)
}
} }
mCurrAsyncTask!!.execute() mCurrAsyncTask!!.execute()
} }
override fun refreshItems() { override fun refreshItems() {
startAsyncTask(true)
} }
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) { override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) {