package com.duolebo.blyrobot.ui

import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.widget.RelativeLayout
import com.duolebo.blyrobot.R
import com.duolebo.blyrobot.data.ApkInfo
import com.duolebo.blyrobot.util.AppUtil
import kotlinx.android.synthetic.main.app_config_item.view.*

class AppConfigListItem(context: Context?) : RelativeLayout(context) {

    init {
        LayoutInflater.from(context).inflate(R.layout.app_config_item, this)
    }

    fun setData(apkInfo: ApkInfo) {
        var tips = ""
        if (!AppUtil.isAppInstalled(context, apkInfo.packageName))
            tips = "(未安装)"
        else if (!apkInfo.monitoring)
            tips = "(监播未启用)"
        this.appName.text = apkInfo.name + tips
        this.packageName.text = "包名:${apkInfo.packageName}\t\t版本:" + AppUtil.getVersionName(context, apkInfo.packageName)
    }

    fun setIcon(drawable: Drawable) {
        this.appIcon.setImageDrawable(drawable)
    }
}