Esempio n. 1
0
        private async void ResetHyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            bool choice    = false;
            var  msgDialog = new Windows.UI.Popups.MessageDialog("确认重置启用站点及顺序?")
            {
                Title = "提示"
            };

            msgDialog.Commands.Add(new Windows.UI.Popups.UICommand("确定", uiCommand => { choice = true; }));
            msgDialog.Commands.Add(new Windows.UI.Popups.UICommand("取消", uiCommand => { choice = false; }));
            await msgDialog.ShowAsync();

            if (choice)
            {
                await BangumiData.ResetSitesEnabledOrder();

                EnabledSites.Clear();
                NotEnabledSites.Clear();
                BangumiData.GetEnabledSites()
                .Select(it => SiteMetaWithKey.FromSiteMeta(it)).ToList()
                .ForEach(it => EnabledSites.Add(it));
                BangumiData.GetDisabledSites()
                .Select(it => SiteMetaWithKey.FromSiteMeta(it)).ToList()
                .ForEach(it => NotEnabledSites.Add(it));
            }
        }
Esempio n. 2
0
 private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
 {
     BangumiData.GetEnabledSites()
     .Select(it => SiteMetaWithKey.FromSiteMeta(it)).ToList()
     .ForEach(it => EnabledSites.Add(it));
     BangumiData.GetDisabledSites()
     .Select(it => SiteMetaWithKey.FromSiteMeta(it)).ToList()
     .ForEach(it => NotEnabledSites.Add(it));
 }
Esempio n. 3
0
        private async void ListView_Drop(object sender, DragEventArgs e)
        {
            ListView target = (ListView)sender;

            if (e.DataView.Contains(StandardDataFormats.Text))
            {
                DragOperationDeferral def = e.GetDeferral();
                string s = await e.DataView.GetTextAsync();

                var site = Newtonsoft.Json.JsonConvert.DeserializeObject <SiteMetaWithKey>(s);

                // Find the insertion index:
                Windows.Foundation.Point pos = e.GetPosition(target.ItemsPanelRoot);

                // Find which ListView is the target, find height of first item
                ListViewItem sampleItem;
                if (target.Name == "EnabledSitesListView")
                {
                    sampleItem = (ListViewItem)NotEnabledSitesListView.ContainerFromIndex(0);
                }
                else
                {
                    sampleItem = (ListViewItem)EnabledSitesListView.ContainerFromIndex(0);
                }

                // Adjust ItemHeight for margins
                double itemHeight = sampleItem.ActualHeight + sampleItem.Margin.Top + sampleItem.Margin.Bottom;

                // Find index based on dividing number of items by height of each item
                int index = Math.Min(target.Items.Count - 1, (int)(pos.Y / itemHeight));

                // Find the item that we want to drop
                ListViewItem targetItem = (ListViewItem)target.ContainerFromIndex(index);

                // Figure out if to insert above or below
                Windows.Foundation.Point positionInItem = e.GetPosition(targetItem);
                if (positionInItem.Y > itemHeight / 2)
                {
                    index++;
                }

                // Don't go out of bounds
                index = Math.Min(target.Items.Count, index);

                // Find correct source list
                if (target.Name == "EnabledSitesListView")
                {
                    EnabledSites.Insert(index, site);
                    foreach (var item in NotEnabledSites)
                    {
                        if (item.Key == site.Key)
                        {
                            NotEnabledSites.Remove(item);
                            break;
                        }
                    }
                }
                else if (target.Name == "NotEnabledSitesListView")
                {
                    NotEnabledSites.Insert(index, site);
                    foreach (var item in EnabledSites)
                    {
                        if (item.Key == site.Key)
                        {
                            EnabledSites.Remove(item);
                            break;
                        }
                    }
                }

                e.AcceptedOperation = DataPackageOperation.Move;
                def.Complete();
            }
        }
Esempio n. 4
0
 private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     await BangumiData.SetSitesEnabledOrder(EnabledSites.Select(it => it.Key).ToArray());
 }