package com.duolebo.blyrobot.data

import com.duolebo.appbase.IModel
import com.duolebo.appbase.prj.XMLHelper
import org.json.JSONArray
import org.json.JSONObject

class ApkInfo: IModel {
    lateinit var name: String
    //包名
    lateinit var packageName: String
    //启动apk配置信息
    lateinit var launcher: String
    //截图存放路径
    lateinit var imagePath: String
    // 过滤媒体视频扩展名信息
    lateinit var mediaExt: String
    // 播放地址过滤url
    lateinit var filterUrl: String
    // 抓取频道数量
    var channelCount = 5
    // 启动延时(秒)
    var launchDelay = 15
    // 频道抓取延时(秒)
    var captureDelay = 15
    // 切换频道按键事件组合
    lateinit var channelKeyEvent: String
    // 弹出界面菜单按键，默认确定键
    lateinit var menuKeyEvent: String

    override fun from(json: JSONObject): Boolean {
        this.name = json.optString(NAME)
        this.packageName = json.optString(PACKAGE_NAME)
        this.launcher = json.optString(LAUNCHER)
        this.launchDelay = json.optInt(LAUNCH_DELAY, 15)
        this.captureDelay = json.optInt(CAPTURE_DELAY, 15)
        this.channelCount = json.optInt(CHANNEL_COUNT, 5)
        this.channelKeyEvent = json.optString(CHANNEL_KEY_EVENT)
        this.mediaExt = json.optString(MEDIA_EXT, VIDEO_EXTS)
        this.filterUrl = json.optString(FILTER_URL)
        this.menuKeyEvent = json.optString(MENU_KEY_EVENT, "ok")

        return true
    }

    override fun from(p0: JSONArray?): Boolean {
        return false
    }

    override fun from(p0: XMLHelper?): Boolean {
        return false
    }

    companion object {
        const val VIDEO_EXTS = "m3u8|.ts|.mp4|.rmvb|.mkv|.wmv"

        //data key
        const val NAME = "name"
        const val PACKAGE_NAME = "packageName"
        const val LAUNCHER = "launcher"
        const val LAUNCH_DELAY = "launchDelay"
        const val CAPTURE_DELAY = "captureDelay"
        const val CHANNEL_KEY_EVENT = "channelKeyEvent"
        const val CHANNEL_COUNT = "channelCount"
        const val MEDIA_EXT = "mediaExt"
        const val FILTER_URL = "filterUrl"
        const val MENU_KEY_EVENT = "menuKeyEvent"
    }

}