GenericItemHeader.kt 1.73 KB
Newer Older
Valere's avatar
Valere committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * Copyright 2019 New Vector Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
16
package im.vector.app.core.ui.list
Valere's avatar
Valere committed
17
18

import android.widget.TextView
Valere's avatar
Valere committed
19
import androidx.annotation.ColorInt
Valere's avatar
Valere committed
20
21
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
22
23
24
25
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.extensions.setTextOrHide
Valere's avatar
Valere committed
26
import im.vector.app.features.themes.ThemeUtils
Valere's avatar
Valere committed
27
28
29
30
31
32
33
34
35
36

/**
 * A generic list item header left aligned with notice color.
 */
@EpoxyModelClass(layout = R.layout.item_generic_header)
abstract class GenericItemHeader : VectorEpoxyModel<GenericItemHeader.Holder>() {

    @EpoxyAttribute
    var text: String? = null

Valere's avatar
Valere committed
37
38
39
40
    @EpoxyAttribute
    @ColorInt
    var textColor: Int? = null

Valere's avatar
Valere committed
41
    override fun bind(holder: Holder) {
42
        super.bind(holder)
Valere's avatar
Valere committed
43
        holder.text.setTextOrHide(text)
Valere's avatar
Valere committed
44
45
46
47
48
        if (textColor != null) {
            holder.text.setTextColor(textColor!!)
        } else {
            holder.text.setTextColor(ThemeUtils.getColor(holder.view.context, R.attr.vctr_notice_text_color))
        }
Valere's avatar
Valere committed
49
50
51
52
53
    }

    class Holder : VectorEpoxyHolder() {
        val text by bind<TextView>(R.id.itemGenericHeaderText)
    }
54
}