From e7edb729a4ae3fb9b4a3de039397c02c453e8343 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 26 Jun 2019 12:06:12 +0200 Subject: [PATCH] add file fetching at the search activity --- .../gallery/pro/activities/SearchActivity.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt index d0939fa2e..b4c678cc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt @@ -8,14 +8,20 @@ import android.view.MenuItem import androidx.appcompat.widget.SearchView import androidx.core.view.MenuItemCompat import com.simplemobiletools.gallery.pro.R +import com.simplemobiletools.gallery.pro.asynctasks.GetMediaAsynctask +import com.simplemobiletools.gallery.pro.extensions.getCachedMedia +import com.simplemobiletools.gallery.pro.models.ThumbnailItem class SearchActivity : SimpleActivity() { private var mIsSearchOpen = false private var mSearchMenuItem: MenuItem? = null + private var mCurrAsyncTask: GetMediaAsynctask? = null + private var mAllMedia = ArrayList() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_search) + getAllMedia() } override fun onStop() { @@ -23,6 +29,11 @@ class SearchActivity : SimpleActivity() { mSearchMenuItem?.collapseActionView() } + override fun onDestroy() { + super.onDestroy() + mCurrAsyncTask?.stopFetching() + } + override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_search, menu) setupSearch(menu) @@ -68,4 +79,22 @@ class SearchActivity : SimpleActivity() { private fun textChanged(text: String) { } + + private fun getAllMedia() { + getCachedMedia("") { + if (it.isNotEmpty()) { + mAllMedia = it + } + startAsyncTask() + } + } + + private fun startAsyncTask() { + mCurrAsyncTask?.stopFetching() + mCurrAsyncTask = GetMediaAsynctask(applicationContext, "", showAll = true) { + mAllMedia = it + } + + mCurrAsyncTask!!.execute() + } }