mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-25 20:42:34 +01:00
Restore license dialog buttons to open the SoftwareComponent's website
Do not keep the active License but the active SoftwareComponent.
This commit is contained in:
parent
242e20316b
commit
e206a26a85
@ -14,6 +14,7 @@ import io.reactivex.rxjava3.core.Observable
|
|||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
import org.schabi.newpipe.BuildConfig
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.databinding.FragmentLicensesBinding
|
import org.schabi.newpipe.databinding.FragmentLicensesBinding
|
||||||
import org.schabi.newpipe.databinding.ItemSoftwareComponentBinding
|
import org.schabi.newpipe.databinding.ItemSoftwareComponentBinding
|
||||||
@ -25,13 +26,13 @@ import org.schabi.newpipe.util.external_communication.ShareUtils
|
|||||||
*/
|
*/
|
||||||
class LicenseFragment : Fragment() {
|
class LicenseFragment : Fragment() {
|
||||||
private lateinit var softwareComponents: Array<SoftwareComponent>
|
private lateinit var softwareComponents: Array<SoftwareComponent>
|
||||||
private var activeLicense: License? = null
|
private var activeSoftwareComponent: SoftwareComponent? = null
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
softwareComponents = arguments?.getParcelableArray(ARG_COMPONENTS) as Array<SoftwareComponent>
|
softwareComponents = arguments?.getParcelableArray(ARG_COMPONENTS) as Array<SoftwareComponent>
|
||||||
activeLicense = savedInstanceState?.getSerializable(LICENSE_KEY) as? License
|
activeSoftwareComponent = savedInstanceState?.getSerializable(SOFTWARE_COMPONENT_KEY) as? SoftwareComponent
|
||||||
// Sort components by name
|
// Sort components by name
|
||||||
softwareComponents.sortBy { it.name }
|
softwareComponents.sortBy { it.name }
|
||||||
}
|
}
|
||||||
@ -48,9 +49,8 @@ class LicenseFragment : Fragment() {
|
|||||||
): View {
|
): View {
|
||||||
val binding = FragmentLicensesBinding.inflate(inflater, container, false)
|
val binding = FragmentLicensesBinding.inflate(inflater, container, false)
|
||||||
binding.licensesAppReadLicense.setOnClickListener {
|
binding.licensesAppReadLicense.setOnClickListener {
|
||||||
activeLicense = StandardLicenses.GPL3
|
|
||||||
compositeDisposable.add(
|
compositeDisposable.add(
|
||||||
showLicense(StandardLicenses.GPL3)
|
showLicense(NEWPIPE_SOFTWARE_COMPONENT)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
for (component in softwareComponents) {
|
for (component in softwareComponents) {
|
||||||
@ -66,7 +66,6 @@ class LicenseFragment : Fragment() {
|
|||||||
val root: View = componentBinding.root
|
val root: View = componentBinding.root
|
||||||
root.tag = component
|
root.tag = component
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
activeLicense = component.license
|
|
||||||
compositeDisposable.add(
|
compositeDisposable.add(
|
||||||
showLicense(component)
|
showLicense(component)
|
||||||
)
|
)
|
||||||
@ -74,39 +73,24 @@ class LicenseFragment : Fragment() {
|
|||||||
binding.licensesSoftwareComponents.addView(root)
|
binding.licensesSoftwareComponents.addView(root)
|
||||||
registerForContextMenu(root)
|
registerForContextMenu(root)
|
||||||
}
|
}
|
||||||
activeLicense?.let { compositeDisposable.add(showLicense(it)) }
|
activeSoftwareComponent?.let { compositeDisposable.add(showLicense(it)) }
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
activeLicense?.let { savedInstanceState.putSerializable(LICENSE_KEY, it) }
|
activeSoftwareComponent?.let { savedInstanceState.putSerializable(SOFTWARE_COMPONENT_KEY, it) }
|
||||||
}
|
|
||||||
|
|
||||||
private fun showLicense(component: SoftwareComponent): Disposable {
|
|
||||||
return showLicense(component.license) {
|
|
||||||
setPositiveButton(R.string.dismiss) { dialog, _ ->
|
|
||||||
dialog.dismiss()
|
|
||||||
}
|
|
||||||
setNeutralButton(R.string.open_website_license) { _, _ ->
|
|
||||||
ShareUtils.openUrlInApp(requireContext(), component.link)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showLicense(license: License) = showLicense(license) {
|
|
||||||
setPositiveButton(R.string.ok) { dialog, _ -> dialog.dismiss() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showLicense(
|
private fun showLicense(
|
||||||
license: License,
|
softwareComponent: SoftwareComponent
|
||||||
block: AlertDialog.Builder.() -> AlertDialog.Builder
|
|
||||||
): Disposable {
|
): Disposable {
|
||||||
return if (context == null) {
|
return if (context == null) {
|
||||||
Disposable.empty()
|
Disposable.empty()
|
||||||
} else {
|
} else {
|
||||||
val context = requireContext()
|
val context = requireContext()
|
||||||
Observable.fromCallable { getFormattedLicense(context, license) }
|
activeSoftwareComponent = softwareComponent
|
||||||
|
Observable.fromCallable { getFormattedLicense(context, softwareComponent.license) }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { formattedLicense ->
|
.subscribe { formattedLicense ->
|
||||||
@ -117,20 +101,38 @@ class LicenseFragment : Fragment() {
|
|||||||
webView.loadData(webViewData, "text/html; charset=UTF-8", "base64")
|
webView.loadData(webViewData, "text/html; charset=UTF-8", "base64")
|
||||||
|
|
||||||
Localization.assureCorrectAppLanguage(context)
|
Localization.assureCorrectAppLanguage(context)
|
||||||
AlertDialog.Builder(requireContext())
|
val builder = AlertDialog.Builder(requireContext())
|
||||||
.setTitle(license.name)
|
.setTitle(softwareComponent.name)
|
||||||
.setView(webView)
|
.setView(webView)
|
||||||
.setOnCancelListener { activeLicense = null }
|
.setOnCancelListener { activeSoftwareComponent = null }
|
||||||
.setOnDismissListener { activeLicense = null }
|
.setOnDismissListener { activeSoftwareComponent = null }
|
||||||
.block()
|
if (softwareComponent == NEWPIPE_SOFTWARE_COMPONENT) {
|
||||||
.show()
|
builder.setPositiveButton(R.string.ok) { dialog, _ -> dialog.dismiss() }
|
||||||
|
} else {
|
||||||
|
builder.setPositiveButton(R.string.dismiss) { dialog, _ ->
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
.setNeutralButton(R.string.open_website_license) { _, _ ->
|
||||||
|
ShareUtils.openUrlInApp(requireContext(), softwareComponent.link)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val ARG_COMPONENTS = "components"
|
private const val ARG_COMPONENTS = "components"
|
||||||
private const val LICENSE_KEY = "ACTIVE_LICENSE"
|
private const val SOFTWARE_COMPONENT_KEY = "ACTIVE_SOFTWARE_COMPONENT"
|
||||||
|
private val NEWPIPE_SOFTWARE_COMPONENT = SoftwareComponent(
|
||||||
|
"NewPipe",
|
||||||
|
"2014-2023",
|
||||||
|
"Team NewPipe",
|
||||||
|
"https://newpipe.net/",
|
||||||
|
StandardLicenses.GPL3,
|
||||||
|
BuildConfig.VERSION_NAME
|
||||||
|
)
|
||||||
fun newInstance(softwareComponents: Array<SoftwareComponent>): LicenseFragment {
|
fun newInstance(softwareComponents: Array<SoftwareComponent>): LicenseFragment {
|
||||||
val fragment = LicenseFragment()
|
val fragment = LicenseFragment()
|
||||||
fragment.arguments = bundleOf(ARG_COMPONENTS to softwareComponents)
|
fragment.arguments = bundleOf(ARG_COMPONENTS to softwareComponents)
|
||||||
|
@ -2,6 +2,7 @@ package org.schabi.newpipe.about
|
|||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class SoftwareComponent
|
class SoftwareComponent
|
||||||
@ -13,4 +14,4 @@ constructor(
|
|||||||
val link: String,
|
val link: String,
|
||||||
val license: License,
|
val license: License,
|
||||||
val version: String? = null
|
val version: String? = null
|
||||||
) : Parcelable
|
) : Parcelable, Serializable
|
||||||
|
Loading…
Reference in New Issue
Block a user