-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
736 lines (643 loc) · 23.2 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
//////////
///所有功能需要重构
///
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using AcFunVideo.Class;
using Windows.UI.ViewManagement;
using Windows.Storage.Streams;
using Windows.Data.Html;
using Windows.Data.Json;
using System.Threading.Tasks;
using AcFunVideo.Model;
using Windows.UI.Xaml.Media.Imaging;
using AcFunVideo.View;
using System.Text;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Microsoft.Graphics.Canvas.Effects;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.UI.Core;
//“空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 上有介绍
namespace AcFunVideo
{
/// <summary>
/// 可用于自身或导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class MainPage : Page
{
Rect DiveRect;
Dictionary<string, AXFContent> _dic;
MainPageFunc _MPF ;
List<AcContent> BananaData;
List<FDImgBox> _FDIMGS = new List<FDImgBox>();
ACChannelsData _ACChannelsData;
public static MainPage kCurrent;
public MainPage()
{
this.NavigationCacheMode = NavigationCacheMode.Required;
this.InitializeComponent();
PageSetting();
this.Loaded += MainPage_Loaded;
InitData();
kCurrent = this;
}
private async void Test()
{
//Encode("sdj", "zx26mfbsuebv72ja");
//Encode("44616713980388605ab4d_030020010057150762B6552D9B7D2F302AAB41-D431-EDEE-DF77-5A4E5E993D74_8466", "zx26mfbsuebv72ja");
var md5str = Utils.GetMD5String("GET:/common/partner/play:1462284491:78554907b127c3853f8e956243dc74c4");
var url = "http://acfun.api.mobile.youku.com/common/partner/play?_t_=1462284491&e=md5&_s_=" + md5str
+ "&point=1&id=CMzQwMTA3Mg==&format=1,5,6,7,8&language=guoyu&did=a721b02c70aa0c2784afa3a39b9356b6&ctype=87&audiolang=1&pid=528a34396e9040f3";
HttpEngine he = new HttpEngine();
var data = await he.Get(url);
var reader = new StreamReader(data.AsStreamForRead());
var str = reader.ReadToEnd();
var obj= Newtonsoft.Json.Linq.JObject.Parse(str);
var keystr = obj["data"].ToString();
var destr = Decode(keystr, Aeskey);
//http://k.youku.com/player/getFlvPath/sid/44616713980388605ab4d_00/st/mp4/fileid/030020010057150762B6552D9B7D2F302AAB41-D431-EDEE-DF77-5A4E5E993D74/?K=8aae87b234a1cb02282b5e1a&hd=1&myp=0&ts=1519.867&ypp=0&ep=C55ccxIEzL9JF0%2FF5gjcoEbkDHaOmE%2FI6YrmN90c%2FieiMqDvcFpZvjPJK9ojN%2BP0ZzFvykhvKduhPiCXpaaWGpUPQos0wjsPI%2BH6PVV%2FwXCORi1awYC9q1DYqq7W&ctype=86&ev=1&token=8466&oip=3550665720
}
const string Aeskey = "qwer3as2jin4fdsa";
private string Decode(string value ,string key)
{
var buffkey = CryptographicBuffer.ConvertStringToBinary(key, BinaryStringEncoding.Utf8);
IBuffer toDecryptBuffer = CryptographicBuffer.DecodeFromBase64String(value);
SymmetricKeyAlgorithmProvider aes =
SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
// Create a symmetric key.
var symetricKey = aes.CreateSymmetricKey(buffkey);
var buffDecrypted = CryptographicEngine.Decrypt(symetricKey, toDecryptBuffer, null);
string strDecrypted = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, buffDecrypted);
return strDecrypted;
}
private void Encode(string value,string key)
{
var bufKey = CryptographicBuffer.ConvertStringToBinary(key, BinaryStringEncoding.Utf8);
SymmetricKeyAlgorithmProvider aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
IBuffer enBuffer;
var data = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8);
enBuffer = data;
var symtricKey = aes.CreateSymmetricKey(bufKey);
IBuffer enoder = CryptographicEngine.Encrypt(symtricKey, enBuffer, null);
string strEncrypted = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, enoder);
}
private async void GetAllChannel()
{
_ACChannelsData = new ACChannelsData();
_ACChannelsData.GetLocalData();
}
private async void InitData()
{
HomeData hd = new HomeData();
_dic=await hd.GetData();
AddMainBanner();
AddSpecailImg();
AddToday();
AddBananaRank();
AddBangumi();
AddMainPageNormalView();
AddCategooryIcon();
AddNewBangumiPage();
GetAllChannel();
}
private async Task<int> AddNewBangumiPage()
{
var url = AcFunAPI.GetHomeBangumiUrl();
NewBangumiData nbd = new NewBangumiData();
await nbd.GetData(url);
NewBangumiGridView.ItemsSource = nbd.ListOfACContent;
return 0;
}
private void AddMainBanner()
{
try
{
if (_dic.Count<=0)
{
return;
}
MainPageFunc.BannerFunc( MainFlipView, _dic["轮播图"].Contents);
}
catch (Exception ex)
{
ACDEBUG.Print(ex.Message);
}
}
private async void AddSpecailImg()
{
try
{
if (_dic.Count <= 0)
{
return;
}
_dic["二次元日历"] = await GetSingleDicData("二次元日历");
CalendarImg.Source = new BitmapImage(new Uri(_dic["二次元日历"].Contents[0].Cover));
}
catch (Exception ex)
{
ACDEBUG.Print(ex.Message);
}
}
private async void AddToday()
{
try
{
if (_dic.Count <= 0)
{
return;
}
_dic["活动banner"] = await GetSingleDicData("活动banner");
TodyImg.Source = new BitmapImage(new Uri(_dic["活动banner"].Contents[0].Cover));
}
catch (Exception ex)
{
ACDEBUG.Print(ex.Message);
}
}
private async void AddBangumi()
{
if (_dic.Count<=0)
{
return;
}
BangumiData bd = new BangumiData();
_dic["番剧"].Contents =await bd.GetData(AcFunAPI.GetRegionUrlById(_dic["番剧"].Id));
BangumiRankView.ItemsSource = _dic["番剧"].Contents;
}
private async void AddBananaRank()
{
if (_dic.Count <= 0)
{
return;
}
_dic["香蕉排行榜"] = await GetSingleDicData("香蕉排行榜");
BananaRankData brd = new BananaRankData();
var brdurl = AcFunAPI.GetBananaRecommendUrl();
var listData =await brd.GetData(brdurl);
if (listData.Count>4)
{
BananaData = listData;
List<AcContent> temp = new List<AcContent>();
for (int i = 0; i < 4; i++)
{
var data = listData[i];
temp.Add(data);
}
BananaRankView.ItemsSource = temp;
}
else
{
BananaRankView.ItemsSource = listData;
}
}
private async void AddMainPageNormalView()
{
AddView(RecommentView, "猴山头条");
AddView(FunRankView, "娱乐");
AddView(GameView, "游戏");
AddView(CartoonRankView, "动画");
AddView(VideoView, "影视");
AddView(MusicView, "音乐");
AddView(DanceView, "舞蹈");
AddView(TechView, "科技");
AddView(SportView, "体育");
AddView(GirlView, "彼女");
AddView(BoyView, "鱼塘");
}
private async void AddCategooryIcon()
{
MainPageFunc.CategoryFunc(CategoryView);
}
private async void AddView( GridView gv,string key )
{
if (_dic.Count<=0)
{
return;
}
var ax = await GetSingleDicData(key);
if (ax!=null)
{
gv.ItemsSource = ax.Contents;
}
}
private async Task<AXFContent> GetSingleDicData(string key)
{
HomeData hd = new HomeData();
if (_dic.ContainsKey(key))
{
_dic[key] = await hd.GetSingleData((_dic[key].Id), key);
return _dic[key];
}
return null;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ApplicationView av = ApplicationView.GetForCurrentView();
av.SetPreferredMinSize(new Size(300, 800));
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
SetDiveRect();
}
void PageSetting()
{
this.Background = ACCOLOR.ACDEEPBLU;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
private void RootGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
SizeChange();
}
private void SizeChange()
{
// System.Diagnostics.Debug.WriteLine(MainGrid.Width);
MainFlipView.Height = MainFlipView.ActualWidth * 9 / 16;
foreach (var item in SectionStackPanel.Children)
{
Grid temp = item as Grid;
if (temp != null)
{
var Left = (MainFlipView.ActualWidth - temp.ActualWidth * 4) / 8;
temp.Margin = new Thickness(Left, 0, Left, 0);
}
}
if (isPartPivotLoad)
{
ReSizeTopBar();
}
}
private void TodyTextBlock_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton clickButton = sender as HyperlinkButton;
AcFunVideo.Model.AcContent ac = clickButton.Tag as AcFunVideo.Model.AcContent;
}
private void TodyImg_Tapped(object sender, TappedRoutedEventArgs e)
{
}
private void SetDiveRect()
{
DiveRect = Window.Current.Bounds;
}
private void NormalView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
NormalView nv = args.ItemContainer.ContentTemplateRoot as NormalView;
if (nv!=null)
{
if (DiveRect==null||DiveRect.Width<=0)
{
SetDiveRect();
}
nv.Width = DiveRect.Width / 2 - 20;
nv.Height = nv.Width - 10;
nv.Margin = new Thickness(10, 0, 5, 0);
nv.AddAllData(args.Item as AcContent);
bool has = false;
for (int i = 0; i < _FDIMGS.Count; i++)
{
if (_FDIMGS[i]==nv.img)
{
has = true;
}
}
if (!has)
{
_FDIMGS.Add(nv.img);
}
}
}
private void BangumiRankView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
CartoonView nv = args.ItemContainer.ContentTemplateRoot as CartoonView;
if (nv != null)
{
if (DiveRect == null || DiveRect.Width <= 0)
{
SetDiveRect();
}
nv.Width = DiveRect.Width / 3 - 25;
nv.Height = nv.Width * 6 / 3;
nv.Margin = new Thickness(10, 0, 5, 0);
nv.AddData(args.Item as AcContent);
}
}
private void MainPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
UnloadGIFView();
switch (MainPivot.SelectedIndex)
{
case 0:
break;
case 1:
break;
case 2:
if (isPartPivotLoad)
{
ReSizeTopBar();
}
break;
default:
break;
}
}
private void UnloadGIFView()
{
if (MainPivot.SelectedIndex != 0)
{
foreach (var item in _FDIMGS)
{
item.UNLOAD();
}
}
else
{
foreach (var item in _FDIMGS)
{
item.LOAD();
}
}
}
private void PvoitTitleMain_Tapped(object sender, TappedRoutedEventArgs e)
{
var clickObj = sender as TextBlock;
if (clickObj!=null)
{
switch (clickObj.Text)
{
case "首页":
MainPivot.SelectedIndex = 0;
break;
case "新番":
MainPivot.SelectedIndex = 1;
break;
default:
MainPivot.SelectedIndex = 2;
ReSizeTopBar();
break;
}
}
}
bool isPartPivotLoad = false;
private void ReSizeTopBar()
{
foreach (var item in PTopStackPanel.Children)
{
Grid sp = item as Grid;
sp.UpdateLayout();
if (sp != null)
{
var left = (PartPiovtItem.ActualWidth-20 - sp.ActualWidth * 4) / 9.5;
sp.Margin = new Thickness(left, 0, left, 0);
}
}
}
private void PTopStackPanel_Loaded(object sender, RoutedEventArgs e)
{
isPartPivotLoad = true;
ReSizeTopBar();
}
private void CategoryView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
CategoryIcon nv = args.ItemContainer.ContentTemplateRoot as CategoryIcon;
if (nv != null)
{
nv.AddData(args.Item as MainPageCategoryData);
if (4*80>(DiveRect.Width-32))
{
nv.Width = nv.Height = (DiveRect.Width- 32) / 4;
nv.RootGrid.Width = nv.RootGrid.Height = nv.Width - 2;
nv.IMG.Width = nv.IMG.Height = nv.IMG.Width - 5;
nv.RootGrid.Margin = new Thickness(0, 2, 0, -2);
nv.Title.FontSize = 13;
nv.Title.Margin = new Thickness(0, 0, 5, 0);
}
}
}
private void NewBangumiGridView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
CartoonView nv = args.ItemContainer.ContentTemplateRoot as CartoonView;
if (!CateisTV)
{
//var s = NewBangumiGridView.ItemTemplate;
if (nv != null)
{
if (DiveRect == null || DiveRect.Width <= 0)
{
SetDiveRect();
}
nv.Width = DiveRect.Width / 3 - 25;
nv.Height = nv.Width * 6 / 3;
nv.Margin = new Thickness(10, 0, 5, 0);
nv.AddData(args.Item as AcContent);
}
}
else
{
var nov = args.ItemContainer.ContentTemplateRoot as CartoonView;
if (nov != null)
{
if (DiveRect == null || DiveRect.Width <= 0)
{
SetDiveRect();
}
nov.Width = DiveRect.Width / 3 - 25;
nov.Height = nov.Width + 20;
nov.Margin = new Thickness(10, 0, 5, 0);
//nov.AddAllData(args.Item as AcContent);
nov.AddTVData(args.Item as AcContent);
}
}
}
private string CateTimeSelect = "N";
private bool CateisTV = false;
private string GetWeekTime()
{
switch (CateTimeSelect)
{
case "N":
return "0";
case "一":
return "1";
case "二":
return "2";
case "三":
return "3";
case "四":
return "4";
case "五":
return "5";
case "六":
return "6";
case "日":
return "7";
default:
break;
}
return "0";
}
private async void CategorySelec()
{
string url;
NewBangumiData nbd = new NewBangumiData();
if (CateisTV)
{
url = AcFunAPI.GetHomenominateUrl(GetWeekTime());
nbd.isTV = true;
}
else
{
url = AcFunAPI.GetHomeBangumiUrl(GetWeekTime());
}
await nbd.GetData(url);
NewBangumiGridView.ItemsSource = nbd.ListOfACContent;
}
private async void Category_Tapped(object sender, TappedRoutedEventArgs e)
{
var grid = sender as Grid;
string SelectText = "";
if (grid!=null)
{
foreach (Grid item in Category.Children)
{
if (item!=grid)
{
item.BorderThickness = new Thickness(0);
var temp = item.Children[0] as TextBlock;
temp.Foreground = ACCOLOR.colorWith(Colors.Black);
}
else
{
item.BorderThickness = new Thickness(1);
var temp = item.Children[0] as TextBlock;
temp.Foreground = ACCOLOR.ACDEEPBLU;
SelectText = temp.Text;
}
}
}
if (SelectText=="剧集")
{
CateisTV = true;
}
else
{
CateisTV = false;
var url = AcFunAPI.GetHomeBangumiUrl();
NewBangumiData nbd = new NewBangumiData();
await nbd.GetData(url);
NewBangumiGridView.ItemsSource = nbd.ListOfACContent;
}
CategorySelec();
}
private void CategoryPart_Tapped(object sender, TappedRoutedEventArgs e)
{
var grid = sender as Grid;
if (grid != null)
{
foreach (Grid item in CategoryPart.Children)
{
if (item != grid)
{
item.BorderThickness = new Thickness(0);
var temp = item.Children[0] as TextBlock;
temp.Foreground = ACCOLOR.colorWith(Colors.Black);
}
else
{
item.BorderThickness = new Thickness(1);
var temp = item.Children[0] as TextBlock;
temp.Foreground = ACCOLOR.ACDEEPBLU;
CateTimeSelect = temp.Text;
}
}
}
CategorySelec();
}
private void NavigationToDetailsPage(AcContent ac)
{
this.Frame.Navigate(typeof(DetailsPage),ac);
}
private void MainFlipView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void MainGridView_ItemClick(object sender, ItemClickEventArgs e)
{
AcContent ac = e.ClickedItem as AcContent;
if (ac!=null)
{
NavigationToDetailsPage(ac);
}
}
private void CategoryView_ItemClick(object sender, ItemClickEventArgs e)
{
var data = e.ClickedItem as MainPageCategoryData;
if (data.title=="下载")
{
this.Frame.Navigate(typeof(DownloadPage));
return;
}
if (data!=null&&_ACChannelsData!=null)
{
foreach (var key in _ACChannelsData.dicOfData.Keys)
{
if (key==data.title)
{
var cc = _ACChannelsData.dicOfData[key];
this.Frame.Navigate(typeof(CategoryPage),cc);
break;
}
}
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
SystemNavigationManager systemNavigationManager = SystemNavigationManager.GetForCurrentView();
systemNavigationManager.BackRequested -= SystemNavigationManager_BackRequested;
systemNavigationManager.BackRequested += SystemNavigationManager_BackRequested;
systemNavigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
}
DateTime preTimeToBack;
private void SystemNavigationManager_BackRequested(object sender, BackRequestedEventArgs e)
{
if (preTimeToBack==new DateTime())
{
preTimeToBack = DateTime.Now;
}
else if ((DateTime.Now-preTimeToBack).TotalMilliseconds<600)
{
preTimeToBack = DateTime.Now;
return;
}
if ( this.Frame.CanGoBack)
{
e.Handled = true;
this.Frame.GoBack();
}
preTimeToBack = DateTime.Now;
}
private void MainSearchButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(SearchPage));
}
private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
{
this.Frame.Navigate(typeof(AboutPage));
}
}
}