using System;
|
using System.Collections.Generic;
|
using Shared.Common;
|
using System.Timers;
|
using System.Globalization;
|
|
namespace Shared.Phone.Device.Room
|
{
|
public class AddRoom:FrameLayout
|
{
|
|
#region ◆ 变量____________________________
|
/// <summary>
|
/// The room.
|
/// </summary>
|
public static Shared.Common.Room room;
|
/// <summary>
|
/// The action.
|
/// </summary>
|
public Action action;
|
/// <summary>
|
/// 图片来源 0--本地图库 1--拍照 2--系统图库
|
/// </summary>
|
public int IconType = 0;
|
/// <summary>
|
/// 新建房间是否保存了
|
/// </summary>
|
public bool NewRoomHadSave;
|
/// <summary>
|
/// 传进来的房间路径
|
/// </summary>
|
public string SendedRoomFilePath;
|
/// <summary>
|
/// 记录更改房间前的背景图片
|
/// </summary>
|
public static string OldBackgroundImagePath;
|
|
/// <summary>
|
/// 房间背景
|
/// </summary>
|
private Button backGround;
|
/// <summary>
|
/// 编辑背景图按钮
|
/// </summary>
|
private Device.CommonForm.SelectedStatuButton editBackgroundPicBtn;
|
/// <summary>
|
/// 传过来的房间路径
|
/// </summary>
|
private string oldRoomFilePath;
|
/// <summary>
|
/// 房间名
|
/// </summary>
|
private EditText nameET;
|
/// <summary>
|
/// 设置内容向右btn
|
/// </summary>
|
private Device.CommonForm.SelectedStatuButton settingRightBtn;
|
/// <summary>
|
/// 设置内容
|
/// </summary>
|
private Device.CommonForm.SelectedStatuButton settingContent;
|
/// <summary>
|
/// 设置内容
|
/// </summary>
|
private FrameLayout settingContentFL;
|
/// <summary>
|
/// 完成
|
/// </summary>
|
private Device.CommonForm.CompleteButton confirm;
|
|
#endregion
|
|
#region ◆ 构造方法_________________________
|
|
/// <summary>
|
/// 添加或者修改房间
|
/// </summary>
|
public AddRoom()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
}
|
|
#endregion
|
|
#region ◆ 重写移除方法_____________________
|
/// <summary>
|
/// Removes from parent.
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
//if (!NewRoomHadSave && SendedRoomFilePath == "" && room.Name.Trim()!="")
|
//{
|
// Application.RunOnMainThread(() =>
|
// {
|
// var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SaveTheNewRoomOrNo), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Save));
|
// alert.Show();
|
// alert.ResultEventHandler += (sender, e) =>
|
// {
|
// if (!e)
|
// {
|
// Common.Room.Remove(room.FileName);
|
// }
|
// action?.Invoke();
|
// base.RemoveFromParent();
|
// };
|
// });
|
//}
|
//else
|
//{
|
//action?.Invoke();
|
base.RemoveFromParent();
|
//}
|
}
|
|
#endregion
|
|
#region ◆ 显示视图_________________________
|
/// <summary>
|
/// 显示视图
|
/// </summary>
|
/// <param name="roomFilePath">Room file path.</param>
|
public void Show(string roomFilePath = "")
|
{
|
ShowAddRoom(roomFilePath);
|
//SendedRoomFilePath = roomFilePath;
|
}
|
|
/// <summary>
|
/// 显示
|
/// </summary>
|
/// <param name="roomFilePath">Room file path.</param>
|
void ShowAddRoom(string roomFilePath = "")
|
{
|
oldRoomFilePath = roomFilePath;
|
#region topview
|
room = new Common.Room
|
{
|
BackgroundImage = "Room/r0.png"
|
};
|
|
var topBGView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(220),
|
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
|
};
|
AddChidren(topBGView);
|
var topView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),
|
Height = Application.GetRealHeight(220-CommonPage.NavigationTitle_Y),
|
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,
|
};
|
this.AddChidren(topView);
|
|
var title = new Button()
|
{
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.AddRoom,
|
TextSize = 20,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
Width = Application.GetRealWidth(1080 - 500),
|
Gravity = Gravity.CenterHorizontal
|
};
|
topView.AddChidren(title);
|
|
var back = new Device.CommonForm.BackButton() { };
|
topView.AddChidren(back);
|
|
back.MouseUpEventHandler += (sender, e) =>
|
{
|
this.RemoveFromParent();
|
action?.Invoke();
|
|
};
|
#endregion
|
|
#region midFrameLayout--
|
var midFl = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(1920 - 220),
|
Y = topView.Bottom,
|
BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCBackgroundColor,
|
};
|
this.AddChidren(midFl);
|
|
var backGroundFL = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(30),
|
Width = Application.GetRealWidth(1080 - CommonPage.XLeft * 2),
|
Height = Application.GetRealHeight(550),
|
Gravity=Gravity.CenterHorizontal,
|
Radius=CommonPage.BigFormRadius
|
};
|
midFl.AddChidren(backGroundFL);
|
|
backGround = new Button()
|
{
|
UnSelectedImagePath = room.BackgroundImage,
|
Radius = CommonPage.BigFormRadius,
|
Width = Application.GetMinRealAverage(1080 - CommonPage.XLeft * 2),
|
Height = Application.GetMinRealAverage(550),
|
};
|
backGroundFL.AddChidren(backGround);
|
|
editBackgroundPicBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
X = backGroundFL.Width- Application.GetRealWidth(100+20),
|
Y = Application.GetRealHeight(20),
|
Width = Application.GetMinRealAverage(100),
|
Height = Application.GetMinRealAverage(100),
|
UnSelectedImagePath = "Room/Edit.png",
|
SelectedImagePath="Room/EditSelected.png",
|
};
|
backGroundFL.AddChidren(editBackgroundPicBtn);
|
|
var editNameFL = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(100) + backGroundFL.Bottom,
|
Height = Application.GetRealHeight(200),
|
};
|
midFl.AddChidren(editNameFL);
|
var nameBtn = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Width=Application.GetRealWidth(700),
|
TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
|
TextID = R.MyInternationalizationString.RoomName,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight(90)
|
};
|
editNameFL.AddChidren(nameBtn);
|
nameET = new EditText()
|
{
|
Y= nameBtn.Bottom,
|
X = Application.GetRealWidth(50),
|
Width = Application.GetRealWidth(900),
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight(99),
|
PlaceholderText=Language.StringByID(R.MyInternationalizationString.PleaseInputRoomName),
|
PlaceholderTextColor=ZigbeeColor.Current.GXCPlaceHolderTextColor,
|
TextSize = 20,
|
|
};
|
editNameFL.AddChidren(nameET);
|
var nameLine = new Button()
|
{
|
Y = Application.GetRealHeight(200)-1,
|
BackgroundColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
|
Height = 1
|
};
|
editNameFL.AddChidren(nameLine);
|
|
|
settingContentFL = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(50) + editNameFL.Bottom,
|
Height = Application.GetRealHeight(200)
|
};
|
midFl.AddChidren(settingContentFL);
|
settingContent = new Device.CommonForm.SelectedStatuButton()
|
{
|
X = Application.GetRealWidth(50),
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 20,
|
TextID = R.MyInternationalizationString.SettingContent,
|
Height = Application.GetRealHeight(90),
|
Width = Application.GetRealWidth(500),
|
Gravity = Gravity.CenterVertical
|
};
|
settingContentFL.AddChidren(settingContent);
|
|
settingRightBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
X = settingContentFL.Right - Application.GetRealWidth(120),
|
Height = Application.GetMinRealAverage(100),
|
Width = Application.GetMinRealAverage(100),
|
UnSelectedImagePath = "Item/Next.png",
|
SelectedImagePath="Item/NextSelected.png",
|
Gravity=Gravity.CenterVertical
|
};
|
settingContentFL.AddChidren(settingRightBtn);
|
|
var settingLine = new Button()
|
{
|
Y = Application.GetRealHeight(200) - 1,
|
BackgroundColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
|
Height = 1
|
};
|
settingContentFL.AddChidren(settingLine);
|
|
confirm = new Device.CommonForm.CompleteButton(1700, 700, 127);
|
confirm.SetTitle(R.MyInternationalizationString.Confrim);
|
this.AddChidren(confirm);
|
#endregion
|
|
//修改房间
|
if(oldRoomFilePath != "")
|
{
|
room = Shared.Common.Room.GetRoomByFilePath(oldRoomFilePath);
|
//标题改为修改房间
|
title.TextID = R.MyInternationalizationString.EditRoom;
|
//背景图改为当前房间的背景图
|
backGround.UnSelectedImagePath = room.BackgroundImage;
|
//房间名称
|
nameET.Text = room.Name;
|
}
|
if (room.IsSharedRoom || room.IsLove)
|
{
|
nameET.Enable = false;
|
}
|
//绑定事件
|
BindEvent();
|
}
|
|
#endregion
|
|
#region ◆ 绑定事件_________________________
|
|
/// <summary>
|
/// 绑定事件
|
/// </summary>
|
private void BindEvent()
|
{
|
//设置背景
|
editBackgroundPicBtn.MouseUpEventHandler += SelectBackgroundImg;
|
//设置内容
|
settingRightBtn.MouseUpEventHandler += SettingContent;
|
settingContent.MouseUpEventHandler += SettingContent;
|
settingContentFL.MouseUpEventHandler += SettingContent;
|
//完成
|
confirm.MouseUpEventHandler += ComfireAdd;
|
}
|
|
#endregion
|
|
#region ◆ 设置背景图_______________________
|
|
/// <summary>
|
/// 选择背景图
|
/// </summary>
|
private void SelectBackgroundImg(object sender,MouseEventArgs mouseEventArgs)
|
{
|
if(room.IsSharedRoom)
|
{
|
RoomCommon.ShowTipRoomIsShared();
|
return;
|
}
|
|
int selectRow_Height = 130;
|
var selectFL = new FrameLayout()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
|
};
|
AddChidren(selectFL);
|
var itemFL = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(CommonPage.AppRealHeight - selectRow_Height * 4 - 20),
|
Height = Application.GetRealHeight(selectRow_Height * 4 + 20)
|
};
|
selectFL.AddChidren(itemFL);
|
|
var localPicBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.LocalPic,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(localPicBtn);
|
var localPicLine = new Button()
|
{
|
Y = localPicBtn.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor,
|
};
|
itemFL.AddChidren(localPicLine);
|
|
var takePhotoBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Y = localPicLine.Bottom,
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.TakePhoto,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(takePhotoBtn);
|
var takePhotoLine = new Button()
|
{
|
Y = takePhotoBtn.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor,
|
};
|
itemFL.AddChidren(takePhotoLine);
|
|
var systemPicBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Y = takePhotoLine.Bottom,
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.SystemPic,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(systemPicBtn);
|
|
var cancelBtn = new Device.CommonForm.SelectedStatuButton()
|
{
|
Y = systemPicBtn.Bottom + Application.GetRealHeight(20),
|
Height = Application.GetRealHeight(selectRow_Height),
|
TextID = R.MyInternationalizationString.Cancel,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
itemFL.AddChidren(cancelBtn);
|
|
itemFL.Animate = Animate.DownToUp;
|
//本地图库
|
localPicBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var localPic = new AddRoomSelectPicByLocal();
|
Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
|
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
|
localPic.Show();
|
localPic.action = (backImgPath) =>
|
{
|
backGround.UnSelectedImagePath = backImgPath;
|
IconType = 0;
|
room.BackgroundImageType = 0;
|
};
|
};
|
//拍照
|
takePhotoBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
Camera.TakePicture((obj) =>
|
{
|
if (obj == null)
|
{
|
return;
|
}
|
|
if (room.BackgroundImageType == 1 || room.BackgroundImageType == 2)
|
{
|
OldBackgroundImagePath = room.BackgroundImage;
|
System.IO.File.Delete(OldBackgroundImagePath);
|
}
|
backGround.UnSelectedImagePath = $"RoomPicture{tradeTime}.png";
|
//room.BackgroundImage = $"{Config.Instance.HomeId}/{backGround.UnSelectedImagePath}";
|
IconType = 1;
|
room.BackgroundImageType = 1;
|
}, $"RoomPicture{tradeTime}.png");
|
};
|
//系统图库
|
systemPicBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
Camera.SelectPicture((obj) =>
|
{
|
if (obj == null)
|
{
|
return;
|
}
|
if (room.BackgroundImageType == 1 || room.BackgroundImageType == 2)
|
{
|
OldBackgroundImagePath = room.BackgroundImage;
|
System.IO.File.Delete(OldBackgroundImagePath);
|
}
|
backGround.UnSelectedImagePath = $"RoomPicture{tradeTime}.png";
|
//room.BackgroundImage = $"{Config.Instance.HomeId}/{backGround.UnSelectedImagePath}";
|
IconType = 2;
|
room.BackgroundImageType = 2;
|
}, $"RoomPicture{tradeTime}.png");
|
};
|
cancelBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
};
|
selectFL.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
};
|
}
|
|
|
#endregion
|
|
#region ◆ 设置内容_________________________
|
|
/// <summary>
|
/// 设置内容
|
/// </summary>
|
private void SettingContent(object sender,MouseEventArgs mouseEventArgs)
|
{
|
if (oldRoomFilePath == "")
|
{
|
room.Name = nameET.Text.Trim();
|
//room.BackgroundImage = backGround.UnSelectedImagePath;
|
var newRoomFilePath = room.FileName;
|
if (nameET.Text.Trim() == "")
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheRoomNameCannotBeNUll);
|
return;
|
}
|
if (Shared.Common.Room.Lists.Find((obj) => obj.Name == room.Name) != null)
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.HadSameRoom);
|
return;
|
}
|
if (Global.IsExistsByHomeId(newRoomFilePath))
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.HadSameRoom);
|
return;
|
}
|
var result= room.AddRoom(room);
|
if (IconType == 1 || IconType == 2)
|
{
|
room.MoveBackGroundIamageFileToDirectory(backGround.UnSelectedImagePath, room.BackgroundImage);
|
}
|
oldRoomFilePath = room.FileName;
|
//SendedRoomFilePath = room.FileName;
|
}
|
if (room.Name != nameET.Text.Trim())
|
{
|
if (Shared.Common.Room.Lists.Find((obj) => obj.Name == nameET.Text.Trim()) != null)
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.HadSameRoom);
|
return;
|
}
|
room.Name = nameET.Text.Trim();
|
oldRoomFilePath = room.FileName;
|
room.Save();
|
}
|
|
var roomContent = new AddRoomContent();
|
UserView.HomePage.Instance.AddChidren(roomContent);
|
UserView.HomePage.Instance.PageIndex += 1;
|
roomContent.Show(Shared.Common.Room.GetRoomByFilePath(room.FileName));
|
}
|
|
#endregion
|
|
#region ◆ 完成____________________________
|
|
/// <summary>
|
/// 完成 添加房间
|
/// </summary>
|
private void ComfireAdd(object sender,MouseEventArgs mouseEventArgs)
|
{
|
if (room.IsSharedRoom)
|
{
|
RoomCommon.ShowTipRoomIsShared();
|
return;
|
}
|
//修改房间
|
if (oldRoomFilePath != "")
|
{
|
if(nameET.Text.Trim()!=room.Name)
|
{
|
if (Shared.Common.Room.Lists.Find((obj) => obj.Name == nameET.Text.Trim()) != null)
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.HadSameRoom);
|
return;
|
}
|
}
|
//NewRoomHadSave = true;
|
//删除原来的图片
|
if (!string.IsNullOrEmpty(OldBackgroundImagePath))
|
{
|
Shared.Common.Room.DeleteBackGroundIamageFilebyHomeId(OldBackgroundImagePath);
|
}
|
if (IconType == 1 || IconType == 2)
|
{
|
room.MoveBackGroundIamageFileToDirectory(backGround.UnSelectedImagePath, backGround.UnSelectedImagePath);
|
room.BackgroundImage = $"{Config.Instance.Guid}/{Config.Instance.HomeId}/{backGround.UnSelectedImagePath}";
|
}
|
else
|
{
|
room.BackgroundImage = backGround.UnSelectedImagePath;
|
}
|
room.Name = nameET.Text.Trim();
|
room.Save();
|
action?.Invoke();
|
RemoveFromParent();
|
}
|
else
|
{
|
try
|
{
|
if (nameET.Text.Trim() == "")
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheRoomNameCannotBeNUll);
|
return;
|
}
|
room.Name = nameET.Text.Trim();
|
var newRoomFilePath = room.FileName;
|
if (Global.IsExistsByHomeId(newRoomFilePath))
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.HadSameRoom);
|
return;
|
}
|
if (Shared.Common.Room.Lists.Find((obj) => obj.Name== room.Name)!=null)
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.HadSameRoom);
|
return;
|
}
|
if (IconType == 1 || IconType == 2)
|
{
|
room.MoveBackGroundIamageFileToDirectory(backGround.UnSelectedImagePath, backGround.UnSelectedImagePath);
|
room.BackgroundImage = $"{Config.Instance.Guid}/{Config.Instance.HomeId}/{backGround.UnSelectedImagePath}";
|
}
|
else
|
{
|
room.BackgroundImage = backGround.UnSelectedImagePath;
|
}
|
var result= room.AddRoom(room);
|
|
if(result==false)
|
{
|
//提示用户添加失败
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL);
|
}
|
else
|
{
|
action?.Invoke();
|
RemoveFromParent();
|
}
|
|
}
|
catch(Exception ex)
|
{
|
System.Console.WriteLine("添加房间异常" + ex.Message);
|
}
|
|
}
|
}
|
|
#endregion
|
|
}
|
}
|