コード例 #1
0
        private void YieldPlaylists()
        {
            MediaSourceItems.Clear();
            foreach (var source in Model.Sources)
            {
                var         i        = -1;
                Func <bool> isLast   = () => i == source.Playlist.Count - 1;
                var         hasColon = source.Playlist.Count > 0;
                var         title    = source.Name.TrimEnd(':');
                var         url      = source.Target;
                MediaProviderLabelViewModel mp;
                if (!string.IsNullOrWhiteSpace(url))
                {
                    mp = new MediaProviderWithUrlViewModel
                    {
                        Title    = title, Url = url,
                        Margin   = Layouts.GenerateLeftJustified(Layouts.StandardSeparationMarginThickness),
                        HasColon = hasColon
                    };
                }
                else
                {
                    mp = new MediaProviderLabelViewModel
                    {
                        Title    = title,
                        Margin   = Layouts.GenerateLeftJustified(Layouts.StandardSeparationMarginThickness),
                        HasColon = hasColon
                    };
                }
                MediaSourceItems.Add(mp);
                var checkConsecutiveness = CheckConsecutiveness();
                int?lastI = null;
                for (i++; i < source.Playlist.Count; i++)
                {
                    var t  = source.Playlist[i];
                    var tt = t.Item1;
                    if (checkConsecutiveness)
                    {
                        if (int.TryParse(tt, out var itt))
                        {
                            var inconsecutive = lastI.HasValue && lastI + 1 != itt;
                            if (inconsecutive)
                            {
                                MediaSourceItems.Add(EllipsisViewModel.Instance);
                            }
                            lastI = itt;
                        }
                    }
                    var tvm = new TrackViewModel {
                        Title = tt, Url = t.Item2
                    };
                    tvm.Margin = Layouts.GenerateLeftJustified(isLast()?
                                                               Layouts.StandardSeparationMarginThickness : Layouts.StandardTrackItemMarginThickness);
                    MediaSourceItems.Add(tvm);
                }
            }

            if (Model.SourcesRemarks?.Contains("<") == true)
            {
                var xsrvm = XamlSourceRemarksViewModel.TryParseBlock(Model.SourcesRemarks);
                if (xsrvm != null)
                {
                    xsrvm.Margin = Layouts.GenerateLeftJustified(Layouts.StandardSeparationMarginThickness);
                    MediaSourceItems.Add(xsrvm);
                }
            }
            else
            {
                var gsrvm = CommonSourceRemarksViewModel.TryParse(Model.SourcesRemarks);
                if (gsrvm != null)
                {
                    gsrvm.Margin = Layouts.GenerateLeftJustified(Layouts.StandardSeparationMarginThickness);
                    MediaSourceItems.Add(gsrvm);
                }
            }
        }