Skip to content
Snippets Groups Projects
LicencesActivity.kt 3.18 KiB
Newer Older
  • Learn to ignore specific revisions
  • package audio.funkwhale.ffa.activities
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
    
    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
    
    import audio.funkwhale.ffa.databinding.ActivityLicencesBinding
    import audio.funkwhale.ffa.databinding.RowLicenceBinding
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
    
    class LicencesActivity : AppCompatActivity() {
    
    
      private lateinit var binding: ActivityLicencesBinding
    
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
      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)
    
    
        binding = ActivityLicencesBinding.inflate(layoutInflater)
        setContentView(binding.root)
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
    
        LicencesAdapter(OnLicenceClick()).also {
    
          binding.licences.layoutManager = LinearLayoutManager(this)
          binding.licences.adapter = it
    
      private inner class LicencesAdapter(val listener: OnLicenceClickListener) :
        RecyclerView.Adapter<LicencesAdapter.ViewHolder>() {
    
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
        val licences = listOf(
          Licence(
            "ExoPlayer",
            "Apache License 2.0",
            "https://github.com/google/ExoPlayer/blob/release-v2/LICENSE"
          ),
    
          Licence(
            "ExoPlayer-Extensions",
            "Apache License 2.0",
            "https://github.com/PaulWoitaschek/ExoPlayer-Extensions/blob/master/LICENSE"
          ),
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
          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 {
    
          val binding = RowLicenceBinding.inflate(layoutInflater)
          return ViewHolder(binding).also {
            binding.root.setOnClickListener(it)
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
          }
        }
    
        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          val item = licences[position]
    
          holder.name.text = item.name
          holder.licence.text = item.licence
        }
    
    
        inner class ViewHolder(binding: RowLicenceBinding) : RecyclerView.ViewHolder(binding.root),
          View.OnClickListener {
          val name = binding.name
          val licence = binding.licence
    
    Antoine POPINEAU's avatar
    Antoine POPINEAU committed
    
          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)
          }
        }
      }
    
    Ryan Harg's avatar
    Ryan Harg committed
    }