Skip to content

Commit

Permalink
finish actionmode and search on swiping between tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed May 19, 2021
1 parent 8226588 commit be0fba6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
getRecyclerAdapter()?.updateDateTimeFormat()
}

fun finishActMode() {
override fun finishActMode() {
getRecyclerAdapter()?.finishActMode()
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {}
Expand All @@ -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()
}
}

0 comments on commit be0fba6

Please sign in to comment.