From b7d8606c8659a32d0916028d449aa02a250c8522 Mon Sep 17 00:00:00 2001 From: DecaTec Date: Tue, 30 May 2017 11:12:57 +0200 Subject: [PATCH] Files/folders can now be marked as favorite from within the app --- .../Converter/FavoriteToIconConverter.cs | 2 +- .../Converter/SyncInfoStoragePathConverter.cs | 3 -- NextcloudApp/Services/DirectoryService.cs | 12 +++++- NextcloudApp/Themes/HelpButtonStyle.xaml | 13 +++++++ NextcloudApp/Utils/ObservableSettings.cs | 2 +- .../ViewModels/DirectoryListPageViewModel.cs | 16 ++++++++ NextcloudApp/Views/DirectoryListPage.xaml | 7 +++- NextcloudClient/NextcloudClient.cs | 39 +++++++++++++++++-- 8 files changed, 84 insertions(+), 10 deletions(-) diff --git a/NextcloudApp/Converter/FavoriteToIconConverter.cs b/NextcloudApp/Converter/FavoriteToIconConverter.cs index b19d835..71480a6 100644 --- a/NextcloudApp/Converter/FavoriteToIconConverter.cs +++ b/NextcloudApp/Converter/FavoriteToIconConverter.cs @@ -9,7 +9,7 @@ namespace NextcloudApp.Converter public object Convert(object value, Type targetType, object parameter, string language) { var item = (ResourceInfo)value; - return item.IsFavorite ? "\uE735" : ""; + return item.IsFavorite ? "\uE735" : "\uE734"; } public object ConvertBack(object value, Type targetType, object parameter, string language) diff --git a/NextcloudApp/Converter/SyncInfoStoragePathConverter.cs b/NextcloudApp/Converter/SyncInfoStoragePathConverter.cs index 030d770..f642eb3 100644 --- a/NextcloudApp/Converter/SyncInfoStoragePathConverter.cs +++ b/NextcloudApp/Converter/SyncInfoStoragePathConverter.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; using System.Threading.Tasks; using Windows.Storage; using Windows.Storage.AccessCache; diff --git a/NextcloudApp/Services/DirectoryService.cs b/NextcloudApp/Services/DirectoryService.cs index bddfc87..180fa63 100644 --- a/NextcloudApp/Services/DirectoryService.cs +++ b/NextcloudApp/Services/DirectoryService.cs @@ -84,7 +84,7 @@ namespace NextcloudApp.Services GroupBySizeDescending(); break; case GroupMode.GroupByTypeAscending: - GroupByTypeAscending(); + GroupByTypeAscending(); break; case GroupMode.GroupByTypeDescending: GroupByTypeDescending(); @@ -579,5 +579,15 @@ namespace NextcloudApp.Services } return success; } + + public async Task ToggleFavorite(ResourceInfo resourceInfo) + { + var client = await ClientService.GetClient(); + + if (client == null) + return; + + await client.ToggleFavorite(resourceInfo); + } } } diff --git a/NextcloudApp/Themes/HelpButtonStyle.xaml b/NextcloudApp/Themes/HelpButtonStyle.xaml index b197180..30af9b9 100644 --- a/NextcloudApp/Themes/HelpButtonStyle.xaml +++ b/NextcloudApp/Themes/HelpButtonStyle.xaml @@ -27,4 +27,17 @@ + + diff --git a/NextcloudApp/Utils/ObservableSettings.cs b/NextcloudApp/Utils/ObservableSettings.cs index 6ba08c2..0c679a3 100644 --- a/NextcloudApp/Utils/ObservableSettings.cs +++ b/NextcloudApp/Utils/ObservableSettings.cs @@ -28,7 +28,7 @@ namespace NextcloudApp.Utils public event PropertyChangedEventHandler PropertyChanged; - protected async Task Set(T value, [CallerMemberName] string propertyName = null) + protected bool Set(T value, [CallerMemberName] string propertyName = null) { if (_applicationDataContainer.Values.ContainsKey(propertyName)) { diff --git a/NextcloudApp/ViewModels/DirectoryListPageViewModel.cs b/NextcloudApp/ViewModels/DirectoryListPageViewModel.cs index dc30583..49b352e 100644 --- a/NextcloudApp/ViewModels/DirectoryListPageViewModel.cs +++ b/NextcloudApp/ViewModels/DirectoryListPageViewModel.cs @@ -56,6 +56,7 @@ namespace NextcloudApp.ViewModels public ICommand MoveSelectedCommand { get; private set; } public ICommand PinToStartCommand { get; private set; } public ICommand SelectToggleCommand { get; private set; } + public ICommand ToggleFavoriteCommand { get; private set; } public DirectoryListPageViewModel(INavigationService navigationService, IResourceLoader resourceLoader, DialogService dialogService) { @@ -148,6 +149,7 @@ namespace NextcloudApp.ViewModels MoveSelectedCommand = new RelayCommand(MoveSelected); //PinToStartCommand = new DelegateCommand(PinToStart, CanPinToStart); PinToStartCommand = new DelegateCommand(PinToStart); + ToggleFavoriteCommand = new RelayCommand(ToggleFavorite); } public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary viewModelState) @@ -578,6 +580,20 @@ namespace NextcloudApp.ViewModels _navigationService.Navigate(PageToken.FileUpload.ToString(), parameters.Serialize()); } + private async void ToggleFavorite(object parameter) + { + var res = parameter as ResourceInfo; + + if (res == null) + return; + + ShowProgressIndicator(); + await Directory.ToggleFavorite(res); + await Directory.Refresh(); + HideProgressIndicator(); + SelectedFileOrFolder = null; + } + private async void CreateDirectory() { while (true) diff --git a/NextcloudApp/Views/DirectoryListPage.xaml b/NextcloudApp/Views/DirectoryListPage.xaml index b09ff14..b694914 100644 --- a/NextcloudApp/Views/DirectoryListPage.xaml +++ b/NextcloudApp/Views/DirectoryListPage.xaml @@ -240,9 +240,13 @@ Foreground="{StaticResource SystemControlForegroundBaseMediumBrush}"/> - + + diff --git a/NextcloudClient/NextcloudClient.cs b/NextcloudClient/NextcloudClient.cs index e790d3d..8d993dc 100644 --- a/NextcloudClient/NextcloudClient.cs +++ b/NextcloudClient/NextcloudClient.cs @@ -518,11 +518,44 @@ namespace NextcloudClient return await _dav.DownloadFileWithProgressAsync(GetDavUriZip(path), localStream, progress, cancellationToken); } -#endregion + public async Task ToggleFavorite(ResourceInfo res) + { + var path = GetParentPath(res); -#region Nextcloud + var items = await _dav.ListAsync(GetDavUri(path, true), nextcloudPropFind); + var item = items.Where(x => x.Name == res.Name).FirstOrDefault(); -#region Remote Shares + if (item == null) + return false; + + var favString = item.AdditionalProperties[NextcloudPropNameConstants.Favorite]; + + if (string.IsNullOrEmpty(favString) || string.CompareOrdinal(favString, "0") == 0) + item.AdditionalProperties[NextcloudPropNameConstants.Favorite] = "1"; + else + item.AdditionalProperties[NextcloudPropNameConstants.Favorite] = "0"; + + return await _dav.UpdateItemAsync(item); + } + + private static string GetParentPath(ResourceInfo resourceInfo) + { + var path = resourceInfo.Path.TrimEnd('/'); + var split = path.Split('/'); + + if (resourceInfo.IsDirectory) + path = "/" + split[split.Length - 2]; + else + path = "/" + split[split.Length - 1]; + + return path; + } + + #endregion + + #region Nextcloud + + #region Remote Shares /// /// Gets the server status.