Пример #1
0
        static Widget _Atomic(BuildContext context, string type, string contentType, string title, string dataUrl,
                              _OriginalImage originalImage, string videoStatus, string videoPoster,
                              string url, string downloadUrl, string attachmentId, Action <string> openUrl,
                              Action <string, bool, int> playVideo, Action loginAction, bool needUpdate, int limitSeconds,
                              Action <string> browserImage = null)
        {
            if (type == "ATTACHMENT" && contentType != "video/mp4")
            {
                return(new Container());
            }

            var playButton = Positioned.fill(
                new Container()
                );

            if (type == "VIDEO" || type == "ATTACHMENT")
            {
                playButton = Positioned.fill(
                    new Center(
                        child: videoStatus == "completed"
                            ? UserInfoManager.isLogin()
                                ? new CustomButton(
                            onPressed: () => {
                    if (type == "ATTACHMENT")
                    {
                        if (url.isEmpty())
                        {
                            playVideo(downloadUrl, false, 0);
                        }
                        else
                        {
                            playVideo($"{Config.apiAddress}/playlist/{attachmentId}", needUpdate,
                                      limitSeconds);
                        }
                    }
                    else
                    {
                        if (url == null || url.Length <= 0)
                        {
                            return;
                        }

                        openUrl(url);
                    }
                },
                            child: new Container(
                                width: 60,
                                height: 60,
                                decoration: new BoxDecoration(
                                    CColors.H5White,
                                    borderRadius: BorderRadius.all(30)
                                    ),
                                child: new Icon(
                                    Icons.play_arrow,
                                    size: 45,
                                    color: CColors.Icon
                                    )
                                )
                            )
                                : (Widget) new GestureDetector(
                            onTap: () => { loginAction(); },
                            child: new Container(
                                color: CColors.Black.withOpacity(0.5f),
                                alignment: Alignment.center,
                                child: new Text("Login to view this video",
                                                style: CTextStyle.PXLargeWhite.merge(
                                                    new TextStyle(decoration: TextDecoration.underline)))
                                ))
                            : new Container(
                            color: CColors.Black.withOpacity(0.5f),
                            alignment: Alignment.center,
                            child: new Text("Video is processing, try it later", style: CTextStyle.PXLargeWhite)
                            )
                        )
                    );
            }

            var attachWidth  = MediaQuery.of(context).size.width - 32;
            var attachHeight = attachWidth * 9 / 16;

            if (type == "ATTACHMENT")
            {
                return(new Container(
                           color: CColors.White,
                           padding: EdgeInsets.only(bottom: 32),
                           alignment: Alignment.center,
                           child: new Container(
                               padding: EdgeInsets.only(16, right: 16),
                               child: new Column(
                                   children: new List <Widget> {
                    new Stack(
                        children: new List <Widget> {
                        new Container(
                            width: attachWidth,
                            height: attachHeight,
                            color: CColors.Black,
                            child: Image.network(
                                videoPoster,
                                fit: BoxFit.cover
                                )
                            ),
                        playButton
                    }
                        )
                }
                                   )
                               )
                           ));
            }

            var width = originalImage.width < MediaQuery.of(context).size.width - 32
                ? originalImage.width
                : MediaQuery.of(context).size.width - 32;
            var height   = width * originalImage.height / originalImage.width;
            var imageUrl = originalImage.url;

            if (imageUrl.isNotEmpty())
            {
                imageUrl = imageUrl.EndsWith(".gif") || imageUrl.EndsWith(".png")
                    ? imageUrl
                    : CImageUtils.SuitableSizeImageUrl(MediaQuery.of(context).size.width, imageUrl);
                imageUrls.Add(imageUrl);
            }

            var nodes = new List <Widget> {
                new Stack(
                    children: new List <Widget> {
                    new GestureDetector(
                        child: new Hero(
                            tag: imageUrl,
                            child: new PlaceholderImage(
                                imageUrl: imageUrl,
                                width: width,
                                height: height,
                                fit: BoxFit.cover,
                                useCachedNetworkImage: true
                                )
                            ), onTap: () => {
                        if (dataUrl.isNotEmpty())
                        {
                            openUrl(obj: dataUrl);
                        }
                        else
                        {
                            browserImage?.Invoke(imageUrl);
                        }
                    }
                        ),
                    playButton
                }
                    )
            };

            if (title != null)
            {
                var imageTitle = new Container(
                    decoration: new BoxDecoration(
                        border: new Border(
                            bottom: new BorderSide(
                                CColors.Separator,
                                2
                                )
                            )
                        ),
                    child: new Container(
                        margin: EdgeInsets.only(4, 8, 4, 4),
                        child: new Text(
                            title,
                            style: CTextStyle.PRegularBody4
                            )
                        )
                    );
                nodes.Add(imageTitle);
            }

            return(new Container(
                       color: CColors.White,
                       padding: EdgeInsets.only(bottom: 32),
                       alignment: Alignment.center,
                       child: new Container(
                           padding: EdgeInsets.only(16, right: 16),
                           child: new Column(
                               children: nodes
                               )
                           )
                       ));
        }
Пример #2
0
        static Widget _Atomic(BuildContext context, string type, string contentType, string title,
                              _OriginalImage originalImage,
                              string url, string downloadUrl, Action <string> openUrl, Action <string> playVideo,
                              Action browserImage = null)
        {
            if (type == "ATTACHMENT" && contentType != "video/mp4")
            {
                return(new Container());
            }

            var playButton = Positioned.fill(
                new Container()
                );

            if (type == "VIDEO" || type == "ATTACHMENT")
            {
                playButton = Positioned.fill(
                    new Center(
                        child: new CustomButton(
                            onPressed: () => {
                    if (type == "ATTACHMENT")
                    {
                        playVideo($"{downloadUrl}?noLoginRequired=true");
                    }
                    else
                    {
                        if (url == null || url.Length <= 0)
                        {
                            return;
                        }

                        openUrl(url);
                    }
                },
                            child: new Container(
                                width: 60,
                                height: 60,
                                decoration: new BoxDecoration(
                                    CColors.H5White,
                                    borderRadius: BorderRadius.all(30)
                                    ),
                                child: new Icon(
                                    Icons.play_arrow,
                                    size: 45,
                                    color: CColors.Icon
                                    )
                                )
                            )
                        )
                    );
            }

            var attachWidth  = MediaQuery.of(context).size.width - 32;
            var attachHeight = attachWidth * 9 / 16;

            if (type == "ATTACHMENT")
            {
                return(new Container(
                           color: CColors.White,
                           padding: EdgeInsets.only(bottom: 32),
                           alignment: Alignment.center,
                           child: new Container(
                               padding: EdgeInsets.only(16, right: 16),
                               child: new Column(
                                   children: new List <Widget> {
                    new Stack(
                        children: new List <Widget> {
                        new Container(
                            width: attachWidth,
                            height: attachHeight,
                            color: CColors.Black
                            ),
                        playButton
                    }
                        )
                }
                                   )
                               )
                           ));
            }

            var width = originalImage.width < MediaQuery.of(context).size.width - 32
                ? originalImage.width
                : MediaQuery.of(context).size.width - 32;
            var height   = width * originalImage.height / originalImage.width;
            var imageUrl = originalImage.url;

            if (imageUrl.isNotEmpty())
            {
                imageUrl = imageUrl.EndsWith(".gif") || imageUrl.EndsWith(".png")
                    ? imageUrl
                    : CImageUtils.SuitableSizeImageUrl(MediaQuery.of(context).size.width, imageUrl);
            }

            var nodes = new List <Widget> {
                new Stack(
                    children: new List <Widget> {
                    new GestureDetector(
                        child: new PlaceholderImage(
                            imageUrl,
                            width,
                            height,
                            fit: BoxFit.cover
                            ), onTap: () => {
                        if (browserImage != null)
                        {
                            browserImage();
                        }
                    }),

                    playButton
                }
                    )
            };

            if (title != null)
            {
                var imageTitle = new Container(
                    decoration: new BoxDecoration(
                        border: new Border(
                            bottom: new BorderSide(
                                CColors.Separator,
                                2
                                )
                            )
                        ),
                    child: new Container(
                        margin: EdgeInsets.only(4, 8, 4, 4),
                        child: new Text(
                            title,
                            style: CTextStyle.PRegularBody4
                            )
                        )
                    );
                nodes.Add(imageTitle);
            }

            return(new Container(
                       color: CColors.White,
                       padding: EdgeInsets.only(bottom: 32),
                       alignment: Alignment.center,
                       child: new Container(
                           padding: EdgeInsets.only(16, right: 16),
                           child: new Column(
                               children: nodes
                               )
                           )
                       ));
        }