-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudyPlanPage.xaml.cs
135 lines (114 loc) · 4.99 KB
/
StudyPlanPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace ExamPrep
{
public partial class StudyPlanPage : ContentPage
{
public QuestionTemplate CurrentTemplate { get; set; }
public StudyPlanPage()
{
InitializeComponent();
NavigationPage.SetBackButtonTitle(this, "Study Plans");
if (AppCache.ItemPressedCount > 0)
RefreshList();
++AppCache.ItemPressedCount;
}
async void OnItemTapped(object sender, ItemTappedEventArgs e)
{
var itemSet = e.Item as StudyPlan;
if (itemSet == null) return;
if (AppCache.QuestionCache != null && Application.Current.Properties.ContainsKey("QuestionTemplate"))
{
object currentTemplate = null;
if (Application.Current.Properties.TryGetValue("QuestionTemplate", out currentTemplate))
{
var currTemplate = currentTemplate as QuestionTemplate;
List<Question> retList = null;
if (currTemplate != null && AppCache.QuestionCache != null && AppCache.QuestionCache.ContainsKey(currTemplate.UniqueGuid))
{
CurrentTemplate = currTemplate;
if (AppCache.QuestionCache.TryGetValue(currTemplate.UniqueGuid, out retList))
{
if (retList != null)
{
RefreshList(); //Saw some random error and adding this line to fix it
await Navigation.PushAsync(new QuestionListPage(retList, itemSet.Category, AppEnums.QuestionListFilter.StudyPlan));
return;
}
}
}
}
}
var list = await AppCache.GetData(null, null);
if (list != null && list.Count > 0)
RefreshList(); //Saw some random error and adding this line to fix it
await Navigation.PushAsync(new QuestionListPage(list, itemSet.Category, AppEnums.QuestionListFilter.StudyPlan));
}
private void RefreshList()
{
if (AppCache.QuestionCache != null && Application.Current.Properties.ContainsKey("QuestionTemplate"))
{
object currentTemplate = null;
if (Application.Current.Properties.TryGetValue("QuestionTemplate", out currentTemplate))
{
var currTemplate = currentTemplate as QuestionTemplate;
List<Question> retList = null;
if (currTemplate != null && AppCache.QuestionCache != null &&
AppCache.QuestionCache.ContainsKey(currTemplate.UniqueGuid))
{
CurrentTemplate = currTemplate;
if (AppCache.QuestionCache.TryGetValue(currTemplate.UniqueGuid, out retList))
{
if (retList != null)
{
foreach (var item in retList)
{
item.Refresh();
}
}
}
}
}
}
}
private void SaveInCache(List<Question> list)
{
if (CurrentTemplate == null)
{
object currentTemplate = null;
if (Application.Current.Properties.TryGetValue("QuestionTemplate", out currentTemplate))
{
var currTemplate = currentTemplate as QuestionTemplate;
if (currentTemplate != null)
{
CurrentTemplate = currTemplate;
}
else
{
//throw application wide exception
}
}
}
if (CurrentTemplate != null && !AppCache.QuestionCache.ContainsKey(CurrentTemplate.UniqueGuid))
{
AppCache.QuestionCache.Add(CurrentTemplate.UniqueGuid, list);
}
else
{
//throw application wide exception
}
}
async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
}
protected override bool OnBackButtonPressed()
{
base.OnBackButtonPressed();
return true;
}
}
}