2018-06-25 13:02:34 +02:00
|
|
|
/* Copyright 2018 Conny Duck
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky.view
|
|
|
|
|
|
|
|
import android.content.Context
|
2022-12-31 13:01:35 +01:00
|
|
|
import android.graphics.Color
|
2018-06-25 13:02:34 +02:00
|
|
|
import android.util.AttributeSet
|
2021-03-07 19:04:22 +01:00
|
|
|
import android.view.LayoutInflater
|
2018-12-17 15:25:35 +01:00
|
|
|
import com.google.android.material.card.MaterialCardView
|
2022-12-31 13:01:35 +01:00
|
|
|
import com.google.android.material.color.MaterialColors
|
2018-06-25 13:02:34 +02:00
|
|
|
import com.keylesspalace.tusky.R
|
2021-03-07 19:04:22 +01:00
|
|
|
import com.keylesspalace.tusky.databinding.CardLicenseBinding
|
2018-06-25 13:02:34 +02:00
|
|
|
import com.keylesspalace.tusky.util.hide
|
2022-02-25 18:56:21 +01:00
|
|
|
import com.keylesspalace.tusky.util.openLink
|
2018-06-25 13:02:34 +02:00
|
|
|
|
|
|
|
class LicenseCard
|
|
|
|
@JvmOverloads constructor(
|
2021-06-28 21:13:24 +02:00
|
|
|
context: Context,
|
|
|
|
attrs: AttributeSet? = null,
|
|
|
|
defStyleAttr: Int = 0
|
2018-12-17 15:25:35 +01:00
|
|
|
) : MaterialCardView(context, attrs, defStyleAttr) {
|
2018-06-25 13:02:34 +02:00
|
|
|
|
|
|
|
init {
|
2021-03-07 19:04:22 +01:00
|
|
|
val binding = CardLicenseBinding.inflate(LayoutInflater.from(context), this)
|
2018-06-25 13:02:34 +02:00
|
|
|
|
2023-02-04 19:58:53 +01:00
|
|
|
setCardBackgroundColor(MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, Color.BLACK))
|
2018-06-25 13:02:34 +02:00
|
|
|
|
|
|
|
val a = context.theme.obtainStyledAttributes(attrs, R.styleable.LicenseCard, 0, 0)
|
|
|
|
|
|
|
|
val name: String? = a.getString(R.styleable.LicenseCard_name)
|
|
|
|
val license: String? = a.getString(R.styleable.LicenseCard_license)
|
|
|
|
val link: String? = a.getString(R.styleable.LicenseCard_link)
|
|
|
|
a.recycle()
|
|
|
|
|
2021-03-07 19:04:22 +01:00
|
|
|
binding.licenseCardName.text = name
|
|
|
|
binding.licenseCardLicense.text = license
|
2021-06-28 21:13:24 +02:00
|
|
|
if (link.isNullOrBlank()) {
|
2021-03-07 19:04:22 +01:00
|
|
|
binding.licenseCardLink.hide()
|
2018-06-25 13:02:34 +02:00
|
|
|
} else {
|
2021-03-07 19:04:22 +01:00
|
|
|
binding.licenseCardLink.text = link
|
2022-02-25 18:56:21 +01:00
|
|
|
setOnClickListener { context.openLink(link) }
|
2018-06-25 13:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|