Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -38,9 +38,9 @@ public Dictionary<string, int> GetUserTopPurchases([FromUri] string userName, [F
.Select(group => new
{
ItemName = group.Key,
Sum = (int)group.Sum(x => x.Price)
})).Take(5)
.OrderByDescending(x => x.Sum)
Sum = (int)group.Count()
}))
.OrderByDescending(x => x.Sum).Take(5)
.ToDictionary(g => g.ItemName, g => g.Sum);

return userPurchases;
Expand Down
176 changes: 91 additions & 85 deletions PriceCompEngn/PriceCompEngnMobile/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ProgressBar
android:id="@+id/load_progress"
style="android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Search" />
<Button
android:id="@+id/user_top_items"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Your most frequent items" />
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
Expand Down
30 changes: 29 additions & 1 deletion PriceCompEngn/PriceCompEngnMobile/ShoppingCartActivity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Android.App;
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Views;
Expand All @@ -16,6 +16,7 @@ namespace PriceCompEngnMobile
public class ShoppingCartActivity : Activity
{
private List<KeyValuePair<string, double>> _args = new List<KeyValuePair<string, double>>();
private List<KeyValuePair<string, double>> userTop = new List<KeyValuePair<string, double>>();

protected override void OnCreate(Bundle savedInstanceState)
{
Expand All @@ -25,6 +26,7 @@ protected override void OnCreate(Bundle savedInstanceState)
SetContentView(Resource.Layout.activity_shopcart);

SetInitialListValues();
GetUserTopBuys();

Button add_item = FindViewById<Button>(Resource.Id.add_item);

Expand All @@ -40,6 +42,7 @@ protected override void OnCreate(Bundle savedInstanceState)
ListView searchResults = promtView.FindViewById<ListView>(Resource.Id.search_items_list);
Button searchButton = promtView.FindViewById<Button>(Resource.Id.search_button);
EditText searchText = promtView.FindViewById<EditText>(Resource.Id.search_items_text);
Button userTopButton = promtView.FindViewById<Button>(Resource.Id.user_top_items);

searchButton.Click += delegate
{
Expand All @@ -51,6 +54,13 @@ protected override void OnCreate(Bundle savedInstanceState)
ExecuteSearchAsync(searchResults, uriBuilder);
};

userTopButton.Click += delegate
{
ShopItemListAdapter adapter = new ShopItemListAdapter(this, Resource.Id.search_items_list, userTop);

searchResults.Adapter = adapter;
};

AlertDialog dialog = builder.Create();
dialog.Show();

Expand Down Expand Up @@ -96,6 +106,24 @@ protected override void OnCreate(Bundle savedInstanceState)
};
}

private async void GetUserTopBuys()
{
PCEUriBuilder uriBuilder = new PCEUriBuilder(ServiceClient.Resources.Purchases);
uriBuilder.AppendStringArgs(new Dictionary<string, string>()
{
{ "userName", MainMenuActivity.User.UserName },
{ "days", "50" }
});
string response = await (new RestRequestExecutor()).ExecuteRestGetRequest(uriBuilder);

string[] items = JsonConvert.DeserializeObject<Dictionary<string, int>>(response).Keys.ToArray();
uriBuilder = new PCEUriBuilder(ServiceClient.Resources.MoreItems);
uriBuilder.AppendArrayArgs("itemNames", items);

string newResponse = await (new RestRequestExecutor()).ExecuteRestGetRequest(uriBuilder);
userTop = JsonConvert.DeserializeObject<List<KeyValuePair<string, double>>>(newResponse);
}

private async void SetInitialListValues()
{
Bundle args = Intent.Extras;
Expand Down
Loading