Skip to content

Commit e206a26

Browse files
committed
Restore license dialog buttons to open the SoftwareComponent's website
Do not keep the active License but the active SoftwareComponent.
1 parent 242e203 commit e206a26

2 files changed

Lines changed: 36 additions & 33 deletions

File tree

app/src/main/java/org/schabi/newpipe/about/LicenseFragment.kt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import io.reactivex.rxjava3.core.Observable
1414
import io.reactivex.rxjava3.disposables.CompositeDisposable
1515
import io.reactivex.rxjava3.disposables.Disposable
1616
import io.reactivex.rxjava3.schedulers.Schedulers
17+
import org.schabi.newpipe.BuildConfig
1718
import org.schabi.newpipe.R
1819
import org.schabi.newpipe.databinding.FragmentLicensesBinding
1920
import org.schabi.newpipe.databinding.ItemSoftwareComponentBinding
@@ -25,13 +26,13 @@ import org.schabi.newpipe.util.external_communication.ShareUtils
2526
*/
2627
class 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)

app/src/main/java/org/schabi/newpipe/about/SoftwareComponent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.schabi.newpipe.about
22

33
import android.os.Parcelable
44
import kotlinx.parcelize.Parcelize
5+
import java.io.Serializable
56

67
@Parcelize
78
class SoftwareComponent
@@ -13,4 +14,4 @@ constructor(
1314
val link: String,
1415
val license: License,
1516
val version: String? = null
16-
) : Parcelable
17+
) : Parcelable, Serializable

0 commit comments

Comments
 (0)