-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExamAlert_Fragment.cs
210 lines (138 loc) · 6.35 KB
/
ExamAlert_Fragment.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using Android.Support.V4.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using ImageSlider.Interface;
using Newtonsoft.Json;
using Refit;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System;
using ImageSlider.API_Interface;
using Android.Content;
using ImageSlider.Model;
using ImageSlider.Adapter;
using Android.Support.V7.Widget;
using System.Threading;
namespace ImageSlider.Fragments
{
public class ExamAlert_Fragment : Fragment
{
List<ExamAlert_Model> alertList;
ExamAlert_API examalertapi;
List<string> ExamAlert_List = new List<string>();
// ListView MyListExamAlert;
RecyclerView MyListExamAlert;
RecyclerView.LayoutManager mLayoutManager;
Android.App.ProgressDialog progress;
DBHelper dba;
ISharedPreferences pref;
public static string alert_Id, alert_Title, alert_Date, alert_File;
string ExamAlertDetails;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
progress = new Android.App.ProgressDialog(Activity);
progress.Indeterminate = true;
progress.SetProgressStyle(Android.App.ProgressDialogStyle.Spinner);
progress.SetCancelable(false);
progress.SetMessage("Please wait...");
pref = Android.App.Application.Context.GetSharedPreferences("ExamAlertInfo", FileCreationMode.Private);
ExamAlertDetails = pref.GetString("FinalAlert", "false");
dba = new DBHelper();
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.ExamAlertLayout, container, false);
MyListExamAlert = v.FindViewById<RecyclerView>(Resource.Id.listViewalert);
Button btnrefresh = v.FindViewById<Button>(Resource.Id.refresh);
btnrefresh.Click += delegate
{
alertList = new List<ExamAlert_Model>();
getAlertList();
};
//==================================Fetch api==========================//
JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = { new StringEnumConverter() }
};
// String apiurl = string.Format("http://mg.mahendras.org);
examalertapi = RestService.For<ExamAlert_API>("http://mg.mahendras.org");
CancellationTokenSource tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(10000);
// getBookMarkList();
//=====================================================================//
if (ExamAlertDetails.Equals("false"))
{
getAlertList();
}
else
{
alertList = dba.Get_ExamAlertData();
mLayoutManager = new LinearLayoutManager(this.Activity);
MyListExamAlert.SetLayoutManager(mLayoutManager);
ExamAlertAdapter mAdapter = new ExamAlertAdapter(Activity, alertList, MyListExamAlert);
mAdapter.ItemClick += MAdapter_ItemClick;
MyListExamAlert.SetAdapter(mAdapter);
}
return v;
}
private void MAdapter_ItemClick(object sender, int e)
{
ExamAlert_Model objmodel5 = alertList[e];
if (objmodel5.content_file == null || objmodel5.content_file == "")
{
Toast.MakeText(Activity, " Sorry...PDF is not available", ToastLength.Long).Show();
}
else
{
var uri = Android.Net.Uri.Parse(objmodel5.content_file);
var intent = new Intent(Intent.ActionView, uri);
StartActivity(intent);
//int counter = e;
//Bundle bundle8 = new Bundle();
//bundle8.PutString("pdfurl", objmodel5.content_file);
//Global_PDF_Reader objreader7 = new Global_PDF_Reader();
//objreader7.Arguments = bundle8;
//Activity.SupportFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, objreader7).AddToBackStack(null).Commit();
}
}
private async void getAlertList()
{
progress.Show();
try
{
ExamAlertAPI_Response response = await examalertapi.GetExamAlertList();
alertList = response.res_data;
for (int i = 0; i < alertList.Count; i++)
{
ExamAlert_List.Add(alertList[i].content_id);
ExamAlert_List.Add(alertList[i].content_title);
ExamAlert_List.Add(alertList[i].content_date);
ExamAlert_List.Add(alertList[i].content_file);
alert_Id = alertList[i].content_id;
alert_Title = alertList[i].content_title;
alert_Date = alertList[i].content_date;
alert_File = alertList[i].content_file;
dba.insertExamAlertData(alert_Id, alert_Title, alert_Date, alert_File);
}
ISharedPreferencesEditor edit = pref.Edit();
edit.PutString("FinalAlert", "true");
edit.Apply();
ExamAlertAdapter W_Adapter = new ExamAlertAdapter(Activity, alertList, MyListExamAlert);
mLayoutManager = new LinearLayoutManager(this.Activity);
MyListExamAlert.SetLayoutManager(mLayoutManager);
ExamAlertAdapter mAdapter = new ExamAlertAdapter(Activity, alertList, MyListExamAlert);
mAdapter.ItemClick += MAdapter_ItemClick;
MyListExamAlert.SetAdapter(mAdapter);
progress.Dismiss();
}
catch (Exception e)
{
progress.Dismiss();
}
}
}
}