Merge pull request #168 from DecaTec/master
Files/folders can now be marked as favorite from within the app
This commit is contained in:
Коммит
cef086b84e
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,17 @@
|
|||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="FavoriteButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Grid Background="{TemplateBinding Background}">
|
||||
<ContentPresenter />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace NextcloudApp.Utils
|
|||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected async Task<bool> Set<T>(T value, [CallerMemberName] string propertyName = null)
|
||||
protected bool Set<T>(T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (_applicationDataContainer.Values.ContainsKey(propertyName))
|
||||
{
|
||||
|
|
|
@ -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<object>(PinToStart, CanPinToStart);
|
||||
PinToStartCommand = new DelegateCommand<object>(PinToStart);
|
||||
ToggleFavoriteCommand = new RelayCommand(ToggleFavorite);
|
||||
}
|
||||
|
||||
public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> 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)
|
||||
|
|
|
@ -240,9 +240,13 @@
|
|||
Foreground="{StaticResource SystemControlForegroundBaseMediumBrush}"/>
|
||||
</StackPanel>
|
||||
|
||||
<FontIcon
|
||||
<Button
|
||||
Grid.Column="2"
|
||||
Grid.RowSpan="2"
|
||||
Style="{StaticResource FavoriteButtonStyle}"
|
||||
Command="{Binding DataContext.ToggleFavoriteCommand, ElementName=Page, Mode=OneTime}"
|
||||
CommandParameter="{Binding}">
|
||||
<FontIcon
|
||||
Glyph="{Binding Converter={StaticResource FavoriteToIconConverter}}"
|
||||
Margin="10,0,10,0"
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
|
@ -250,6 +254,7 @@
|
|||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="{StaticResource SystemControlHighlightAccentBrush}"/>
|
||||
</Button>
|
||||
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="Holding">
|
||||
|
|
|
@ -518,11 +518,44 @@ namespace NextcloudClient
|
|||
return await _dav.DownloadFileWithProgressAsync(GetDavUriZip(path), localStream, progress, cancellationToken);
|
||||
}
|
||||
|
||||
#endregion
|
||||
public async Task<bool> 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
|
||||
|
||||
/// <summary>
|
||||
/// Gets the server status.
|
||||
|
|
Загрузка…
Ссылка в новой задаче