Skip to content

Commit 1d6f180

Browse files
authored
Merge pull request #59 from duke7553/less-static-everywhere
Greatly Improve Code Architecture
2 parents d75798d + 7918673 commit 1d6f180

20 files changed

+877
-472
lines changed

Files UWP/AddItem.xaml.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
3434
{
3535

3636
GenericFileBrowser.AddItemBox.Hide();
37-
var currentPath = ItemViewModel.PUIP.Path;
37+
var currentPath = App.ViewModel.Universal.path;
3838
StorageFolder folderToCreateItem = await StorageFolder.GetFolderFromPathAsync(currentPath);
3939
if ((e.ClickedItem as AddListItem).Header == "Folder")
4040
{
@@ -43,7 +43,7 @@ private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
4343
if (userInput != null)
4444
{
4545
await folderToCreateItem.CreateFolderAsync(userInput, CreationCollisionOption.FailIfExists);
46-
ItemViewModel.FilesAndFolders.Add(new ListedItem(){ FileName = userInput, FileDate = "Now", EmptyImgVis = Visibility.Collapsed, FolderImg = Visibility.Visible, FileIconVis = Visibility.Collapsed, FileExtension = "Folder", FileImg = null, FilePath = (ItemViewModel.PUIP.Path + "\\" + userInput) });
46+
App.ViewModel.FilesAndFolders.Add(new ListedItem(){ FileName = userInput, FileDate = "Now", EmptyImgVis = Visibility.Collapsed, FolderImg = Visibility.Visible, FileIconVis = Visibility.Collapsed, FileExtension = "Folder", FileImg = null, FilePath = (App.ViewModel.Universal.path + "\\" + userInput) });
4747
}
4848
}
4949
else if ((e.ClickedItem as AddListItem).Header == "Text Document")
@@ -53,7 +53,7 @@ private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
5353
if (userInput != null)
5454
{
5555
await folderToCreateItem.CreateFileAsync(userInput + ".txt", CreationCollisionOption.FailIfExists);
56-
ItemViewModel.FilesAndFolders.Add(new ListedItem() { FileName = userInput, FileDate = "Now", EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileExtension = "Text Document", FileImg = null, FilePath = (ItemViewModel.PUIP.Path + "\\" + userInput + ".txt"), DotFileExtension = ".txt" });
56+
App.ViewModel.FilesAndFolders.Add(new ListedItem() { FileName = userInput, FileDate = "Now", EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileExtension = "Text Document", FileImg = null, FilePath = (App.ViewModel.Universal.path + "\\" + userInput + ".txt"), DotFileExtension = ".txt" });
5757
}
5858
}
5959
else if ((e.ClickedItem as AddListItem).Header == "Bitmap Image")
@@ -63,7 +63,7 @@ private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
6363
if (userInput != null)
6464
{
6565
await folderToCreateItem.CreateFileAsync(userInput + ".bmp", CreationCollisionOption.FailIfExists);
66-
ItemViewModel.FilesAndFolders.Add(new ListedItem() { FileName = userInput, FileDate = "Now", EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileExtension = "BMP File", FileImg = null, FilePath = (ItemViewModel.PUIP.Path + "\\" + userInput + ".bmp"), DotFileExtension = ".bmp" });
66+
App.ViewModel.FilesAndFolders.Add(new ListedItem() { FileName = userInput, FileDate = "Now", EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileExtension = "BMP File", FileImg = null, FilePath = (App.ViewModel.Universal.path + "\\" + userInput + ".bmp"), DotFileExtension = ".bmp" });
6767

6868
}
6969
}

Files UWP/App.xaml.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System;
1+
using Files.Navigation;
2+
using System;
23
using System.Diagnostics;
4+
using System.Threading;
35
using Windows.ApplicationModel;
46
using Windows.ApplicationModel.Activation;
57
using Windows.UI;
@@ -54,6 +56,8 @@ public App()
5456
this.RequestedTheme = SettingsPages.Personalization.TV.ThemeValue;
5557
Debug.WriteLine("!!Requested Theme!!" + RequestedTheme.ToString());
5658
}
59+
public static Filesystem.ItemViewModel ViewModel = new Filesystem.ItemViewModel();
60+
public static DisplayedPathText PathText { get; set; } = new DisplayedPathText();
5761

5862
/// <summary>
5963
/// Invoked when the application is launched normally by the end user. Other entry points

Files UWP/ClassicMode.xaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
x:Class="Files.ClassicMode"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Files"
56
xmlns:local1="using:Files.Filesystem"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -53,7 +54,7 @@
5354
<SplitView DisplayMode="Inline" IsPaneOpen="True" HorizontalAlignment="Stretch" Margin="0,0,0,0" Grid.RowSpan="1" Grid.Row="1" VerticalAlignment="Stretch">
5455
<SplitView.Pane>
5556
<Grid Background="{StaticResource SystemControlAcrylicWindowMediumHighBrush}">
56-
<UILib:TreeView ScrollViewer.HorizontalScrollMode="Enabled" Expanding="DirectoryView_Expanding" UILib:ItemsSource="{x:Bind local1:ItemViewModel.ClassicFolderList}" Name="DirectoryView">
57+
<UILib:TreeView ScrollViewer.HorizontalScrollMode="Enabled" Expanding="DirectoryView_Expanding" UILib:ItemsSource="{x:Bind local:App.ViewModel.ClassicFolderList}" Name="DirectoryView">
5758
<UILib:TreeView.ItemTemplate>
5859
<DataTemplate>
5960
<UILib:TreeViewItem ItemsSource="{Binding Children}" HasUnrealizedChildren="True">

Files UWP/ClassicMode.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ClassicMode()
2222
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
2323
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
2424
ClassicView = ClassicModePage;
25-
ItemViewModel viewModel = new ItemViewModel(@"C:\", ClassicView);
25+
App.ViewModel.MemoryFriendlyGetItemsAsync(@"C:\", ClassicView);
2626
}
2727

2828

Files UWP/Filesystem/ItemViewModel.cs

+62-137
Original file line numberDiff line numberDiff line change
@@ -22,143 +22,76 @@ namespace Files.Filesystem
2222
{
2323
public class ItemViewModel
2424
{
25-
public static ObservableCollection<Classic_ListedFolderItem> classicFolderList = new ObservableCollection<Classic_ListedFolderItem>();
26-
public static ObservableCollection<Classic_ListedFolderItem> ClassicFolderList { get { return classicFolderList; } }
27-
28-
public static ObservableCollection<ListedItem> classicFileList = new ObservableCollection<ListedItem>();
29-
public static ObservableCollection<ListedItem> ClassicFileList { get { return classicFileList; } }
30-
31-
public static ObservableCollection<ListedItem> filesAndFolders = new ObservableCollection<ListedItem>();
32-
public static ObservableCollection<ListedItem> FilesAndFolders { get { return filesAndFolders; } }
33-
34-
StorageFolder folder;
35-
static string gotName;
36-
static string gotDate;
37-
static string gotType;
38-
static string gotPath;
39-
static string gotFolName;
40-
static string gotFolDate;
41-
static string gotFolPath;
42-
static string gotDotFileExtension;
43-
static string gotFolType;
44-
static Visibility gotFileImgVis;
45-
static Visibility gotEmptyImgVis;
46-
static Visibility gotFolImg;
47-
static StorageItemThumbnail gotFileImg;
48-
public static ObservableCollection<Classic_ListedFolderItem> ChildrenList;
49-
public static IReadOnlyList<StorageFolder> folderList;
50-
public static IReadOnlyList<StorageFile> fileList;
51-
public static bool isPhotoAlbumMode;
52-
public static string pageName;
53-
54-
public static ItemViewModel vm;
55-
public static ItemViewModel ViewModel { get { return vm; } set { } }
56-
57-
public static BackState bs = new BackState();
58-
public static BackState BS
59-
{
60-
get
61-
{
62-
return bs;
63-
}
64-
}
65-
66-
public static ForwardState fs = new ForwardState();
67-
public static ForwardState FS
25+
public ObservableCollection<Classic_ListedFolderItem> ClassicFolderList { get; set; } = new ObservableCollection<Classic_ListedFolderItem>();
26+
public ObservableCollection<ListedItem> ClassicFileList { get; set; } = new ObservableCollection<ListedItem>();
27+
public ObservableCollection<ListedItem> FilesAndFolders { get; set; } = new ObservableCollection<ListedItem>();
28+
public ObservableCollection<Classic_ListedFolderItem> ChildrenList;
29+
public ListedItem LI { get; } = new ListedItem();
30+
public UniversalPath Universal { get; } = new UniversalPath();
31+
public EmptyFolderTextState TextState { get; set; } = new EmptyFolderTextState();
32+
public BackState BS { get; set; } = new BackState();
33+
public ForwardState FS { get; set; } = new ForwardState();
34+
public ProgressUIVisibility PVIS { get; set; } = new ProgressUIVisibility();
35+
private StorageFolder folder;
36+
private string gotName;
37+
private string gotDate;
38+
private string gotType;
39+
private string gotPath;
40+
private string gotFolName;
41+
private string gotFolDate;
42+
private string gotFolPath;
43+
private string gotDotFileExtension;
44+
private string gotFolType;
45+
private Visibility gotFileImgVis;
46+
private Visibility gotEmptyImgVis;
47+
private Visibility gotFolImg;
48+
private StorageItemThumbnail gotFileImg;
49+
private bool isPhotoAlbumMode;
50+
public string pageName;
51+
private StorageFileQueryResult fileQueryResult;
52+
private StorageFolderQueryResult folderQueryResult;
53+
public CancellationTokenSource tokenSource;
54+
55+
56+
public ItemViewModel()
6857
{
69-
get
70-
{
71-
return fs;
72-
}
58+
7359
}
7460

75-
public static ProgressUIVisibility pvis = new ProgressUIVisibility();
76-
public static ProgressUIVisibility PVIS
61+
private async void DisplayConsentDialog()
7762
{
78-
get
79-
{
80-
return pvis;
81-
}
63+
await MainPage.permissionBox.ShowAsync();
8264
}
83-
84-
private ListedItem li = new ListedItem();
85-
public ListedItem LI { get { return this.li; } }
86-
87-
private static ProgressUIHeader pUIh = new ProgressUIHeader();
88-
public static ProgressUIHeader PUIH { get { return ItemViewModel.pUIh; } }
89-
90-
private static ProgressUIPath pUIp = new ProgressUIPath();
91-
public static ProgressUIPath PUIP { get { return ItemViewModel.pUIp; } }
92-
93-
private static EmptyFolderTextState textState = new EmptyFolderTextState();
94-
public static EmptyFolderTextState TextState { get { return textState; } }
95-
96-
public static int NumOfItems;
97-
public static int NumItemsRead;
98-
public static int NumOfFiles;
99-
public static int NumOfFolders;
100-
StorageFileQueryResult fileQueryResult;
101-
StorageFolderQueryResult folderQueryResult;
102-
public static CancellationToken token;
103-
public static CancellationTokenSource tokenSource;
104-
105-
public ItemViewModel(string viewPath, Page p)
65+
public async void MemoryFriendlyGetItemsAsync(string path, Page passedPage)
10666
{
107-
108-
pageName = p.Name;
67+
TextState.isVisible = Visibility.Collapsed;
68+
tokenSource = new CancellationTokenSource();
69+
CancellationToken token = App.ViewModel.tokenSource.Token;
70+
pageName = passedPage.Name;
71+
Universal.path = path;
10972
// Personalize retrieved items for view they are displayed in
110-
if (p.Name == "GenericItemView" || p.Name == "ClassicModePage")
73+
switch (pageName)
11174
{
112-
isPhotoAlbumMode = false;
113-
}
114-
else if (p.Name == "PhotoAlbumViewer")
115-
{
116-
isPhotoAlbumMode = true;
75+
case "GenericItemView":
76+
isPhotoAlbumMode = false;
77+
break;
78+
case "PhotoAlbumViewer":
79+
isPhotoAlbumMode = true;
80+
break;
81+
case "ClassicModePage":
82+
isPhotoAlbumMode = false;
83+
break;
11784
}
11885

11986
if (pageName != "ClassicModePage")
12087
{
121-
GenericFileBrowser.P.path = viewPath;
12288
FilesAndFolders.Clear();
12389
}
12490

125-
tokenSource = new CancellationTokenSource();
126-
token = tokenSource.Token;
127-
MemoryFriendlyGetItemsAsync(viewPath, token);
128-
129-
if (pageName != "ClassicModePage")
130-
{
131-
History.AddToHistory(viewPath);
132-
133-
if (History.HistoryList.Count == 1)
134-
{
135-
BS.isEnabled = false;
136-
//Debug.WriteLine("Disabled Property");
137-
138-
139-
}
140-
else if (History.HistoryList.Count > 1)
141-
{
142-
BS.isEnabled = true;
143-
//Debug.WriteLine("Enabled Property");
144-
}
145-
}
146-
147-
148-
}
149-
150-
private async void DisplayConsentDialog()
151-
{
152-
await MainPage.permissionBox.ShowAsync();
153-
}
154-
string sort = "By_Name";
155-
SortEntry entry;
156-
public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken token)
157-
{
15891
Stopwatch stopwatch = new Stopwatch();
15992
stopwatch.Start();
16093

161-
PUIP.Path = path;
94+
Universal.path = path; // Set visible path to reflect new navigation
16295
try
16396
{
16497

@@ -170,16 +103,16 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
170103
FolderDepth = FolderDepth.Shallow,
171104
IndexerOption = IndexerOption.UseIndexerWhenAvailable
172105
};
173-
106+
string sort = "By_Name";
174107
if (sort == "By_Name")
175108
{
176-
entry = new SortEntry()
109+
SortEntry entry = new SortEntry()
177110
{
178111
AscendingOrder = true,
179112
PropertyName = "System.FileName"
180113
};
114+
options.SortOrder.Add(entry);
181115
}
182-
options.SortOrder.Add(entry);
183116

184117
uint index = 0;
185118
const uint step = 250;
@@ -309,7 +242,7 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
309242
}
310243
else
311244
{
312-
FilesAndFolders.Add(new ListedItem() { EmptyImgVis = gotEmptyImgVis, FileImg = icon, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotName, FileDate = gotDate, FileExtension = gotType, FilePath = gotPath });
245+
FilesAndFolders.Add(new ListedItem() { DotFileExtension = gotDotFileExtension, EmptyImgVis = gotEmptyImgVis, FileImg = icon, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotName, FileDate = gotDate, FileExtension = gotType, FilePath = gotPath });
313246
}
314247
}
315248
catch
@@ -360,27 +293,19 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
360293
rootFrame.Navigate(typeof(MainPage), new SuppressNavigationTransitionInfo());
361294
}
362295

363-
}
364-
365-
public static ProgressPercentage progressPER = new ProgressPercentage();
296+
History.AddToHistory(Universal.path);
366297

367-
public static ProgressPercentage PROGRESSPER
368-
{
369-
get
298+
if (History.HistoryList.Count == 1)
370299
{
371-
return progressPER;
300+
BS.isEnabled = false;
372301
}
373-
set
302+
else if (History.HistoryList.Count > 1)
374303
{
375-
304+
BS.isEnabled = true;
376305
}
306+
tokenSource = null;
377307
}
378308

379-
public static int UpdateProgUI(int level)
380-
{
381-
PROGRESSPER.prog = level;
382-
return (int)level;
383-
}
384309

385310
public static async void FillTreeNode(object item, TreeView EntireControl)
386311
{

0 commit comments

Comments
 (0)