XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

STHApplication

【MAUI】寄当家——安卓端交易管理系统

公开
关注 0 Fork 0 Star 0
UTF-8
using JiDangJia.Contracts;
using JiDangJia.Services;

namespace JiDangJia.Views;

internal sealed class CommunityVideo : ContentView
{
    private static readonly List<WeakReference<CommunityVideo>> players=[];
    internal static bool Backgrounded{get;private set;}
    internal readonly CommunityVideoSurface Surface;
    public CommunityVideo(CommunityMedia media,ContentPage page,bool sound,Func<Task> open)
    {
        var error=Ui.Text("",12,Ui.Muted);error.IsVisible=false;
        Surface=new(media,page,sound,open){HeightRequest=sound?280:200};Surface.Failed=()=>{error.Text="视频暂不可用,稍后重新进入页面重试";error.IsVisible=true;};
        SemanticProperties.SetDescription(Surface,sound?"详情视频":"推荐视频");
        Content=Ui.Stack(Surface,Ui.Text(sound?"视频播放 · 有声音":"视频静音自动播放 · 点击查看",11,Ui.Muted),error);
        players.RemoveAll(p=>!p.TryGetTarget(out _));players.Add(new(this));
    }
    public static void StopAll(){foreach(var reference in players.ToArray())if(reference.TryGetTarget(out var item))item.Surface.Pause?.Invoke();}
    internal static void Starting(CommunityVideoSurface surface){if(!surface.Sound)return;foreach(var reference in players.ToArray())if(reference.TryGetTarget(out var item)&&item.Surface.Sound&&!ReferenceEquals(item.Surface,surface))item.Surface.Pause?.Invoke();}
    public static void SetBackgrounded(bool value){Backgrounded=value;if(value)StopAll();}
    public static void SetActive(IVisualTreeElement tree,bool value)
    {if(tree is CommunityVideo video){video.Surface.Active=value;if(!value)video.Surface.Pause?.Invoke();}foreach(var child in tree.GetVisualChildren())SetActive(child,value);}
}

internal sealed class CommunityVideoSurface(CommunityMedia media,ContentPage host,bool sound,Func<Task> open) : View
{
    internal CommunityMedia Media{get;}=media;
    internal ContentPage Host{get;}=host;
    internal bool Sound{get;}=sound;
    internal string Account{get;}=AuthClient.Current.AccountId;
    internal bool Active{get;set;}=true;
    internal Func<Task> Open{get;}=open;
    internal Action? Pause,Failed;
}