replace licenses dialog and about dialog with about fragment
This commit is contained in:
@ -169,6 +169,15 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
||||
}
|
||||
}
|
||||
|
||||
fun showAboutFragment() {
|
||||
val aboutFragment = AboutFragment()
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.nav_host_fragment, aboutFragment, "AboutFragment")
|
||||
addToBackStack(aboutFragment.javaClass.name)
|
||||
show(aboutFragment)
|
||||
}
|
||||
}
|
||||
|
||||
fun startPlayer(mediaId: Int, episodeId: Int) {
|
||||
val intent = Intent(this, PlayerActivity::class.java).apply {
|
||||
putExtra(getString(R.string.intent_media_id), mediaId)
|
||||
|
105
app/src/main/java/org/mosad/teapod/ui/fragments/AboutFragment.kt
Normal file
105
app/src/main/java/org/mosad/teapod/ui/fragments/AboutFragment.kt
Normal file
@ -0,0 +1,105 @@
|
||||
package org.mosad.teapod.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.RawRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentAboutBinding
|
||||
import org.mosad.teapod.databinding.ItemComponentBinding
|
||||
import org.mosad.teapod.util.DataTypes.License
|
||||
import org.mosad.teapod.util.ThirdPartyComponent
|
||||
import java.lang.StringBuilder
|
||||
|
||||
class AboutFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentAboutBinding
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentAboutBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.textVersion.text = getString(R.string.info_about_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
|
||||
|
||||
getThirdPartyComponents().forEach { thirdParty ->
|
||||
val componentBinding = ItemComponentBinding.inflate(layoutInflater) //(R.layout.item_component, container, false)
|
||||
componentBinding.textComponentTitle.text = thirdParty.name
|
||||
componentBinding.textComponentDesc.text = getString(
|
||||
R.string.third_party_component_desc,
|
||||
thirdParty.year,
|
||||
thirdParty.copyrightOwner,
|
||||
thirdParty.license.short
|
||||
)
|
||||
componentBinding.linearComponent.setOnClickListener {
|
||||
showLicense(thirdParty.license)
|
||||
}
|
||||
|
||||
binding.linearThirdParty.addView(componentBinding.root)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getThirdPartyComponents(): List<ThirdPartyComponent> {
|
||||
return listOf<ThirdPartyComponent>(
|
||||
ThirdPartyComponent("AndroidX", "", "The Android Open Source Project",
|
||||
"https://developer.android.com/jetpack/androidx", License.APACHE2),
|
||||
ThirdPartyComponent("Material Components for Android", "2020", "The Android Open Source Project",
|
||||
"https://github.com/material-components/material-components-android", License.APACHE2),
|
||||
ThirdPartyComponent("ExoPlayer", "2014 - 2020", "The Android Open Source Project",
|
||||
"https://github.com/google/ExoPlayer", License.APACHE2),
|
||||
ThirdPartyComponent("Gson", "2008", "Google Inc.",
|
||||
"https://github.com/google/gson", License.APACHE2),
|
||||
ThirdPartyComponent("Material design icons", "2020", "Google Inc.",
|
||||
"https://github.com/google/material-design-icons", License.APACHE2),
|
||||
ThirdPartyComponent("Material Dialogs", "", "Aidan Follestad",
|
||||
"https://github.com/afollestad/material-dialogs", License.APACHE2),
|
||||
ThirdPartyComponent("Jsoup", "2009 - 2020", "Jonathan Hedley",
|
||||
"https://jsoup.org/", License.MIT),
|
||||
ThirdPartyComponent("kotlinx.coroutines", "2016 - 2019", "JetBrains",
|
||||
"https://github.com/Kotlin/kotlinx.coroutines", License.APACHE2),
|
||||
ThirdPartyComponent("Glide", "2014", "Google Inc.",
|
||||
"https://github.com/bumptech/glide", License.BSD2),
|
||||
ThirdPartyComponent("Glide Transformations", "2020", "Wasabeef",
|
||||
"https://github.com/wasabeef/glide-transformations", License.APACHE2)
|
||||
)
|
||||
}
|
||||
|
||||
private fun showLicense(license: License) {
|
||||
val licenseText = when(license) {
|
||||
License.APACHE2 -> parseLicense(R.raw.al_20_full)
|
||||
License.BSD2 -> parseLicense(R.raw.bsd_2_full)
|
||||
License.GPL3 -> parseLicense(R.raw.gpl_3_full)
|
||||
License.MIT -> parseLicense(R.raw.mit_full)
|
||||
}
|
||||
|
||||
println("showing: ${license.long}")
|
||||
|
||||
MaterialDialog(requireContext())
|
||||
.title(text = license.long)
|
||||
.message(text = licenseText)
|
||||
.show()
|
||||
|
||||
}
|
||||
|
||||
private fun parseLicense(@RawRes id: Int): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
resources.openRawResource(id).bufferedReader().forEachLine {
|
||||
if (it.isEmpty()) {
|
||||
sb.appendLine(" ")
|
||||
} else {
|
||||
sb.append(it.trim() + " ")
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,6 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.list.listItemsSingleChoice
|
||||
import de.psdev.licensesdialog.LicensesDialog
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.MainActivity
|
||||
import org.mosad.teapod.R
|
||||
@ -54,32 +53,7 @@ class AccountFragment : Fragment() {
|
||||
}
|
||||
|
||||
binding.linearInfo.setOnClickListener {
|
||||
MaterialDialog(requireContext())
|
||||
.title(R.string.info_about)
|
||||
.message(R.string.info_about_dialog)
|
||||
.show()
|
||||
}
|
||||
|
||||
binding.textLicenses.setOnClickListener {
|
||||
|
||||
val dialogCss = when (Preferences.theme) {
|
||||
Theme.DARK -> R.string.license_dialog_style_dark
|
||||
else -> R.string.license_dialog_style_light
|
||||
}
|
||||
|
||||
val themeId = when (Preferences.theme) {
|
||||
Theme.DARK -> R.style.LicensesDialogTheme_Dark
|
||||
else -> R.style.AppTheme_Light
|
||||
}
|
||||
|
||||
LicensesDialog.Builder(requireContext())
|
||||
.setNotices(R.raw.notices)
|
||||
.setTitle(R.string.licenses)
|
||||
.setIncludeOwnLicense(true)
|
||||
.setThemeResourceId(themeId)
|
||||
.setNoticesCssStyle(dialogCss)
|
||||
.build()
|
||||
.show()
|
||||
(activity as MainActivity).showAboutFragment()
|
||||
}
|
||||
|
||||
binding.switchSecondary.setOnClickListener {
|
||||
|
@ -11,8 +11,23 @@ class DataTypes {
|
||||
LIGHT("Light"),
|
||||
DARK("Dark")
|
||||
}
|
||||
|
||||
enum class License(val short: String, val long: String) {
|
||||
APACHE2("AL 2.0", "Apache License Version 2.0"),
|
||||
MIT("MIT", "MIT License"),
|
||||
GPL3("GPL 3", "GNU General Public License Version 3"),
|
||||
BSD2("BSD 2", "BSD 2-Clause License")
|
||||
}
|
||||
}
|
||||
|
||||
data class ThirdPartyComponent(
|
||||
val name: String,
|
||||
val year: String,
|
||||
val copyrightOwner: String,
|
||||
val link: String,
|
||||
val license: DataTypes.License
|
||||
)
|
||||
|
||||
/**
|
||||
* this class is used to represent the item media
|
||||
* it is uses in the ItemMediaAdapter (RecyclerView)
|
||||
|
Reference in New Issue
Block a user