-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
839 lines (709 loc) · 28.5 KB
/
MainWindow.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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using System;
using System.Collections.Generic;
using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.Storage;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage.FileProperties;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Threading;
using System.ComponentModel;
using Microsoft.UI.Windowing;
using ImageRate.Assets;
using Windows.ApplicationModel.DataTransfer;
using Windows.UI.Core;
using Windows.System;
using Microsoft.UI;
using WinRT.Interop;
using AppUIBasics.ControlPages;
using Microsoft.UI.Xaml.Media;
using Windows.Storage.Search;
using System.Linq;
using System.IO;
using Windows.Media.Core;
using Windows.Media.Playback;
using Windows.Media;
using Windows.UI.ViewManagement;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace ImageRate
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
enum ViewMode
{
SingleImage,
List
}
ViewMode currentViewMode
{
get { return SegmentedControl.SelectedIndex == 0 ? ViewMode.List : ViewMode.SingleImage; }
set { SegmentedControl.SelectedIndex = value == ViewMode.List ? 0 : 1; }
}
List<ImageItem> listItems = new List<ImageItem>();
public ObservableCollection<ImageItem> listItemsFiltered { get; } =
new ObservableCollection<ImageItem>();
int currentIndex = -1;
int filter = 0;
DateTime lastItemClick = DateTime.MinValue;
ImageItem lastClickedItem = null;
FullscreenWindow fullscreenWindow;
public MediaPlayer mediaPlayer;
//public MediaTimelineController mediaTimelineController;
public MainWindow()
{
this.InitializeComponent();
this.AppWindow.SetIcon("Assets/ImageRate_Icon.ico");
string[] cmdargs = Environment.GetCommandLineArgs();
int len = cmdargs.Length;
if (len > 0 && (cmdargs[len-1].ToLower().EndsWith(".jpg") || cmdargs[len - 1].ToLower().EndsWith(".jpeg")))
{
LoadImagePath(cmdargs[len - 1]);
currentViewMode = ViewMode.SingleImage;
}
else
{
loadStorageFolder(KnownFolders.PicturesLibrary);
currentViewMode = ViewMode.List;
}
this.Closed += (s, a) => fullscreenWindow?.Close();
GetAppWindowForCurrentWindow().Closing += OnClosing;
mediaPlayer = new MediaPlayer();
VideoView.SetMediaPlayer(mediaPlayer);
//mediaTimelineController = new MediaTimelineController();
foreach (RadioMenuFlyoutItem item in SortSubmenu.Items)
{
if (item.Tag.ToString() == SettingsHelper.getStringOrDefault("sort", "System.FileName")) item.IsChecked = true;
}
}
private AppWindow GetAppWindowForCurrentWindow()
{
IntPtr hWnd = WindowNative.GetWindowHandle(this);
WindowId myWndId = Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(myWndId);
}
private void OnClosing(object sender, AppWindowClosingEventArgs e)
{
if (currentViewMode != ViewMode.List)
{
currentViewMode = ViewMode.List;
e.Cancel = true; // cancel close
}
}
private void MainWindow_KeyDown(object sender, KeyRoutedEventArgs args)
{
if (args.Key == VirtualKey.Left && currentViewMode == ViewMode.SingleImage)
{
loadPrevImg();
}
if (args.Key == VirtualKey.Right && currentViewMode == ViewMode.SingleImage)
{
loadNextImg();
}
if (args.Key == VirtualKey.Add || (int) args.Key == 187)
{
Rating.Value = Math.Min(Rating.Value + 1, 5);
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.Subtract || (int) args.Key == 189)
{
if (Rating.Value == 1) Rating.Value = -1;
else Rating.Value -= 1;
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.Number0 || args.Key == VirtualKey.NumberPad0)
{
Rating.Value = -1;
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.Number1 || args.Key == VirtualKey.NumberPad1)
{
Rating.Value = 1;
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.Number2 || args.Key == VirtualKey.NumberPad2)
{
Rating.Value = 2;
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.Number3 || args.Key == VirtualKey.NumberPad3)
{
Rating.Value = 3;
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.Number4 || args.Key == VirtualKey.NumberPad4)
{
Rating.Value = 4;
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.Number5 || args.Key == VirtualKey.NumberPad5)
{
Rating.Value = 5;
RatingControl_ValueChanged(Rating, null);
}
if (args.Key == VirtualKey.L)
{
currentViewMode = ViewMode.List;
}
if (args.Key == VirtualKey.P)
{
currentViewMode = ViewMode.SingleImage;
}
if (args.Key == VirtualKey.F11)
{
launchFullscreen();
}
if (args.Key == VirtualKey.Escape)
{
if (currentViewMode == ViewMode.SingleImage)
{
currentViewMode = ViewMode.List;
} else if (fullscreenWindow != null)
{
fullscreenWindow.Close();
}
}
if (args.Key == VirtualKey.Space)
{
if (fullscreenWindow != null)
{
fullscreenWindow.toggleAutoplay();
}
}
//Rating.Caption = args.Key.ToString();
}
private async void LoadImagePath(string path)
{
string folderPath = path.Substring(0, path.LastIndexOf('\\'));
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folderPath);
await loadStorageFolder(folder);
for (int i = 0; i < listItemsFiltered.Count; i++)
{
if (listItemsFiltered[i].Path == path)
{
currentIndex = i;
loadImg();
ImagesGridView.SelectedIndex = currentIndex;
ImagesGridView.ScrollIntoView(ImagesGridView.SelectedItem);
}
}
}
private async void PickFolderButton_Click(object sender, RoutedEventArgs e)
{
FolderPicker openPicker = new FolderPicker();
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, hWnd);
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add("*");
StorageFolder folder = await openPicker.PickSingleFolderAsync();
if (folder != null)
{
await loadStorageFolder(folder);
}
else
{
//dialog canceled;
}
}
private async Task loadStorageFolder(StorageFolder folder)
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
if (folder.Path == "")
{
BreadcrumbBar.ItemsSource = new[] { "Picture Library" };
} else
{
BreadcrumbBar.ItemsSource = folder.Path.Split('\\');
PickFolderButton.Style = (Style)Application.Current.Resources["DefaultButtonStyle"];
}
ImageView.Source = null;
ProgressIndicator.IsActive = true;
Text_NothingToShow.Visibility = Visibility.Collapsed;
listItems.Clear();
listItemsFiltered.Clear();
var dialog = showWaitDialog("Load files...");
IReadOnlyList<StorageFolder> folders = await folder.GetFoldersAsync();
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
dialog.Hide();
var tempList = new List<ImageItem>();
for (int i = 0; i < files.Count; i++)
{
if (files[i].ContentType.StartsWith("image/") || files[i].ContentType.StartsWith("video/"))
{
var item = new ImageItem(files[i]);
tempList.Add(item);
}
}
var anotherTempList = SettingsHelper.getStringOrDefault("sort", "System.FileName") switch
{
"System.FileName" => tempList.OrderBy(item => item.Name), // maybe not neccesary as images are already sorted by name?
"System.ItemDate" => tempList.OrderBy(item => item.DateTaken),
"System.Rating" => tempList.OrderByDescending(item => item.Rating),
_ => throw new ArgumentOutOfRangeException("unknown sorting key")
};
foreach (var f in folders)
{
var item = new ImageItem(f);
listItems.Add(item);
if (filter == 0)
{
listItemsFiltered.Add(item);
}
}
foreach(var item in anotherTempList)
{
item.Index = listItems.Count; // set correct index here!
listItems.Add(item);
if (filter == 0 || item.Rating >= filter)
{
listItemsFiltered.Add(item);
}
}
currentIndex = -1;
await loadNextImg();
if (currentIndex == -1)
{
ProgressIndicator.IsActive = false;
if (folders.Count == 0 || filter > 0 || currentViewMode == ViewMode.SingleImage) Text_NothingToShow.Visibility = Visibility.Visible;
}
}
private void launchFullscreen()
{
if (fullscreenWindow == null)
{
fullscreenWindow = new(this);
if (currentIndex >= 0)
{
fullscreenWindow.SetCurrentImagePath(listItemsFiltered[currentIndex]);
}
fullscreenWindow.AppWindow.Move(this.AppWindow.Position);
fullscreenWindow.AppWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
fullscreenWindow.Closed += (sender, args) => fullscreenWindow = null;
}
fullscreenWindow.Activate();
}
private void updateViewMode()
{
var visibleSingleImage = currentViewMode == ViewMode.SingleImage ? Visibility.Visible : Visibility.Collapsed;
var visibleList = currentViewMode == ViewMode.List ? Visibility.Visible : Visibility.Collapsed;
Button_Prev.Visibility = visibleSingleImage;
Button_Next.Visibility = visibleSingleImage;
ImageView.Visibility = visibleSingleImage;
VideoView.Visibility = visibleSingleImage;
ProgressIndicator.Visibility = visibleSingleImage;
Rating.Visibility = visibleSingleImage;
InfoNoMoreImages.Visibility = visibleSingleImage;
ImagesGridView.Visibility = visibleList;
var visibleVideoPlaybackStartButton = currentViewMode == ViewMode.SingleImage && currentIndex >= 0 && listItemsFiltered[currentIndex].File.ContentType.StartsWith("video/") ? Visibility.Visible : Visibility.Collapsed;
VideoPlaybackStartButton.Visibility = visibleVideoPlaybackStartButton;
VideoPlaybackStartButtonBackground.Visibility = visibleVideoPlaybackStartButton;
}
private void Image_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var fromGrid = sender is GridView;
foreach(var item in ContextMenu.Items)
{
if (item == ContextMenuItem_Refresh) item.Visibility = fromGrid ? Visibility.Visible : Visibility.Collapsed;
else if (item != SortSubmenu) item.Visibility = fromGrid ? Visibility.Collapsed : Visibility.Visible;
}
ContextMenu.ShowAt(sender as UIElement, e.GetPosition(sender as UIElement));
}
private void Flyout_Refresh(object sender, RoutedEventArgs e)
{
if (currentIndex >= 0) LoadImagePath(listItemsFiltered[currentIndex].Path);
}
private void Flyout_ShowInExplorer(object sender, RoutedEventArgs e) =>
ExternalActionsUtil.ShowInExplorer(listItemsFiltered[currentIndex].Path);
private void Flyout_OpenWith(object sender, RoutedEventArgs e) =>
ExternalActionsUtil.OpenWithDialog(listItemsFiltered[currentIndex].Path);
private void Flyout_SortingChanged(object sender, RoutedEventArgs e)
{
if (sender is MenuFlyoutItem selectedItem)
{
string sortOption = selectedItem.Tag.ToString();
SettingsHelper.set("sort", sortOption);
if (currentIndex >= 0) LoadImagePath(listItemsFiltered[currentIndex].Path);
}
}
private void Button_Left(object sender, RoutedEventArgs e)
{
loadPrevImg();
}
private void Button_Right(object sender, RoutedEventArgs e)
{
loadNextImg();
}
public async Task loadNextImg()
{
bool result = await Task.Run(() => searchNextImg());
if (result)
{
// close possible error message
RatingError.IsOpen = false;
loadImg();
}
InfoNoMoreImages.IsOpen = !result;
}
private bool searchNextImg()
{
int filter_cached = filter;
int index = currentIndex;
while (true)
{
index += 1;
if (index >= listItemsFiltered.Count)
{
return false;
}
else
{
if (filter_cached != filter) return false;
if (!listItemsFiltered[index].IsFolder)
{
currentIndex = index;
return true;
}
}
}
}
public async Task loadPrevImg()
{
bool result = await Task.Run(() => searchPrevImg());
if (result)
{
// close possible error message
RatingError.IsOpen = false;
loadImg();
}
InfoNoMoreImages.IsOpen = !result;
}
private bool searchPrevImg()
{
int filter_cached = filter;
int index = currentIndex;
while (true)
{
index -= 1;
if (index < 0)
{
return false;
}
else
{
if (filter_cached != filter) return false;
if (!listItemsFiltered[index].IsFolder)
{
currentIndex = index;
return true;
}
}
}
}
private void loadImg()
{
if (currentIndex < 0)
{
return;
}
if (fullscreenWindow != null)
{
fullscreenWindow.SetCurrentImagePath(listItemsFiltered[currentIndex]);
}
var itemPath = new Uri(listItemsFiltered[currentIndex].Path, UriKind.Absolute);
if (listItemsFiltered[currentIndex].File.ContentType.StartsWith("video/"))
{
VideoView.MediaPlayer.Source = MediaSource.CreateFromUri(itemPath);
VideoView.AreTransportControlsEnabled = true;
VideoView.MediaPlayer.PlaybackSession.Position = listItemsFiltered[currentIndex].StartTimestamp;
refreshPlaybackStartButtonStyle();
if (currentViewMode == ViewMode.SingleImage)
{
VideoPlaybackStartButton.Visibility = Visibility.Visible;
VideoPlaybackStartButtonBackground.Visibility = Visibility.Visible;
}
ImageView.Source = null;
} else
{
VideoView.MediaPlayer.Source = null;
VideoView.AreTransportControlsEnabled = false;
VideoPlaybackStartButton.Visibility = Visibility.Collapsed;
VideoPlaybackStartButtonBackground.Visibility = Visibility.Collapsed;
ImageView.Source = new BitmapImage(itemPath);
}
Title = $"ImageRate - {listItemsFiltered[currentIndex].Name}";
var rating = listItemsFiltered[currentIndex].Rating;
if (rating != 0)
{
Rating.Value = rating;
}
else
{
Rating.Value = -1;
}
}
private async void RatingControl_ValueChanged(RatingControl sender, object args)
{
if ((ImageView.Source == null && VideoView.MediaPlayer.Source == null) || currentIndex < 0)
{
Rating.Value = -1;
return;
}
var rating = Math.Max(0, (int)sender.Value);
var success = await listItemsFiltered[currentIndex].updateRating(rating);
if (!success)
{
RatingError.Title = "Failed to store rating";
RatingError.IsOpen = true;
// reseting rating to last stored rating
Rating.Value = listItemsFiltered[currentIndex].Rating;
}
}
private void SegmentedControl_ViewModeChanged(object sender, SelectionChangedEventArgs e)
{
if (currentViewMode == ViewMode.List)
{
if (currentIndex >= 0)
{
ImagesGridView.SelectedIndex = currentIndex;
ImagesGridView.ScrollIntoView(ImagesGridView.SelectedItem);
}
}
if (currentIndex == -1 && listItemsFiltered.Count > 0)
{
Text_NothingToShow.Visibility = currentViewMode == ViewMode.List ? Visibility.Collapsed : Visibility.Visible;
}
updateViewMode();
}
private async void FilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string filterString = e.AddedItems[0].ToString();
switch (filterString)
{
case "No Filter":
filter = 0;
break;
case "≥ 1 star":
filter = 1;
break;
case "≥ 2 stars":
filter = 2;
break;
case "≥ 3 stars":
filter = 3;
break;
case "≥ 4 stars":
filter = 4;
break;
case "= 5 stars":
filter = 5;
break;
default:
throw new Exception($"Invalid argument: {filterString}");
}
Text_NothingToShow.Visibility = Visibility.Collapsed;
ProgressIndicator.IsActive = true;
ImageView.Source = null;
var searchIndex = -1;
if (currentIndex >= 0)
{
searchIndex = listItemsFiltered[currentIndex].Index;
}
var dialog = showWaitDialog("Updating filter...");
await Task.Run(() =>
{
foreach (var item in listItems)
{
var _ = item.Rating; // pre-fetch rating so UI thread operation is faster
}
});
dialog.Hide();
listItemsFiltered.Clear();
foreach (var item in listItems)
{
if (filter == 0 || item.Rating >= filter)
{
listItemsFiltered.Add(item);
}
}
currentIndex = -1;
for (int i = listItemsFiltered.Count - 1; i >= 0; i--)
{
if (!listItemsFiltered[i].IsFolder && (currentIndex == -1 || listItemsFiltered[i].Index >= searchIndex))
{
currentIndex = i;
}
}
if (filter > 0 && (currentIndex < 0 || filter > listItemsFiltered[currentIndex].Rating))
{
ImageView.Source = null;
Rating.Value = -1;
ProgressIndicator.IsActive = false;
Text_NothingToShow.Visibility = Visibility.Visible;
} else
{
loadImg();
}
}
private ContentDialog showWaitDialog(string text)
{
ContentDialog dialog = new ContentDialog();
dialog.XamlRoot = Content.XamlRoot;
dialog.Title = text;
dialog.Content = new LoadDialogContent();
if (dialog.XamlRoot != null) dialog.ShowAsync(); // do not wait
return dialog;
}
private void FilterComboBox_Loaded(object sender, RoutedEventArgs e)
{
FilterComboBox.SelectedIndex = 0;
}
private void ImageGridView_ContainerContentChanging(object sender, ContainerContentChangingEventArgs args)
{
if (args.InRecycleQueue)
{
var templateRoot = args.ItemContainer.ContentTemplateRoot as RelativePanel;
var image = templateRoot.FindName("ItemImage") as Image;
image.Source = null;
}
if (args.Phase == 0)
{
args.RegisterUpdateCallback(ShowImageThumbnail);
args.Handled = true;
}
}
private async void ShowImageThumbnail(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (args.Phase == 1)
{
var templateRoot = args.ItemContainer.ContentTemplateRoot as RelativePanel;
var image = templateRoot.FindName("ItemImage") as Image;
var source = templateRoot.FindName("SourceStorage") as TextBlock;
var item = args.Item as ImageItem;
source.Text = item.Path;
var thumbnail = await item.GetImageThumbnailAsync();
if (item.Path == source.Text) // workaround to check if view already got recycled
{
image.Source = thumbnail;
}
}
}
private void ImagesGridView_ItemClick(object sender, ItemClickEventArgs e)
{
var item = e.ClickedItem as ImageItem;
var shouldSwitch = lastClickedItem == item && (DateTime.Now - lastItemClick).TotalMilliseconds < 750;
lastClickedItem = item;
/*if (!item.IsFolder)
{
currentIndex = listItemsFiltered.IndexOf(item);
loadImg();
}*/ // moved to SelectionChanged callback
if (shouldSwitch)
{
if (item.IsFolder) loadStorageFolder(item.Folder);
else currentViewMode = ViewMode.SingleImage;
}
else lastItemClick = DateTime.Now;
}
private void FullscreenButton_Click(object sender, RoutedEventArgs e)
{
launchFullscreen();
}
private void Grid_DragOver(object sender, DragEventArgs e)
{
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
e.AcceptedOperation = DataPackageOperation.Link;
} else
{
e.AcceptedOperation = DataPackageOperation.None;
}
}
private async void Grid_Drop(object sender, DragEventArgs e)
{
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
var items = await e.DataView.GetStorageItemsAsync();
if (items.Count > 0)
{
var storageFile = items[0];
if (storageFile.IsOfType(StorageItemTypes.Folder)) {
loadStorageFolder(storageFile as StorageFolder);
} else
{
LoadImagePath(storageFile.Path);
}
}
}
}
private void ImageView_DragStarting(UIElement sender, DragStartingEventArgs args)
{
args.Data.SetStorageItems(new[] { listItemsFiltered[currentIndex].File });
args.Data.RequestedOperation = DataPackageOperation.Copy;
args.DragUI.SetContentFromDataPackage();
}
private void ImagesGridView_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
var storageItems = new IStorageItem[e.Items.Count];
for (int i = 0; i < e.Items.Count; i++)
{
var item = (e.Items[i] as ImageItem);
storageItems[i] = item.IsFolder ? item.Folder : item.File;
}
e.Data.SetStorageItems(storageItems);
e.Data.RequestedOperation = DataPackageOperation.Copy;
}
private async void BreadcrumbBar_ItemClicked(BreadcrumbBar sender, BreadcrumbBarItemClickedEventArgs args)
{
var items = BreadcrumbBar.ItemsSource as String[];
var folderPath = String.Join("\\", items, 0, args.Index + 1);
await loadStorageFolder(await StorageFolder.GetFolderFromPathAsync(folderPath));
}
private void ImagesGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = ImagesGridView.SelectedItem as ImageItem;
if (item == null) return;
if (!item.IsFolder)
{
var oldIndex = currentIndex;
currentIndex = listItemsFiltered.IndexOf(item);
if (oldIndex != currentIndex) loadImg();
}
}
private void refreshPlaybackStartButtonStyle()
{
VideoPlaybackStartButton.Style = listItemsFiltered[currentIndex].StartTimestamp == TimeSpan.Zero ? (Style)Application.Current.Resources["DefaultButtonStyle"] : (Style)Application.Current.Resources["AccentButtonStyle"];
}
private async void VideoPlaybackStartSelector_Opening(object sender, object e)
{
if (listItemsFiltered[currentIndex].StartTimestamp == TimeSpan.Zero)
{
VideoPlaybackStartSelector.Hide();
await listItemsFiltered[currentIndex].updateStartTimestamp(VideoView.MediaPlayer.PlaybackSession.Position);
refreshPlaybackStartButtonStyle();
}
}
private void VideoPlaybackStartSelector_Jump_Click(object sender, RoutedEventArgs e)
{
VideoView.MediaPlayer.Pause();
VideoView.MediaPlayer.PlaybackSession.Position = listItemsFiltered[currentIndex].StartTimestamp;
}
private async void VideoPlaybackStartSelector_Delete_Click(object sender, RoutedEventArgs e)
{
await listItemsFiltered[currentIndex].updateStartTimestamp(TimeSpan.Zero);
refreshPlaybackStartButtonStyle();
}
private async void VideoPlaybackStartSelector_Set_Click(object sender, RoutedEventArgs e)
{
await listItemsFiltered[currentIndex].updateStartTimestamp(VideoView.MediaPlayer.PlaybackSession.Position);
}
}
}