mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
refactor (library): delay search when typing
This commit is contained in:
parent
3c152e04d1
commit
96770ebc5a
1 changed files with 19 additions and 1 deletions
|
@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.lagradost.cloudstream3.APIHolder
|
||||
import com.lagradost.cloudstream3.APIHolder.allProviders
|
||||
|
@ -163,7 +164,16 @@ class LibraryFragment : Fragment() {
|
|||
return true
|
||||
}
|
||||
|
||||
libraryViewModel.sort(ListSorting.Query, newText)
|
||||
val callback = Runnable {
|
||||
libraryViewModel.sort(ListSorting.Query, newText)
|
||||
}
|
||||
|
||||
binding?.mainSearch?.removeCallbacks(callback)
|
||||
|
||||
// Delay the execution of the search operation by 0.5 second (adjust as needed)
|
||||
// this prevents running search when the user is typing
|
||||
binding?.mainSearch?.postDelayed(callback, 1000)
|
||||
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
@ -451,6 +461,14 @@ class LibraryFragment : Fragment() {
|
|||
}
|
||||
}.attach()
|
||||
|
||||
binding?.libraryTabLayout?.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
|
||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||
libraryViewModel.currentPage = binding?.libraryTabLayout?.selectedTabPosition ?:0
|
||||
}
|
||||
override fun onTabUnselected(tab: TabLayout.Tab?) {}
|
||||
override fun onTabReselected(tab: TabLayout.Tab?) {}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue