-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookMarkFragment.cs
146 lines (101 loc) · 4.48 KB
/
BookMarkFragment.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
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;
namespace ImageSlider.Fragments
{
public class BookMarkFragment : Fragment
{
List<BookMarkData> bookmarkList;
BookMark_API bookmarkapi;
List<string> BookMark_List = new List<string>();
ListView MyListBookMark;
Android.App.ProgressDialog progress;
DBHelper dba;
ISharedPreferences pref;
public static string Book_Id, Book_Title, Book_Date, Book_File;
string BookMarkDetails;
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("BookMarkInfo", FileCreationMode.Private);
BookMarkDetails = pref.GetString("FinalBookMark", "false");
dba = new DBHelper();
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.BookMark_Layout, container, false);
MyListBookMark = v.FindViewById<ListView>(Resource.Id.listViewbookmark);
//==================================Fetch api==========================//
JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = { new StringEnumConverter() }
};
// String apiurl = string.Format("http://mg.mahendras.org);
bookmarkapi = RestService.For<BookMark_API>("http://mg.mahendras.org");
// getBookMarkList();
//=====================================================================//
if (BookMarkDetails.Equals("false"))
{
getBookMarkList();
}
else
{
//getAboutExam();
bookmarkList = dba.Get_BookMarkData();
for (int i = 0; i < bookmarkList.Count; i++)
{
BookMark_List.Add(bookmarkList[0].content_title);
}
MyListBookMark.Adapter = new ArrayAdapter(Activity, Android.Resource.Layout.SimpleSpinnerItem, BookMark_List);
}
return v;
}
private async void getBookMarkList()
{
progress.Show();
try
{
BookMarkAPI_Response response = await bookmarkapi.GetBookMarkList();
bookmarkList = response.res_data;
// Toast.MakeText(this.Activity, "-->" + myFinalList[0].name,ToastLength.Short).Show();
for (int i = 0; i < bookmarkList.Count; i++)
{
BookMark_List.Add(bookmarkList[i].content_id);
BookMark_List.Add(bookmarkList[i].content_title);
BookMark_List.Add(bookmarkList[i].content_date);
BookMark_List.Add(bookmarkList[i].content_file);
Book_Id = bookmarkList[i].content_id;
Book_Title = bookmarkList[i].content_title;
Book_Date = bookmarkList[i].content_date;
Book_File = bookmarkList[i].content_file;
dba.insertBookMarkData(Book_Id, Book_Title, Book_Date, Book_File);
}
ISharedPreferencesEditor edit = pref.Edit();
edit.PutString("FinalBookMark", "true");
edit.Apply();
MyListBookMark.Adapter = new ArrayAdapter(Activity, Android.Resource.Layout.SimpleSpinnerItem, BookMark_List);
progress.Dismiss();
}
catch (Exception e)
{
progress.Dismiss();
}
}
}
}