using System;
using Shared.Common;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.DoorLock
{
public class UserDoorLockPage : DoorLockCommonLayout, ZigBee.Common.IStatus
{
public UserDoorLockPage(Shared.Common.Room room, DeviceUI doorLock)
{
this.doorLock = doorLock.CommonDevice as ZigBee.Device.DoorLock;
currentRoom = room;
deviceUI = doorLock;
BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor;
ZigBee.Device.ZbGateway.StatusList.Add(this);
}
#region ◆ 变量申明__________________________
ZigBee.Device.DoorLock doorLock;
FrameLayout bottomFrameLayout;
Shared.Common.Room currentRoom;
DeviceUI deviceUI;
Action action;
Button btnDoorLockTitle;
#endregion
///
/// UI显示
///
public void Show()
{
this.TopFrameLayout(this, "");
EventHandler eHandlerBack = (sender, e) =>
{
RemoveFromParent();
};
this.btnBack.MouseUpEventHandler += eHandlerBack;
this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
this.MidFrameLayout(this);
var btnShare = new Button
{
X = Application.GetRealWidth(850 - 116),
Height = Application.GetRealHeight(69),
Width = Application.GetRealWidth(69),
};
this.titleFrameLayout.AddChidren(btnShare);
var btnFuncSetFrameLayout = new FrameLayout
{
X = Application.GetRealWidth(850 - 116),
Height = Application.GetRealHeight(69),
Width = Application.GetRealWidth(69 * 2 + 58),
};
this.titleFrameLayout.AddChidren(btnFuncSetFrameLayout);
var btnFuncSet = new Button
{
X = Application.GetRealWidth(103),
Height = Application.GetRealHeight(69),
Width = Application.GetRealWidth(69),
UnSelectedImagePath = "DoorLock/SettingIcon.png",
};
btnFuncSetFrameLayout.AddChidren(btnFuncSet);
btnFuncSet.MouseDownEventHandler += (sender, e) =>
{
if (UserCenterResourse.UserInfo.AuthorityNo == 1)
{
var functionSetting = new Shared.Phone.UserCenter.DoorLock.FunctionSetting(doorLock);
Shared.Phone.UserView.HomePage.Instance.AddChidren(functionSetting);
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
functionSetting.Show();
functionSetting.devicNameAction += (deviceRename) =>
{
if (!string.IsNullOrEmpty(deviceRename))
{
btnDoorLockTitle.Text = deviceRename;
//改房间
Shared.Common.Room.CurrentRoom.ChangedRoom(deviceUI.CommonDevice, currentRoom.Id);
deviceUI.CommonDevice.ReSave();
}
};
}
else
{
var functionSettingSub = new Shared.Phone.UserCenter.DoorLock.FunctionSettingSub(doorLock);
Shared.Phone.UserView.HomePage.Instance.AddChidren(functionSettingSub);
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
functionSettingSub.Show();
functionSettingSub.devicNameAction += (deviceRename) =>
{
if (!string.IsNullOrEmpty(deviceRename))
{
btnDoorLockTitle.Text = deviceRename;
}
};
}
};
btnShare.MouseDownEventHandler += (sender, e) =>
{
};
MidFrameLayoutContent();
}
public void MidFrameLayoutContent()
{
#region UI
var midTopFrameLayout = new FrameLayout()
{
X = Application.GetRealWidth(58),
Y = Application.GetRealHeight(115),
Height = Application.GetRealHeight(1238),
Width = Application.GetRealWidth(965),
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
};
this.midFrameLayout.AddChidren(midTopFrameLayout);
btnDoorLockTitle = new Button()
{
Width = Application.GetRealWidth(250),
Height = Application.GetRealHeight(60),
X = Application.GetRealWidth(372),
Y = Application.GetRealHeight(46),
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
Text = string.IsNullOrEmpty(doorLock.DeviceName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : doorLock.DeviceName,
TextSize = 15,
TextAlignment = TextAlignment.Center,
};
midTopFrameLayout.AddChidren(btnDoorLockTitle);
var btnRecord = new Button()
{
Width = Application.GetRealWidth(69),
Height = Application.GetRealHeight(69),
X = Application.GetRealWidth(752),
Y = Application.GetRealHeight(46),
UnSelectedImagePath = "DoorLock/RecordIcon.png",
};
midTopFrameLayout.AddChidren(btnRecord);
btnRecord.MouseDownEventHandler += (sender, e) =>
{
//历史记录 ---- stan
var form = new DeviceDoorLock.DoorLockHistoryLogForm();
form.AddForm(this.doorLock.DeviceAddr);
};
var btnCollect = new Button()
{
Width = Application.GetRealWidth(69),
Height = Application.GetRealHeight(69),
X = Application.GetRealWidth(850),
Y = Application.GetRealHeight(46),
UnSelectedImagePath = "Item/Collection.png",
SelectedImagePath = "Item/CollectionSelected.png"
};
midTopFrameLayout.AddChidren(btnCollect);
var de = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == deviceUI.FileName);
if (de == null)
{
btnCollect.IsSelected = false;
}
else
{
btnCollect.IsSelected = true;
}
btnCollect.MouseDownEventHandler += (sender, e) =>
{
btnCollect.IsSelected = !btnCollect.IsSelected;
if (btnCollect.IsSelected)
{
Shared.Common.Room.CurrentRoom.GetLoveRoom().AddDevice(deviceUI.FileName);//收藏
}
else
{
Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(deviceUI.FileName); //取消收藏
}
};
var btnCurrentText = new Button()
{
Width = Application.GetRealWidth(100),
Height = Application.GetRealHeight(40),
X = Application.GetRealWidth(415),
Y = Application.GetRealHeight(118),
Text = Language.StringByID(R.MyInternationalizationString.Current),
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
TextSize = 10,
TextAlignment = TextAlignment.CenterLeft,
};
midTopFrameLayout.AddChidren(btnCurrentText);
var btnStatus = new Button()
{
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(40),
X = btnCurrentText.Right,
Y = Application.GetRealHeight(118),
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
Text = Language.StringByID(R.MyInternationalizationString.CLose),
TextSize = 10,
TextAlignment = TextAlignment.CenterLeft,
};
midTopFrameLayout.AddChidren(btnStatus);
var btnDoorLockPic = new Button()
{
Width = Application.GetRealWidth(383),
Height = Application.GetRealHeight(343),
X = Application.GetRealWidth(161),
Y = Application.GetRealHeight(415),
UnSelectedImagePath = "DoorLock/DoorLockPicClose.png",
SelectedImagePath = "DoorLock/DooorLockPicOpen.png",
};
midTopFrameLayout.AddChidren(btnDoorLockPic);
var btnFrameLayout = new FrameLayout()
{
Width = Application.GetRealWidth(420 - 46),
Height = Application.GetRealHeight(446),
X = btnDoorLockPic.Right,
Y = Application.GetRealHeight(354),
BackgroundColor = ZigbeeColor.Current.XMWhite,
};
midTopFrameLayout.AddChidren(btnFrameLayout);
var openFrameLayout = new FrameLayout()
{
Width = Application.GetRealWidth(420),//639-35
Height = Application.GetRealHeight(446 / 2),
BackgroundColor = ZigbeeColor.Current.XMWhite,
};
btnFrameLayout.AddChidren(openFrameLayout);
var closeFrameLayout = new FrameLayout()
{
Width = Application.GetRealWidth(420),//639-35
Height = Application.GetRealHeight(446 / 2),
Y = Application.GetRealHeight(446 / 2),
BackgroundColor = ZigbeeColor.Current.XMWhite,
};
btnFrameLayout.AddChidren(closeFrameLayout);
var progressFrameLayout = new FrameLayout()
{
Width = Application.GetRealWidth(9),//639-35
Height = Application.GetRealHeight(446),
X = Application.GetRealWidth(95),
Y = Application.GetRealHeight(0),
BackgroundColor = ZigbeeColor.Current.XMVerticalSeekBar,
};
btnFrameLayout.AddChidren(progressFrameLayout);
var progressButton = new Button()
{
Width = Application.GetRealWidth(81),//639-35
Height = Application.GetRealHeight(89),
X = Application.GetRealWidth(58),
Y = Application.GetRealHeight(347),
UnSelectedImagePath = "DoorLock/UnLockButton.png",
SelectedImagePath = "DoorLock/UnLockButton.png",
};
btnFrameLayout.AddChidren(progressButton);
var btnDoorOpenPic = new Button()
{
Width = Application.GetRealWidth(81),
Height = Application.GetRealHeight(81),
X = Application.GetRealWidth(164),
Y = Application.GetRealHeight(6),
UnSelectedImagePath = "DoorLock/DoorLockOpen.png",
};
openFrameLayout.AddChidren(btnDoorOpenPic);
var btnDoorClosePic = new Button()
{
Width = Application.GetRealWidth(81),
Height = Application.GetRealHeight(81),
X = Application.GetRealWidth(164),
Y = Application.GetRealHeight(117),
UnSelectedImagePath = "DoorLock/DoorLockClose.png",
};
closeFrameLayout.AddChidren(btnDoorClosePic);
var btnCurrentFrameLayout = new FrameLayout()
{
Width = Application.GetRealWidth(965),
Height = Application.GetRealHeight(138),
Y = Application.GetRealHeight(1100),
BackgroundColor = ZigbeeColor.Current.XMBlack,
};
midTopFrameLayout.AddChidren(btnCurrentFrameLayout);
var btnCurrentRoomPic = new Button()
{
Width = Application.GetRealWidth(81),
Height = Application.GetRealHeight(81),
X = Application.GetRealWidth(58),
Y = Application.GetRealHeight(29),
UnSelectedImagePath = "DoorLock/RoomPic.png",
};
btnCurrentFrameLayout.AddChidren(btnCurrentRoomPic);
var btnCurrentRoomName = new Button()
{
Width = Application.GetRealWidth(172),
Height = Application.GetRealHeight(49),
X = Application.GetRealWidth(150),
Y = Application.GetRealHeight(46),
Text = currentRoom.Name,
TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
TextSize = 12,
TextAlignment = TextAlignment.CenterLeft,
};
btnCurrentFrameLayout.AddChidren(btnCurrentRoomName);
#endregion
EventHandler hander1 = async (sender, e) =>
{
if (UserCenterResourse.UserInfo.AuthorityNo != 1)
{
var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, Shared.Common.Config.Instance.Guid);
if (result == false)
{
var result1 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockUnlockAccess(doorLock, Shared.Common.Config.Instance.Guid);
if (result1 == true)
{
RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus, btnDoorLockTitle);
devicNameSecAction += (deviceRename) =>
{
if (!string.IsNullOrEmpty(deviceRename))
{
btnDoorLockTitle.Text = deviceRename;
//改房间
Shared.Common.Room.CurrentRoom.ChangedRoom(deviceUI.CommonDevice, currentRoom.Id);
deviceUI.CommonDevice.ReSave();
}
};
}
else
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.NoAccess), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
}
}
else
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.AccountIsFreezed), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
}
}
else
{
RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus, btnDoorLockTitle);
devicNameSecAction += (deviceRename) =>
{
if (!string.IsNullOrEmpty(deviceRename))
{
btnDoorLockTitle.Text = deviceRename;
//改房间
Shared.Common.Room.CurrentRoom.ChangedRoom(deviceUI.CommonDevice, currentRoom.Id);
deviceUI.CommonDevice.ReSave();
}
};
}
};
openFrameLayout.MouseUpEventHandler += hander1;
btnDoorOpenPic.MouseUpEventHandler += hander1;
EventHandler hander2 = (sender, e) =>
{
btnDoorLockPic.IsSelected = false;
progressButton.Y = Application.GetRealHeight(347);
};
closeFrameLayout.MouseUpEventHandler += hander2;
btnDoorClosePic.MouseUpEventHandler += hander2;
}
#region ◆ 接口实现__________________________
///
/// 处理变化事件 --将弃用 改用DeviceInfoChange()
///
/// The changed.
/// Common.
public void Changed(CommonDevice common)
{
}
///
/// 处理变化事件
///
///
///
public void DeviceInfoChange(CommonDevice common, string typeTag)
{
}
///
/// Changeds the IL ogic status.
///
/// Logic.
public void ChangedILogicStatus(ZigBee.Device.Logic logic)
{
}
///
/// Changeds the IS cene status.
///
/// Scene.
public void ChangedISceneStatus(Scene scene)
{
}
#endregion
}
}