finish actionmode and search on swiping between tabs

This commit is contained in:
tibbi 2021-05-19 20:23:11 +02:00
parent 8226588d95
commit be0fba6be8
4 changed files with 34 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import androidx.viewpager.widget.ViewPager
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
@ -316,6 +317,25 @@ class MainActivity : SimpleActivity() {
)
setupTabColors(tabToOpen)
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
if (isSearchOpen) {
getCurrentFragment()?.searchQueryChanged("")
searchMenuItem?.collapseActionView()
}
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) {
main_tabs_holder.getTabAt(position)?.select()
getAllFragments().forEach {
it?.finishActMode()
}
invalidateOptionsMenu()
}
})
}
private fun setupTabColors(lastUsedTab: Int) {

View File

@ -77,7 +77,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
getRecyclerAdapter()?.updateDateTimeFormat()
}
fun finishActMode() {
override fun finishActMode() {
getRecyclerAdapter()?.finishActMode()
}
@ -276,7 +276,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
openPath(path)
}
fun searchQueryChanged(text: String) {
override fun searchQueryChanged(text: String) {
val searchText = text.trim()
lastSearchedText = searchText
ensureBackgroundThread {

View File

@ -13,4 +13,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
abstract fun setupFontSize()
abstract fun setupDateTimeFormat()
abstract fun searchQueryChanged(text: String)
abstract fun finishActMode()
}

View File

@ -64,6 +64,8 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
}
private fun getRecyclerAdapter() = recents_list.adapter as? ItemsAdapter
override fun refreshItems() {}
override fun deleteFiles(files: ArrayList<FileDirItem>) {}
@ -73,4 +75,10 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
override fun setupFontSize() {}
override fun setupDateTimeFormat() {}
override fun searchQueryChanged(text: String) {}
override fun finishActMode() {
getRecyclerAdapter()?.finishActMode()
}
}