Use Kotlin methods in LicenseFragment.

This commit is contained in:
Isira Seneviratne 2021-07-16 07:10:35 +05:30
parent eef568b24c
commit e2b044d2ee

View file

@ -11,8 +11,6 @@ import org.schabi.newpipe.R
import org.schabi.newpipe.about.LicenseFragmentHelper.showLicense import org.schabi.newpipe.about.LicenseFragmentHelper.showLicense
import org.schabi.newpipe.databinding.FragmentLicensesBinding import org.schabi.newpipe.databinding.FragmentLicensesBinding
import org.schabi.newpipe.databinding.ItemSoftwareComponentBinding import org.schabi.newpipe.databinding.ItemSoftwareComponentBinding
import java.util.Arrays
import java.util.Objects
/** /**
* Fragment containing the software licenses. * Fragment containing the software licenses.
@ -24,16 +22,10 @@ class LicenseFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
softwareComponents = softwareComponents = arguments?.getParcelableArray(ARG_COMPONENTS) as Array<SoftwareComponent>
arguments?.getParcelableArray(ARG_COMPONENTS) as Array<SoftwareComponent> activeLicense = savedInstanceState?.getSerializable(LICENSE_KEY) as? License
if (savedInstanceState != null) {
val license = savedInstanceState.getSerializable(LICENSE_KEY)
if (license != null) {
activeLicense = license as License?
}
}
// Sort components by name // Sort components by name
Arrays.sort(softwareComponents, Comparator.comparing(SoftwareComponent::name)) softwareComponents.sortBy { it.name }
} }
override fun onDestroy() { override fun onDestroy() {
@ -74,19 +66,13 @@ class LicenseFragment : Fragment() {
binding.licensesSoftwareComponents.addView(root) binding.licensesSoftwareComponents.addView(root)
registerForContextMenu(root) registerForContextMenu(root)
} }
if (activeLicense != null) { activeLicense?.let { compositeDisposable.add(showLicense(activity, it)) }
compositeDisposable.add(
showLicense(activity, activeLicense!!)
)
}
return binding.root return binding.root
} }
override fun onSaveInstanceState(savedInstanceState: Bundle) { override fun onSaveInstanceState(savedInstanceState: Bundle) {
super.onSaveInstanceState(savedInstanceState) super.onSaveInstanceState(savedInstanceState)
if (activeLicense != null) { activeLicense?.let { savedInstanceState.putSerializable(LICENSE_KEY, it) }
savedInstanceState.putSerializable(LICENSE_KEY, activeLicense)
}
} }
companion object { companion object {
@ -94,8 +80,7 @@ class LicenseFragment : Fragment() {
private const val LICENSE_KEY = "ACTIVE_LICENSE" private const val LICENSE_KEY = "ACTIVE_LICENSE"
fun newInstance(softwareComponents: Array<SoftwareComponent>): LicenseFragment { fun newInstance(softwareComponents: Array<SoftwareComponent>): LicenseFragment {
val fragment = LicenseFragment() val fragment = LicenseFragment()
fragment.arguments = fragment.arguments = bundleOf(ARG_COMPONENTS to softwareComponents)
bundleOf(ARG_COMPONENTS to Objects.requireNonNull(softwareComponents))
return fragment return fragment
} }
} }