mac
2024-07-25 3f6685c77beeb12baf840733fb890860f4c26e7c
HDL_ON/UI/UI2/FuntionControlView/Aks/YkPage.cs
@@ -1,179 +1,360 @@
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using HDL_ON.DriverLayer;
using HDL_ON.UI.Music;
using HDL_ON.UI.UI2.Intelligence.Automation;
using System.Linq;
using HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView;
using HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock;
using HDL_ON.UI.UI2.FuntionControlView.Aks.Entity;
using System.Linq;
namespace HDL_ON.UI.UI2.FuntionControlView.Aks
{
    /// <summary>
    /// 影库界面
    /// </summary>
    public class YkPage:FrameLayout
    public class YkPage : FrameLayout
    {
        /// <summary>
        /// 头部布局
        /// </summary>
        private TopView topView;
        /// <summary>
        /// 删除设备后需要更新界面的回调
        /// </summary>
        public Action action;
        public YkPage()
        private Dictionary<string, Filters> FiltersList = new Dictionary<string, Filters>();
        /// <summary>
        ///
        /// </summary>
        /// <param name="remoteControlEntity">遥控器对象</param>
        public YkPage(RemoteControlEntity remoteControlEntity)
        {
            this.remoteControl = remoteControlEntity;
        }
        List<ImageFramlayout> imageFramlayoutList =new List<ImageFramlayout>();
        /// <summary>
        /// 当前的遥控器对象
        /// </summary>
        RemoteControlEntity remoteControl;
        /// <summary>
        /// 影片一级分类列表
        /// </summary>
        List<FilterCategoryEntity> mFilterCategoryList;
        /// <summary>
        /// 影片列表
        /// </summary>
        List<MovieLibrary> mMovieLibraryList=new List<MovieLibrary>();
        /// <summary>
        /// 顶部布局
        /// </summary>
        TopView topView;
        FrameLayout fLayout;
        /// <summary>
        /// 影片上下滑动父容器
        /// </summary>
        VerticalRefreshLayout vv;
        /// <summary>
        /// 水平滑动父容器
        /// </summary>
        CornerFramLayout horizontalFl;
        CornerFramLayout imageFLayout;
        /// <summary>
        /// 页数
        /// </summary>
        private int pageNo = 1;
        public void Show()
        {
            //初始化UI
            this.InitTop();
            this.InitMiddle();
            //初始化事件监听器
            this.EventListener();
            this.InitUI();
            //读取数据
            this.ReadData();
        }
        /// <summary>
        /// 初始化头部界面
        /// 初始化界面
        /// </summary>
        private void InitTop()
        private void InitUI()
        {
            this.BackgroundColor = MusicColor.ViewColor;
            this.topView = new TopView();
            this.topView.setBtn.Visible = true;
            this.topView.setBtn.Width = Application.GetMinRealAverage(32);
            this.topView.setBtn.Height = Application.GetMinRealAverage(32);
            this.topView.setBtn.UnSelectedImagePath = "Collection/CollectionGrayIcon.png";
            this.topView.setBtn.UnSelectedImagePath = "AksIcon/like.png";
            this.topView.topNameBtn.TextID = StringId.yingku;
            this.AddChidren(topView.TopFLayoutView());
        }
        /// <summary>
        /// 初始化中部界面
        /// </summary>
        private void InitMiddle()
        {
            var fLayout = new FrameLayout {
            fLayout = new FrameLayout
            {
                Y = topView.fLayout.Bottom,
                Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
                BackgroundColor = MusicColor.WhiteColor,
            };
            this.AddChidren(fLayout);
            BaseFramLayout typeFLayout = new BaseFramLayout();
            fLayout.AddChidren(typeFLayout);
            int span= 20;//间隔
            int x= 16;//X轴偏移量
            int width =375-x;
            int height = 28;
            HorizontalFramLayout horizontalFram = new HorizontalFramLayout(width, height);
            typeFLayout.AddChidren(horizontalFram);
            horizontalFram.Y = Application.GetRealHeight(span);
            horizontalFram.X = Application.GetRealHeight(x);
            horizontalFram.SetIndex(2);
            horizontalFram.SetList(horizontalFram.GetTestData);
            horizontalFram.InitControl();
            horizontalFram.SelectTypeEvent += (index) => {
                Console.WriteLine("1");
            };
            HorizontalFramLayout horizontalFram1 = new HorizontalFramLayout(width, height);
            typeFLayout.AddChidren(horizontalFram1);
            horizontalFram1.Y = horizontalFram.Bottom + Application.GetRealHeight(span);
            horizontalFram1.X = Application.GetRealHeight(x);
            horizontalFram1.SetIndex(2);
            horizontalFram1.SetList(horizontalFram1.GetTestData);
            horizontalFram1.InitControl();
            horizontalFram1.SelectTypeEvent += (index) => {
                Console.WriteLine("2");
            };
            HorizontalFramLayout horizontalFram2 = new HorizontalFramLayout(width, height);
            typeFLayout.AddChidren(horizontalFram2);
            horizontalFram2.Y = horizontalFram1.Bottom + Application.GetRealHeight(span);
            horizontalFram2.X = Application.GetRealHeight(x);
            horizontalFram2.SetIndex(2);
            horizontalFram2.SetList(horizontalFram2.GetTestData);
            horizontalFram2.InitControl();
            horizontalFram2.SelectTypeEvent += (index) => {
                Console.WriteLine("3");
            };
            HorizontalFramLayout horizontalFram3 = new HorizontalFramLayout(width, height);
            typeFLayout.AddChidren(horizontalFram3);
            horizontalFram3.Y = horizontalFram2.Bottom + Application.GetRealHeight(span);
            horizontalFram3.X = Application.GetRealHeight(x);
            horizontalFram3.SetIndex(2);
            horizontalFram3.SetList(horizontalFram3.GetTestData);
            horizontalFram3.InitControl();
            horizontalFram3.SelectTypeEvent += (index) => {
                Console.WriteLine("4");
            };
            typeFLayout.AdjustRealHeight();
            var vv = new VerticalRefreshLayout()
            {
                Y = typeFLayout.Bottom,
                Height = fLayout.Height- typeFLayout.Bottom,
            };
            fLayout.AddChidren(vv);
            vv.BeginHeaderRefreshingAction += () =>
            {
                //关闭刷新View;
                vv.EndHeaderRefreshing();
            };
            CornerFramLayout imageFLayout = new CornerFramLayout(343, 20 * 168, 0);
            vv.AddChidren(imageFLayout);
            imageFLayout.X = Application.GetRealWidth(16);
            imageFLayout.LoadImagePage(new List<Entity.KeypadEntity>());
            imageFLayout.selectAction += (index) =>
            {
                CommonMethod.Current.MainThread(() =>
                {
                    DetailPage detailPage = new DetailPage();
                    MainPage.BasePageView.AddChidren(detailPage);
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    detailPage.Show();
                });
            };
            imageFLayout.AdjustRealHeight(16);
        }
        /// <summary>
        /// 注册事件
        /// </summary>
        private void EventListener()
        {
            //this.LoadFTypeLayout();
            //this.LoadImageFLayout();
            //返回
            this.topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            //设置
            //收藏图标点击事件
            this.topView.clickSetBtn.MouseUpEventHandler += (sender, e) =>
            {
                CommonMethod.Current.MainThread(() =>
                {
                    CollectPage collectPage = new CollectPage();
                    CollectPage collectPage = new CollectPage(remoteControl);
                    MainPage.BasePageView.AddChidren(collectPage);
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    collectPage.Show();
                });
            };
        }
        /// <summary>
        /// 加载一级分类布局
        /// </summary>
        private void LoadFTypeLayout()
        {
            fLayout.RemoveAll();
            int count = this.mFilterCategoryList == null ? 0 : this.mFilterCategoryList.Count;
            horizontalFl = new CornerFramLayout(375, count * 75);
            fLayout.AddChidren(horizontalFl);
            horizontalFl.LoadHorizontalPage(this.mFilterCategoryList);
            horizontalFl.AdjustRealHeight(20);
            vv = new VerticalRefreshLayout()
            {
                Y = horizontalFl.Bottom,
                Height = fLayout.Height - horizontalFl.Bottom,
            };
            fLayout.AddChidren(vv);
            //二级过滤事件
            horizontalFl.selectKeyAction += (filters) =>
            {
                pageNo = 1;//还原页数
                AddMemoryFilters(filters);
                UpdateData(true);
            };
        }
        /// <summary>
        /// 加载影片列表布局
        /// </summary>
        private void LoadImageFLayout()
        {
            if (vv == null)
            {
                return;
            }
            vv.RemoveAll();
            int count = this.mMovieLibraryList == null ? 0 : this.mMovieLibraryList.Count;
            imageFLayout = new CornerFramLayout(343, count * 168, 0);
            vv.AddChidren(imageFLayout);
            imageFLayout.X = Application.GetRealWidth(16);
            //imageFLayout.LoadImagePage(this.mMovieLibraryList);
            imageFLayout.LoadImagePage(imageFramlayoutList);
            imageFLayout.AdjustRealHeight(16);
            //更多的
            var btnMore = new Button
            {
                Width = Application.GetRealWidth(375),
                Height = Application.GetRealHeight(30),
                TextSize = TextSize.Text14,
                TextColor = MusicColor.TextColor,
                TextID = StringId.LoadMore,
                TextAlignment = TextAlignment.TopCenter,
                Padding = new Padding(0, 20, 0, 20),
            };
            vv.AddChidren(btnMore);
            btnMore.MouseDownEventHandler += (sender,e) => {
                //主动更新数据
                UpdateData(false);
            };
            //影片事件
            imageFLayout.selectImageAction += (movieLibrary) =>
            {
                CommonMethod.Current.MainThread(() =>
                {
                    DetailPage detailPage = new DetailPage(remoteControl, movieLibrary);
                    MainPage.BasePageView.AddChidren(detailPage);
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    detailPage.Show();
                });
            };
            //下拉刷新
            vv.BeginHeaderRefreshingAction += () =>
            {
                //关闭刷新View;
                vv.EndHeaderRefreshing();
                //主动更新数据
                //UpdateData();
            };
        }
        /// <summary>
        /// 加载图片容器
        /// </summary>
        /// <param name="movieLibrary">movieLibrary</param>
        private void AddImageFramlayout(MovieLibrary movieLibrary)
        {
            CommonMethod.Current.MainThread(() =>
            {
                if (movieLibrary == null)
                {
                    return;
                }
                ImageFramlayout imageFram = new ImageFramlayout();
                //imageFram.AddView(this);
                imageFram.Tag = movieLibrary;
                imageFram.btnName.Text = movieLibrary.name;
                imageFram.btnImage.ImageBytes = movieLibrary.imageBytes;
                imageFram.btnScore.Text = movieLibrary.rating;
                //添加缓存
                imageFramlayoutList.Add(imageFram);
            });
        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void ReadData()
        {
            CommonMethod.Current.Loading.Start();
            CommonMethod.Current.SunThread(() =>
            {
                try
                {
                    this.mFilterCategoryList = SendMethod.Current.GetFilterCategoryLits(this.remoteControl.deviceId, this.remoteControl.rcId);
                    var newList = SendMethod.Current.GetMovieLibraryPage(this.remoteControl.deviceId, this.remoteControl.rcId, new List<Filters>(), pageNo, SendMethod.pageSize);
                    DataTreating(newList);
                }
                catch { }
                finally
                {
                    CommonMethod.Current.MainThread(() =>
                    {
                        CommonMethod.Current.Loading.Hide();
                        this.LoadFTypeLayout();
                        this.LoadImageFLayout();
                    });
                }
            });
        }
        /// <summary>
        /// 主动更新数据
        /// </summary>
        /// <param name="isUpdateData">是否是二级过滤,true表示是二级过滤过来的</param>
        private void UpdateData(bool isUpdateData)
        {
            CommonMethod.Current.Loading.Start();
            CommonMethod.Current.SunThread(() =>
            {
                try
                {
                    var newList = SendMethod.Current.GetMovieLibraryPage(this.remoteControl.deviceId, this.remoteControl.rcId, this.FiltersList.Values.ToList(), pageNo, SendMethod.pageSize);
                    DataTreating(newList);
                }
                catch { }
                finally
                {
                    CommonMethod.Current.MainThread(() =>
                    {
                        CommonMethod.Current.Loading.Hide();
                        if (isUpdateData)
                        {
                            //清空所有旧影片数据,重新加载新影片数据
                            this.LoadImageFLayout();
                        }
                        else
                        {
                            //追加新数据在旧数据后面
                            imageFLayout.LoadImagePage(imageFramlayoutList);
                            imageFLayout.AdjustRealHeight(16);
                        }
                    });
                }
            });
        }
        /// <summary>
        /// 数据处理逻辑
        /// </summary>
        /// <param name="newList">新列表数据</param>
        private void DataTreating(List<MovieLibrary> newList)
        {
            if (newList == null || newList.Count == 0)
            {
                return;
            }
            //有新数据,清空旧数据
            imageFramlayoutList.Clear();
            for (int i = 0; i < newList.Count; i++)
            {
                var mMovieLibrary = newList[i];
                //图片的字节流
                var bytes = SendMethod.Current.GetImage(mMovieLibrary.posterUrl);
                //更新值
                mMovieLibrary.imageBytes = bytes;
            }
            for (int i = 0; i < newList.Count; i++)
            {
                //去重
                var mMovieLibrary = this.mMovieLibraryList.Find((o) => o.movieId == newList[i].movieId);
                if (mMovieLibrary == null)
                {
                    //新列表默认加在最前面
                    this.mMovieLibraryList.Insert(0, newList[i]);
                }
                //添加图片容器
                AddImageFramlayout(newList[i]);
            }
            if (newList.Count == SendMethod.pageSize)
            {
                //更新页数
                pageNo++;
            }
        }
        /// <summary>
        /// 添加过滤数据
        /// </summary>
        /// <param name="filters">过滤条件</param>
        private void AddMemoryFilters(Filters filters)
        {
            if (FiltersList.ContainsKey(filters.category))
            {
                FiltersList.Remove(filters.category);
            }
            FiltersList.Add(filters.category, filters);
        }
    }
}