Refactor open source licenses
This commit is contained in:
@@ -13,6 +13,8 @@ import com.afollestad.materialdialogs.MaterialDialog
|
||||
import de.mm20.launcher2.R
|
||||
import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import de.mm20.launcher2.helper.DebugInformationDumper
|
||||
import de.mm20.launcher2.licenses.AppLicense
|
||||
import de.mm20.launcher2.licenses.OpenSourceLicenses
|
||||
|
||||
|
||||
class PreferencesAboutFragment : PreferenceFragmentCompat() {
|
||||
@@ -64,11 +66,10 @@ class PreferencesAboutFragment : PreferenceFragmentCompat() {
|
||||
}
|
||||
|
||||
val licenses = findPreference<Preference>("category_licenses") as PreferenceCategory
|
||||
for (l in LICENSES) {
|
||||
val license = resources.obtainTypedArray(l)
|
||||
for (l in OpenSourceLicenses.sortedBy { it.name.lowercase() }) {
|
||||
val preference = Preference(activity, null, 0, R.style.Preference_Material)
|
||||
preference.title = license.getString(0)
|
||||
preference.summary = license.getString(1)
|
||||
preference.title = l.name
|
||||
preference.summary = l.description
|
||||
preference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
parentFragmentManager.beginTransaction()
|
||||
.setCustomAnimations(
|
||||
@@ -78,12 +79,11 @@ class PreferencesAboutFragment : PreferenceFragmentCompat() {
|
||||
R.anim.preference_fragment_child_exit
|
||||
)
|
||||
.replace(android.R.id.content,
|
||||
PreferencesLicenseFragment().apply { library = l })
|
||||
PreferencesLicenseFragment(l))
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
true
|
||||
}
|
||||
license.recycle()
|
||||
licenses.addPreference(preference)
|
||||
}
|
||||
findPreference<Preference>("crash_reporter")?.setOnPreferenceClickListener {
|
||||
@@ -132,7 +132,7 @@ class PreferencesAboutFragment : PreferenceFragmentCompat() {
|
||||
R.anim.preference_fragment_child_exit
|
||||
)
|
||||
.replace(android.R.id.content,
|
||||
PreferencesLicenseFragment().apply { library = R.array.license_mm20launcher2 })
|
||||
PreferencesLicenseFragment(AppLicense.get(requireContext())))
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
true
|
||||
@@ -143,34 +143,4 @@ class PreferencesAboutFragment : PreferenceFragmentCompat() {
|
||||
super.onResume()
|
||||
(activity as AppCompatActivity).supportActionBar?.setTitle(R.string.preference_screen_about)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val LICENSES = intArrayOf(
|
||||
R.array.license_accompanist,
|
||||
R.array.license_android_jetpack,
|
||||
R.array.license_suncalc,
|
||||
R.array.license_crashreporter,
|
||||
R.array.license_draglinearlayout,
|
||||
R.array.license_glide,
|
||||
R.array.license_glide_transformations,
|
||||
R.array.license_google_apiclient,
|
||||
R.array.license_google_auth,
|
||||
R.array.license_groupie,
|
||||
R.array.license_gson,
|
||||
R.array.license_jsoup,
|
||||
R.array.license_kotlin_stdlib,
|
||||
R.array.license_lottie,
|
||||
R.array.license_mdicons,
|
||||
R.array.license_material_components,
|
||||
R.array.license_materialdialogs,
|
||||
R.array.license_msal,
|
||||
R.array.license_msgraph,
|
||||
R.array.license_mxparser,
|
||||
R.array.license_okhttp,
|
||||
R.array.license_retrofit,
|
||||
R.array.license_textdrawable,
|
||||
R.array.license_viewpropertyobjectanimator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,27 +14,18 @@ import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.bumptech.glide.Glide
|
||||
import de.mm20.launcher2.R
|
||||
import de.mm20.launcher2.licenses.OpenSourceLibrary
|
||||
|
||||
class PreferencesLicenseFragment : Fragment() {
|
||||
var library: Int = 0
|
||||
class PreferencesLicenseFragment(
|
||||
val library: OpenSourceLibrary
|
||||
) : Fragment() {
|
||||
|
||||
@SuppressLint("ResourceType")
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_license, null, false)
|
||||
val license = resources.obtainTypedArray(library)
|
||||
(activity as AppCompatActivity).supportActionBar?.title = license.getString(0)
|
||||
val icon = view.findViewById<ImageView>(R.id.icon)
|
||||
val iconUri = license.getString(2)
|
||||
if (iconUri == null) icon.visibility = View.GONE
|
||||
else {
|
||||
Glide
|
||||
.with(icon)
|
||||
.load(iconUri)
|
||||
.into(icon)
|
||||
icon.visibility = View.VISIBLE
|
||||
}
|
||||
val url = license.getString(6)
|
||||
(activity as AppCompatActivity).supportActionBar?.title = library.name
|
||||
val url = library.url
|
||||
val website = view.findViewById<TextView>(R.id.website)
|
||||
website.setOnClickListener {
|
||||
val intent = CustomTabsIntent.Builder()
|
||||
@@ -47,14 +38,13 @@ class PreferencesLicenseFragment : Fragment() {
|
||||
intent.launchUrl(activity as AppCompatActivity, Uri.parse(url))
|
||||
}
|
||||
val description = view.findViewById<TextView>(R.id.description)
|
||||
description.text = license.getString(1)
|
||||
description.text = library.description
|
||||
val licenseTitle = view.findViewById<TextView>(R.id.licenseTitle)
|
||||
val licenseText = view.findViewById<TextView>(R.id.licenseText)
|
||||
val licenseCopyright = view.findViewById<TextView>(R.id.licenseCopyright)
|
||||
licenseTitle.text = license.getString(3)
|
||||
licenseCopyright.text = license.getString(4)
|
||||
licenseText.text = resources.openRawResource(license.getResourceId(5, 0)).reader().readText()
|
||||
license.recycle()
|
||||
licenseTitle.text = getString(library.licenseName)
|
||||
licenseCopyright.text = library.copyrightNote
|
||||
licenseText.text = resources.openRawResource(library.licenseText).reader().readText()
|
||||
return view
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user