forked from Programming-With-Chris/ShoppingList
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added archived lists functionality - will expand
- Loading branch information
1 parent
03d16d9
commit 50c87dc
Showing
10 changed files
with
225 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:model="clr-namespace:ShoppingList.Model" | ||
xmlns:viewmodel="clr-namespace:ShoppingList.ViewModels" | ||
x:DataType="viewmodel:ArchivedListViewModel" | ||
Title="{Binding Title}" | ||
x:Name="CurrentPage" | ||
BackgroundColor="{DynamicResource Secondary}" | ||
x:Class="ShoppingList.ArchivedListView"> | ||
|
||
<Grid ColumnDefinitions="*,*" | ||
ColumnSpacing="5" | ||
RowDefinitions="*,Auto"> | ||
|
||
<CollectionView Grid.ColumnSpan="2" | ||
ItemsSource="{Binding UserLists}" | ||
SelectionMode="None"> | ||
<CollectionView.ItemTemplate > | ||
<DataTemplate x:DataType="model:UserList"> | ||
<Grid Padding="10"> | ||
<Frame BackgroundColor="{DynamicResource Tertiary}"> | ||
<Frame.GestureRecognizers> | ||
<TapGestureRecognizer CommandParameter="{Binding .}" | ||
Tapped="FrameTapped"/> | ||
</Frame.GestureRecognizers> | ||
<VerticalStackLayout> | ||
<Label Text="{Binding Name}" | ||
FontSize="Medium" | ||
TextColor="{DynamicResource Accent}"/> | ||
<Label Text="{Binding Type}" | ||
FontSize="Micro" | ||
TextColor="{DynamicResource Accent}" | ||
Margin="25,0,0,0"/> | ||
</VerticalStackLayout> | ||
</Frame> | ||
</Grid> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
|
||
</Grid> | ||
|
||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using ShoppingList.ViewModels; | ||
using ShoppingList.Controls; | ||
|
||
namespace ShoppingList; | ||
|
||
public partial class ArchivedListView : ContentPage | ||
{ | ||
ArchivedListViewModel _alvm; | ||
|
||
public ArchivedListView(ArchivedListViewModel archivedListViewModel) | ||
{ | ||
InitializeComponent(); | ||
BindingContext = archivedListViewModel; | ||
_alvm = archivedListViewModel; | ||
_alvm.GetArchivedLists(); | ||
|
||
} | ||
|
||
//There is currently a bug in .net maui where OnAppearing doesn't trigger on Shell Items | ||
// like it should - Leaving this here anyways for when it's fixed | ||
// https://github.com/dotnet/maui/issues/8164 | ||
protected override void OnAppearing() | ||
{ | ||
base.OnAppearing(); | ||
_alvm.GetArchivedLists(); | ||
|
||
} | ||
|
||
private async void FrameTapped(object sender, EventArgs e) | ||
{ | ||
|
||
var frame = sender as Frame; | ||
await frame.ScaleTo(1.1, 75, Easing.BounceIn); | ||
await frame.ScaleTo(1.0, 75, Easing.BounceOut); | ||
|
||
var userList = ((TappedEventArgs)e).Parameter as UserList; | ||
|
||
_alvm.RestoreUserList(userList); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using ShoppingList.Model.Api; | ||
|
||
namespace ShoppingList.ViewModels; | ||
|
||
public partial class ArchivedListViewModel : BaseViewModel | ||
{ | ||
|
||
private UserListService _uls; | ||
private ItemService _itemService; | ||
|
||
public ObservableCollection<UserList> UserLists { get; } = new(); | ||
|
||
public bool CreateFlag { get; set; } = false; | ||
|
||
public ArchivedListViewModel(UserListService userListService, ItemService itemService) | ||
{ | ||
_uls = userListService; | ||
_itemService = itemService; | ||
Title = "My Archived Lists"; | ||
} | ||
|
||
[RelayCommand] | ||
public void GetArchivedLists() | ||
{ | ||
if (IsBusy) | ||
return; | ||
|
||
try | ||
{ | ||
IsBusy = true; | ||
var userLists = _uls.GetArchivedUserLists(); | ||
|
||
if (UserLists.Count != 0) | ||
UserLists.Clear(); | ||
|
||
foreach (var userList in userLists) | ||
{ | ||
UserLists.Add(userList); | ||
} | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
Debug.WriteLine(e); | ||
Shell.Current.DisplayAlert("Error!", | ||
$"Unable to get UserLists: {e.Message}", "Ok"); | ||
} | ||
finally | ||
{ | ||
IsBusy = false; | ||
} | ||
} | ||
[RelayCommand] | ||
public async void CreateUserList() | ||
{ | ||
if (IsBusy) | ||
return; | ||
|
||
|
||
await Shell.Current.GoToAsync($"{nameof(UserListDataInput)}", true, | ||
new Dictionary<string, object> | ||
{ | ||
{"UserLists", UserLists} | ||
}); | ||
|
||
} | ||
|
||
[RelayCommand] | ||
public async void RestoreUserList(UserList restoreList) | ||
{ | ||
if (IsBusy) | ||
return; | ||
|
||
bool shouldRestore = await Shell.Current.DisplayAlert("Restore List?", "Would You Like To Restore This List", | ||
"Yes", "Cancel"); | ||
|
||
if (shouldRestore) | ||
_uls.UnarchiveUserList(restoreList); | ||
|
||
|
||
GetArchivedLists(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters