mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-11 23:04:32 +02:00
This commit is contained in:
parent
0baa889de5
commit
58ddd3c8cc
2 changed files with 20 additions and 13 deletions
|
@ -9,8 +9,7 @@ import android.window.OnBackInvokedDispatcher
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.fragment.app.FragmentPagerAdapter
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
|
||||||
import de.jrpie.android.launcher.Application
|
import de.jrpie.android.launcher.Application
|
||||||
import de.jrpie.android.launcher.R
|
import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.actions.LauncherAction
|
import de.jrpie.android.launcher.actions.LauncherAction
|
||||||
|
@ -225,13 +224,10 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
updateTitle()
|
updateTitle()
|
||||||
|
|
||||||
val sectionsPagerAdapter = ListSectionsPagerAdapter(this)
|
val sectionsPagerAdapter = ListSectionsPagerAdapter(this)
|
||||||
binding.listViewpager.apply {
|
binding.listViewpager.let {
|
||||||
adapter = sectionsPagerAdapter
|
it.adapter = sectionsPagerAdapter
|
||||||
currentItem = 0
|
binding.listTabs.setupWithViewPager(it)
|
||||||
}
|
}
|
||||||
TabLayoutMediator(binding.listTabs, binding.listViewpager) { tab, position ->
|
|
||||||
tab.text = sectionsPagerAdapter.getPageTitle(position)
|
|
||||||
}.attach()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,11 +239,17 @@ private val TAB_TITLES = arrayOf(
|
||||||
/**
|
/**
|
||||||
* The [ListSectionsPagerAdapter] returns the fragment,
|
* The [ListSectionsPagerAdapter] returns the fragment,
|
||||||
* which corresponds to the selected tab in [ListActivity].
|
* which corresponds to the selected tab in [ListActivity].
|
||||||
|
*
|
||||||
|
* This should eventually be replaced by a [FragmentStateAdapter]
|
||||||
|
* However this keyboard does not open when using [ViewPager2]
|
||||||
|
* so currently [ViewPager] is used here.
|
||||||
|
* https://github.com/jrpie/launcher/issues/130
|
||||||
*/
|
*/
|
||||||
|
@Suppress("deprecation")
|
||||||
class ListSectionsPagerAdapter(private val activity: ListActivity) :
|
class ListSectionsPagerAdapter(private val activity: ListActivity) :
|
||||||
FragmentStateAdapter(activity) {
|
FragmentPagerAdapter(activity.supportFragmentManager) {
|
||||||
|
|
||||||
override fun createFragment(position: Int): Fragment {
|
override fun getItem(position: Int): Fragment {
|
||||||
return when (position) {
|
return when (position) {
|
||||||
0 -> ListFragmentApps()
|
0 -> ListFragmentApps()
|
||||||
1 -> ListFragmentOther()
|
1 -> ListFragmentOther()
|
||||||
|
@ -255,11 +257,11 @@ class ListSectionsPagerAdapter(private val activity: ListActivity) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPageTitle(position: Int): CharSequence {
|
override fun getPageTitle(position: Int): CharSequence {
|
||||||
return activity.resources.getString(TAB_TITLES[position])
|
return activity.resources.getString(TAB_TITLES[position])
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getCount(): Int {
|
||||||
return when (activity.intention) {
|
return when (activity.intention) {
|
||||||
ListActivity.ListActivityIntention.VIEW -> 1
|
ListActivity.ListActivityIntention.VIEW -> 1
|
||||||
else -> 2
|
else -> 2
|
||||||
|
|
|
@ -95,7 +95,12 @@
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<!--
|
||||||
|
Should be replaced by androidx.viewpager2.widget.ViewPager2
|
||||||
|
but there is an issue with opening the keyboard:
|
||||||
|
https://github.com/jrpie/launcher/issues/130
|
||||||
|
-->
|
||||||
|
<androidx.viewpager.widget.ViewPager
|
||||||
android:id="@+id/list_viewpager"
|
android:id="@+id/list_viewpager"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
|
Loading…
Add table
Reference in a new issue