diff --git a/FileManager.Helpers/Constants.cs b/FileManager.Helpers/Constants.cs index f645e4e..ab2a559 100644 --- a/FileManager.Helpers/Constants.cs +++ b/FileManager.Helpers/Constants.cs @@ -3,7 +3,7 @@ public static class Constants { public const string Resources = "FileManager.Resources"; - public const string StringResources = "Resources"; + public const string StringResources = "FileManager.Resources/Resources"; public const string Image = "image"; public const string Video = "video"; public const string Audio = "audio"; @@ -31,7 +31,6 @@ public static class Constants public const string ConnectionError = "connectionError"; public const string ResponseError = "responseError"; public const string ConnectionErrorContent = "connectionErrorContent"; - public const string Failed = "failed"; public const string AccessToken = "access_token"; public const string ExpiresIn = "expires_in"; public const string UrlencodedContentType = "application/x-www-form-urlencoded"; @@ -67,7 +66,7 @@ public static class Constants public const string FreeSpaceKey = "System.FreeSpace"; public const string RamIcon = "ramIcon"; public const string DiskStorageIcon = "diskStorage"; - public const string Success = "Success"; + public const string Failed = "failed"; public const string RefreshToken = "refresh_token"; public const string TokenType = "token_type"; public const string Scope = "scope"; @@ -78,5 +77,9 @@ public static class Constants public const string InformationPage = "InformationPage"; public const string GoogleDrivePage = "GoogleDrivePage"; public const string FtpPage = "FtpPage"; + public const string OneDrivePage = "OneDrivePage"; + public const string FileControl = "FileControl"; + public const string OnlineFileControl = "OnlineFileControl"; + public const string InformationControl = "InformationControl"; } } diff --git a/FileManager.Helpers/ControlExtensions.cs b/FileManager.Helpers/ControlExtensions.cs new file mode 100644 index 0000000..040d007 --- /dev/null +++ b/FileManager.Helpers/ControlExtensions.cs @@ -0,0 +1,80 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media.Animation; + +namespace FileManager.Helpers +{ + public static class ControlExtensions + { + public static async Task GoToVisualStateAsync(this Control control, FrameworkElement visualStatesHost, string stateGroupName, string stateName) + { + if (control != null) + { + var taskCompletionSource = new TaskCompletionSource(); + + var storyboard = GetStoryboardForVisualState(visualStatesHost, stateGroupName, stateName); + if (storyboard != null) + { + EventHandler handler = null; + handler = (s, e) => + { + storyboard.Completed -= handler; + taskCompletionSource.SetResult(storyboard); + }; + + storyboard.Completed += handler; + } + + VisualStateManager.GoToState(control, stateName, true); + + if (storyboard != null) + { + await taskCompletionSource.Task; + } + } + } + + private static Storyboard GetStoryboardForVisualState(FrameworkElement visualStatesHost, string stateGroupName, string stateName) + { + Storyboard storyboard = null; + + if (visualStatesHost != null) + { + VisualStateGroup stateGroup = null; + var stateGroups = VisualStateManager.GetVisualStateGroups(visualStatesHost); + if (!string.IsNullOrEmpty(stateGroupName)) + { + stateGroup = stateGroups.FirstOrDefault(visualStateGroup => visualStateGroup.Name == stateGroupName); + } + + VisualState state = null; + if (stateGroup != null) + { + state = stateGroup.States.FirstOrDefault(visualState => visualState.Name == stateName); + } + + if (state == null) + { + foreach (var group in stateGroups) + { + state = group.States.FirstOrDefault(visualState => visualState.Name == stateName); + if (state != null) + { + break; + } + } + } + + if (state != null) + { + storyboard = state.Storyboard; + } + } + + return storyboard; + } + } +} \ No newline at end of file diff --git a/FileManager.Helpers/Enums.cs b/FileManager.Helpers/Enums.cs new file mode 100644 index 0000000..f34f398 --- /dev/null +++ b/FileManager.Helpers/Enums.cs @@ -0,0 +1,13 @@ +namespace FileManager.Helpers +{ + public enum Enums + { + Failed, + Success, + FullBattery = 100, + BitDischargedBattery = 76, + HalfBattery = 51, + ThirdBattery = 31, + LowBattery = 21, + } +} diff --git a/FileManager.Helpers/FileManager.Helpers.csproj b/FileManager.Helpers/FileManager.Helpers.csproj index 5222182..d8809d9 100644 --- a/FileManager.Helpers/FileManager.Helpers.csproj +++ b/FileManager.Helpers/FileManager.Helpers.csproj @@ -122,7 +122,9 @@ + + diff --git a/FileManager.Models/ColorMode.cs b/FileManager.Models/ColorMode.cs new file mode 100644 index 0000000..fa6db4f --- /dev/null +++ b/FileManager.Models/ColorMode.cs @@ -0,0 +1,11 @@ +using Windows.ApplicationModel.Resources; +using Windows.UI; + +namespace FileManager.Models +{ + public class ColorMode + { + public Color BackgroundColor { get; set; } + public ResourceLoader ThemeResourceLoader { get; set; } + } +} diff --git a/FileManager.Models/Dialogs/DialogResult.cs b/FileManager.Models/Dialogs/DialogResult.cs new file mode 100644 index 0000000..a7490a3 --- /dev/null +++ b/FileManager.Models/Dialogs/DialogResult.cs @@ -0,0 +1,11 @@ +using FileManager.Models.Enums; + +namespace FileManager.Models.Dialogs +{ + public class DialogResult + { + public object Value { get; set; } + + public OperationResult OperationResult { get; set; } + } +} \ No newline at end of file diff --git a/FileManager.Models/Enums/OperationResult.cs b/FileManager.Models/Enums/OperationResult.cs new file mode 100644 index 0000000..043a8c3 --- /dev/null +++ b/FileManager.Models/Enums/OperationResult.cs @@ -0,0 +1,22 @@ +namespace FileManager.Models.Enums +{ + public enum OperationResult + { + Canceled, + + Ok, + + /* storage item */ + + Add, + + Remove, + + /*rate dialog*/ + + Rate, + + Feedback + + } +} \ No newline at end of file diff --git a/FileManager.Models/FileManager.Models.csproj b/FileManager.Models/FileManager.Models.csproj index 89060eb..8410f23 100644 --- a/FileManager.Models/FileManager.Models.csproj +++ b/FileManager.Models/FileManager.Models.csproj @@ -120,9 +120,14 @@ PackageReference + + + + + diff --git a/FileManager.Models/Interfaces/IDialog.cs b/FileManager.Models/Interfaces/IDialog.cs new file mode 100644 index 0000000..68c6dbc --- /dev/null +++ b/FileManager.Models/Interfaces/IDialog.cs @@ -0,0 +1,17 @@ +using FileManager.Models.Dialogs; +using System.Threading.Tasks; + +namespace FileManager.Models.Interfaces +{ + public interface IDialog : IDialog + { + Task ShowAsync(T parameter); + } + + public interface IDialog + { + void Dismiss(); + + void OnEnterKeyUp(); + } +} \ No newline at end of file diff --git a/FileManager.Models/Interfaces/IWebViewDialog.cs b/FileManager.Models/Interfaces/IWebViewDialog.cs new file mode 100644 index 0000000..4181746 --- /dev/null +++ b/FileManager.Models/Interfaces/IWebViewDialog.cs @@ -0,0 +1,4 @@ +namespace FileManager.Models.Interfaces +{ + public interface IAuthWebViewDialog : IDialog { } +} diff --git a/FileManager.Resources/Batteries.resw b/FileManager.Resources/Batteries.resw index 38ebe22..7566687 100644 --- a/FileManager.Resources/Batteries.resw +++ b/FileManager.Resources/Batteries.resw @@ -118,24 +118,24 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - /Images/Battery/battery.png + /Assets/Images/Battery/battery.png - /Images/Battery/batteryAttention.png + /Assets/Images/Battery/batteryAttention.png - /Images/Battery/batteryCharge.png + /Assets/Images/Battery/batteryCharge.png - /Images/Battery/emptyBattery.png + /Assets/Images/Battery/emptyBattery.png - /Images/Battery/fullBattery.png + /Assets/Images/Battery/fullBattery.png - /Images/Battery/halfBattery.png + /Assets/Images/Battery/halfBattery.png - /Images/Battery/lowBattery.png + /Assets/Images/Battery/lowBattery.png \ No newline at end of file diff --git a/FileManager.Resources/FileManager.Resources.csproj b/FileManager.Resources/FileManager.Resources.csproj index b30f43b..513f027 100644 --- a/FileManager.Resources/FileManager.Resources.csproj +++ b/FileManager.Resources/FileManager.Resources.csproj @@ -137,6 +137,12 @@ + + + + + + 14.0 diff --git a/FileManager.Resources/ImagesDark.resw b/FileManager.Resources/ImagesDark.resw index e8311ae..5d37efd 100644 --- a/FileManager.Resources/ImagesDark.resw +++ b/FileManager.Resources/ImagesDark.resw @@ -118,18 +118,18 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - /Images/FileIcons/AudioDark.png + /Assets/Images/FileIcons/AudioDark.png - /Images/FileIcons/FileDark.png + /Assets/Images/FileIcons/FileDark.png - /Images/FileIcons/FolderDark.png + /Assets/Images/FileIcons/FolderDark.png - /Images/FileIcons/ImageDark.png + /Assets/Images/FileIcons/ImageDark.png - /Images/FileIcons/VideoDark.png + /Assets/Images/FileIcons/VideoDark.png \ No newline at end of file diff --git a/FileManager.Resources/ImagesLight.resw b/FileManager.Resources/ImagesLight.resw index bd548f0..9dd18d7 100644 --- a/FileManager.Resources/ImagesLight.resw +++ b/FileManager.Resources/ImagesLight.resw @@ -118,24 +118,24 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - /Images/FileIcons/AudioLight.png + /Assets/Images/FileIcons/AudioLight.png - /Images/DiskStorage/diskStorage.png + /Assets/Images/DiskStorage/diskStorage.png - /Images/FIleIcons/FileLight.png + /Assets/Images/FIleIcons/FileLight.png - /Images/FileIcons/FolderLight.jpg + /Assets/Images/FileIcons/FolderLight.jpg - /Images/FileIcons/ImageLight.png + /Assets/Images/FileIcons/ImageLight.png - /Images/ram.png + /Assets/Images/ram.png - /Images/FileIcons/VideoLight.png + /Assets/Images/FileIcons/VideoLight.png \ No newline at end of file diff --git a/FileManager/Strings/en-US/Resources.resw b/FileManager.Resources/Strings/en-US/Resources.resw similarity index 99% rename from FileManager/Strings/en-US/Resources.resw rename to FileManager.Resources/Strings/en-US/Resources.resw index 9cb500f..3fd1419 100644 --- a/FileManager/Strings/en-US/Resources.resw +++ b/FileManager.Resources/Strings/en-US/Resources.resw @@ -189,6 +189,9 @@ New folder + + OneDrive + Enter file name diff --git a/FileManager/Strings/ru-RU/Resources.resw b/FileManager.Resources/Strings/ru-RU/Resources.resw similarity index 99% rename from FileManager/Strings/ru-RU/Resources.resw rename to FileManager.Resources/Strings/ru-RU/Resources.resw index b9af8b6..85dfbe7 100644 --- a/FileManager/Strings/ru-RU/Resources.resw +++ b/FileManager.Resources/Strings/ru-RU/Resources.resw @@ -189,6 +189,9 @@ Новая папка + + OneDrive + Введите название diff --git a/FileManager.Services/FileManager.Services.csproj b/FileManager.Services/FileManager.Services.csproj index 80aa569..cf0424a 100644 --- a/FileManager.Services/FileManager.Services.csproj +++ b/FileManager.Services/FileManager.Services.csproj @@ -120,7 +120,9 @@ PackageReference + + @@ -132,8 +134,15 @@ 6.2.14 + + 1.0.0.22 + + + {AEF42671-CCBA-4303-A8DA-1C062D1D7409} + FileManager.Dependencies + {73f81792-c4c2-4ec2-8805-c6d19972bc3c} FileManager.Helpers diff --git a/FileManager.Services/FtpService.cs b/FileManager.Services/FtpService.cs index 1bf3026..83cf118 100644 --- a/FileManager.Services/FtpService.cs +++ b/FileManager.Services/FtpService.cs @@ -23,11 +23,11 @@ public async Task TryConnectAsync(string hostLink, string username, stri request.Credentials = new NetworkCredential(username, password); var response = (FtpWebResponse)await request.GetResponseAsync().ConfigureAwait(true); response.Close(); - connectionResult = Constants.Success; + connectionResult = Enums.Success.ToString(); } catch (WebException) { - connectionResult = Constants.Failed; + connectionResult = Enums.Failed.ToString(); } catch (UriFormatException) { @@ -86,9 +86,9 @@ private FtpFile GetFtpFile(string line) }; return ftpFile; } - public async Task DownloadFileAsync(StorageFolder downloadFolder, string filePath, string username, string password) + public async Task DownloadFileAsync(StorageFolder downloadFolder, string filePath, string username, string password) { - string downloadingResult; + Enums downloadingResult; Stream stream; string fileName = filePath?.Split('/').Last(); StorageFile destinationFile = await downloadFolder?.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName); @@ -109,19 +109,19 @@ public async Task DownloadFileAsync(StorageFolder downloadFolder, string { await stream.CopyToAsync(fileStream).ConfigureAwait(true); } - downloadingResult = Constants.Success; + downloadingResult = Enums.Success; } catch (WebException) { - downloadingResult = Constants.Failed; + downloadingResult = Enums.Failed; await destinationFile?.DeleteAsync(); } return downloadingResult; } - public async Task UploadFileAsync(StorageFile uploadFile, string destinationPath, string username, string password) + public async Task UploadFileAsync(StorageFile uploadFile, string destinationPath, string username, string password) { - string uploadingResult; + Enums uploadingResult; Stream responseStream; try { @@ -134,21 +134,21 @@ public async Task UploadFileAsync(StorageFile uploadFile, string destina { await fileStream.CopyToAsync(responseStream).ConfigureAwait(true); } - uploadingResult = Constants.Success; + uploadingResult = Enums.Success; } catch (WebException) { - uploadingResult = Constants.Failed; + uploadingResult = Enums.Failed; } catch(FileLoadException) { - uploadingResult = Constants.Failed; + uploadingResult = Enums.Failed; } return uploadingResult; } - public async Task DeleteFileAsync(string path, string type, string username, string password) + public async Task DeleteFileAsync(string path, string type, string username, string password) { - string result; + Enums result; try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path); @@ -165,17 +165,17 @@ public async Task DeleteFileAsync(string path, string type, string usern FtpWebResponse response = (FtpWebResponse)await request.GetResponseAsync().ConfigureAwait(true); response.Close(); - result = Constants.Success; + result = Enums.Success; } catch (WebException) { - result = Constants.Failed; + result = Enums.Failed; } return result; } - public async Task CreateNewFolderAsync(string path, string folderName, string username, string password) + public async Task CreateNewFolderAsync(string path, string folderName, string username, string password) { - string creatingResult; + Enums creatingResult; try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path + "/" + folderName); @@ -184,17 +184,17 @@ public async Task CreateNewFolderAsync(string path, string folderName, s FtpWebResponse response = (FtpWebResponse)await request.GetResponseAsync().ConfigureAwait(true); response.Close(); - creatingResult = Constants.Success; + creatingResult = Enums.Success; } catch (WebException) { - creatingResult = Constants.Failed; + creatingResult = Enums.Failed; } return creatingResult; } - public async Task RenameFileAsync(string path, string oldFileName, string newFileName, string username, string password) + public async Task RenameFileAsync(string path, string oldFileName, string newFileName, string username, string password) { - string renameResult; + Enums renameResult; try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path + "/" + oldFileName); @@ -203,11 +203,11 @@ public async Task RenameFileAsync(string path, string oldFileName, strin request.RenameTo = newFileName; FtpWebResponse response = (FtpWebResponse)await request.GetResponseAsync().ConfigureAwait(true); response.Close(); - renameResult = Constants.Success; + renameResult = Enums.Success; } catch (WebException) { - renameResult = Constants.Failed; + renameResult = Enums.Failed; } return renameResult; } diff --git a/FileManager.Services/GoogleDriveService.cs b/FileManager.Services/GoogleDriveService.cs index 77d000f..af79d60 100644 --- a/FileManager.Services/GoogleDriveService.cs +++ b/FileManager.Services/GoogleDriveService.cs @@ -19,26 +19,26 @@ namespace FileManager.Services { public class GoogleDriveService { - public async Task CheckInternetConnectionAsync(string source) + public async Task CheckInternetConnectionAsync(string source) { - string result; + Enums result; using (var client = new HttpClient()) { try { var responce = await client.GetAsync(source).ConfigureAwait(true); - result = Constants.Success; + result = Enums.Success; } catch (HttpRequestException) { - result = Constants.Failed; + result = Enums.Failed; } } return result; } - public async Task ExchangeCodeOnTokenAsync(string exchangeCode, string clientId, string secret, TokenResult accessToken) + public async Task ExchangeCodeOnTokenAsync(string exchangeCode, string clientId, string secret, TokenResult accessToken) { - string result = Constants.Failed; + Enums result = Enums.Failed; using (HttpClient client = new HttpClient()) { string request = string.Join('&', $"code={exchangeCode}", $"client_id={clientId}", $"client_secret={secret}", @@ -57,12 +57,12 @@ public async Task ExchangeCodeOnTokenAsync(string exchangeCode, string c accessToken.Expires_in = token.Expires_in; accessToken.Scope = token.Scope; accessToken.LastRefreshTime = DateTime.Now; - result = Constants.Success; + result = Enums.Success; } } catch (HttpRequestException) { - result = Constants.Failed; + result = Enums.Failed; } finally { @@ -114,14 +114,14 @@ public async Task GetRootFolderIdAsync(string tokenType, string accessTo } catch (HttpRequestException) { - result = Constants.Failed; + result = Enums.Failed.ToString(); } } return result; } - public async Task DownloadFileAsync(Uri source, StorageFolder destinationFolder, string fileName, string tokenType, string accessToken) + public async Task DownloadFileAsync(Uri source, StorageFolder destinationFolder, string fileName, string tokenType, string accessToken) { - string result = Constants.Failed; + Enums result = Enums.Failed; if (destinationFolder != null) { StorageFile destinationFile = await destinationFolder.CreateFileAsync( @@ -137,20 +137,20 @@ public async Task DownloadFileAsync(Uri source, StorageFolder destinatio { await stream.CopyToAsync(fileStream).ConfigureAwait(true); } - result = Constants.Success; + result = Enums.Success; } catch (HttpRequestException) { - result = Constants.Failed; + result = Enums.Failed; await destinationFile.DeleteAsync(); } } } return result; } - public async Task UploadFileAsync(StorageFile uploadFile, Collection parents, string accessToken) + public async Task UploadFileAsync(StorageFile uploadFile, Collection parents, string accessToken) { - string result = Constants.Failed; + Enums result = Enums.Failed; var credentional = GoogleCredential.FromAccessToken(accessToken).CreateScoped(DriveService.Scope.Drive); using (var service = new DriveService(new BaseClientService.Initializer() { @@ -171,15 +171,15 @@ public async Task UploadFileAsync(StorageFile uploadFile, Collection DeleteFileAsync(string fileId, string accessToken) + public async Task DeleteFileAsync(string fileId, string accessToken) { - string result = Constants.Failed; + Enums result = Enums.Failed; DeleteRequest request; var credentional = GoogleCredential.FromAccessToken(accessToken).CreateScoped(DriveService.Scope.Drive); using (var service = new DriveService(new BaseClientService.Initializer() @@ -193,19 +193,19 @@ public async Task DeleteFileAsync(string fileId, string accessToken) try { await request.ExecuteAsync().ConfigureAwait(true); - result = Constants.Success; + result = Enums.Success; } catch (HttpRequestException) { - result = Constants.Failed; + result = Enums.Failed; } } } return result; } - public async Task CreateNewFolderAsync(string folderName, Collection parents, string accessToken) + public async Task CreateNewFolderAsync(string folderName, Collection parents, string accessToken) { - string result; + Enums result; var credentional = GoogleCredential.FromAccessToken(accessToken).CreateScoped(DriveService.Scope.Drive); using (var service = new DriveService(new BaseClientService.Initializer() { @@ -224,18 +224,18 @@ public async Task CreateNewFolderAsync(string folderName, Collection RenameFileAsync(string itemId, string fileName, string accessToken) + public async Task RenameFileAsync(string itemId, string fileName, string accessToken) { - string result = string.Empty; + Enums result = Enums.Failed; var credentional = GoogleCredential.FromAccessToken(accessToken).CreateScoped(DriveService.Scope.Drive); using (var service = new DriveService(new BaseClientService.Initializer() { @@ -251,19 +251,19 @@ public async Task RenameFileAsync(string itemId, string fileName, string { var request = service.Files.Update(fileMetadata, itemId); await request.ExecuteAsync().ConfigureAwait(true); - result = Constants.Success; + result = Enums.Success; } catch (HttpRequestException) { - result = Constants.Failed; + result = Enums.Failed; } } return result; } - public async Task RefreshTokenAsync(string clientId, string secret, TokenResult accessToken) + public async Task RefreshTokenAsync(string clientId, string secret, TokenResult accessToken) { HttpResponseMessage response; - string result = string.Empty; + Enums result = Enums.Failed; using (HttpClient client = new HttpClient()) { if (accessToken != null) @@ -278,11 +278,11 @@ public async Task RefreshTokenAsync(string clientId, string secret, Toke accessToken.Access_token = token.Access_token; accessToken.Expires_in = token.Expires_in; accessToken.LastRefreshTime = DateTime.Now; - result = Constants.Success; + result = Enums.Success; } catch (HttpRequestException) { - result = Constants.Failed; + result = Enums.Failed; } finally { diff --git a/FileManager.Services/OneDriveService.cs b/FileManager.Services/OneDriveService.cs new file mode 100644 index 0000000..3e91795 --- /dev/null +++ b/FileManager.Services/OneDriveService.cs @@ -0,0 +1,238 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using ThirdPartyServices.Shared.Interfaces; +using ThirdPartyServices.Shared.Models; +using ThirdPartyServices.Shared.Models.Parameters; +using ThirdPartyServices.Shared.Models.Responses.Microsoft; +using Windows.Storage; +using Autofac; +using FileManager.Dependencies; +using FileManager.Helpers; +using FileManager.Models; +using Newtonsoft.Json.Linq; + +namespace FileManager.Services +{ + public class OneDriveService + { + private readonly IOneDriveCloudService oneDriveCloudService; + private readonly IMicrosoftAuthorizationService microsoftAuthService; + public OneDriveService() + { + microsoftAuthService = VMDependencies.Container.Resolve(); + oneDriveCloudService = VMDependencies.Container.Resolve(); + } + public async Task CheckInternetConnectionAsync(string source) + { + Enums result; + using (var client = new HttpClient()) + { + try + { + var responce = await client.GetAsync(source).ConfigureAwait(true); + result = Enums.Success; + } + catch (HttpRequestException) + { + result = Enums.Failed; + } + } + return result; + } + public async Task OneDriveAuthAsync(MicrosoftAuthParams microsoftParams, TokenResult accessToken) + { + Enums result; + try + { + var token = await microsoftAuthService.AuthorizeAsync(microsoftParams); + accessToken.Access_token = token.Token; + accessToken.Refresh_token = token.RefreshToken; + accessToken.Expires_in = token.ExpiresIn.ToString(); + accessToken.LastRefreshTime = DateTime.Now; + accessToken.Token_type = "Bearer"; + result = Enums.Success; + } + catch (Exception) + { + result = Enums.Failed; + } + return result; + } + public async Task GetFilesAsync(string folderId, string accessToken) + { + ItemsResponse items; + try + { + items = await oneDriveCloudService.GetFilesByFolderIdAsync(accessToken, folderId); + } + catch + { + items = null; + } + return items; + } + public async Task DownloadFileAsync(StorageFolder destinationFolder, string fileName, string fileId, string accessToken) + { + Enums result = Enums.Failed; + if (destinationFolder != null) + { + StorageFile destinationFile = await destinationFolder.CreateFileAsync( + fileName, CreationCollisionOption.GenerateUniqueName); + + var file = await oneDriveCloudService.DownloadItemAsync(new DownloadParams + { + Token = accessToken, + FileName = fileId, + }); + if (file.Name != null) + { + try + { + await FileIO.WriteBytesAsync(destinationFile, (file.StreamContent as MemoryStream).ToArray()); + result = Enums.Success; + } + catch (Exception) + { + await destinationFile.DeleteAsync(); + result = Enums.Failed; + } + } + else + { + await destinationFile.DeleteAsync(); + result = Enums.Failed; + } + } + return result; + } + public async Task UploadFileAsync(StorageFile uploadFile, string accessToken) + { + Enums result = Enums.Failed; + + if (!string.IsNullOrEmpty(accessToken) && uploadFile != null) + { + var streamData = await uploadFile.OpenReadAsync(); + var stream = streamData.AsStreamForRead(); + try + { + await oneDriveCloudService.UploadItemAsync(stream, new UploadParams + { + Token = accessToken, + FileName = uploadFile.Name, + }); + result = Enums.Success; + } + catch (Exception) + { + result = Enums.Failed; + } + } + return result; + } + public async Task DeleteFileAsync(string fileId, string accessToken) + { + Enums result = Enums.Failed; + if (fileId != null) + { + try + { + await oneDriveCloudService.DeleteFileAsync(accessToken, fileId); + result = Enums.Success; + } + catch (HttpRequestException) + { + result = Enums.Failed; + } + } + return result; + } + public async Task CreateNewFolderAsync(string folderName, string parent, string tokenType, string accessToken) + { + Enums result; + using (HttpClient client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken); + string source = $"https://graph.microsoft.com/v1.0/me/drive/items/{parent}/children"; + var folderObject = JObject.FromObject(new + { + name = folderName, + folder = new { }, + }); + HttpContent content = new StringContent(folderObject.ToString(), Encoding.UTF8, "application/json"); + try + { + HttpResponseMessage response = await client.PostAsync(source, content); + result = Enums.Success; + } + catch (HttpRequestException) + { + result = Enums.Failed; + } + finally + { + content.Dispose(); + } + } + return result; + } + public async Task RenameFileAsync(string itemId, string fileName, string tokenType, string accessToken) + { + Enums result; + string source = $"https://graph.microsoft.com/v1.0/me/drive/items/{itemId}"; + using (HttpClient client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken); + var folderObject = JObject.FromObject(new + { + name = fileName, + }); + HttpContent content = new StringContent(folderObject.ToString(), Encoding.UTF8, "application/json"); + var method = "PATCH"; + var httpVerb = new HttpMethod(method); + HttpRequestMessage httpRequestMessage = new HttpRequestMessage(httpVerb, source) + { + Content = content, + }; + try + { + HttpResponseMessage response = await client.SendAsync(httpRequestMessage); + result = Enums.Success; + } + catch (HttpRequestException) + { + result = Enums.Failed; + } + finally + { + content.Dispose(); + } + } + return result; + } + public async Task RefreshTokenAsync(MicrosoftAuthParams microsoftParams, TokenResult accessToken) + { + Enums result = Enums.Failed; + if (accessToken != null) + { + try + { + var token = await microsoftAuthService.ExchangeRefreshTokenAsync(microsoftParams, accessToken.Refresh_token); + accessToken.Access_token = token.Result.AccessToken; + accessToken.Expires_in = token.Result.ExpiresIn.ToString(); + accessToken.Refresh_token = token.Result.RefreshToken; + accessToken.LastRefreshTime = DateTime.Now; + result = Enums.Success; + } + catch (Exception) + { + result = Enums.Failed; + } + } + return result; + } + } +} diff --git a/FileManager.Services/ThemeService.cs b/FileManager.Services/ThemeService.cs new file mode 100644 index 0000000..655db46 --- /dev/null +++ b/FileManager.Services/ThemeService.cs @@ -0,0 +1,36 @@ +using Windows.ApplicationModel.Resources; +using Windows.UI; +using Windows.UI.ViewManagement; +using FileManager.Helpers; +using FileManager.Models; + +namespace FileManager.Services +{ + public static class ThemeService + { + public static ColorMode ChangeColorMode(UISettings uiSettings, Color backgroundColor) + { + string resourcePath; + ResourceLoader themeResourceLoader; + ColorMode colorMode; + var currentBackgroundColor = uiSettings?.GetColorValue(UIColorType.Background); + if (currentBackgroundColor == Colors.Black) + { + resourcePath = string.Join('\\', Constants.Resources, Constants.ImagesDark); + backgroundColor = Colors.Black; + } + else + { + resourcePath = string.Join('\\', Constants.Resources, Constants.ImagesLight); + backgroundColor = Colors.White; + } + themeResourceLoader = ResourceLoader.GetForViewIndependentUse(resourcePath); + colorMode = new ColorMode + { + BackgroundColor = backgroundColor, + ThemeResourceLoader = themeResourceLoader + }; + return colorMode; + } + } +} diff --git a/FileManager.ViewModels/BaseDialogControl.cs b/FileManager.ViewModels/BaseDialogControl.cs new file mode 100644 index 0000000..b7f7d2e --- /dev/null +++ b/FileManager.ViewModels/BaseDialogControl.cs @@ -0,0 +1,228 @@ +using CommonToolkit.Core.Extensions; +using FileManager.Helpers; +using FileManager.Models.Dialogs; +using FileManager.Models.Enums; +using FileManager.Models.Interfaces; +using System; +using System.Linq; +using System.Threading.Tasks; +using Windows.System; +using Windows.UI; +using Windows.UI.Core; +using Windows.UI.ViewManagement; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Media; + +namespace FileManager.ViewModels +{ + public class BaseDialogControl : Control, IDialog + { + protected const string PopupStatesGroupName = "PopupStates"; + protected const string OpenPopupStateName = "OpenPopupState"; + protected const string ClosedPopupStateName = "ClosedPopupState"; + + protected const string LayoutPanelName = "LayoutRoot"; + protected const string ContentBorderName = "ContentBorder"; + protected const string ContentGridName = "ContentGrid"; + + protected const string CloseButtonName = "CloseButton"; + + private bool isShowing; + + private Panel parentPanel; + private Popup dialogPopup; + + private Button closeButton; + + private Color originalColor; + + private ApplicationView AppView = ApplicationView.GetForCurrentView(); + + public BaseDialogControl() + { + this.Visibility = Visibility.Collapsed; + + this.Loaded += this.OnLoaded; + this.Unloaded += this.OnUnloaded; + } + + protected Panel LayoutPanel { get; private set; } + + protected TaskCompletionSource ApplyTemplateTaskSource { get; } = new TaskCompletionSource(); + + protected TaskCompletionSource DismissTaskSource { get; private set; } + + protected virtual void OnUnloaded(object sender, RoutedEventArgs e) + { + if (this.closeButton != null) + { + this.closeButton.Click -= this.OnCloseButtonClick; + } + } + + protected virtual async void OnLoaded(object sender, RoutedEventArgs e) + { + await this.ApplyTemplateTaskSource.Task; + + if (this.closeButton != null) + { + this.closeButton.Click += this.OnCloseButtonClick; + } + } + + protected override void OnApplyTemplate() + { + this.LayoutPanel = this.GetTemplateChild(LayoutPanelName) as Panel; + this.closeButton = this.GetTemplateChild(CloseButtonName) as Button; + + base.OnApplyTemplate(); + + this.ApplyTemplateTaskSource.TrySetResult(true); + } + + public virtual async Task ShowAsync(T param) + { + if (this.isShowing) + { + throw new InvalidOperationException("The dialog is already shown."); + } + + //originalColor = AppView.TitleBar.ButtonForegroundColor.Value; + //AppView.TitleBar.ButtonForegroundColor = Color.FromArgb(0, 255, 255, 255); + + this.Visibility = Visibility.Visible; + this.isShowing = true; + + Window.Current.CoreWindow.KeyDown += this.OnCoreWindowKeyDown; + + this.DismissTaskSource = new TaskCompletionSource(); + + this.dialogPopup = new Popup { Child = this }; + + this.parentPanel = Window.Current.Content.GetFirstDescendantOfType(); + if (this.parentPanel != null) + { + this.parentPanel.Children.Add(this.dialogPopup); + this.parentPanel.SizeChanged += this.OnParentSizeChanged; + } + + this.dialogPopup.IsOpen = true; + + this.LayoutUpdated += this.OnLayoutUpdated; + + var result = await this.DismissTaskSource.Task; + + await this.CloseAsync(); + + Window.Current.CoreWindow.KeyDown -= this.OnCoreWindowKeyDown; + + return result; + } + + public void Dismiss() + { + this.DismissDialog(); + } + + private async void OnLayoutUpdated(object sender, object e) + { + this.LayoutUpdated -= this.OnLayoutUpdated; + this.ResizeLayoutRoot(); + + this.SetAdditionalLayout(); + + await this.GoToVisualStateAsync(this.LayoutPanel, PopupStatesGroupName, OpenPopupStateName); + + // set focus to opened dialog + this.Focus(FocusState.Programmatic); + } + + protected virtual void SetAdditionalLayout() { } + + protected void ResizeLayoutRoot() + { + if (this.parentPanel != null && this.LayoutPanel != null) + { + this.LayoutPanel.Width = this.parentPanel.ActualWidth; + this.LayoutPanel.Height = this.parentPanel.ActualHeight; + } + } + + protected void InvertResizeLayoutRoot() + { + if (this.parentPanel != null && this.LayoutPanel != null) + { + this.LayoutPanel.Width = this.parentPanel.ActualHeight; + this.LayoutPanel.Height = this.parentPanel.ActualWidth; + } + } + + private void OnParentSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs) + { + if (sizeChangedEventArgs.NewSize != sizeChangedEventArgs.PreviousSize) + { + this.ResizeLayoutRoot(); + } + } + + protected virtual void OnCloseButtonClick(object sender, RoutedEventArgs e) + { + this.DismissDialog(); + } + + private void OnCoreWindowKeyDown(CoreWindow sender, KeyEventArgs e) + { + if (!e.Handled) + { + var lastDailog = VisualTreeHelper.GetOpenPopups(Window.Current).FirstOrDefault(popup => popup.Child is IDialog)?.Child as IDialog; + if (e.VirtualKey == VirtualKey.Escape) + { + lastDailog?.Dismiss(); + } + else if (e.VirtualKey == VirtualKey.Enter) + { + lastDailog?.OnEnterKeyUp(); + } + + e.Handled = true; + } + } + + public virtual void OnEnterKeyUp() { } + + protected virtual void DismissDialog() + { + this.DismissTaskSource.TrySetResult(new DialogResult { OperationResult = OperationResult.Canceled }); + + AppView.TitleBar.ButtonForegroundColor = originalColor; + } + + protected virtual async Task CloseAsync() + { + if (!this.isShowing) + { + throw new InvalidOperationException("The dialog isn't shown, so it can't be closed."); + } + + await this.GoToVisualStateAsync(this.LayoutPanel, PopupStatesGroupName, ClosedPopupStateName); + + this.dialogPopup.IsOpen = false; + this.dialogPopup.Child = null; + + if (this.parentPanel != null) + { + this.parentPanel.Children.Remove(this.dialogPopup); + this.parentPanel.SizeChanged -= this.OnParentSizeChanged; + this.parentPanel = null; + } + + this.dialogPopup = null; + this.Visibility = Visibility.Collapsed; + this.isShowing = false; + + AppView.TitleBar.ButtonForegroundColor = originalColor; + } + } +} \ No newline at end of file diff --git a/FileManager.ViewModels/Factory/FileControlCreator.cs b/FileManager.ViewModels/Factory/FileControlCreator.cs index b8cecdf..1523b2f 100644 --- a/FileManager.ViewModels/Factory/FileControlCreator.cs +++ b/FileManager.ViewModels/Factory/FileControlCreator.cs @@ -1,19 +1,40 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.UI.Xaml.Controls; -using FileManager.ViewModels; -using FileManager.ViewModels.OnlineFileControls; +using Windows.ApplicationModel.Resources; +using FileManager.Helpers; namespace FileManager.ViewModels.Factory { public class FileControlCreator { - public FileControlViewModel CreateFileControl() + public static FileControlViewModel CreateFileControl(ResourceLoader themeResourceLoader, string name, string type, string path = "") { - return new FileControlViewModel(); + FileControlViewModel fileControl = new FileControlViewModel + { + DisplayName = name, + Path = path, + }; + if (type.Contains(Constants.Image, StringComparison.Ordinal)) + { + fileControl.Image = themeResourceLoader.GetString(Constants.Image); + fileControl.Type = Constants.Image; + } + else if (type.Contains(Constants.Video, StringComparison.Ordinal)) + { + fileControl.Image = themeResourceLoader.GetString(Constants.Video); + fileControl.Type = Constants.Video; + } + else if (type.Contains(Constants.Audio, StringComparison.Ordinal)) + { + fileControl.Image = themeResourceLoader.GetString(Constants.Audio); + fileControl.Type = Constants.Image; + } + else + { + fileControl.Image = themeResourceLoader.GetString(Constants.File); + fileControl.Type = Constants.File; + } + + return fileControl; } } } diff --git a/FileManager.ViewModels/Factory/OnlineFileControlCreator.cs b/FileManager.ViewModels/Factory/OnlineFileControlCreator.cs index 021c617..e7033ed 100644 --- a/FileManager.ViewModels/Factory/OnlineFileControlCreator.cs +++ b/FileManager.ViewModels/Factory/OnlineFileControlCreator.cs @@ -20,7 +20,7 @@ public static class OnlineFileControlCreator { ".mp3", Constants.Audio }, { ".ogg", Constants.Audio }, { ".wma", Constants.Audio }, - { ".wav", Constants.Audio }, + { ".wav", Constants.Audio }, { "application/vnd.google-apps.audio", Constants.Audio }, { "application/vnd.google-apps.video", Constants.Video }, { "application/vnd.google-apps.drawing", Constants.Image }, @@ -32,6 +32,13 @@ public static class OnlineFileControlCreator { "video/mp4", Constants.Video }, { "image/png", Constants.Image }, { "drwxr-xr-x", Constants.Folder }, + { "audio/mpeg", Constants.Audio }, + { "audio/ogg", Constants.Audio }, + { "image/gif", Constants.Image }, + { "image/x-icon", Constants.Image }, + { "video/mpeg", Constants.Video }, + { "video/x-msvideo", Constants.Video }, + { "folder", Constants.Folder }, }; public static OnlineFileControlViewModel CreateFileControl(ResourceLoader themeResourceLoader, string id, string name, string type, string path = "") diff --git a/FileManager.ViewModels/FileManager.ViewModels.csproj b/FileManager.ViewModels/FileManager.ViewModels.csproj index c5cb91c..cf0e617 100644 --- a/FileManager.ViewModels/FileManager.ViewModels.csproj +++ b/FileManager.ViewModels/FileManager.ViewModels.csproj @@ -120,12 +120,14 @@ PackageReference + + @@ -145,6 +147,7 @@ + @@ -154,6 +157,9 @@ 6.2.14 + + 1.0.0.22 + diff --git a/FileManager.ViewModels/FtpViewModel.cs b/FileManager.ViewModels/FtpViewModel.cs index 9e39449..ef065dc 100644 --- a/FileManager.ViewModels/FtpViewModel.cs +++ b/FileManager.ViewModels/FtpViewModel.cs @@ -324,34 +324,20 @@ public FtpViewModel() } protected override void ChangeColorMode(UISettings uiSettings, object sender) { - var currentBackgroundColor = uiSettings?.GetColorValue(UIColorType.Background); - string resourcePath; - if (backgroundColor != currentBackgroundColor || storageFiles == null) - { - if (currentBackgroundColor == Colors.Black) - { - resourcePath = string.Join('\\', Constants.Resources, Constants.ImagesDark); - backgroundColor = Colors.Black; - } - else - { - resourcePath = string.Join('\\', Constants.Resources, Constants.ImagesLight); - backgroundColor = Colors.White; - } - themeResourceLoader = ResourceLoader.GetForViewIndependentUse(resourcePath); - - if (storageFiles != null) - { - CoreApplication.MainView.CoreWindow.Dispatcher - .RunAsync(CoreDispatcherPriority.Normal, - () => + var colorMode = ThemeService.ChangeColorMode(uiSettings, backgroundColor); + backgroundColor = colorMode.BackgroundColor; + themeResourceLoader = colorMode.ThemeResourceLoader; + if (storageFiles != null) + { + CoreApplication.MainView.CoreWindow.Dispatcher + .RunAsync(CoreDispatcherPriority.Normal, + () => + { + foreach (var storageFile in storageFiles) { - foreach (var storageFile in storageFiles) - { - storageFile.ChangeColorMode(themeResourceLoader); - } - }).AsTask().ConfigureAwait(true); - } + storageFile.ChangeColorMode(themeResourceLoader); + } + }).AsTask().ConfigureAwait(true); } } @@ -359,8 +345,8 @@ private async void ConnectAsync(object sender) { IsLoginFormVisible = false; IsLoadingVisible = true; - var result = await ftpService.TryConnectAsync(hostLink, username, password).ConfigureAwait(true); - if (result == Constants.Success) + string result = await ftpService.TryConnectAsync(hostLink, username, password).ConfigureAwait(true); + if (result == Enums.Success.ToString()) { currentPath = HostLink; IsCommandPanelVisible = true; @@ -451,7 +437,7 @@ await Task.Run(() => private async void DownloadFileAsync(object sender) { string filePath = selectedGridItem.Path; - string result; + Enums result; if (selectedGridItem != null && !string.IsNullOrEmpty(selectedGridItem.DisplayName) && selectedGridItem.Type != Constants.Folder) { StorageFolder downloadFolder = await GetDestinationFolderAsync().ConfigureAwait(true); @@ -466,7 +452,7 @@ private async void DownloadFileAsync(object sender) var downloadingFile = storageFiles.FirstOrDefault(f => f.Path == filePath); if (downloadingFile != null) { - if (result == Constants.Success) + if (result == Enums.Success) { downloadingFile.DownloadStatus = stringsResourceLoader.GetString(Constants.DownloadCompleted); } @@ -500,7 +486,7 @@ private async Task CloseDownloadingAsync(OnlineFileControlViewModel file) private async void UploadFileAsync(object sender) { - string result; + Enums result; string destinationPath = currentPath; StorageFile uploadFile = await GetUploadFileAsync().ConfigureAwait(true); @@ -509,7 +495,7 @@ private async void UploadFileAsync(object sender) if (storageFiles.FirstOrDefault(f => f.DisplayName == uploadFile.Name) == null) { result = await ftpService.UploadFileAsync(uploadFile, currentPath, username, password).ConfigureAwait(true); - if (result == Constants.Success && destinationPath == currentPath) + if (result == Enums.Success && destinationPath == currentPath) { _ = GetItemsAsync(currentPath).ConfigureAwait(true); } @@ -539,7 +525,7 @@ private async Task GetUploadFileAsync() private async void DeleteFileAsync(object sender) { - string deletingResult; + Enums deletingResult; if (selectedGridItem != null && !string.IsNullOrEmpty(selectedGridItem.DisplayName)) { var contentDialog = new ContentDialog() @@ -554,7 +540,7 @@ private async void DeleteFileAsync(object sender) if (confirmationResult == ContentDialogResult.Primary) { deletingResult = await ftpService.DeleteFileAsync(selectedGridItem.Path, selectedGridItem.Type, username, password).ConfigureAwait(true); - if (deletingResult == Constants.Success) + if (deletingResult == Enums.Success) { _ = GetItemsAsync(currentPath).ConfigureAwait(true); } @@ -569,7 +555,7 @@ await ShowMessageDialogAsync(stringsResourceLoader.GetString(Constants.Connectio private async void CreateNewFolderAsync(object sender) { - string creatingResult; + Enums creatingResult; string dialogTitle = stringsResourceLoader.GetString(Constants.NewFolder); string placeHolder = stringsResourceLoader.GetString(Constants.PlaceHolderFileName); string inputText = string.Empty; @@ -585,7 +571,7 @@ private async void CreateNewFolderAsync(object sender) if (storageFiles.FirstOrDefault(f => f.DisplayName == folderName) == null) { creatingResult = await ftpService.CreateNewFolderAsync(currentPath, folderName, username, password).ConfigureAwait(true); - if (creatingResult == Constants.Success) + if (creatingResult == Enums.Success) { _ = GetItemsAsync(currentPath).ConfigureAwait(true); } @@ -615,7 +601,7 @@ private async void RenameFileAsync(object sender) string placeHolder = stringsResourceLoader.GetString(Constants.PlaceHolderFileName); string primaryButton = stringsResourceLoader.GetString(Constants.YesButton); string secondaryButton = stringsResourceLoader.GetString(Constants.CancelButton); - string result; + Enums result; if (selectedGridItem != null) { string inputText = selectedGridItem.DisplayName; @@ -629,7 +615,7 @@ private async void RenameFileAsync(object sender) if (storageFiles.FirstOrDefault(f => f.DisplayName == newFileName) == null) { result = await ftpService.RenameFileAsync(currentPath, selectedGridItem.DisplayName, newFileName, username, password).ConfigureAwait(true); - if (result == Constants.Success) + if (result == Enums.Success) { _ = GetItemsAsync(currentPath).ConfigureAwait(true); } diff --git a/FileManager.ViewModels/GoogleDriveViewModel.cs b/FileManager.ViewModels/GoogleDriveViewModel.cs index 1e15bf7..c654f78 100644 --- a/FileManager.ViewModels/GoogleDriveViewModel.cs +++ b/FileManager.ViewModels/GoogleDriveViewModel.cs @@ -334,40 +334,27 @@ public GoogleDriveViewModel() protected override void ChangeColorMode(UISettings uiSettings, object sender) { - var currentBackgroundColor = uiSettings?.GetColorValue(UIColorType.Background); - string resourcePath; - if (backgroundColor != currentBackgroundColor || storageFiles == null) + var colorMode = ThemeService.ChangeColorMode(uiSettings, backgroundColor); + backgroundColor = colorMode.BackgroundColor; + themeResourceLoader = colorMode.ThemeResourceLoader; + if (storageFiles != null) { - if (currentBackgroundColor == Colors.Black) + CoreApplication.MainView.CoreWindow.Dispatcher + .RunAsync(CoreDispatcherPriority.Normal, + () => { - resourcePath = string.Join('\\', Constants.Resources, Constants.ImagesDark); - backgroundColor = Colors.Black; - } - else - { - resourcePath = string.Join('\\', Constants.Resources, Constants.ImagesLight); - backgroundColor = Colors.White; - } - themeResourceLoader = ResourceLoader.GetForViewIndependentUse(resourcePath); - if (storageFiles != null) - { - CoreApplication.MainView.CoreWindow.Dispatcher - .RunAsync(CoreDispatcherPriority.Normal, - () => + foreach (var storageFile in storageFiles) { - foreach (var storageFile in storageFiles) - { - storageFile.ChangeColorMode(themeResourceLoader); - } - }).AsTask().ConfigureAwait(true); - } + storageFile.ChangeColorMode(themeResourceLoader); + } + }).AsTask().ConfigureAwait(true); } } private async Task CheckInternetConnectionAsync() { - string result = await googleDriveService.CheckInternetConnectionAsync(GoogleUri).ConfigureAwait(true); - if (result == Constants.Failed) + Enums result = await googleDriveService.CheckInternetConnectionAsync(GoogleUri).ConfigureAwait(true); + if (result == Enums.Failed) { IsErrorVisible = true; IsCommandPanelVisible = false; @@ -415,8 +402,8 @@ private async Task ExchangeCodeOnTokenAsync(string exchangeCode) { string errorContent; string errorTitle; - string result = await googleDriveService.ExchangeCodeOnTokenAsync(exchangeCode, ClientId, Secret, tokenResult).ConfigureAwait(true); - if (result == Constants.Failed) + Enums result = await googleDriveService.ExchangeCodeOnTokenAsync(exchangeCode, ClientId, Secret, tokenResult).ConfigureAwait(true); + if (result == Enums.Failed) { errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); @@ -480,7 +467,7 @@ private async Task> GetFilesFromGoogleDriveAsync(string fo private async Task GetRootFolderIdAsync() { string result = await googleDriveService.GetRootFolderIdAsync(tokenResult.Token_type, tokenResult.Access_token).ConfigureAwait(true); - if (result == Constants.Failed) + if (result == Enums.Failed.ToString()) { string errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); string errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); @@ -503,11 +490,11 @@ private void CheckFilesForDownloading() private async Task RefreshTokenAsync() { - string result; + Enums result; string errorContent; string errorTitle; result = await googleDriveService.RefreshTokenAsync(ClientId, Secret, tokenResult).ConfigureAwait(true); - if (result == Constants.Failed) + if (result == Enums.Failed) { errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); @@ -549,7 +536,7 @@ private void GetParent(object sender) private async void DownloadFileAsync(object sender) { - string result; + Enums result; string errorContent; string errorTitle; string fileId = selectedGridItem.Id; @@ -571,7 +558,7 @@ private async void DownloadFileAsync(object sender) var downloadingFile = storageFiles.FirstOrDefault(f => f.Id == fileId); if (downloadingFile != null) { - if (result == Constants.Success) + if (result == Enums.Success) { downloadingFile.DownloadStatus = stringsResourceLoader.GetString(Constants.DownloadCompleted); } @@ -606,7 +593,7 @@ private async Task CloseDownloadingAsync(OnlineFileControlViewModel file) private async void UploadFileAsync(object sender) { - string result; + Enums result; string errorContent; string errorTitle; string folderId = currentFolderId; @@ -628,7 +615,7 @@ private async void UploadFileAsync(object sender) await RefreshTokenAsync().ConfigureAwait(true); } result = await googleDriveService.UploadFileAsync(uploadFile, parents, tokenResult.Access_token).ConfigureAwait(true); - if (result == Constants.Success) + if (result == Enums.Success) { if (folderId == currentFolderId) { @@ -647,7 +634,7 @@ private async void UploadFileAsync(object sender) private async void DeleteFileAsync(object sender) { string folderId = currentFolderId; - string result; + Enums result; string errorContent; string errorTitle; if (selectedGridItem != null && !string.IsNullOrEmpty(selectedGridItem.DisplayName)) @@ -667,7 +654,7 @@ private async void DeleteFileAsync(object sender) await RefreshTokenAsync().ConfigureAwait(true); } result = await googleDriveService.DeleteFileAsync(selectedGridItem.Id, tokenResult.Access_token).ConfigureAwait(true); - if (result == Constants.Success) + if (result == Enums.Success) { if (currentFolderId == folderId) { @@ -691,7 +678,7 @@ private async void CreateNewFolderAsync(object sender) string inputText = string.Empty; string primaryButton = stringsResourceLoader.GetString(Constants.CreateButton); string secondaryButton = stringsResourceLoader.GetString(Constants.CancelButton); - string result; + Enums result; string errorContent; string errorTitle; var parents = new Collection() @@ -710,7 +697,7 @@ private async void CreateNewFolderAsync(object sender) await RefreshTokenAsync().ConfigureAwait(true); } result = await googleDriveService.CreateNewFolderAsync(folderName, parents, tokenResult.Access_token).ConfigureAwait(true); - if (result == Constants.Success) + if (result == Enums.Success) { _ = GetItemsAsync(currentFolderId); } @@ -735,7 +722,7 @@ private async void RenameFileAsync(object sender) string placeHolder = stringsResourceLoader.GetString(Constants.PlaceHolderFileName); string primaryButton = stringsResourceLoader.GetString(Constants.YesButton); string secondaryButton = stringsResourceLoader.GetString(Constants.CancelButton); - string result; + Enums result; if (selectedGridItem != null) { string inputText = selectedGridItem.DisplayName; @@ -754,7 +741,7 @@ private async void RenameFileAsync(object sender) await RefreshTokenAsync().ConfigureAwait(true); } result = await googleDriveService.RenameFileAsync(selectedGridItem.Id, fileName, tokenResult.Access_token).ConfigureAwait(true); - if (result == Constants.Success) + if (result == Enums.Success) { _ = GetItemsAsync(currentFolderId); } diff --git a/FileManager.ViewModels/Information/BatteryControlViewModel.cs b/FileManager.ViewModels/Information/BatteryControlViewModel.cs index 2436a95..5734d9e 100644 --- a/FileManager.ViewModels/Information/BatteryControlViewModel.cs +++ b/FileManager.ViewModels/Information/BatteryControlViewModel.cs @@ -9,12 +9,6 @@ namespace FileManager.ViewModels.Information { public class BatteryControlViewModel : InformationControlViewModel { - private const int FullBattery = 100; - private const int BitDischargedBattery = 76; - private const int HalfBattery = 51; - private const int ThirdBattery = 31; - private const int LowBattery = 21; - public BatteryControlViewModel() { Background = "#FFF4B717"; @@ -53,19 +47,19 @@ await CoreApplication.MainView.CoreWindow.Dispatcher Image = batteryResourceLoader.GetString(Constants.BatteryCharge); break; case BatteryStatus.Discharging: - if (ProgressBarValue <= FullBattery && ProgressBarValue > BitDischargedBattery) + if (ProgressBarValue <= (double)Enums.FullBattery && ProgressBarValue > (double)Enums.BitDischargedBattery) { Image = batteryResourceLoader.GetString(Constants.FullBattery); } - else if (ProgressBarValue <= BitDischargedBattery && ProgressBarValue > HalfBattery) + else if (ProgressBarValue <= (double)Enums.BitDischargedBattery && ProgressBarValue > (double)Enums.HalfBattery) { Image = batteryResourceLoader.GetString(Constants.Battery); } - else if (ProgressBarValue <= HalfBattery && ProgressBarValue > ThirdBattery) + else if (ProgressBarValue <= (double)Enums.HalfBattery && ProgressBarValue > (double)Enums.ThirdBattery) { Image = batteryResourceLoader.GetString(Constants.Halfbattery); } - else if (ProgressBarValue <= ThirdBattery && ProgressBarValue > LowBattery) + else if (ProgressBarValue <= (double)Enums.ThirdBattery && ProgressBarValue > (double)Enums.LowBattery) { Image = batteryResourceLoader.GetString(Constants.LowBattery); } diff --git a/FileManager.ViewModels/Libraries/LibrariesBaseViewModel.cs b/FileManager.ViewModels/Libraries/LibrariesBaseViewModel.cs index baa77cf..fafac22 100644 --- a/FileManager.ViewModels/Libraries/LibrariesBaseViewModel.cs +++ b/FileManager.ViewModels/Libraries/LibrariesBaseViewModel.cs @@ -16,6 +16,8 @@ using FileManager.Helpers.Commands; using FileManager.Helpers; using FileManager.Helpers.Validation; +using FileManager.Services; +using FileManager.ViewModels.Factory; namespace FileManager.ViewModels.Libraries { @@ -249,49 +251,37 @@ public LibrariesBaseViewModel(StorageFolder library) protected override void ChangeColorMode(UISettings uiSettings, object sender) { - var currentBackgroundColor = uiSettings?.GetColorValue(UIColorType.Background); - if (backgroundColor != currentBackgroundColor || storageFiles == null) + var colorMode = ThemeService.ChangeColorMode(uiSettings, backgroundColor); + backgroundColor = colorMode.BackgroundColor; + themeResourceLoader = colorMode.ThemeResourceLoader; + if (storageFiles != null) { - if (currentBackgroundColor == Colors.Black) - { - themeResourceLoader = ResourceLoader.GetForViewIndependentUse(string.Join('\\', Constants.Resources, Constants.ImagesDark)); - backgroundColor = Colors.Black; - } - else - { - themeResourceLoader = ResourceLoader.GetForViewIndependentUse(string.Join('\\',Constants.Resources, Constants.ImagesLight)); - backgroundColor = Colors.White; - } - - if (storageFiles != null) + CoreApplication.MainView.CoreWindow.Dispatcher + .RunAsync(CoreDispatcherPriority.Normal, + () => { - CoreApplication.MainView.CoreWindow.Dispatcher - .RunAsync(CoreDispatcherPriority.Normal, - () => + foreach (var storageFile in storageFiles) { - foreach (var storageFile in storageFiles) + switch (storageFile.Type) { - switch (storageFile.Type) - { - case Constants.Image: - storageFile.Image = themeResourceLoader.GetString(Constants.Image); - break; - case Constants.Video: - storageFile.Image = themeResourceLoader.GetString(Constants.Video); - break; - case Constants.Audio: - storageFile.Image = themeResourceLoader.GetString(Constants.Audio); - break; - case Constants.Folder: - storageFile.Image = themeResourceLoader.GetString(Constants.Folder); - break; - default: - storageFile.Image = themeResourceLoader.GetString(Constants.File); - break; - } + case Constants.Image: + storageFile.Image = themeResourceLoader.GetString(Constants.Image); + break; + case Constants.Video: + storageFile.Image = themeResourceLoader.GetString(Constants.Video); + break; + case Constants.Audio: + storageFile.Image = themeResourceLoader.GetString(Constants.Audio); + break; + case Constants.Folder: + storageFile.Image = themeResourceLoader.GetString(Constants.Folder); + break; + default: + storageFile.Image = themeResourceLoader.GetString(Constants.File); + break; } - }).AsTask().ConfigureAwait(true); - } + } + }).AsTask().ConfigureAwait(true); } } @@ -325,32 +315,8 @@ private async Task GetItemsAsync() IReadOnlyList storageFiles = await currentFolder.GetFilesAsync(); foreach (var item in storageFiles) { - FileControlViewModel viewModel = new FileControlViewModel() - { - DisplayName = item.Name, - Path = item.Path, - }; - if (item.ContentType.Contains(Constants.Image, StringComparison.Ordinal)) - { - viewModel.Image = themeResourceLoader.GetString(Constants.Image); - viewModel.Type = Constants.Image; - } - else if (item.ContentType.Contains(Constants.Video, StringComparison.Ordinal)) - { - viewModel.Image = themeResourceLoader.GetString(Constants.Video); - viewModel.Type = Constants.Video; - } - else if (item.ContentType.Contains(Constants.Audio, StringComparison.Ordinal)) - { - viewModel.Image = themeResourceLoader.GetString(Constants.Audio); - viewModel.Type = Constants.Image; - } - else - { - viewModel.Image = themeResourceLoader.GetString(Constants.File); - viewModel.Type = Constants.File; - } - + FileControlViewModel viewModel = FileControlCreator.CreateFileControl(themeResourceLoader, item.DisplayName, + item.ContentType, item.Path); fileControls.Add(viewModel); } StorageFiles = fileControls; diff --git a/FileManager.ViewModels/MainViewModel.cs b/FileManager.ViewModels/MainViewModel.cs index 2deb7ab..fb4175d 100644 --- a/FileManager.ViewModels/MainViewModel.cs +++ b/FileManager.ViewModels/MainViewModel.cs @@ -1,23 +1,18 @@ -using System; -using Windows.ApplicationModel.Resources; +using Windows.ApplicationModel.Resources; using Windows.UI.Xaml.Controls; using Autofac; -using FileManager.Helpers; using FileManager.Dependencies; +using FileManager.Helpers; namespace FileManager.ViewModels { public class MainViewModel : BindableBase { - private const string GoogleDriveIconPath = "ms-appx:///Images/googleDrive.png"; - private const string FtpIconPath = "ms-appx:///Images/ftpFolder.png"; private readonly ResourceLoader resourceLoader; private Page currentContent; private Page googleDrivePage; private string currentTitle; private NavigationViewItem selectedItem; - private Uri googleDriveIconUri; - private Uri ftpIconUri; public Page CurrentContent { @@ -56,38 +51,12 @@ public string CurrentTitle } } } - public Uri GoogleDriveIconUri - { - get => googleDriveIconUri; - set - { - if (googleDriveIconUri != value) - { - googleDriveIconUri = value; - OnPropertyChanged(); - } - } - } - public Uri FtpIconUri - { - get => ftpIconUri; - set - { - if (ftpIconUri != value) - { - ftpIconUri = value; - OnPropertyChanged(); - } - } - } public MainViewModel() { currentContent = (Page)VMDependencies.Container.Resolve(VMDependencies.Views[Constants.MainTitlePage]); resourceLoader = ResourceLoader.GetForCurrentView(Constants.StringResources); CurrentTitle = resourceLoader.GetString(Constants.MainPage); - GoogleDriveIconUri = new Uri(GoogleDriveIconPath); - FtpIconUri = new Uri(FtpIconPath); } private void SelectionChanged() @@ -120,7 +89,7 @@ private void SelectionChanged() } else { - CurrentContent = (Page )VMDependencies.Container.Resolve(VMDependencies.Views[Constants.GoogleDrivePage]); + CurrentContent = (Page)VMDependencies.Container.Resolve(VMDependencies.Views[Constants.GoogleDrivePage]); } } else @@ -134,6 +103,10 @@ private void SelectionChanged() CurrentContent = (Page)VMDependencies.Container.Resolve(VMDependencies.Views[Constants.FtpPage]); CurrentTitle = resourceLoader.GetString(Constants.FtpServer); break; + case "6": + CurrentContent = (Page)VMDependencies.Container.Resolve(VMDependencies.Views[Constants.OneDrivePage]); + CurrentTitle = resourceLoader.GetString(Constants.OneDrivePage); + break; default: CurrentContent = (Page)VMDependencies.Container.Resolve(VMDependencies.Views[Constants.MainTitlePage]); CurrentTitle = resourceLoader.GetString(Constants.MainNavigation); diff --git a/FileManager.ViewModels/OneDriveViewModel.cs b/FileManager.ViewModels/OneDriveViewModel.cs new file mode 100644 index 0000000..34f9b8d --- /dev/null +++ b/FileManager.ViewModels/OneDriveViewModel.cs @@ -0,0 +1,734 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Input; +using ThirdPartyServices.Shared.Models; +using ThirdPartyServices.Shared.Models.Enums; +using ThirdPartyServices.Shared.Models.Responses.Microsoft; +using Windows.ApplicationModel.Core; +using Windows.ApplicationModel.Resources; +using Windows.Storage; +using Windows.Storage.Pickers; +using Windows.UI.Core; +using Windows.UI.Popups; +using Windows.UI.ViewManagement; +using Windows.UI.Xaml.Controls; +using Autofac; +using FileManager.Dependencies; +using FileManager.Helpers; +using FileManager.Helpers.Commands; +using FileManager.Helpers.Factory; +using FileManager.Helpers.Validation; +using FileManager.Models; +using FileManager.Models.Interfaces; +using FileManager.Services; +using FileManager.ViewModels.OnlineFileControls; + +namespace FileManager.ViewModels +{ + public class OneDriveViewModel : BindableBase + { + private const string OneDriveUri = "https://graph.microsoft.com/v1.0/me/drive/items/"; + private readonly MicrosoftAuthParams microsoftParams = new MicrosoftAuthParams() + { + ClientId = "128ced40-e64a-454d-acb4-3752c08a0814", //"4d6596ac-0602-49e6-be9e-ed97fdea89f5", + ClientSecret = "k9k8Q~BzgRKh59sc.C8lZtCyGexcf~NNGdxBudtN", //"Ofq8Q~ARZDOVNJ12brW9nUkIFEFeJ6eHxnA1-caD", + RedirectUri = "http://localhost:3000", + ScopeType = MicrosoftScope.OneDrive + }; + private readonly TokenResult tokenResult; + private readonly ResourceLoader stringsResourceLoader; + private readonly Stack openedFoldersId = new Stack(); + private readonly List downloadingFilesId; + private readonly OneDriveService oneDriveService; + private string loadingText; + private string errorText; + private string currentFolderId; + private Uri webViewCurrentSource; + private bool isCommandPanelVisible; + private bool isLoadingVisible; + private bool isFilesVisible; + private bool isBackButtonAvailable; + private bool isErrorVisible; + private Collection storageFiles; + private OnlineFileControlViewModel selectedGridItem; + private ResourceLoader themeResourceLoader; + private ICommand doubleClickedCommand; + private ICommand getParentCommand; + private ICommand downloadFileCommand; + private ICommand uploadFileCommand; + private ICommand deleteFileCommand; + private ICommand createNewFolderCommand; + private ICommand renameFileCommand; + private ICommand itemClickedCommand; + + public Uri WebViewCurrentSource + { + get => webViewCurrentSource; + set + { + if (webViewCurrentSource != value) + { + webViewCurrentSource = value; + OnPropertyChanged(); + } + } + } + public bool IsCommandPanelVisible + { + get => isCommandPanelVisible; + set + { + if (isCommandPanelVisible != value) + { + isCommandPanelVisible = value; + OnPropertyChanged(); + } + } + } + public bool IsLoadingVisible + { + get => isLoadingVisible; + set + { + if (isLoadingVisible != value) + { + isLoadingVisible = value; + OnPropertyChanged(); + } + } + } + public bool IsFilesVisible + { + get => isFilesVisible; + set + { + if (isFilesVisible != value) + { + isFilesVisible = value; + OnPropertyChanged(); + } + } + } + public bool IsBackButtonAvailable + { + get => isBackButtonAvailable; + set + { + if (isBackButtonAvailable != value) + { + isBackButtonAvailable = value; + OnPropertyChanged(); + } + } + } + public bool IsErrorVisible + { + get => isErrorVisible; + set + { + if (isErrorVisible != value) + { + isErrorVisible = value; + OnPropertyChanged(); + } + } + } + public string LoadingText + { + get => loadingText; + set + { + if (loadingText != value) + { + loadingText = value; + OnPropertyChanged(); + } + } + } + public string ErrorText + { + get => errorText; + set + { + if (errorText != value) + { + errorText = value; + OnPropertyChanged(); + } + } + } + public OnlineFileControlViewModel SelectedGridItem + { + get => selectedGridItem; + set + { + if (selectedGridItem != value) + { + selectedGridItem = value; + OnPropertyChanged(); + } + } + } + public Collection StorageFiles + { + get => storageFiles; + set + { + if (storageFiles != value) + { + storageFiles = value; + OnPropertyChanged(); + } + } + } + public ICommand DoubleClickedCommand + { + get => doubleClickedCommand; + set + { + if (doubleClickedCommand != value) + { + doubleClickedCommand = value; + OnPropertyChanged(); + } + } + } + public ICommand GetParentCommand + { + get => getParentCommand; + set + { + if (getParentCommand != value) + { + getParentCommand = value; + OnPropertyChanged(); + } + } + } + public ICommand DownloadFileCommand + { + get => downloadFileCommand; + set + { + if (downloadFileCommand != value) + { + downloadFileCommand = value; + OnPropertyChanged(); + } + } + } + public ICommand UploadFileCommand + { + get => uploadFileCommand; + set + { + if (uploadFileCommand != value) + { + uploadFileCommand = value; + OnPropertyChanged(); + } + } + } + public ICommand DeleteFileCommand + { + get => deleteFileCommand; + set + { + if (deleteFileCommand != value) + { + deleteFileCommand = value; + OnPropertyChanged(); + } + } + } + public ICommand CreateNewFolderCommand + { + get => createNewFolderCommand; + set + { + if (createNewFolderCommand != value) + { + createNewFolderCommand = value; + OnPropertyChanged(); + } + } + } + public ICommand RenameFileCommand + { + get => renameFileCommand; + set + { + if (renameFileCommand != value) + { + renameFileCommand = value; + OnPropertyChanged(); + } + } + } + public ICommand ItemClickedCommand + { + get => itemClickedCommand; + set + { + if (itemClickedCommand != value) + { + itemClickedCommand = value; + OnPropertyChanged(); + } + } + } + + public OneDriveViewModel() + { + tokenResult = new TokenResult(); + ChangeColorMode(settings, this); + downloadingFilesId = new List(); + oneDriveService = new OneDriveService(); + if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox") + { + ItemClickedCommand = new RelayCommand(OpenFolder); + DoubleClickedCommand = new RelayCommand((o) => { }); + } + else + { + DoubleClickedCommand = new RelayCommand(OpenFolder); + ItemClickedCommand = new RelayCommand((o) => { }); + } + DoubleClickedCommand = new RelayCommand(OpenFolder); + GetParentCommand = new RelayCommand(GetParent); + DownloadFileCommand = new RelayCommand(DownloadFileAsync); + UploadFileCommand = new RelayCommand(UploadFileAsync); + DeleteFileCommand = new RelayCommand(DeleteFileAsync); + CreateNewFolderCommand = new RelayCommand(CreateNewFolderAsync); + RenameFileCommand = new RelayCommand(RenameFileAsync); + stringsResourceLoader = ResourceLoader.GetForCurrentView(Constants.StringResources); + _ = CheckInternetConnectionAsync(); + LoadingText = stringsResourceLoader.GetString(Constants.Loading); + ErrorText = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + _ = OneDriveAuthAsync(); + } + + protected override void ChangeColorMode(UISettings uiSettings, object sender) + { + var colorMode = ThemeService.ChangeColorMode(uiSettings, backgroundColor); + backgroundColor = colorMode.BackgroundColor; + themeResourceLoader = colorMode.ThemeResourceLoader; + if (storageFiles != null) + { + CoreApplication.MainView.CoreWindow.Dispatcher + .RunAsync(CoreDispatcherPriority.Normal, + () => + { + foreach (var storageFile in storageFiles) + { + storageFile.ChangeColorMode(themeResourceLoader); + } + }).AsTask().ConfigureAwait(true); + } + } + + private async Task CheckInternetConnectionAsync() + { + Enums result = await oneDriveService.CheckInternetConnectionAsync(OneDriveUri).ConfigureAwait(true); + if (result == Enums.Failed) + { + IsErrorVisible = true; + IsCommandPanelVisible = false; + } + } + + private async Task OneDriveAuthAsync() + { + string errorContent; + string errorTitle; + var dialog = VMDependencies.Container.Resolve(); + var dialogResult = dialog.ShowAsync(null); + Enums result = await oneDriveService.OneDriveAuthAsync(microsoftParams, tokenResult); + if (result == Enums.Failed) + { + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + IsErrorVisible = true; + } + else if (IsErrorVisible == false) + { + IsLoadingVisible = true; + currentFolderId = "root"; + _ = GetItemsAsync(currentFolderId); + IsCommandPanelVisible = true; + } + dialog.Dismiss(); + } + private async Task GetItemsAsync(string folderId = "") + { + IsFilesVisible = false; + IsLoadingVisible = true; + _ = CheckInternetConnectionAsync(); + ItemsResponse responseFiles = await GetFilesFromOneDriveAsync(folderId).ConfigureAwait(true); + List driveFiles = new List(); + foreach (var driveFile in responseFiles.Value) + { + string type; + if (driveFile.File == null) + { + type = Constants.Folder; + } + else + { + type = driveFile.File.ToString().Split(':', ',')[1].Trim().Replace("\"", ""); + } + var viewModel = OnlineFileControlCreator.CreateFileControl(themeResourceLoader, driveFile.Id, driveFile.Name, type); + if (viewModel.Type == Constants.Folder) + { + var lastIndexOfFolder = driveFiles.FindLastIndex(f => f.Type == Constants.Folder); + driveFiles.Insert(lastIndexOfFolder + 1, viewModel); + } + else + { + driveFiles.Add(viewModel); + } + } + StorageFiles = new Collection(driveFiles); + CheckFilesForDownloading(); + IsLoadingVisible = false; + IsFilesVisible = true; + } + + private async Task GetFilesFromOneDriveAsync(string folderId) + { + ItemsResponse driveFiles; + string errorContent; + string errorTitle; + if (DateTime.Now.Subtract(tokenResult.LastRefreshTime).Seconds >= int.Parse(tokenResult.Expires_in)) + { + await RefreshTokenAsync().ConfigureAwait(true); + } + driveFiles = await oneDriveService.GetFilesAsync(folderId, tokenResult.Access_token).ConfigureAwait(true); + if (driveFiles.Value == null) + { + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + driveFiles.Value = new List(); + } + return driveFiles; + } + private void CheckFilesForDownloading() + { + foreach (var file in storageFiles) + { + if (downloadingFilesId.Exists(id => id == file.Id)) + { + file.IsDownloading = true; + file.DownloadStatus = stringsResourceLoader.GetString(Constants.DownloadingText); + } + } + } + + private async Task RefreshTokenAsync() + { + Enums result; + string errorContent; + string errorTitle; + result = await oneDriveService.RefreshTokenAsync(microsoftParams, tokenResult).ConfigureAwait(true); + if (result == Enums.Failed) + { + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + } + + private void OpenFolder(object sender) + { + if (sender != null) + { + var gridItems = (GridView)sender; + if (gridItems.SelectedItem is OnlineFileControlViewModel selectedItem && !string.IsNullOrEmpty(selectedItem.DisplayName) && selectedItem.Type == Constants.Folder) + { + if (openedFoldersId.Count == 0) + { + IsBackButtonAvailable = true; + } + openedFoldersId.Push(currentFolderId); + currentFolderId = selectedItem.Id; + GetItemsAsync(currentFolderId).ConfigureAwait(true); + } + } + + } + + private void GetParent(object sender) + { + if (openedFoldersId.Count != 0) + { + currentFolderId = openedFoldersId.Pop(); + GetItemsAsync(currentFolderId).ConfigureAwait(true); + if (openedFoldersId.Count == 0) + { + IsBackButtonAvailable = false; + } + } + } + + private async void DownloadFileAsync(object sender) + { + Enums result; + string errorContent; + string errorTitle; + string fileId = selectedGridItem.Id; + if (selectedGridItem != null && !string.IsNullOrEmpty(selectedGridItem.DisplayName) && selectedGridItem.Type != Constants.Folder) + { + StorageFolder downloadFolder = await GetDestinationFolderAsync().ConfigureAwait(true); + if (DateTime.Now.Subtract(tokenResult.LastRefreshTime).Seconds >= int.Parse(tokenResult.Expires_in)) + { + await RefreshTokenAsync().ConfigureAwait(true); + } + SelectedGridItem.IsDownloading = true; + SelectedGridItem.DownloadStatus = stringsResourceLoader.GetString(Constants.DownloadingText); + downloadingFilesId.Add(SelectedGridItem.Id); + result = await oneDriveService.DownloadFileAsync(downloadFolder, selectedGridItem.DisplayName, + selectedGridItem.Id, tokenResult.Access_token).ConfigureAwait(true); + + downloadingFilesId.Remove(fileId); + var downloadingFile = storageFiles.FirstOrDefault(f => f.Id == fileId); + if (downloadingFile != null) + { + if (result == Enums.Success) + { + downloadingFile.DownloadStatus = stringsResourceLoader.GetString(Constants.DownloadCompleted); + } + else + { + downloadingFile.DownloadStatus = stringsResourceLoader.GetString(Constants.Failed); + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + _ = CloseDownloadingAsync(downloadingFile); + } + } + } + private async void UploadFileAsync(object sender) + { + Enums result; + string errorContent; + string errorTitle; + string folderId = currentFolderId; + var picker = new FileOpenPicker + { + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.Downloads + }; + picker.FileTypeFilter.Add("*"); + StorageFile uploadFile = await picker.PickSingleFileAsync(); + if (uploadFile != null) + { + if (DateTime.Now.Subtract(tokenResult.LastRefreshTime).Seconds >= int.Parse(tokenResult.Expires_in)) + { + await RefreshTokenAsync().ConfigureAwait(true); + } + result = await oneDriveService.UploadFileAsync(uploadFile, tokenResult.Access_token).ConfigureAwait(true); + if (result == Enums.Success) + { + if (folderId == currentFolderId) + { + _ = GetItemsAsync(currentFolderId); + } + } + else + { + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + } + } + + private async void DeleteFileAsync(object sender) + { + string folderId = currentFolderId; + Enums result; + string errorContent; + string errorTitle; + if (selectedGridItem != null && !string.IsNullOrEmpty(selectedGridItem.DisplayName)) + { + var contentDialog = new ContentDialog() + { + Title = stringsResourceLoader.GetString(Constants.Confirmation), + Content = stringsResourceLoader.GetString(Constants.DeleteConfirmText) + $" \"{selectedGridItem.DisplayName}\"?", + PrimaryButtonText = stringsResourceLoader.GetString(Constants.YesButton), + CloseButtonText = stringsResourceLoader.GetString(Constants.CancelButton), + }; + var confirmationResult = await contentDialog.ShowAsync(); + if (confirmationResult == ContentDialogResult.Primary) + { + if (DateTime.Now.Subtract(tokenResult.LastRefreshTime).Seconds >= int.Parse(tokenResult.Expires_in)) + { + await RefreshTokenAsync().ConfigureAwait(true); + } + result = await oneDriveService.DeleteFileAsync(selectedGridItem.Id, tokenResult.Access_token).ConfigureAwait(true); + if (result == Enums.Success) + { + if (currentFolderId == folderId) + { + _ = GetItemsAsync(currentFolderId).ConfigureAwait(true); + } + } + else + { + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + } + } + } + + private async void CreateNewFolderAsync(object sender) + { + string dialogTitle = stringsResourceLoader.GetString(Constants.NewFolder); + string placeHolder = stringsResourceLoader.GetString(Constants.PlaceHolderFileName); + string inputText = string.Empty; + string primaryButton = stringsResourceLoader.GetString(Constants.CreateButton); + string secondaryButton = stringsResourceLoader.GetString(Constants.CancelButton); + Enums result; + string errorContent; + string errorTitle; + var contentDialog = CreateInputContentDialog(dialogTitle, placeHolder, inputText, primaryButton, secondaryButton); + var dialogResult = await contentDialog.ShowAsync(); + var gridItem = (ContentDialogControlViewModel)contentDialog.DataContext; + var folderName = gridItem.InputText; + folderName = ValidateItemName(folderName); + if (dialogResult == ContentDialogResult.Primary && !string.IsNullOrEmpty(folderName)) + { + if (DateTime.Now.Subtract(tokenResult.LastRefreshTime).Seconds >= int.Parse(tokenResult.Expires_in)) + { + await RefreshTokenAsync().ConfigureAwait(true); + } + result = await oneDriveService.CreateNewFolderAsync(folderName, currentFolderId, tokenResult.Token_type, tokenResult.Access_token).ConfigureAwait(true); + if (result == Enums.Success) + { + _ = GetItemsAsync(currentFolderId); + } + else + { + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + } + else if (dialogResult == ContentDialogResult.Primary) + { + errorContent = stringsResourceLoader.GetString(Constants.InvalidInput); + errorTitle = stringsResourceLoader.GetString(Constants.InputError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + } + + private async void RenameFileAsync(object sender) + { + string dialogTitle = stringsResourceLoader.GetString(Constants.Rename); + string placeHolder = stringsResourceLoader.GetString(Constants.PlaceHolderFileName); + string primaryButton = stringsResourceLoader.GetString(Constants.YesButton); + string secondaryButton = stringsResourceLoader.GetString(Constants.CancelButton); + Enums result; + if (selectedGridItem != null) + { + string inputText = selectedGridItem.DisplayName; + string errorContent; + string errorTitle; + var contentDialog = CreateInputContentDialog(dialogTitle, placeHolder, inputText, primaryButton, secondaryButton); + var dialogResult = await contentDialog.ShowAsync(); + var gridItem = (ContentDialogControlViewModel)contentDialog.DataContext; + var fileName = gridItem.InputText; + fileName = ValidateItemName(fileName); + + if (dialogResult == ContentDialogResult.Primary && !string.IsNullOrEmpty(fileName)) + { + if (DateTime.Now.Subtract(tokenResult.LastRefreshTime).Seconds >= int.Parse(tokenResult.Expires_in)) + { + await RefreshTokenAsync().ConfigureAwait(true); + } + result = await oneDriveService.RenameFileAsync(selectedGridItem.Id, fileName, tokenResult.Token_type, tokenResult.Access_token).ConfigureAwait(true); + if (result == Enums.Success) + { + _ = GetItemsAsync(currentFolderId); + } + else + { + errorContent = stringsResourceLoader.GetString(Constants.ConnectionErrorContent); + errorTitle = stringsResourceLoader.GetString(Constants.ConnectionError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + } + else if (dialogResult == ContentDialogResult.Primary) + { + errorContent = stringsResourceLoader.GetString(Constants.InvalidInput); + errorTitle = stringsResourceLoader.GetString(Constants.InputError); + _ = ShowMessageDialogAsync(errorContent, errorTitle); + } + } + } + private async Task GetDestinationFolderAsync() + { + var picker = new FolderPicker + { + ViewMode = PickerViewMode.Thumbnail, + SuggestedStartLocation = PickerLocationId.Downloads + }; + picker.FileTypeFilter.Add("*"); + return await picker.PickSingleFolderAsync(); + } + + private async Task CloseDownloadingAsync(OnlineFileControlViewModel file) + { + await Task.Delay(3000).ConfigureAwait(true); + file.IsDownloading = false; + file.DownloadStatus = string.Empty; + } + private async Task ShowMessageDialogAsync(string content, string title) + { + var messageDialog = new MessageDialog(content) + { + Title = title + }; + await messageDialog.ShowAsync(); + } + private ContentDialog CreateInputContentDialog(string title, string placeHolder, string inputText, string primaryButton, string secondaryButton) + { + var parameters = new List() + { + new NamedParameter("title", title), + new NamedParameter("placeHolder", placeHolder), + new NamedParameter("primaryButtonText", primaryButton), + new NamedParameter("secondaryButtonText", secondaryButton), + new NamedParameter("inputText", inputText), + }; + var contentDialog = (ContentDialog)VMDependencies.Container.Resolve(VMDependencies.Views["ContentDialogControl"]); + contentDialog.DataContext = VMDependencies.Container.Resolve(parameters); + return contentDialog; + } + private string ValidateItemName(string itemName) + { + string result = string.Empty; + if (ItemNameValidation.Validate(itemName)) + { + while (itemName.EndsWith(' ')) + { + itemName = itemName.Remove(itemName.Length - 1); + } + while (itemName.StartsWith(' ')) + { + itemName = itemName.Remove(0, 1); + } + result = itemName; + } + return result; + } + } +} diff --git a/FileManager/VMLocator/ViewModelLocator.cs b/FileManager.ViewModels/VMLocator/ViewModelLocator.cs similarity index 76% rename from FileManager/VMLocator/ViewModelLocator.cs rename to FileManager.ViewModels/VMLocator/ViewModelLocator.cs index 724cce2..86cd74a 100644 --- a/FileManager/VMLocator/ViewModelLocator.cs +++ b/FileManager.ViewModels/VMLocator/ViewModelLocator.cs @@ -4,11 +4,11 @@ using System.Linq; using Windows.UI.Xaml; using Autofac; -using FileManager.Controlls; +using FileManager.Dependencies; +using FileManager.Helpers; using FileManager.ViewModels.Libraries; -using FileManager.Views; -namespace FileManager.VMLocator +namespace FileManager.ViewModels.VMLocator { public static class ViewModelLocator { @@ -40,25 +40,25 @@ private static void Bind(DependencyObject view) var viewModelType = FindViewModel(frameworkElement.GetType()); var typesWithoutActivation = new List() { - typeof(FileControl), - typeof(OnlineFileControl), - typeof(InformationControl) + VMDependencies.Views[Constants.FileControl], + VMDependencies.Views[Constants.OnlineFileControl], + VMDependencies.Views[Constants.InformationControl], }; if (!typesWithoutActivation.Any(t => t == frameworkElement.GetType())) { switch (frameworkElement.GetType().Name) { - case nameof(PicturesLibraryPage): - frameworkElement.DataContext = App.Container.Resolve(); + case Constants.PicturesLibraryPage: + frameworkElement.DataContext = VMDependencies.Container.Resolve(); break; - case nameof(VideosLibraryPage): - frameworkElement.DataContext = App.Container.Resolve(); + case Constants.VideosLibraryPage: + frameworkElement.DataContext = VMDependencies.Container.Resolve(); break; - case nameof(MusicsLibraryPage): - frameworkElement.DataContext = App.Container.Resolve(); + case Constants.MusicsLibraryPage: + frameworkElement.DataContext = VMDependencies.Container.Resolve(); break; default: - frameworkElement.DataContext = App.Container.Resolve(viewModelType); + frameworkElement.DataContext = VMDependencies.Container.Resolve(viewModelType); break; } } diff --git a/FileManager/App.xaml b/FileManager/App.xaml index 6cfcd7e..b66a013 100644 --- a/FileManager/App.xaml +++ b/FileManager/App.xaml @@ -3,7 +3,14 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:FileManager"> - - + + + + 16 + + + + + diff --git a/FileManager/App.xaml.cs b/FileManager/App.xaml.cs index a8a7bb7..346dee7 100644 --- a/FileManager/App.xaml.cs +++ b/FileManager/App.xaml.cs @@ -12,6 +12,11 @@ using FileManager.Views; using FileManager.Dependencies; using FileManager.Controlls; +using FileManager.Models.Interfaces; +using ThirdPartyServices.UWP.AuthorizationServices; +using ThirdPartyServices.Shared.Interfaces; +using ThirdPartyServices.UWP.CloudServices; +using ThirdPartyServices.UWP.DataAccess; namespace FileManager { @@ -34,6 +39,7 @@ public App() } private IContainer ConfigureServices() { + ThirdPartyService.Instance.InitializeThirdPartySevices(); var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterType() .AsSelf().WithParameters(new List @@ -49,7 +55,7 @@ private IContainer ConfigureServices() containerBuilder.RegisterType() .AsSelf(); containerBuilder.RegisterType() - .AsSelf(); + .AsSelf(); containerBuilder.RegisterType() .AsSelf(); containerBuilder.RegisterType() @@ -60,6 +66,8 @@ private IContainer ConfigureServices() .AsSelf(); containerBuilder.RegisterType() .AsSelf(); + containerBuilder.RegisterType() + .AsSelf(); containerBuilder.RegisterType().AsSelf(); containerBuilder.RegisterType().AsSelf(); containerBuilder.RegisterType().AsSelf(); @@ -69,9 +77,14 @@ private IContainer ConfigureServices() containerBuilder.RegisterType().AsSelf(); containerBuilder.RegisterType().AsSelf(); containerBuilder.RegisterType().AsSelf(); + containerBuilder.RegisterType().AsSelf(); + + containerBuilder.RegisterType().As(); + containerBuilder.RegisterType().As(); + containerBuilder.RegisterType().As(); VMDependencies.ConfigureServices(typeof(MainPage), typeof(MainTitlePage), typeof(FtpPage), typeof(GoogleDrivePage), typeof(InformationPage), typeof(MusicsLibraryPage), typeof(PicturesLibraryPage), typeof(VideosLibraryPage), - typeof(ContentDialogControl)); + typeof(ContentDialogControl), typeof(OneDrivePage), typeof(FileControl), typeof(InformationControl), typeof(OnlineFileControl)); var container = containerBuilder.Build(); return container; } diff --git a/FileManager/Images/Battery/battery.png b/FileManager/Assets/Images/Battery/battery.png similarity index 100% rename from FileManager/Images/Battery/battery.png rename to FileManager/Assets/Images/Battery/battery.png diff --git a/FileManager/Images/Battery/batteryAttention.png b/FileManager/Assets/Images/Battery/batteryAttention.png similarity index 100% rename from FileManager/Images/Battery/batteryAttention.png rename to FileManager/Assets/Images/Battery/batteryAttention.png diff --git a/FileManager/Images/Battery/batteryCharge.png b/FileManager/Assets/Images/Battery/batteryCharge.png similarity index 100% rename from FileManager/Images/Battery/batteryCharge.png rename to FileManager/Assets/Images/Battery/batteryCharge.png diff --git a/FileManager/Images/Battery/emptyBattery.png b/FileManager/Assets/Images/Battery/emptyBattery.png similarity index 100% rename from FileManager/Images/Battery/emptyBattery.png rename to FileManager/Assets/Images/Battery/emptyBattery.png diff --git a/FileManager/Images/Battery/fullBattery.png b/FileManager/Assets/Images/Battery/fullBattery.png similarity index 100% rename from FileManager/Images/Battery/fullBattery.png rename to FileManager/Assets/Images/Battery/fullBattery.png diff --git a/FileManager/Images/Battery/halfBattery.png b/FileManager/Assets/Images/Battery/halfBattery.png similarity index 100% rename from FileManager/Images/Battery/halfBattery.png rename to FileManager/Assets/Images/Battery/halfBattery.png diff --git a/FileManager/Images/Battery/lowBattery.png b/FileManager/Assets/Images/Battery/lowBattery.png similarity index 100% rename from FileManager/Images/Battery/lowBattery.png rename to FileManager/Assets/Images/Battery/lowBattery.png diff --git a/FileManager/Images/DiskStorage/diskStorage.png b/FileManager/Assets/Images/DiskStorage/diskStorage.png similarity index 100% rename from FileManager/Images/DiskStorage/diskStorage.png rename to FileManager/Assets/Images/DiskStorage/diskStorage.png diff --git a/FileManager/Images/FileIcons/AudioDark.png b/FileManager/Assets/Images/FileIcons/AudioDark.png similarity index 100% rename from FileManager/Images/FileIcons/AudioDark.png rename to FileManager/Assets/Images/FileIcons/AudioDark.png diff --git a/FileManager/Images/FileIcons/AudioLight.png b/FileManager/Assets/Images/FileIcons/AudioLight.png similarity index 100% rename from FileManager/Images/FileIcons/AudioLight.png rename to FileManager/Assets/Images/FileIcons/AudioLight.png diff --git a/FileManager/Images/FileIcons/FileDark.png b/FileManager/Assets/Images/FileIcons/FileDark.png similarity index 100% rename from FileManager/Images/FileIcons/FileDark.png rename to FileManager/Assets/Images/FileIcons/FileDark.png diff --git a/FileManager/Images/FileIcons/FileLight.png b/FileManager/Assets/Images/FileIcons/FileLight.png similarity index 100% rename from FileManager/Images/FileIcons/FileLight.png rename to FileManager/Assets/Images/FileIcons/FileLight.png diff --git a/FileManager/Images/FileIcons/FolderDark.png b/FileManager/Assets/Images/FileIcons/FolderDark.png similarity index 100% rename from FileManager/Images/FileIcons/FolderDark.png rename to FileManager/Assets/Images/FileIcons/FolderDark.png diff --git a/FileManager/Images/FileIcons/FolderLight.jpg b/FileManager/Assets/Images/FileIcons/FolderLight.jpg similarity index 100% rename from FileManager/Images/FileIcons/FolderLight.jpg rename to FileManager/Assets/Images/FileIcons/FolderLight.jpg diff --git a/FileManager/Images/FileIcons/ImageDark.png b/FileManager/Assets/Images/FileIcons/ImageDark.png similarity index 100% rename from FileManager/Images/FileIcons/ImageDark.png rename to FileManager/Assets/Images/FileIcons/ImageDark.png diff --git a/FileManager/Images/FileIcons/ImageLight.png b/FileManager/Assets/Images/FileIcons/ImageLight.png similarity index 100% rename from FileManager/Images/FileIcons/ImageLight.png rename to FileManager/Assets/Images/FileIcons/ImageLight.png diff --git a/FileManager/Images/FileIcons/VideoDark.png b/FileManager/Assets/Images/FileIcons/VideoDark.png similarity index 100% rename from FileManager/Images/FileIcons/VideoDark.png rename to FileManager/Assets/Images/FileIcons/VideoDark.png diff --git a/FileManager/Images/FileIcons/VideoLight.png b/FileManager/Assets/Images/FileIcons/VideoLight.png similarity index 100% rename from FileManager/Images/FileIcons/VideoLight.png rename to FileManager/Assets/Images/FileIcons/VideoLight.png diff --git a/FileManager/Images/ftpFolder.png b/FileManager/Assets/Images/ftpFolder.png similarity index 100% rename from FileManager/Images/ftpFolder.png rename to FileManager/Assets/Images/ftpFolder.png diff --git a/FileManager/Images/googleDrive.png b/FileManager/Assets/Images/googleDrive.png similarity index 100% rename from FileManager/Images/googleDrive.png rename to FileManager/Assets/Images/googleDrive.png diff --git a/FileManager/Assets/Images/onedrive.png b/FileManager/Assets/Images/onedrive.png new file mode 100644 index 0000000..be88e67 Binary files /dev/null and b/FileManager/Assets/Images/onedrive.png differ diff --git a/FileManager/Images/ram.png b/FileManager/Assets/Images/ram.png similarity index 100% rename from FileManager/Images/ram.png rename to FileManager/Assets/Images/ram.png diff --git a/FileManager/Controlls/ContentDialogControl.xaml b/FileManager/Controlls/ContentDialogControl.xaml index 101d694..f6b4c83 100644 --- a/FileManager/Controlls/ContentDialogControl.xaml +++ b/FileManager/Controlls/ContentDialogControl.xaml @@ -6,7 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" Title="{Binding Title}" PrimaryButtonText="{Binding PrimaryButtonContent}" diff --git a/FileManager/Controlls/FileControl.xaml b/FileManager/Controlls/FileControl.xaml index 1aa2e93..8e29a1c 100644 --- a/FileManager/Controlls/FileControl.xaml +++ b/FileManager/Controlls/FileControl.xaml @@ -5,7 +5,7 @@ xmlns:local="using:FileManager.Controlls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" Height="120" Width="120"> diff --git a/FileManager/Controlls/InformationControl.xaml b/FileManager/Controlls/InformationControl.xaml index 0965cd8..445300b 100644 --- a/FileManager/Controlls/InformationControl.xaml +++ b/FileManager/Controlls/InformationControl.xaml @@ -6,7 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" d:DesignHeight="240" d:DesignWidth="440"> diff --git a/FileManager/Controlls/OnlineFileControl.xaml b/FileManager/Controlls/OnlineFileControl.xaml index 01eabc3..40e2f30 100644 --- a/FileManager/Controlls/OnlineFileControl.xaml +++ b/FileManager/Controlls/OnlineFileControl.xaml @@ -5,7 +5,7 @@ xmlns:local="using:FileManager.Controlls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" Height="130" Width="120"> diff --git a/FileManager/Controlls/WebViewDialog.cs b/FileManager/Controlls/WebViewDialog.cs new file mode 100644 index 0000000..1279932 --- /dev/null +++ b/FileManager/Controlls/WebViewDialog.cs @@ -0,0 +1,54 @@ +using FileManager.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml; +using FileManager.Models.Interfaces; + +namespace FileManager.Controlls +{ + [TemplatePart(Name = CancelButtonName, Type = typeof(Button))] + public class WebViewDialog : BaseDialogControl, IAuthWebViewDialog + { + #region Template + private const string CancelButtonName = "CancelButton"; + + private Button cancelButton; + #endregion + + public WebViewDialog() : base() + { + DefaultStyleKey = typeof(WebViewDialog); + Visibility = Visibility.Collapsed; + } + + protected override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + cancelButton = GetTemplateChild(CancelButtonName) as Button; + } + + protected override void OnLoaded(object sender, RoutedEventArgs e) + { + base.OnLoaded(sender, e); + + if (cancelButton != null) + { + cancelButton.Click += OnCancelled; + } + } + + private void OnCancelled(object sender, RoutedEventArgs e) + { + if (cancelButton != null) + { + base.DismissDialog(); + } + } + } +} diff --git a/FileManager/Controlls/WebViewDialog.xaml b/FileManager/Controlls/WebViewDialog.xaml new file mode 100644 index 0000000..b673a56 --- /dev/null +++ b/FileManager/Controlls/WebViewDialog.xaml @@ -0,0 +1,39 @@ + + + + diff --git a/FileManager/FileManager.csproj b/FileManager/FileManager.csproj index 1c13e20..f01d3cd 100644 --- a/FileManager/FileManager.csproj +++ b/FileManager/FileManager.csproj @@ -132,9 +132,13 @@ FileControl.xaml + FtpPage.xaml + + OneDrivePage.xaml + GoogleDrivePage.xaml @@ -156,7 +160,6 @@ VideosLibraryPage.xaml - @@ -165,27 +168,28 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + @@ -216,10 +220,18 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -273,8 +285,6 @@ - - diff --git a/FileManager/Package.appxmanifest b/FileManager/Package.appxmanifest index 828a937..bd6d0ea 100644 --- a/FileManager/Package.appxmanifest +++ b/FileManager/Package.appxmanifest @@ -33,7 +33,7 @@ Executable="$targetnametoken$.exe" EntryPoint="FileManager.App"> diff --git a/FileManager/Views/GoogleDrivePage.xaml b/FileManager/Views/GoogleDrivePage.xaml index 42d2e78..188d149 100644 --- a/FileManager/Views/GoogleDrivePage.xaml +++ b/FileManager/Views/GoogleDrivePage.xaml @@ -6,7 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewmodels="using:FileManager.ViewModels.OnlineFileControls" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" xmlns:Custom="using:FileManager.Controlls" vml:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" diff --git a/FileManager/Views/InformationPage.xaml b/FileManager/Views/InformationPage.xaml index a319b57..28d74b8 100644 --- a/FileManager/Views/InformationPage.xaml +++ b/FileManager/Views/InformationPage.xaml @@ -7,7 +7,7 @@ xmlns:viewmodels="using:FileManager.ViewModels.Information" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> diff --git a/FileManager/Views/MainPage.xaml b/FileManager/Views/MainPage.xaml index ab833b1..2e9258d 100644 --- a/FileManager/Views/MainPage.xaml +++ b/FileManager/Views/MainPage.xaml @@ -4,7 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> @@ -19,12 +19,17 @@ - + - + + + + + + diff --git a/FileManager/Views/MainTitlePage.xaml b/FileManager/Views/MainTitlePage.xaml index 9b3b580..fdbfa1a 100644 --- a/FileManager/Views/MainTitlePage.xaml +++ b/FileManager/Views/MainTitlePage.xaml @@ -5,7 +5,7 @@ xmlns:local="using:FileManager.Views" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:vml ="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> diff --git a/FileManager/Views/MusicsLibraryPage.xaml b/FileManager/Views/MusicsLibraryPage.xaml index 47fab54..5e12cd4 100644 --- a/FileManager/Views/MusicsLibraryPage.xaml +++ b/FileManager/Views/MusicsLibraryPage.xaml @@ -6,7 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewmodels="using:FileManager.ViewModels" - xmlns:vml="using:FileManager.VMLocator" + xmlns:vml="using:FileManager.ViewModels.VMLocator" vml:ViewModelLocator.AutoWireViewModel="True" xmlns:Custom="using:FileManager.Controlls" mc:Ignorable="d" diff --git a/FileManager/Views/OneDrivePage.xaml b/FileManager/Views/OneDrivePage.xaml new file mode 100644 index 0000000..74be337 --- /dev/null +++ b/FileManager/Views/OneDrivePage.xaml @@ -0,0 +1,59 @@ + + + + + + + + + + +