|
1 | 1 | package org.schabi.newpipe.about |
2 | 2 |
|
3 | 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.annotation.StringRes |
| 4 | +import androidx.activity.compose.setContent |
| 5 | +import androidx.activity.enableEdgeToEdge |
10 | 6 | import androidx.appcompat.app.AppCompatActivity |
11 | | -import androidx.fragment.app.Fragment |
12 | | -import androidx.fragment.app.FragmentActivity |
13 | | -import androidx.viewpager2.adapter.FragmentStateAdapter |
14 | | -import com.google.android.material.tabs.TabLayoutMediator |
15 | | -import org.schabi.newpipe.BuildConfig |
| 7 | +import androidx.compose.ui.res.stringResource |
16 | 8 | import org.schabi.newpipe.R |
17 | | -import org.schabi.newpipe.databinding.ActivityAboutBinding |
18 | | -import org.schabi.newpipe.databinding.FragmentAboutBinding |
| 9 | +import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar |
| 10 | +import org.schabi.newpipe.ui.screens.AboutScreen |
| 11 | +import org.schabi.newpipe.ui.theme.AppTheme |
19 | 12 | import org.schabi.newpipe.util.Localization |
20 | | -import org.schabi.newpipe.util.ThemeHelper |
21 | | -import org.schabi.newpipe.util.external_communication.ShareUtils |
22 | 13 |
|
23 | 14 | class AboutActivity : AppCompatActivity() { |
24 | | - |
25 | 15 | override fun onCreate(savedInstanceState: Bundle?) { |
26 | 16 | Localization.assureCorrectAppLanguage(this) |
| 17 | + enableEdgeToEdge() |
27 | 18 | super.onCreate(savedInstanceState) |
28 | | - ThemeHelper.setTheme(this) |
29 | | - title = getString(R.string.title_activity_about) |
30 | | - |
31 | | - val aboutBinding = ActivityAboutBinding.inflate(layoutInflater) |
32 | | - setContentView(aboutBinding.root) |
33 | | - setSupportActionBar(aboutBinding.aboutToolbar) |
34 | | - supportActionBar?.setDisplayHomeAsUpEnabled(true) |
35 | | - |
36 | | - // Create the adapter that will return a fragment for each of the three |
37 | | - // primary sections of the activity. |
38 | | - val mAboutStateAdapter = AboutStateAdapter(this) |
39 | | - // Set up the ViewPager with the sections adapter. |
40 | | - aboutBinding.aboutViewPager2.adapter = mAboutStateAdapter |
41 | | - TabLayoutMediator( |
42 | | - aboutBinding.aboutTabLayout, |
43 | | - aboutBinding.aboutViewPager2 |
44 | | - ) { tab, position -> |
45 | | - tab.setText(mAboutStateAdapter.getPageTitle(position)) |
46 | | - }.attach() |
47 | | - } |
48 | | - |
49 | | - override fun onOptionsItemSelected(item: MenuItem): Boolean { |
50 | | - if (item.itemId == android.R.id.home) { |
51 | | - finish() |
52 | | - return true |
53 | | - } |
54 | | - return super.onOptionsItemSelected(item) |
55 | | - } |
56 | | - |
57 | | - /** |
58 | | - * A placeholder fragment containing a simple view. |
59 | | - */ |
60 | | - class AboutFragment : Fragment() { |
61 | | - private fun Button.openLink(@StringRes url: Int) { |
62 | | - setOnClickListener { |
63 | | - ShareUtils.openUrlInApp(context, requireContext().getString(url)) |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - override fun onCreateView( |
68 | | - inflater: LayoutInflater, |
69 | | - container: ViewGroup?, |
70 | | - savedInstanceState: Bundle? |
71 | | - ): View { |
72 | | - FragmentAboutBinding.inflate(inflater, container, false).apply { |
73 | | - aboutAppVersion.text = BuildConfig.VERSION_NAME |
74 | | - aboutGithubLink.openLink(R.string.github_url) |
75 | | - aboutDonationLink.openLink(R.string.donation_url) |
76 | | - aboutWebsiteLink.openLink(R.string.website_url) |
77 | | - aboutPrivacyPolicyLink.openLink(R.string.privacy_policy_url) |
78 | | - faqLink.openLink(R.string.faq_url) |
79 | | - return root |
80 | | - } |
81 | | - } |
82 | | - } |
83 | 19 |
|
84 | | - /** |
85 | | - * A [FragmentStateAdapter] that returns a fragment corresponding to |
86 | | - * one of the sections/tabs/pages. |
87 | | - */ |
88 | | - private class AboutStateAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) { |
89 | | - private val posAbout = 0 |
90 | | - private val posLicense = 1 |
91 | | - private val totalCount = 2 |
92 | | - |
93 | | - override fun createFragment(position: Int): Fragment { |
94 | | - return when (position) { |
95 | | - posAbout -> AboutFragment() |
96 | | - posLicense -> LicenseFragment.newInstance(SOFTWARE_COMPONENTS) |
97 | | - else -> throw IllegalArgumentException("Unknown position for ViewPager2") |
| 20 | + setContent { |
| 21 | + AppTheme { |
| 22 | + ScaffoldWithToolbar( |
| 23 | + title = stringResource(R.string.title_activity_about), |
| 24 | + onBackClick = { onBackPressedDispatcher.onBackPressed() } |
| 25 | + ) { padding -> |
| 26 | + AboutScreen(padding) |
| 27 | + } |
98 | 28 | } |
99 | 29 | } |
100 | | - |
101 | | - override fun getItemCount(): Int { |
102 | | - // Show 2 total pages. |
103 | | - return totalCount |
104 | | - } |
105 | | - |
106 | | - fun getPageTitle(position: Int): Int { |
107 | | - return when (position) { |
108 | | - posAbout -> R.string.tab_about |
109 | | - posLicense -> R.string.tab_licenses |
110 | | - else -> throw IllegalArgumentException("Unknown position for ViewPager2") |
111 | | - } |
112 | | - } |
113 | | - } |
114 | | - |
115 | | - companion object { |
116 | | - /** |
117 | | - * List of all software components. |
118 | | - */ |
119 | | - private val SOFTWARE_COMPONENTS = arrayListOf( |
120 | | - SoftwareComponent( |
121 | | - "ACRA", "2013", "Kevin Gaudin", |
122 | | - "https://github.com/ACRA/acra", StandardLicenses.APACHE2 |
123 | | - ), |
124 | | - SoftwareComponent( |
125 | | - "AndroidX", "2005 - 2011", "The Android Open Source Project", |
126 | | - "https://developer.android.com/jetpack", StandardLicenses.APACHE2 |
127 | | - ), |
128 | | - SoftwareComponent( |
129 | | - "ExoPlayer", "2014 - 2020", "Google, Inc.", |
130 | | - "https://github.com/google/ExoPlayer", StandardLicenses.APACHE2 |
131 | | - ), |
132 | | - SoftwareComponent( |
133 | | - "GigaGet", "2014 - 2015", "Peter Cai", |
134 | | - "https://github.com/PaperAirplane-Dev-Team/GigaGet", StandardLicenses.GPL3 |
135 | | - ), |
136 | | - SoftwareComponent( |
137 | | - "Groupie", "2016", "Lisa Wray", |
138 | | - "https://github.com/lisawray/groupie", StandardLicenses.MIT |
139 | | - ), |
140 | | - SoftwareComponent( |
141 | | - "Android-State", "2018", "Evernote", |
142 | | - "https://github.com/Evernote/android-state", StandardLicenses.EPL1 |
143 | | - ), |
144 | | - SoftwareComponent( |
145 | | - "Bridge", "2021", "Livefront", |
146 | | - "https://github.com/livefront/bridge", StandardLicenses.APACHE2 |
147 | | - ), |
148 | | - SoftwareComponent( |
149 | | - "Jsoup", "2009 - 2020", "Jonathan Hedley", |
150 | | - "https://github.com/jhy/jsoup", StandardLicenses.MIT |
151 | | - ), |
152 | | - SoftwareComponent( |
153 | | - "Markwon", "2019", "Dimitry Ivanov", |
154 | | - "https://github.com/noties/Markwon", StandardLicenses.APACHE2 |
155 | | - ), |
156 | | - SoftwareComponent( |
157 | | - "Material Components for Android", "2016 - 2020", "Google, Inc.", |
158 | | - "https://github.com/material-components/material-components-android", |
159 | | - StandardLicenses.APACHE2 |
160 | | - ), |
161 | | - SoftwareComponent( |
162 | | - "NewPipe Extractor", "2017 - 2020", "Christian Schabesberger", |
163 | | - "https://github.com/TeamNewPipe/NewPipeExtractor", StandardLicenses.GPL3 |
164 | | - ), |
165 | | - SoftwareComponent( |
166 | | - "NoNonsense-FilePicker", "2016", "Jonas Kalderstam", |
167 | | - "https://github.com/spacecowboy/NoNonsense-FilePicker", StandardLicenses.MPL2 |
168 | | - ), |
169 | | - SoftwareComponent( |
170 | | - "OkHttp", "2019", "Square, Inc.", |
171 | | - "https://square.github.io/okhttp/", StandardLicenses.APACHE2 |
172 | | - ), |
173 | | - SoftwareComponent( |
174 | | - "Coil", "2023", "Coil Contributors", |
175 | | - "https://coil-kt.github.io/coil/", StandardLicenses.APACHE2 |
176 | | - ), |
177 | | - SoftwareComponent( |
178 | | - "PrettyTime", "2012 - 2020", "Lincoln Baxter, III", |
179 | | - "https://github.com/ocpsoft/prettytime", StandardLicenses.APACHE2 |
180 | | - ), |
181 | | - SoftwareComponent( |
182 | | - "ProcessPhoenix", "2015", "Jake Wharton", |
183 | | - "https://github.com/JakeWharton/ProcessPhoenix", StandardLicenses.APACHE2 |
184 | | - ), |
185 | | - SoftwareComponent( |
186 | | - "RxAndroid", "2015", "The RxAndroid authors", |
187 | | - "https://github.com/ReactiveX/RxAndroid", StandardLicenses.APACHE2 |
188 | | - ), |
189 | | - SoftwareComponent( |
190 | | - "RxBinding", "2015", "Jake Wharton", |
191 | | - "https://github.com/JakeWharton/RxBinding", StandardLicenses.APACHE2 |
192 | | - ), |
193 | | - SoftwareComponent( |
194 | | - "RxJava", "2016 - 2020", "RxJava Contributors", |
195 | | - "https://github.com/ReactiveX/RxJava", StandardLicenses.APACHE2 |
196 | | - ), |
197 | | - SoftwareComponent( |
198 | | - "SearchPreference", "2018", "ByteHamster", |
199 | | - "https://github.com/ByteHamster/SearchPreference", StandardLicenses.MIT |
200 | | - ), |
201 | | - ) |
202 | 30 | } |
203 | 31 | } |
0 commit comments