Skip to content

Commit

Permalink
A few small cleanup items - getting closer to working on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Programming-With-Chris committed Aug 16, 2022
1 parent a6284cb commit 0a8d153
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
26 changes: 16 additions & 10 deletions ShoppingList/View/UserListDetails.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Maui.Graphics.Platform;
//using Microsoft.Maui.Graphics.Platform;
using System.Reflection;
using ShoppingList.ViewModels;
using IImage = Microsoft.Maui.Graphics.IImage;
Expand All @@ -9,6 +9,8 @@ public partial class UserListDetails : ContentPage
{
UserListDetailViewModel _ulvm;

bool _firstTime = true;

public UserListDetails(UserListDetailViewModel userListDetailViewModel)
{
InitializeComponent();
Expand All @@ -23,35 +25,39 @@ public UserListDetails(UserListDetailViewModel userListDetailViewModel)
circularButton.Width = 75;
circularButton.Height = 75;

IImage image;
Assembly assembly = GetType().GetTypeInfo().Assembly;
using (Stream stream = assembly.GetManifestResourceStream("ShoppingList.Resources.Images.plus_solid.svg"))
{
image = PlatformImage.FromStream(stream);
}
circularButton.Image = image;
//IImage image;
//Assembly assembly = GetType().GetTypeInfo().Assembly;
//using (Stream stream = assembly.GetManifestResourceStream("ShoppingList.Resources.Images.plus_solid.svg"))
//{
// image = PlatformImage.FromStream(stream);
//}
//circularButton.Image = image;
circularButtonGV.Invalidate();


}

public void OnCheckboxClicked(object sender, CheckedChangedEventArgs e)
{
if (_ulvm.PreventCheckEvent == true)
return;

CheckBox thisCheckbox = sender as CheckBox;

Frame currentFrame = thisCheckbox.BindingContext as Frame;

Item itemThatWasClicked = currentFrame.BindingContext as Item;



if (thisCheckbox.IsChecked)
currentFrame.FadeTo(.4, 1000);
else
currentFrame.FadeTo(1, 1000);

itemThatWasClicked.IsCompleted = thisCheckbox.IsChecked;
//thisCheckbox.CheckedChanged -= OnCheckboxClicked;
//itemThatWasClicked.IsCompleted = thisCheckbox.IsChecked;
_ulvm.ItemWasChecked(itemThatWasClicked);
//thisCheckbox.CheckedChanged += OnCheckboxClicked;

}

Expand Down
47 changes: 20 additions & 27 deletions ShoppingList/ViewModel/UserListDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace ShoppingList.ViewModels;
Expand All @@ -9,6 +10,8 @@ public partial class UserListDetailViewModel : BaseViewModel
readonly ItemService _itemService;
readonly KrogerAPIService _krogerAPIService;

public bool PreventCheckEvent { get; set; } = false;

public UserListDetailViewModel()
{
_itemService = new();
Expand Down Expand Up @@ -40,24 +43,6 @@ public UserList UserList
[ObservableProperty]
public bool isRefreshing;

[RelayCommand]
public async void CreateItem(UserList ul)
{
if (IsBusy)
return;

var newItem = new Item();
newItem.Name = "new item";
ul.Items.Add(newItem);
ul = ul;

/*await Shell.Current.GoToAsync($"{nameof(ItemInput)}", true,
new Dictionary<string, object>
{
{"UserList", userList}
}); */
}

[RelayCommand]
public async void GoBackToListScreen()
{
Expand All @@ -80,8 +65,7 @@ public void RefreshUserListDetailScreen()

ListSorter.SortUserListItems(userList);

// Forces CollectionView to update on refresh, otherwise, it doesn't work!
UserList = UserList;
UserListNotifers();

IsRefreshing = false;
}
Expand All @@ -95,13 +79,12 @@ await Shell.Current.DisplayAlert(item.Name, $"Category: {item.Category} \nDescri

[RelayCommand]
public void ItemWasChecked(Item item)
{
{
_itemService.UpdateItem(item);

UserList.Items = ListSorter.SortUserListItems(userList);

//This forces on check to refresh collection view, but breaks opening a list for some reason
//UserList = UserList;
//UserListNotifers();

}

Expand All @@ -113,8 +96,8 @@ public void DeleteItem(Item item)

UserList.Items = ListSorter.SortUserListItems(userList);

UserList = UserList;

//UserList = UserList;
UserListNotifers();
}

[RelayCommand]
Expand Down Expand Up @@ -167,9 +150,19 @@ public async void OnItemEntryCompleted(string itemName)
ListSorter.SortUserListItems(userList);


UserList = UserList;
//UserList = UserList;
UserListNotifers();

}

private void UserListNotifers()
{
PreventCheckEvent = true;
OnUserListChanged(UserList);
OnPropertyChanged(nameof(UserList));
OnPropertyChanged(nameof(UserList.Items));
PreventCheckEvent = false;
}
}


0 comments on commit 0a8d153

Please sign in to comment.