Skip to content

Commit

Permalink
Adding List Types
Browse files Browse the repository at this point in the history
  • Loading branch information
Programming-With-Chris committed Jul 27, 2022
1 parent 9af678d commit 3663d20
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 31 deletions.
9 changes: 9 additions & 0 deletions ShoppingList/Model/UserList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class UserList : ObservableObject
[OneToMany]
public List<Item> Items { get; set; }

public enum ListType
{
WeeklyGrocery,
ForAParty,
OutOfSnacks
}

[Column("type")]
public ListType Type { get; set; }

public UserList()
{
Expand Down
3 changes: 1 addition & 2 deletions ShoppingList/Services/KrogerAPIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ public async Task<Dictionary<string, string>> GetLocationNearZipAsync(string zip
if (res.IsSuccessStatusCode)
{
string content = await res.Content.ReadAsStringAsync();
var fixedContent = content.Replace(@"\", String.Empty);
var jsonRes = JsonSerializer.Deserialize<Root>(fixedContent);
var jsonRes = JsonSerializer.Deserialize<Root>(content);

foreach(var jsonItem in jsonRes.data)
{
Expand Down
18 changes: 12 additions & 6 deletions ShoppingList/View/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
<CollectionView.ItemTemplate >
<DataTemplate x:DataType="model:UserList">
<Grid Padding="10">
<Frame HeightRequest="100">
<Frame>
<Frame.GestureRecognizers>
<TapGestureRecognizer CommandParameter="{Binding .}"
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:UserListViewModel}}, Path=GoToListItemsCommand}"/>
</Frame.GestureRecognizers>
<Label Text="{Binding Name}"/>
<VerticalStackLayout>
<Label Text="{Binding Name}"
FontSize="Medium"/>
<Label Text="{Binding Type}"
FontSize="Micro"
Margin="25,0,0,0"/>
</VerticalStackLayout>
</Frame>
</Grid>
</DataTemplate>
Expand All @@ -32,17 +38,17 @@
<Button Text="Get UserLists"
Command="{Binding GetUserListsCommand}"
IsEnabled="{Binding IsNotBusy}"
TextColor="{StaticResource Primary}"
BackgroundColor="{StaticResource Secondary}"
TextColor="{StaticResource Secondary}"
BackgroundColor="{StaticResource Primary}"
Grid.Row="1"
Margin="8"/>


<Button Text="Create New List"
Command="{Binding CreateUserListCommand}"
IsEnabled="{Binding IsNotBusy}"
TextColor="{StaticResource Primary}"
BackgroundColor="{StaticResource Secondary}"
TextColor="{StaticResource Secondary}"
BackgroundColor="{StaticResource Primary}"
Grid.Row="1"
Grid.Column="3"
Margin="8"/>
Expand Down
22 changes: 22 additions & 0 deletions ShoppingList/View/UserListDataInput.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@
ReturnCommand="{Binding UserListCompletedCommand}"/>


<HorizontalStackLayout>
<Label Text="Type of List: "
TextColor="{StaticResource Primary}"
Margin="0,5,5,0"/>

<Picker ItemsSource="{Binding TypeList}"
SelectedIndexChanged="Picker_SelectedIndexChanged"
TextColor="{StaticResource Primary}"
SelectedIndex="0"/>

</HorizontalStackLayout>


<HorizontalStackLayout>
<Label Text="Pre-populate list with Items from last time?"
TextColor="{StaticResource Primary}"/>

<CheckBox IsChecked="{Binding PrepopulateList}"
Color="{StaticResource Primary}"/>

</HorizontalStackLayout>

</StackLayout>

<Button Text="Create New List"
Expand Down
13 changes: 8 additions & 5 deletions ShoppingList/View/UserListDataInput.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ namespace ShoppingList;

public partial class UserListDataInput : ContentPage
{
private UserListDataInputViewModel _uldiv = new();

public UserListDataInput(UserListDataInputViewModel userListDataInputViewModel)
{
InitializeComponent();
BindingContext = userListDataInputViewModel;
_uldiv = userListDataInputViewModel;

}

/* public void OnUserListNameCompleted(object sender, EventArgs e)
private void Picker_SelectedIndexChanged(object sender, EventArgs e)
{
string name = ((Entry)sender).Text;
var picker = sender as Picker;

Console.WriteLine(name);
Shell.Current.DisplayAlert("Your list name:", name, "Ok");
}*/

_uldiv.UserListType = (UserList.ListType) picker.SelectedIndex;

}
}

8 changes: 4 additions & 4 deletions ShoppingList/View/UserListDetails.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public UserListDetails(UserListDetailViewModel userListDetailViewModel)

public void OnCheckboxClicked(object sender, CheckedChangedEventArgs e )
{
CheckBox thisCheckbox = (CheckBox)sender;
CheckBox thisCheckbox = sender as CheckBox;

Frame currentFrame = (Frame)(thisCheckbox).BindingContext;
Frame currentFrame = thisCheckbox.BindingContext as Frame;

Item itemThatWasClicked = (Item)(currentFrame).BindingContext;
Item itemThatWasClicked = currentFrame.BindingContext as Item;



Expand All @@ -30,7 +30,7 @@ public void OnCheckboxClicked(object sender, CheckedChangedEventArgs e )
else
currentFrame.FadeTo(1, 1000);

itemThatWasClicked.IsCompleted = ((CheckBox)sender).IsChecked;
itemThatWasClicked.IsCompleted = thisCheckbox.IsChecked;
_ulvm.ItemWasChecked(itemThatWasClicked);

}
Expand Down
2 changes: 1 addition & 1 deletion ShoppingList/ViewModel/ItemInputViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async void OnItemEntryCompleted()
newItem.LocationData.ParentId = newItem.Id;
UserList.Items.Add(newItem);

ListSorter.SortUserListItems(UserList);
//ListSorter.SortUserListItems(UserList);
ListSorter.SortUserListItems(userList);

await Shell.Current.GoToAsync($"{nameof(UserListDetails)}?", true,
Expand Down
23 changes: 22 additions & 1 deletion ShoppingList/ViewModel/UserListDataInputViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,38 @@ public UserListDataInputViewModel()
_userListService = new();
}

public List<string> TypeList
{
get
{
return Enum.GetNames(typeof(UserList.ListType)).ToList();
}
}

[ObservableProperty]
public bool prepopulateList;

[ObservableProperty]
private UserList.ListType userListType;


[RelayCommand]
public async void OnUserListCompleted()
{
userList = new();

userList.Name = UlName;
userList.TargetStore = ulTargetStore;
userList.TargetStore = ulTargetStore;
userList.Type = UserListType;

userList = _userListService.CreateUserList(userList);

if (PrepopulateList)
{
Console.WriteLine("Yup");
}


await Shell.Current.GoToAsync("..?id=" + userList.Id + "&createflag=true");

}
Expand Down
14 changes: 2 additions & 12 deletions ShoppingList/ViewModel/UserListDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,15 @@ public void RefreshUserListDetailScreen()

UserList.Items = _itemService.GetUserListItems(UserList);

/*var apiConfig = await _krogerAPIService.GetStartupConfig();
var done = await _krogerAPIService.SetAuthTokens(apiConfig);
foreach (var item in UserList.Items)
{
ItemLocationData ild = await _krogerAPIService.GetProductInfo(item.Name, Preferences.Get("KrogerLocation", "0000000"), apiConfig);
item.LocationData = ild;
}*/

ListSorter.SortUserListItems(userList);
ListSorter.SortUserListItems(UserList);


Items.Clear();
foreach (var item in userList.Items)
{
Items.Add(item);
}

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

IsRefreshing = false;
Expand Down

0 comments on commit 3663d20

Please sign in to comment.