Esempio n. 1
0
		private void InitialProgress(int page)
		{

			try {

				string mySoalToken = setupMySoalData ();
				string mySoalRawData = getMySoalPetiMasukJSONData(mySoalToken.ToString(), page);
				WebServices.MySoalPetiMasukRObj mySoalJSONed = JsonConvert.DeserializeObject<WebServices.MySoalPetiMasukRObj> (mySoalRawData);

				int totalPage = 0;

				Console.WriteLine ("[MySoal - Peti Masuk] Raw Data MySoal: {0}",mySoalRawData);

				foreach (var mySoalPaging in mySoalJSONed.paging) {
					Console.WriteLine ("[MySoal - Peti Masuk] Paging: {0}",mySoalPaging.count);
					totalPage = mySoalPaging.count;
					lastPage = mySoalPaging.pageCount;
				}

				if (totalPage != 0) {

					if(isRefreshing==true){
						mySoalListData.Clear ();	
					}

					Activity.RunOnUiThread (() => {
						llMST1ErrorLayout.Visibility = ViewStates.Gone;
						recyclerView.Visibility = ViewStates.Visible;
					});
					/*
					mySoalListData.Add (new MySoal_PetiMasuk_ListData () { 
						mTitle = "Gangguan Bekalan Air", 
						mContent = "Sila sedia maklum bahawa kawasan Felda Mat Daling akan mengalami gangguan bekalan air."
					});

					mySoalListData.Add (new MySoal_PetiMasuk_ListData () { 
						mTitle = "Ancaman Binatang Buas", 
						mContent = "Pihak berkuasa sedang mencari kaedah untuk menyelesaikan masalah tersebut."
					});

					mySoalListData.Add (new MySoal_PetiMasuk_ListData () { 
						mTitle = "Kebakaran Hutan",
						mContent = "Laporan berkenaan kebakaran hutan telah diterima dan sedang disiasat."
					});
					*/

					int count = 0;
					string content = "";

					foreach (var jsonedMySoal in mySoalJSONed.mail) {

						//string contentParsed = jsonedMySoal.content.Replace("s/<(.*?)>//g","");
						//Console.WriteLine ("[Tab1] Parsed: {0}",contentParsed);

						try{

							count = Html.FromHtml (jsonedMySoal.content).ToString().Count(char.IsLetter);

							Console.WriteLine ("[Tab 1] Counted: {0}",count);

							if(count <= 100)
							{
								content = Html.FromHtml(jsonedMySoal.content).ToString();
							}
							else
							{
								content = Html.FromHtml(jsonedMySoal.content).ToString().Substring(0,100)+"...";
							}

							mySoalListData.Add (new MySoal_PetiMasuk_ListData () { 
								mTitle = jsonedMySoal.title, 
								mContent = content
							});

							mySoalTitleList.Add (jsonedMySoal.title);
							mySoalContentList.Add (jsonedMySoal.content);

						}catch(Exception e){

							Console.WriteLine ("[Tab1 MySoal] Error on adding data: {0}",e);

						}


					}
					/*
					Activity.RunOnUiThread (() => {

						listData = new MySoal_PetiMasuk_ListDataHolderList (mySoalListData);

						mLayoutManager = new LinearLayoutManager (Activity);
						recyclerView.SetLayoutManager (mLayoutManager);


						recyclerAdapter = new MySoal_RecyclerViewAdapter (Activity, listData);
						recyclerView.SetAdapter (recyclerAdapter);
						//recyclerView.AddView(footerViewUL);

						recyclerAdapter.ItemClick += ItemClicked;

						progressDialog.Hide();
					});
					*/
					if (Activity != null) {

						Activity.RunOnUiThread (() => {
							if (page == 1) {

								listData = new MySoal_PetiMasuk_ListDataHolderList (mySoalListData);

								mLayoutManager = new LinearLayoutManager (Activity);
								recyclerView.SetLayoutManager (mLayoutManager);

								recyclerAdapter = new MySoal_RecyclerViewAdapter (Activity, listData, totalPage);
								recyclerView.SetAdapter (recyclerAdapter);
								//recyclerView.AddView(footerViewUL);

								recyclerAdapter.ItemClick += ItemClicked;

								progressDialog.Hide ();

								//if is refresing only toast
								if (isRefreshing == true) { 
									Toast.MakeText (Activity, "Data terkini telah dimuatkan..", ToastLength.Short).Show ();
								}

							} else {
								recyclerAdapter.NotifyDataSetChanged ();
							}
						});
					}

				} else {

					Activity.RunOnUiThread (() => {
						llMST1ErrorLayout.Visibility = ViewStates.Visible;
						recyclerView.Visibility = ViewStates.Gone;
						tvMST1ErrorStatus.Text = "Tiada maklumat tersedia buat masa ini.";
						progressDialog.Hide();
					});
				}
			}
			catch(Exception e)
			{
				
				Console.WriteLine ("[Tab 1 MySoal] Error while retrieving Peti Masuk data: {0}",e);

				Activity.RunOnUiThread (() => {
					llMST1ErrorLayout.Visibility = ViewStates.Visible;
					recyclerView.Visibility = ViewStates.Gone;
					tvMST1ErrorStatus.Text = "Terdapat ralat pada akaun anda. Sila hubungi pihak PI1M untuk tindakan.";
					progressDialog.Hide();
				});

			}
		}
		public MySoal_RecyclerViewAdapter (Activity context, MySoal_PetiMasuk_ListDataHolderList data, int totalPage)
		{
			this.context = context;
			mData = data;
			this.totalPage = totalPage;
		}