@@ -14,6 +14,7 @@ import io.reactivex.rxjava3.core.Observable
1414import io.reactivex.rxjava3.disposables.CompositeDisposable
1515import io.reactivex.rxjava3.disposables.Disposable
1616import io.reactivex.rxjava3.schedulers.Schedulers
17+ import org.schabi.newpipe.BuildConfig
1718import org.schabi.newpipe.R
1819import org.schabi.newpipe.databinding.FragmentLicensesBinding
1920import org.schabi.newpipe.databinding.ItemSoftwareComponentBinding
@@ -25,13 +26,13 @@ import org.schabi.newpipe.util.external_communication.ShareUtils
2526 */
2627class LicenseFragment : Fragment () {
2728 private lateinit var softwareComponents: Array <SoftwareComponent >
28- private var activeLicense : License ? = null
29+ private var activeSoftwareComponent : SoftwareComponent ? = null
2930 private val compositeDisposable = CompositeDisposable ()
3031
3132 override fun onCreate (savedInstanceState : Bundle ? ) {
3233 super .onCreate(savedInstanceState)
3334 softwareComponents = arguments?.getParcelableArray(ARG_COMPONENTS ) as Array <SoftwareComponent >
34- activeLicense = savedInstanceState?.getSerializable(LICENSE_KEY ) as ? License
35+ activeSoftwareComponent = savedInstanceState?.getSerializable(SOFTWARE_COMPONENT_KEY ) as ? SoftwareComponent
3536 // Sort components by name
3637 softwareComponents.sortBy { it.name }
3738 }
@@ -48,9 +49,8 @@ class LicenseFragment : Fragment() {
4849 ): View {
4950 val binding = FragmentLicensesBinding .inflate(inflater, container, false )
5051 binding.licensesAppReadLicense.setOnClickListener {
51- activeLicense = StandardLicenses .GPL3
5252 compositeDisposable.add(
53- showLicense(StandardLicenses . GPL3 )
53+ showLicense(NEWPIPE_SOFTWARE_COMPONENT )
5454 )
5555 }
5656 for (component in softwareComponents) {
@@ -66,47 +66,31 @@ class LicenseFragment : Fragment() {
6666 val root: View = componentBinding.root
6767 root.tag = component
6868 root.setOnClickListener {
69- activeLicense = component.license
7069 compositeDisposable.add(
7170 showLicense(component)
7271 )
7372 }
7473 binding.licensesSoftwareComponents.addView(root)
7574 registerForContextMenu(root)
7675 }
77- activeLicense ?.let { compositeDisposable.add(showLicense(it)) }
76+ activeSoftwareComponent ?.let { compositeDisposable.add(showLicense(it)) }
7877 return binding.root
7978 }
8079
8180 override fun onSaveInstanceState (savedInstanceState : Bundle ) {
8281 super .onSaveInstanceState(savedInstanceState)
83- activeLicense?.let { savedInstanceState.putSerializable(LICENSE_KEY , it) }
84- }
85-
86- private fun showLicense (component : SoftwareComponent ): Disposable {
87- return showLicense(component.license) {
88- setPositiveButton(R .string.dismiss) { dialog, _ ->
89- dialog.dismiss()
90- }
91- setNeutralButton(R .string.open_website_license) { _, _ ->
92- ShareUtils .openUrlInApp(requireContext(), component.link)
93- }
94- }
95- }
96-
97- private fun showLicense (license : License ) = showLicense(license) {
98- setPositiveButton(R .string.ok) { dialog, _ -> dialog.dismiss() }
82+ activeSoftwareComponent?.let { savedInstanceState.putSerializable(SOFTWARE_COMPONENT_KEY , it) }
9983 }
10084
10185 private fun showLicense (
102- license : License ,
103- block : AlertDialog .Builder .() -> AlertDialog .Builder
86+ softwareComponent : SoftwareComponent
10487 ): Disposable {
10588 return if (context == null ) {
10689 Disposable .empty()
10790 } else {
10891 val context = requireContext()
109- Observable .fromCallable { getFormattedLicense(context, license) }
92+ activeSoftwareComponent = softwareComponent
93+ Observable .fromCallable { getFormattedLicense(context, softwareComponent.license) }
11094 .subscribeOn(Schedulers .io())
11195 .observeOn(AndroidSchedulers .mainThread())
11296 .subscribe { formattedLicense ->
@@ -117,20 +101,38 @@ class LicenseFragment : Fragment() {
117101 webView.loadData(webViewData, " text/html; charset=UTF-8" , " base64" )
118102
119103 Localization .assureCorrectAppLanguage(context)
120- AlertDialog .Builder (requireContext())
121- .setTitle(license .name)
104+ val builder = AlertDialog .Builder (requireContext())
105+ .setTitle(softwareComponent .name)
122106 .setView(webView)
123- .setOnCancelListener { activeLicense = null }
124- .setOnDismissListener { activeLicense = null }
125- .block()
126- .show()
107+ .setOnCancelListener { activeSoftwareComponent = null }
108+ .setOnDismissListener { activeSoftwareComponent = null }
109+ if (softwareComponent == NEWPIPE_SOFTWARE_COMPONENT ) {
110+ builder.setPositiveButton(R .string.ok) { dialog, _ -> dialog.dismiss() }
111+ } else {
112+ builder.setPositiveButton(R .string.dismiss) { dialog, _ ->
113+ dialog.dismiss()
114+ }
115+ .setNeutralButton(R .string.open_website_license) { _, _ ->
116+ ShareUtils .openUrlInApp(requireContext(), softwareComponent.link)
117+ }
118+ }
119+
120+ builder.show()
127121 }
128122 }
129123 }
130124
131125 companion object {
132126 private const val ARG_COMPONENTS = " components"
133- private const val LICENSE_KEY = " ACTIVE_LICENSE"
127+ private const val SOFTWARE_COMPONENT_KEY = " ACTIVE_SOFTWARE_COMPONENT"
128+ private val NEWPIPE_SOFTWARE_COMPONENT = SoftwareComponent (
129+ " NewPipe" ,
130+ " 2014-2023" ,
131+ " Team NewPipe" ,
132+ " https://newpipe.net/" ,
133+ StandardLicenses .GPL3 ,
134+ BuildConfig .VERSION_NAME
135+ )
134136 fun newInstance (softwareComponents : Array <SoftwareComponent >): LicenseFragment {
135137 val fragment = LicenseFragment ()
136138 fragment.arguments = bundleOf(ARG_COMPONENTS to softwareComponents)
0 commit comments