You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iceraven-browser/app/src/main/java/org/mozilla/fenix/settings/DeleteBrowsingDataItem.kt

74 lines
2.4 KiB
Kotlin

/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.settings
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import kotlinx.android.synthetic.main.delete_browsing_data_item.view.*
import org.mozilla.fenix.R
class DeleteBrowsingDataItem @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
val titleView: TextView
get() = title
val subtitleView: TextView
get() = subtitle
val isChecked: Boolean
get() = checkbox.isChecked
var onCheckListener: ((Boolean) -> Unit)? = null
init {
LayoutInflater.from(context).inflate(R.layout.delete_browsing_data_item, this, true)
setOnClickListener {
checkbox.isChecked = !checkbox.isChecked
}
checkbox.setOnCheckedChangeListener { _, isChecked ->
onCheckListener?.invoke(isChecked)
}
attrs.let {
context.theme.obtainStyledAttributes(
it,
R.styleable.DeleteBrowsingDataItem,
0, 0
).apply {
try {
val iconId = getResourceId(
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemIcon,
R.drawable.library_icon_reading_list_circle_background
)
val titleId = getResourceId(
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemTitle,
R.string.browser_menu_your_library
)
val subtitleId = getResourceId(
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemSubtitle,
R.string.browser_menu_your_library
)
icon.background = resources.getDrawable(iconId, context.theme)
title.text = resources.getString(titleId)
subtitle.text = resources.getString(subtitleId)
} finally {
recycle()
}
}
}
}
}