aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/adapter/EventListAdapter.kt
blob: b38bf25e8ea9012c7c86fa8e15f883959c57f096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package net.lacolaco.smileessence.view.adapter

import android.app.Activity
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.list_item_status.view.*
import net.lacolaco.smileessence.R
import net.lacolaco.smileessence.World
import net.lacolaco.smileessence.data.ImageCache
import net.lacolaco.smileessence.entity.Event
import net.lacolaco.smileessence.preference.UserPreferenceHelper
import net.lacolaco.smileessence.util.StringUtils
import net.lacolaco.smileessence.view.DialogHelper
import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment

class EventListAdapter(private val world: World, private val activity: Activity) : CustomListAdapter<Event>() {
    override val list: List<Event>
        get() = world.events

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = convertView ?: activity.layoutInflater.inflate(R.layout.list_item_status, parent, false)
        val event = getItem(position)

        val textSize = UserPreferenceHelper.instance.textSize

        view.imageview_status_icon.setImageUrl(event.source.profileImageUrl, ImageCache.getImageLoader())
        view.textview_status_header.text = event.formattedString
        view.textview_status_header.textSize = textSize.toFloat()
        view.textview_status_text.textSize = textSize.toFloat()
        view.textview_status_text.text = event.targetObject?.text ?: ""
        view.textview_status_footer.textSize = (textSize - 2).toFloat()
        view.textview_status_footer.text = StringUtils.dateToString(event.createdAt)
        view.imageview_status_favorited.visibility = View.GONE
        view.setOnClickListener {
            DialogHelper.showDialog(activity, UserDetailDialogFragment.newInstance(event.source))
        }

        return view
    }
}