public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.fragment_content_cropmanager, null); try { lstbase = new List <ItemPayloadModel>(); objbase_level1 = new ItemPayloadModel(); objbase_level1 = Newtonsoft.Json.JsonConvert.DeserializeObject <ItemPayloadModel>(Arguments.GetString("siteparam")); imgCrop = root.FindViewById <ImageView>(Resource.Id.imgCrop); imgCrop.SetImageResource(objbase_level1.ItemIcon); txt_croptitle = root.FindViewById <TextView>(Resource.Id.txt_croptitle); txt_croptitle.Text = objbase_level1.ItemName; lstbase.Add(objbase_level1); } catch { } gridViewString = new string[] { "Corn", "Barley", "Onion", "Sweet Potato", "Flour", "Back" }; gridViewCodeString = new string[] { "Corn", "Barley", "Onion", "SweetPotato", "Flour", "BCK" }; gridViewImageId = new int[] { Resource.Drawable.ic_corn, Resource.Drawable.ic_barley, Resource.Drawable.ic_onion, Resource.Drawable.ic_sweetpotato, Resource.Drawable.ic_flour, Resource.Drawable.ic_back }; _generic_grid_menu_helper adapterViewAndroid = new _generic_grid_menu_helper(this.Activity, gridViewString, gridViewCodeString, gridViewImageId); androidGridView = root.FindViewById <GridView>(Resource.Id.grid_view_crops); new System.Threading.Thread(new System.Threading.ThreadStart(() => { if (this.Activity != null) { this.Activity.RunOnUiThread(() => { androidGridView.SetAdapter(adapterViewAndroid); }); } })).Start(); androidGridView.ItemClick += (sndr, argus) => ItemSearch_clicked(sndr, argus, this.Activity); return(root); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.fragment_content_myfarm, null); gridViewString = new string[] { "Add New Plot", "View Existing Plot(s)" }; gridViewCodeString = new string[] { "AP", "VP" }; gridViewImageId = new int[] { Resource.Drawable.add_plot, Resource.Drawable.view_plot }; _generic_grid_menu_helper adapterViewAndroid = new _generic_grid_menu_helper(this.Activity, gridViewString, gridViewCodeString, gridViewImageId); androidGridView = root.FindViewById <GridView>(Resource.Id.grid_view_farm_dashitems_nw); new System.Threading.Thread(new System.Threading.ThreadStart(() => { if (this.Activity != null) { this.Activity.RunOnUiThread(() => { androidGridView.SetAdapter(adapterViewAndroid); }); } })).Start(); androidGridView.ItemClick += (sndr, argus) => ItemSearch_clicked(sndr, argus, this.Activity); btn_addnewplot = root.FindViewById <Button>(Resource.Id.btn_addnewplot); btn_viewexistingplot = root.FindViewById <Button>(Resource.Id.btn_viewexistingplot); btn_addnewplot.Click += (sndr, argus) => AddNewPlot(sndr, argus, this.Activity); btn_viewexistingplot.Click += (sndr, argus) => ViewAvailablePlots(sndr, argus, this.Activity); txt_FarmID = root.FindViewById <TextView>(Resource.Id.txt_FarmID); txt_FarmName = root.FindViewById <TextView>(Resource.Id.txt_FarmName); txt_FarmAddress = root.FindViewById <TextView>(Resource.Id.txt_FarmAddress); txt_FarmSize = root.FindViewById <TextView>(Resource.Id.txt_FarmSize); txt_FarmEstablishedDate = root.FindViewById <TextView>(Resource.Id.txt_FarmEstablishedDate); txt_CoOpName = root.FindViewById <TextView>(Resource.Id.txt_CoOpName); try { string mStringLoginInfo = string.Empty; string mStringSessionToken = string.Empty; try { objdb = new DBaseOperations(); var lstu = objdb.selectTable(); if (lstu != null && lstu.Count > default(int)) { var uobj = lstu.FirstOrDefault(); if (uobj.Password == " ") { throw new Exception("Please login again"); } mStringLoginInfo = uobj.EmailId; mStringSessionToken = uobj.AuthToken; } } catch { } if (string.IsNullOrEmpty(mStringSessionToken)) { throw new Exception("Token does not exists"); } var client = new RestClient(Common.UrlBase); var request = new RestRequest("Farm/GetFarmsDetails", Method.GET); request.AddHeader("Content-Type", "application/json"); request.AddHeader("TokenKey", mStringSessionToken); IRestResponse response = client.Execute(request); var content = response.Content; var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <FarmDetailResponse>(content); if (responseObj != null && !string.IsNullOrEmpty(responseObj.FarmName)) { txt_FarmID.Text = responseObj.FarmId; txt_FarmSize.Text = string.Format("{0} {1}", Convert.ToString(responseObj.FarmSize), responseObj.FarmSizeUnit); txt_FarmName.Text = responseObj.FarmName; txt_FarmAddress.Text = responseObj.FarmAddress; txt_CoOpName.Text = responseObj.CoOpName; txt_FarmEstablishedDate.Text = responseObj.FarmEstablishedDate.ToString("MMMM-yy"); } else { MapFarmFragment objFragment = new MapFarmFragment(); Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction(); tx.Replace(Resource.Id.m_main, objFragment, Constants.mapfarm); tx.Commit(); } } catch (Exception ex) { Intent intent = new Intent(this.Activity, typeof(DashboardFragment)); StartActivity(intent); this.Activity.Finish(); } return(root); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.fragment_content_dashboard, null); try { if (Build.VERSION.SdkInt >= Build.VERSION_CODES.M) { if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.Camera) != (int)Permission.Granted || Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.WriteExternalStorage) != (int)Permission.Granted || Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.AccessFineLocation) != (int)Permission.Granted || Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.AccessCoarseLocation) != (int)Permission.Granted || Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.AccessWifiState) != (int)Permission.Granted || Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.AccessNetworkState) != (int)Permission.Granted) { Android.Support.V4.App.ActivityCompat.RequestPermissions(this.Activity, new string[] { Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage, Manifest.Permission.AccessFineLocation, Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessWifiState, Manifest.Permission.AccessNetworkState }, 54); /*FragmentManager.FindFragmentById(Resource.Layout.fragment_content_addproduct).RequestPermissions(new string[] * { * Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage, * Manifest.Permission.ReadExternalStorage * }, 54);*/ } } } catch { } gridViewString = new string[] { "Welcome Note", "My Farm", "View Activities" }; gridViewCodeString = new string[] { "WLC", "MYFRM", "VWACT" }; gridViewImageId = new int[] { Resource.Drawable.welcome, Resource.Drawable.myfarmnew, Resource.Drawable.activity }; _generic_grid_menu_helper adapterViewAndroid = new _generic_grid_menu_helper(this.Activity, gridViewString, gridViewCodeString, gridViewImageId); androidGridView = root.FindViewById <GridView>(Resource.Id.grid_view_dashitems); new System.Threading.Thread(new System.Threading.ThreadStart(() => { if (this.Activity != null) { this.Activity.RunOnUiThread(() => { androidGridView.SetAdapter(adapterViewAndroid); }); } })).Start(); androidGridView.ItemClick += (sndr, argus) => ItemSearch_clicked(sndr, argus, this.Activity); text_datenow = root.FindViewById <TextView>(Resource.Id.text_datenow); text_datenow.Text = DateTime.Now.ToString("dd-MM-yyyy"); text_datetomorrow = root.FindViewById <TextView>(Resource.Id.text_datetomorrow); text_datetomorrow.Text = DateTime.Now.AddDays(1).ToString("dd-MM-yyyy"); btn_myaggiewelcome = root.FindViewById <Button>(Resource.Id.btn_myaggiewelcome); btn_myaggiewelcome.Click += (sndr, argus) => btn_myaggiewelcome_Click(sndr, argus, this.Activity); btn_addactivity = root.FindViewById <Button>(Resource.Id.btn_addactivity); btn_addactivity.Click += (sndr, argus) => btn_addactivity_Click(sndr, argus, this.Activity); btn_viewactivity = root.FindViewById <Button>(Resource.Id.btn_viewactivity); btn_viewactivity.Click += (sndr, argus) => btn_viewactivity_Click(sndr, argus, this.Activity); btn_askaggie = root.FindViewById <Button>(Resource.Id.btn_askaggie); btn_askaggie.Click += (sndr, argus) => btn_askAnAggie_Click(sndr, argus, this.Activity); btn_myfarmdash = root.FindViewById <Button>(Resource.Id.btn_myfarmdash); btn_myfarmdash.Click += (sndr, argus) => NavigateToMyFarm(sndr, argus, this.Activity); try { /*ISharedPreferences prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(this.Activity); * string mStringLoginInfo = prefs.GetString(SessionConstants.LoginInfo, default(string)); * string mStringSessionToken = prefs.GetString(SessionConstants.SessionToken, default(string));*/ string mStringLoginInfo = string.Empty; string mStringSessionToken = string.Empty; try { objdb = new DBaseOperations(); var lstu = objdb.selectTable(); if (lstu != null && lstu.Count > default(int)) { var uobj = lstu.FirstOrDefault(); if (uobj.Password == " ") { throw new Exception("Please login again"); } mStringLoginInfo = uobj.EmailId; mStringSessionToken = uobj.AuthToken; } } catch { } if (string.IsNullOrEmpty(mStringSessionToken)) { throw new Exception("Token does not exists"); } } catch (Exception ex) { this.Activity.RunOnUiThread(() => { Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(this.Activity); alertDiag.SetTitle(Resource.String.DialogHeaderError); alertDiag.SetMessage(ex.Message); alertDiag.SetIcon(Resource.Drawable.alert); alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) => { Intent intent = new Intent(this.Activity, typeof(MainActivity)); StartActivity(intent); this.Activity.Finish(); }); Dialog diag = alertDiag.Create(); diag.Show(); diag.SetCanceledOnTouchOutside(false); }); } try { this.GetCityByGeoLocation(this.Activity); } catch { } return(root); }