-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlbumPage.xaml.cs
141 lines (117 loc) · 4.56 KB
/
AlbumPage.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.Storage.Search;
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.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace PhotoLibraryApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class AlbumPage : Page
{
public AlbumPage()
{
this.InitializeComponent();
}
private async Task LoadPicturesFromAlbums()
{
//Ordering album files by date
// initialize queryOptions using a common query
QueryOptions queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new string[] { ".txt" });
// clear all existing sorts
queryOptions.SortOrder.Clear();
// add ascending sort by date modified
SortEntry se = new SortEntry();
se.PropertyName = "System.DateModified";
se.AscendingOrder = true;
queryOptions.SortOrder.Add(se);
//Open folder containing album files
var storageFolder = ApplicationData.Current.LocalFolder;
//Use query to sort album data text files by date
StorageFileQueryResult queryResult = storageFolder.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> textFiles = await queryResult.GetFilesAsync();
foreach (var textFile in textFiles)
{
if (textFile.Name != "Library.txt")
{
await dynamicControlAsync(textFile.Name);
}
}
}
private async Task dynamicControlAsync(string textFileName)
{
//Add flipview dynamically
// Create a new flip view, add content
FlipView flipView1 = new FlipView
{
Width = 200,
Height = 200,
BorderThickness = new Thickness(4)
};
//Capture the album name
TextBlock textBlock1 = new TextBlock();
string[] split = textFileName.Split('.');
textBlock1.Text = split[0];
StackPanel stackPanel = new StackPanel();
// Data source
//Get photos from Albums
string content = await FileHelper.ReadTextFileAsync(textFileName);
if (!string.IsNullOrWhiteSpace(content))
{
var fileList = content.Split('\n', '\r');
foreach (string filePath in fileList)
{
if (string.IsNullOrEmpty(filePath))
{
continue;
}
var storageFile = await StorageFile.GetFileFromPathAsync(filePath);
var bitmapImage = new BitmapImage();
Image image = new Image();
using (StorageItemThumbnail thumb = await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem))
{
bitmapImage.SetSource(thumb);
}
image.Source = bitmapImage;
flipView1.Items.Add(image);
}
}
// Add the flip view to a parent container in the visual tree.
stackPanel.Children.Add(textBlock1);
stackPanel.Children.Add(flipView1);
stack1.Children.Add(stackPanel);
}
private void Add_Album_Button_ClickAsync(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(CreateAlbum));
}
private void Collection_Button_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(MainPage));
}
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
await LoadPicturesFromAlbums();
}
private void CancelSelectionBtn_Click_1(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(MainPage));
}
}
}