package com.test.basd.smartjunkcleaner.bean

import android.app.usage.UsageEvents
import android.app.usage.UsageStats
import android.graphics.drawable.Drawable
import com.google.gson.ExclusionStrategy
import com.google.gson.FieldAttributes
import com.google.gson.GsonBuilder

data class AppBean(
    val icIcon: Drawable,//Drawable会导致序列化失败
    val appName: String,
    val pkg: String,
    var isSelected: Boolean = false,
    var installTime: Long = 0,
    var appSize: Long = -1L,//0 没有大小  -1没有权限
    var lastUsedTime: Long = -1L, //-1没有权限 -2超过30没用
) {
    var pinYin: String = ""
    var usageEvents: List<UsageEvents.Event>? = null
    var usageStats: List<UsageStats>? = null

    var launchTimes = 0
    var foregroundTimes = 0
    var backgroundTimes = 0
    var isRunning = false
    var screenTime: Long = 0

    companion object {
        val appBeanGson = GsonBuilder().setExclusionStrategies(object : ExclusionStrategy {
            override fun shouldSkipField(f: FieldAttributes): Boolean {
                val skipField = arrayOf("icIcon")
                return skipField.contains(f.name)
            }

            override fun shouldSkipClass(clazz: Class<*>): Boolean {
//                val skipClass = arrayOf("List")
//                skipClass.contains(clazz.name)
                return false
            }

        }).create()
    }
}
