2021-07-12 10:14:26 +02:00
|
|
|
package audio.funkwhale.ffa.activities
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.net.Uri
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2021-07-16 10:03:52 +02:00
|
|
|
import audio.funkwhale.ffa.databinding.ActivityLicencesBinding
|
|
|
|
import audio.funkwhale.ffa.databinding.RowLicenceBinding
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
class LicencesActivity : AppCompatActivity() {
|
2021-07-16 10:03:52 +02:00
|
|
|
|
|
|
|
private lateinit var binding: ActivityLicencesBinding
|
|
|
|
|
2019-08-19 16:50:33 +02:00
|
|
|
data class Licence(val name: String, val licence: String, val url: String)
|
|
|
|
|
|
|
|
interface OnLicenceClickListener {
|
|
|
|
fun onClick(url: String)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
2021-07-16 10:03:52 +02:00
|
|
|
binding = ActivityLicencesBinding.inflate(layoutInflater)
|
|
|
|
setContentView(binding.root)
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
LicencesAdapter(OnLicenceClick()).also {
|
2021-07-16 10:03:52 +02:00
|
|
|
binding.licences.layoutManager = LinearLayoutManager(this)
|
|
|
|
binding.licences.adapter = it
|
2019-08-19 16:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 10:03:52 +02:00
|
|
|
private inner class LicencesAdapter(val listener: OnLicenceClickListener) :
|
|
|
|
RecyclerView.Adapter<LicencesAdapter.ViewHolder>() {
|
|
|
|
|
2019-08-19 16:50:33 +02:00
|
|
|
val licences = listOf(
|
|
|
|
Licence(
|
|
|
|
"ExoPlayer",
|
|
|
|
"Apache License 2.0",
|
|
|
|
"https://github.com/google/ExoPlayer/blob/release-v2/LICENSE"
|
|
|
|
),
|
2019-10-23 21:41:50 +02:00
|
|
|
Licence(
|
|
|
|
"ExoPlayer-Extensions",
|
|
|
|
"Apache License 2.0",
|
|
|
|
"https://github.com/PaulWoitaschek/ExoPlayer-Extensions/blob/master/LICENSE"
|
|
|
|
),
|
2019-08-19 16:50:33 +02:00
|
|
|
Licence(
|
|
|
|
"Fuel",
|
|
|
|
"MIT License",
|
|
|
|
"https://github.com/kittinunf/fuel/blob/master/LICENSE.md"
|
|
|
|
),
|
|
|
|
Licence(
|
|
|
|
"Gson",
|
|
|
|
"Apache License 2.0",
|
|
|
|
"https://github.com/google/gson/blob/master/LICENSE"
|
|
|
|
),
|
|
|
|
Licence(
|
|
|
|
"Picasso",
|
|
|
|
"Apache License 2.0",
|
|
|
|
"https://github.com/square/picasso/blob/master/LICENSE.txt"
|
|
|
|
),
|
|
|
|
Licence(
|
|
|
|
"Picasso Transformations",
|
|
|
|
"Apache License 2.0",
|
|
|
|
"https://github.com/wasabeef/picasso-transformations/blob/master/LICENSE"
|
|
|
|
),
|
|
|
|
Licence(
|
|
|
|
"PowerPreference",
|
|
|
|
"Apache License 2.0",
|
|
|
|
"https://github.com/AliAsadi/PowerPreference/blob/master/LICENSE"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
override fun getItemCount() = licences.size
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
2021-07-16 10:03:52 +02:00
|
|
|
val binding = RowLicenceBinding.inflate(layoutInflater)
|
|
|
|
return ViewHolder(binding).also {
|
|
|
|
binding.root.setOnClickListener(it)
|
2019-08-19 16:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
|
val item = licences[position]
|
|
|
|
|
|
|
|
holder.name.text = item.name
|
|
|
|
holder.licence.text = item.licence
|
|
|
|
}
|
|
|
|
|
2021-09-09 09:56:15 +02:00
|
|
|
inner class ViewHolder(binding: RowLicenceBinding) :
|
|
|
|
RecyclerView.ViewHolder(binding.root),
|
2021-07-16 10:03:52 +02:00
|
|
|
View.OnClickListener {
|
|
|
|
val name = binding.name
|
|
|
|
val licence = binding.licence
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
override fun onClick(view: View?) {
|
|
|
|
listener.onClick(licences[layoutPosition].url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inner class OnLicenceClick : OnLicenceClickListener {
|
|
|
|
override fun onClick(url: String) {
|
|
|
|
Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {
|
|
|
|
startActivity(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-02 13:55:49 +02:00
|
|
|
}
|