package com.sheep.gamegroup.model.entity;

import android.annotation.SuppressLint;
import android.app.usage.UsageStats;

import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

import java.io.Serializable;

/**
 * Created by realicing on 2018/5/11.
 */
@Table(name = "app_usage")
public class AppUsage implements Serializable {

    @Column(name = "package_name", isId = true)
    private String packageName;
    @Column(name = "lastTimeStamp")
    private long lastTimeStamp;
    @Column(name = "firstTimeStamp")
    private long firstTimeStamp;
    @Column(name = "totalTimeInForeground")
    private long totalTimeInForeground;


    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public long getLastTimeStamp() {
        return lastTimeStamp;
    }

    public void setLastTimeStamp(long lastTimeStamp) {
        this.lastTimeStamp = lastTimeStamp;
    }

    public long getFirstTimeStamp() {
        return firstTimeStamp;
    }

    public void setFirstTimeStamp(long firstTimeStamp) {
        this.firstTimeStamp = firstTimeStamp;
    }

    public long getTotalTimeInForeground() {
        return totalTimeInForeground;
    }

    public void setTotalTimeInForeground(long totalTimeInForeground) {
        this.totalTimeInForeground = totalTimeInForeground;
    }


    @SuppressLint("NewApi")
    public static AppUsage getInstance(UsageStats usageStats) {
        AppUsage appUsage = new AppUsage();
        if(usageStats != null) {
            appUsage.setPackageName(usageStats.getPackageName());
            appUsage.setTotalTimeInForeground(usageStats.getTotalTimeInForeground());
            appUsage.setFirstTimeStamp(usageStats.getFirstTimeStamp());
            appUsage.setLastTimeStamp(usageStats.getLastTimeStamp());
        }
        return appUsage;
    }
}
