@@ -10,7 +10,6 @@ import androidx.appcompat.app.AppCompatActivity
1010import androidx.fragment.app.Fragment
1111import androidx.fragment.app.FragmentActivity
1212import androidx.viewpager2.adapter.FragmentStateAdapter
13- import com.google.android.material.tabs.TabLayout
1413import com.google.android.material.tabs.TabLayoutMediator
1514import org.schabi.newpipe.BuildConfig
1615import org.schabi.newpipe.R
@@ -21,30 +20,28 @@ import org.schabi.newpipe.util.ThemeHelper
2120import org.schabi.newpipe.util.external_communication.ShareUtils
2221
2322class AboutActivity : AppCompatActivity () {
23+
2424 override fun onCreate (savedInstanceState : Bundle ? ) {
2525 Localization .assureCorrectAppLanguage(this )
2626 super .onCreate(savedInstanceState)
2727 ThemeHelper .setTheme(this )
2828 title = getString(R .string.title_activity_about)
29+
2930 val aboutBinding = ActivityAboutBinding .inflate(layoutInflater)
3031 setContentView(aboutBinding.root)
3132 setSupportActionBar(aboutBinding.aboutToolbar)
32- supportActionBar!! .setDisplayHomeAsUpEnabled(true )
33+ supportActionBar?.setDisplayHomeAsUpEnabled(true )
34+
3335 // Create the adapter that will return a fragment for each of the three
3436 // primary sections of the activity.
3537 val mAboutStateAdapter = AboutStateAdapter (this )
36-
3738 // Set up the ViewPager with the sections adapter.
3839 aboutBinding.aboutViewPager2.adapter = mAboutStateAdapter
3940 TabLayoutMediator (
4041 aboutBinding.aboutTabLayout,
4142 aboutBinding.aboutViewPager2
42- ) { tab: TabLayout .Tab , position: Int ->
43- when (position) {
44- POS_ABOUT -> tab.setText(R .string.tab_about)
45- POS_LICENSE -> tab.setText(R .string.tab_licenses)
46- else -> throw IllegalArgumentException (" Unknown position for ViewPager2" )
47- }
43+ ) { tab, position ->
44+ tab.setText(mAboutStateAdapter.getPageTitle(position))
4845 }.attach()
4946 }
5047
@@ -75,13 +72,14 @@ class AboutActivity : AppCompatActivity() {
7572 container : ViewGroup ? ,
7673 savedInstanceState : Bundle ?
7774 ): View {
78- val aboutBinding = FragmentAboutBinding .inflate(inflater, container, false )
79- aboutBinding.aboutAppVersion.text = BuildConfig .VERSION_NAME
80- aboutBinding.aboutGithubLink.openLink(R .string.github_url)
81- aboutBinding.aboutDonationLink.openLink(R .string.donation_url)
82- aboutBinding.aboutWebsiteLink.openLink(R .string.website_url)
83- aboutBinding.aboutPrivacyPolicyLink.openLink(R .string.privacy_policy_url)
84- return aboutBinding.root
75+ FragmentAboutBinding .inflate(inflater, container, false ).apply {
76+ aboutAppVersion.text = BuildConfig .VERSION_NAME
77+ aboutGithubLink.openLink(R .string.github_url)
78+ aboutDonationLink.openLink(R .string.donation_url)
79+ aboutWebsiteLink.openLink(R .string.website_url)
80+ aboutPrivacyPolicyLink.openLink(R .string.privacy_policy_url)
81+ return root
82+ }
8583 }
8684 }
8785
@@ -90,17 +88,29 @@ class AboutActivity : AppCompatActivity() {
9088 * one of the sections/tabs/pages.
9189 */
9290 private class AboutStateAdapter (fa : FragmentActivity ) : FragmentStateAdapter(fa) {
91+ private val posAbout = 0
92+ private val posLicense = 1
93+ private val totalCount = 2
94+
9395 override fun createFragment (position : Int ): Fragment {
9496 return when (position) {
95- POS_ABOUT -> AboutFragment ()
96- POS_LICENSE -> LicenseFragment .newInstance(SOFTWARE_COMPONENTS )
97+ posAbout -> AboutFragment ()
98+ posLicense -> LicenseFragment .newInstance(SOFTWARE_COMPONENTS )
9799 else -> throw IllegalArgumentException (" Unknown position for ViewPager2" )
98100 }
99101 }
100102
101103 override fun getItemCount (): Int {
102104 // Show 2 total pages.
103- return TOTAL_COUNT
105+ return totalCount
106+ }
107+
108+ fun getPageTitle (position : Int ): Int {
109+ return when (position) {
110+ posAbout -> R .string.tab_about
111+ posLicense -> R .string.tab_licenses
112+ else -> throw IllegalArgumentException (" Unknown position for ViewPager2" )
113+ }
104114 }
105115 }
106116
@@ -187,8 +197,5 @@ class AboutActivity : AppCompatActivity() {
187197 " https://github.com/ByteHamster/SearchPreference" , StandardLicenses .MIT
188198 ),
189199 )
190- private const val POS_ABOUT = 0
191- private const val POS_LICENSE = 1
192- private const val TOTAL_COUNT = 2
193200 }
194201}
0 commit comments