2016-05-18 06:09:20 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2016-05-19 06:30:46 +03:00
|
|
|
|
using System.Linq;
|
2016-05-18 06:09:20 +03:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Controls;
|
|
|
|
|
using Bit.App.Models.Page;
|
|
|
|
|
using Bit.App.Resources;
|
2016-05-19 06:30:46 +03:00
|
|
|
|
using Bit.App.Utilities;
|
2016-05-18 06:09:20 +03:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
2016-06-28 02:53:31 +03:00
|
|
|
|
public class SettingsListFoldersPage : ExtendedContentPage
|
2016-05-18 06:09:20 +03:00
|
|
|
|
{
|
|
|
|
|
private readonly IFolderService _folderService;
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
public SettingsListFoldersPage()
|
|
|
|
|
{
|
|
|
|
|
_folderService = Resolver.Resolve<IFolderService>();
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-19 06:30:46 +03:00
|
|
|
|
public ExtendedObservableCollection<SettingsFolderPageModel> Folders { get; private set; } = new ExtendedObservableCollection<SettingsFolderPageModel>();
|
2016-05-18 06:09:20 +03:00
|
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(new AddFolderToolBarItem(this));
|
|
|
|
|
|
|
|
|
|
var listView = new ListView
|
|
|
|
|
{
|
2016-06-17 07:01:25 +03:00
|
|
|
|
ItemsSource = Folders
|
2016-05-18 06:09:20 +03:00
|
|
|
|
};
|
|
|
|
|
listView.ItemSelected += FolderSelected;
|
|
|
|
|
listView.ItemTemplate = new DataTemplate(() => new SettingsFolderListViewCell(this));
|
|
|
|
|
|
|
|
|
|
Title = "Folders";
|
|
|
|
|
Content = listView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
|
|
|
|
LoadFoldersAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadFoldersAsync()
|
|
|
|
|
{
|
|
|
|
|
var folders = await _folderService.GetAllAsync();
|
2016-08-03 01:45:25 +03:00
|
|
|
|
var pageFolders = folders.Select(f => new SettingsFolderPageModel(f)).OrderBy(f => f.Name);
|
2016-05-19 06:30:46 +03:00
|
|
|
|
Folders.ResetWithRange(pageFolders);
|
2016-05-18 06:09:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FolderSelected(object sender, SelectedItemChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var folder = e.SelectedItem as SettingsFolderPageModel;
|
|
|
|
|
var page = new ExtendedNavigationPage(new SettingsEditFolderPage(folder.Id));
|
|
|
|
|
Navigation.PushModalAsync(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class AddFolderToolBarItem : ToolbarItem
|
|
|
|
|
{
|
|
|
|
|
private readonly SettingsListFoldersPage _page;
|
|
|
|
|
|
|
|
|
|
public AddFolderToolBarItem(SettingsListFoldersPage page)
|
|
|
|
|
{
|
|
|
|
|
_page = page;
|
|
|
|
|
Text = AppResources.Add;
|
2016-06-15 05:19:40 +03:00
|
|
|
|
Icon = "plus";
|
2016-05-18 06:09:20 +03:00
|
|
|
|
Clicked += ClickedItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void ClickedItem(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var page = new ExtendedNavigationPage(new SettingsAddFolderPage());
|
|
|
|
|
await _page.Navigation.PushModalAsync(page);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class SettingsFolderListViewCell : ExtendedTextCell
|
|
|
|
|
{
|
|
|
|
|
public SettingsFolderListViewCell(SettingsListFoldersPage page)
|
|
|
|
|
{
|
|
|
|
|
this.SetBinding<SettingsFolderPageModel>(TextProperty, s => s.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|