MultiItemBean

64 阅读2分钟
package com.alibaba.genie.panel.model.data;

import com.alibaba.fastjson.annotation.JSONField;

public abstract class MultiItemBean {

    public static final int TYPE_DEFAULT = 0;
    /**
     * 首页设备,UI同一套,暂不区分
     */
    public static final int TYPE_DEVICE_HOME = 10;
    /**
     * 灯光(控制页)
     */
    public static final int TYPE_DEVICE_LIGHT = 1;
    /**
     * 窗帘(控制页)
     */
    public static final int TYPE_DEVICE_CURTAIN = 2;

    /**
     * 开关(控制页)包含单键、双键、三键、四键,开关在一级面板只能执行全开/全关
     */
    public static final int TYPE_DEVICE_SWITCH = 3;
    /**
     * 空调
     */
    public static final int TYPE_DEVICE_AIR_CONDITION = 4;
    /**
     * 晾衣机
     */
    public static final int TYPE_DEVICE_HANGER = 5;
    /**
     * 浴霸
     */
    public static final int TYPE_DEVICE_BATH_HEATER = 6;
    /**
     * 继电器
     */
    public static final int TYPE_DEVICE_RELAY = 7;
    /**
     * 人体感应器
     */
    public static final int TYPE_DEVICE_HUMAN_SENSOR = 9;
    /**
     * 门磁
     */
    public static final int TYPE_DEVICE_DOOR_SENSOR = 10;

    /**
     * 开关设备映射为场景
     */
    public static final int TYPE_DEVICE_SWITCH_ORM_SCENE = 8;

    /**
     * 场景
     */
    public static final int TYPE_SCENE = 100;

    /**
     * 场景组
     */
    public static final int TYPE_SCENE_GROUP = 101;


    /**
     * 小组件--时钟
     */
    public static final int TYPE_WIDGET_CLOCK = 200;
    /**
     * 小组件--音乐
     */
    public static final int TYPE_WIDGET_MUSIC = 201;

    /**
     * 小组件--天气
     */
    public static final int TYPE_WIDGET_WEATHER = 202;
    /**
     * 小组件--闹钟
     */
    public static final int TYPE_WIDGET_ALARM = 203;


    public static final int TYPE_ITEM_EDIT_FOOTER = 300;
    /**
     * 用户绑定
     */
    public static final int TYPE_USER_BIND = 400;

    private int itemType;

    public MultiItemBean() {
    }

    public MultiItemBean(int type) {
        this.itemType = type;
    }

    public int getItemType() {
        return itemType;
    }

    public void setItemType(int itemType) {
        this.itemType = itemType;
    }

    @JSONField(serialize = false)
    public boolean isTypeFooter() {
        return TYPE_ITEM_EDIT_FOOTER == itemType;
    }

    /**
     * 包含继电器的设备类型
     *
     * @return
     */
    @JSONField(serialize = false)
    public boolean isDeviceType() {
        return itemType < 100;
    }

    /**
     * 是否为灯设备
     *
     * @return
     */
    @JSONField(serialize = false)
    public boolean isDeviceLight() {
        return itemType == TYPE_DEVICE_LIGHT;
    }

    /**
     * 是否为窗帘
     *
     * @return
     */
    @JSONField(serialize = false)
    public boolean isDeviceCurtain() {
        return itemType == TYPE_DEVICE_CURTAIN;
    }

    @JSONField(serialize = false)
    public boolean isDeviceRelay() {
        return itemType == TYPE_DEVICE_RELAY;
    }

    @JSONField(serialize = false)
    public boolean isDeviceSwitch() {
        return itemType == TYPE_DEVICE_SWITCH;
    }

    /**
     * 是否为开关映射为场景
     *
     * @return
     */
    @JSONField(serialize = false)
    public boolean isDeviceSwitchOrmScene() {
        return getItemType() == TYPE_DEVICE_SWITCH_ORM_SCENE;
    }

    /**
     * 不包含继电器的设备类型
     *
     * @return
     */
    @JSONField(serialize = false)
    public boolean isDeviceWithoutRelay() {
        return !isDeviceRelay() && isDeviceType();
    }

    /**
     * 场景、场景组
     *
     * @return
     */
    @JSONField(serialize = false)
    public boolean isSceneType() {
        return !isDeviceType() && itemType < 200;
    }

    @JSONField(serialize = false)
    public boolean isSceneTypeOnly() {
        return itemType == TYPE_SCENE;
    }

    @JSONField(serialize = false)
    public boolean isSceneGroupType() {
        return itemType == TYPE_SCENE_GROUP;
    }

    @JSONField(serialize = false)
    public static boolean isSceneGroupType(int itemType) {
        return itemType == TYPE_SCENE_GROUP;
    }

    /**
     * 小组件
     *
     * @return
     */
    @JSONField(serialize = false)
    public boolean isWidgetType() {
        return 200 <= itemType && itemType < 300;
    }

    @JSONField(serialize = false)
    public static boolean isWidgetType(int itemType) {
        return 200 <= itemType && itemType < 300;
    }

    @JSONField(serialize = false)
    public boolean isWidgetTypeClock() {
        return itemType == TYPE_WIDGET_CLOCK;
    }

    @JSONField(serialize = false)
    public boolean isWidgetTypeAlarm() {
        return itemType == TYPE_WIDGET_ALARM;
    }

    @JSONField(serialize = false)
    public boolean isWidgetTypeMusic() {
        return itemType == TYPE_WIDGET_MUSIC;
    }

    @JSONField(serialize = false)
    public boolean isWidgetTypeWeather() {
        return itemType == TYPE_WIDGET_WEATHER;
    }

    @JSONField(serialize = false)
    public boolean isUserBindType() {
        return itemType == TYPE_USER_BIND;
    }


    public static boolean isDeviceLight(int itemType) {
        return TYPE_DEVICE_LIGHT == itemType;
    }

    public static boolean isDeviceAirCondition(int itemType) {
        return TYPE_DEVICE_AIR_CONDITION == itemType;
    }

    public static boolean isDeviceCurtain(int itemType) {
        return TYPE_DEVICE_CURTAIN == itemType;
    }

    public static boolean isDeviceClothesDryer(int itemType) {
        return TYPE_DEVICE_HANGER == itemType;
    }

    public static boolean isDeviceSwitch(int itemType) {
        return TYPE_DEVICE_SWITCH == itemType;
    }

    public static boolean isDeviceRelay(int itemType) {
        return TYPE_DEVICE_RELAY == itemType;
    }

    public static boolean isUserBindType(int itemType) {
        return TYPE_USER_BIND == itemType;
    }

    public boolean disableWhenUnbind() {
        return itemType == TYPE_WIDGET_ALARM ||
                itemType == TYPE_WIDGET_MUSIC ||
                itemType == TYPE_WIDGET_WEATHER;
    }
}