-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoMockTestFragment.cs
132 lines (113 loc) · 5.65 KB
/
DoMockTestFragment.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.V4.App;
using Android.Support.V7.Widget;
using Android.Util;
using Android.Views;
using Android.Widget;
using Newtonsoft.Json;
using ImageSlider.Model;
using Refit;
using ImageSlider.Connection;
namespace ImageSlider.MyTest
{
public class DoMockTestFragment : Fragment
{
Android.Support.V7.Widget.RecyclerView mRecycleView;
RecyclerView.LayoutManager mLayoutManager;
List<AllTestModelData> AllTestList;
public static string question;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
// return inflater.Inflate(Resource.Layout.YourFragment, container, false);
base.OnCreateView(inflater, container, savedInstanceState);
View v = inflater.Inflate(Resource.Layout.DoOnlineTestFragment, container, false);
// var AllTestlistserlizeRecord = Arguments.GetString("AllTestList");
AllTestList = JsonConvert.DeserializeObject<List<AllTestModelData>>(MyTest.myFinalMOckTestlistserilize);
mRecycleView = v.FindViewById<RecyclerView>(Resource.Id.onlinetestlist);
mLayoutManager = new LinearLayoutManager(this.Activity);
mRecycleView.SetLayoutManager(mLayoutManager);
DoOnlineTestAapter mAdapter = new DoOnlineTestAapter(this.Activity, mRecycleView, AllTestList);
mAdapter.ItemClick += MAdapter_ItemClick;
mRecycleView.SetAdapter(mAdapter);
return v;
}
private void MAdapter_ItemClick(object sender, int e)
{
int photoNum = e + 1;
//Toast.MakeText(this.Activity, "This is item number " + photoNum, ToastLength.Short).Show();
if (!AllTestList[e].Text.Equals("Taken"))
{
var intent = new Intent(this.Activity, typeof(TestInstruction));
intent.PutExtra("TestID", AllTestList[e].ID);
intent.PutExtra("TestName", AllTestList[e].Title);
intent.PutExtra("TestDuration", AllTestList[e].Duration);
intent.PutExtra("testtype", "mock");
Activity.StartActivityForResult(intent, 101);
Activity.OverridePendingTransition(Resource.Animation.slide_left, Resource.Animation.hold);
}
else
{
try
{
ISharedPreferences pref = Activity.GetSharedPreferences(AllTestList[e].ID + "", FileCreationMode.Private);
ISharedPreferencesEditor edit = pref.Edit();
string path = pref.GetString("path", String.Empty);
if (path.Length > 0)
{
FetchSumaryFromServer(AllTestList[e].ID);
//string item = pref.GetString("item", String.Empty);
//question = pref.GetString("TestRecord", String.Empty);
//string startingquestionposition = pref.GetString("startingquestionposition", String.Empty);
//var intent = new Intent(Activity, typeof(TestSummary));
//intent.PutExtra("path", path);
//intent.PutExtra("item", item);
//intent.PutExtra("startingquestionposition", startingquestionposition);
//Activity.StartActivityForResult(intent, 102);
//Activity.OverridePendingTransition(Resource.Animation.slide_left, Resource.Animation.hold);
}
else
{
FetchSumaryFromServer(AllTestList[e].ID);
//Toast.MakeText(Activity, "You had already given this test", ToastLength.Short).Show();
}
}
catch (Exception)
{
FetchSumaryFromServer(AllTestList[e].ID);
//Toast.MakeText(Activity, "You had already given this test", ToastLength.Short).Show();
}
//Toast.MakeText(Activity, "You had already given this test", ToastLength.Short).Show();
}
}
async void FetchSumaryFromServer(int testid)
{
CustomProgressDialog cpd = new CustomProgressDialog(Activity);
cpd.SetCancelable(false);
cpd.Show();
var apiresponse = RestService.For<ApiConnectionForTestPackage>(Utility.stapibaseUrl);
var responseforsummary = await apiresponse.GetTestSummary(MainActivity1.userid + "", testid + "");
List<TestSummaryDataModel> summarylist = JsonConvert.DeserializeObject<List<TestSummaryDataModel>>(responseforsummary.Data);
cpd.DismissDialog();
var intent = new Intent(Activity, typeof(TestSummary));
intent.PutExtra("path", "portal");
intent.PutExtra("testsummarylist", responseforsummary.Data);
Activity.StartActivityForResult(intent, 102);
Activity.OverridePendingTransition(Resource.Animation.slide_left, Resource.Animation.hold);
}
public override void OnSaveInstanceState(Bundle outState)
{
}
}
}