|  | 
|  | 1 | +package org.schabi.newpipelegacy.about | 
|  | 2 | + | 
|  | 3 | +import android.os.Bundle | 
|  | 4 | +import android.view.LayoutInflater | 
|  | 5 | +import android.view.MenuItem | 
|  | 6 | +import android.view.View | 
|  | 7 | +import android.view.ViewGroup | 
|  | 8 | +import android.widget.Button | 
|  | 9 | +import androidx.appcompat.app.AppCompatActivity | 
|  | 10 | +import androidx.fragment.app.Fragment | 
|  | 11 | +import androidx.fragment.app.FragmentActivity | 
|  | 12 | +import androidx.viewpager2.adapter.FragmentStateAdapter | 
|  | 13 | +import com.google.android.material.tabs.TabLayout | 
|  | 14 | +import com.google.android.material.tabs.TabLayoutMediator | 
|  | 15 | +import org.schabi.newpipelegacy.BuildConfig | 
|  | 16 | +import org.schabi.newpipelegacy.R | 
|  | 17 | +import org.schabi.newpipelegacy.databinding.ActivityAboutBinding | 
|  | 18 | +import org.schabi.newpipelegacy.databinding.FragmentAboutBinding | 
|  | 19 | +import org.schabi.newpipelegacy.util.Localization | 
|  | 20 | +import org.schabi.newpipelegacy.util.ShareUtils | 
|  | 21 | +import org.schabi.newpipelegacy.util.ThemeHelper | 
|  | 22 | + | 
|  | 23 | +class AboutActivity : AppCompatActivity() { | 
|  | 24 | +    override fun onCreate(savedInstanceState: Bundle?) { | 
|  | 25 | +        Localization.assureCorrectAppLanguage(this) | 
|  | 26 | +        super.onCreate(savedInstanceState) | 
|  | 27 | +        ThemeHelper.setTheme(this) | 
|  | 28 | +        title = getString(R.string.title_activity_about) | 
|  | 29 | +        val aboutBinding = ActivityAboutBinding.inflate(layoutInflater) | 
|  | 30 | +        setContentView(aboutBinding.root) | 
|  | 31 | +        setSupportActionBar(aboutBinding.aboutToolbar) | 
|  | 32 | +        supportActionBar!!.setDisplayHomeAsUpEnabled(true) | 
|  | 33 | +        // Create the adapter that will return a fragment for each of the three | 
|  | 34 | +        // primary sections of the activity. | 
|  | 35 | +        val mAboutStateAdapter = AboutStateAdapter(this) | 
|  | 36 | + | 
|  | 37 | +        // Set up the ViewPager with the sections adapter. | 
|  | 38 | +        aboutBinding.aboutViewPager2.adapter = mAboutStateAdapter | 
|  | 39 | +        TabLayoutMediator( | 
|  | 40 | +            aboutBinding.aboutTabLayout, | 
|  | 41 | +            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 | +            } | 
|  | 48 | +        }.attach() | 
|  | 49 | +    } | 
|  | 50 | + | 
|  | 51 | +    override fun onOptionsItemSelected(item: MenuItem): Boolean { | 
|  | 52 | +        if (item.itemId == android.R.id.home) { | 
|  | 53 | +            finish() | 
|  | 54 | +            return true | 
|  | 55 | +        } | 
|  | 56 | +        return super.onOptionsItemSelected(item) | 
|  | 57 | +    } | 
|  | 58 | + | 
|  | 59 | +    /** | 
|  | 60 | +     * A placeholder fragment containing a simple view. | 
|  | 61 | +     */ | 
|  | 62 | +    class AboutFragment : Fragment() { | 
|  | 63 | +        private fun Button.openLink(url: Int) { | 
|  | 64 | +            setOnClickListener { | 
|  | 65 | +                ShareUtils.openUrlInBrowser( | 
|  | 66 | +                    context, | 
|  | 67 | +                    requireContext().getString(url), | 
|  | 68 | +                    false | 
|  | 69 | +                ) | 
|  | 70 | +            } | 
|  | 71 | +        } | 
|  | 72 | + | 
|  | 73 | +        override fun onCreateView( | 
|  | 74 | +            inflater: LayoutInflater, | 
|  | 75 | +            container: ViewGroup?, | 
|  | 76 | +            savedInstanceState: Bundle? | 
|  | 77 | +        ): 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 | 
|  | 85 | +        } | 
|  | 86 | +    } | 
|  | 87 | + | 
|  | 88 | +    /** | 
|  | 89 | +     * A [FragmentStateAdapter] that returns a fragment corresponding to | 
|  | 90 | +     * one of the sections/tabs/pages. | 
|  | 91 | +     */ | 
|  | 92 | +    private class AboutStateAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) { | 
|  | 93 | +        override fun createFragment(position: Int): Fragment { | 
|  | 94 | +            return when (position) { | 
|  | 95 | +                POS_ABOUT -> AboutFragment() | 
|  | 96 | +                POS_LICENSE -> LicenseFragment.newInstance(SOFTWARE_COMPONENTS) | 
|  | 97 | +                else -> throw IllegalArgumentException("Unknown position for ViewPager2") | 
|  | 98 | +            } | 
|  | 99 | +        } | 
|  | 100 | + | 
|  | 101 | +        override fun getItemCount(): Int { | 
|  | 102 | +            // Show 2 total pages. | 
|  | 103 | +            return TOTAL_COUNT | 
|  | 104 | +        } | 
|  | 105 | +    } | 
|  | 106 | + | 
|  | 107 | +    companion object { | 
|  | 108 | +        /** | 
|  | 109 | +         * List of all software components. | 
|  | 110 | +         */ | 
|  | 111 | +        private val SOFTWARE_COMPONENTS = arrayOf( | 
|  | 112 | +            SoftwareComponent( | 
|  | 113 | +                "ACRA", "2013", "Kevin Gaudin", | 
|  | 114 | +                "https://github.com/ACRA/acra", StandardLicenses.APACHE2 | 
|  | 115 | +            ), | 
|  | 116 | +            SoftwareComponent( | 
|  | 117 | +                "AndroidX", "2005 - 2011", "The Android Open Source Project", | 
|  | 118 | +                "https://developer.android.com/jetpack", StandardLicenses.APACHE2 | 
|  | 119 | +            ), | 
|  | 120 | +            SoftwareComponent( | 
|  | 121 | +                "CircleImageView", "2014 - 2020", "Henning Dodenhof", | 
|  | 122 | +                "https://github.com/hdodenhof/CircleImageView", StandardLicenses.APACHE2 | 
|  | 123 | +            ), | 
|  | 124 | +            SoftwareComponent( | 
|  | 125 | +                "ExoPlayer", "2014 - 2020", "Google, Inc.", | 
|  | 126 | +                "https://github.com/google/ExoPlayer", StandardLicenses.APACHE2 | 
|  | 127 | +            ), | 
|  | 128 | +            SoftwareComponent( | 
|  | 129 | +                "GigaGet", "2014 - 2015", "Peter Cai", | 
|  | 130 | +                "https://github.com/PaperAirplane-Dev-Team/GigaGet", StandardLicenses.GPL3 | 
|  | 131 | +            ), | 
|  | 132 | +            SoftwareComponent( | 
|  | 133 | +                "Groupie", "2016", "Lisa Wray", | 
|  | 134 | +                "https://github.com/lisawray/groupie", StandardLicenses.MIT | 
|  | 135 | +            ), | 
|  | 136 | +            SoftwareComponent( | 
|  | 137 | +                "Icepick", "2015", "Frankie Sardo", | 
|  | 138 | +                "https://github.com/frankiesardo/icepick", StandardLicenses.EPL1 | 
|  | 139 | +            ), | 
|  | 140 | +            SoftwareComponent( | 
|  | 141 | +                "Jsoup", "2009 - 2020", "Jonathan Hedley", | 
|  | 142 | +                "https://github.com/jhy/jsoup", StandardLicenses.MIT | 
|  | 143 | +            ), | 
|  | 144 | +            SoftwareComponent( | 
|  | 145 | +                "Markwon", "2019", "Dimitry Ivanov", | 
|  | 146 | +                "https://github.com/noties/Markwon", StandardLicenses.APACHE2 | 
|  | 147 | +            ), | 
|  | 148 | +            SoftwareComponent( | 
|  | 149 | +                "Material Components for Android", "2016 - 2020", "Google, Inc.", | 
|  | 150 | +                "https://github.com/material-components/material-components-android", | 
|  | 151 | +                StandardLicenses.APACHE2 | 
|  | 152 | +            ), | 
|  | 153 | +            SoftwareComponent( | 
|  | 154 | +                "NewPipe Extractor", "2017 - 2020", "Christian Schabesberger", | 
|  | 155 | +                "https://github.com/TeamNewPipe/NewPipeExtractor", StandardLicenses.GPL3 | 
|  | 156 | +            ), | 
|  | 157 | +            SoftwareComponent( | 
|  | 158 | +                "NoNonsense-FilePicker", "2016", "Jonas Kalderstam", | 
|  | 159 | +                "https://github.com/spacecowboy/NoNonsense-FilePicker", StandardLicenses.MPL2 | 
|  | 160 | +            ), | 
|  | 161 | +            SoftwareComponent( | 
|  | 162 | +                "OkHttp", "2019", "Square, Inc.", | 
|  | 163 | +                "https://square.github.io/okhttp/", StandardLicenses.APACHE2 | 
|  | 164 | +            ), | 
|  | 165 | +            SoftwareComponent( | 
|  | 166 | +                "PrettyTime", "2012 - 2020", "Lincoln Baxter, III", | 
|  | 167 | +                "https://github.com/ocpsoft/prettytime", StandardLicenses.APACHE2 | 
|  | 168 | +            ), | 
|  | 169 | +            SoftwareComponent( | 
|  | 170 | +                "RxAndroid", "2015", "The RxAndroid authors", | 
|  | 171 | +                "https://github.com/ReactiveX/RxAndroid", StandardLicenses.APACHE2 | 
|  | 172 | +            ), | 
|  | 173 | +            SoftwareComponent( | 
|  | 174 | +                "RxBinding", "2015", "Jake Wharton", | 
|  | 175 | +                "https://github.com/JakeWharton/RxBinding", StandardLicenses.APACHE2 | 
|  | 176 | +            ), | 
|  | 177 | +            SoftwareComponent( | 
|  | 178 | +                "RxJava", "2016 - 2020", "RxJava Contributors", | 
|  | 179 | +                "https://github.com/ReactiveX/RxJava", StandardLicenses.APACHE2 | 
|  | 180 | +            ), | 
|  | 181 | +            SoftwareComponent( | 
|  | 182 | +                "Universal Image Loader", "2011 - 2015", "Sergey Tarasevich", | 
|  | 183 | +                "https://github.com/nostra13/Android-Universal-Image-Loader", | 
|  | 184 | +                StandardLicenses.APACHE2 | 
|  | 185 | +            ) | 
|  | 186 | +        ) | 
|  | 187 | +        private const val POS_ABOUT = 0 | 
|  | 188 | +        private const val POS_LICENSE = 1 | 
|  | 189 | +        private const val TOTAL_COUNT = 2 | 
|  | 190 | +    } | 
|  | 191 | +} | 
0 commit comments