public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.fragment_content_chatbot, null); edittext_chatbox = root.FindViewById <EditText>(Resource.Id.edittext_chatbox); button_chatbox_send = root.FindViewById <Button>(Resource.Id.button_chatbox_send); button_chatbox_send.Click += (sndr, argus) => Send_Clicked(sndr, argus, this.Activity, root); if (msg == null) { msg = new List <Message>(); } string name = string.Empty; UserLoginInfo uobj = new UserLoginInfo(); try { objdb = new DBaseOperations(); var lstu = objdb.selectTable(); if (lstu != null && lstu.Count > default(int)) { uobj = lstu.FirstOrDefault(); if (uobj.Password == " ") { throw new Exception("Please login again"); } name = uobj.GoodName; } } catch { } var objmsg = new Message(); objmsg.sender = new UserLoginInfo(); objmsg.sender.GoodName = Constants.ChatBotName; objmsg.sender.ProfilePicture = BitmapHelpers.BitmapToBase64(BitmapHelpers.GetBitmapFromResource(this.Activity.Resources, Resource.Drawable.chatbot)); objmsg.message = string.Format("Hi, {0}! How may I help you?", name); objmsg.createdAt = DateTime.Now; msg.Add(objmsg); this.MessageSetter(msg, this.Activity, root, (Android.Support.V4.App.Fragment)FragmentManager.FindFragmentByTag(Constants.chatbot)); return(root); }
private async System.Threading.Tasks.Task ResponseChat(ViewGroup root, Activity currentActivity, string Question) { await System.Threading.Tasks.Task.Run(() => { try { var answer = this.Communicator(Question).FirstOrDefault().answer.Trim(); if (!string.IsNullOrEmpty(answer)) { var objmsgAns = new Message(); objmsgAns.sender = new UserLoginInfo(); objmsgAns.sender.GoodName = Constants.ChatBotName; objmsgAns.sender.ProfilePicture = BitmapHelpers.BitmapToBase64(BitmapHelpers.GetBitmapFromResource(currentActivity.Resources, Resource.Drawable.chatbot)); objmsgAns.message = answer; objmsgAns.createdAt = DateTime.Now; msg.Add(objmsgAns); this.MessageSetter(msg, currentActivity, root, (Android.Support.V4.App.Fragment)FragmentManager.FindFragmentByTag(Constants.chatbot)); } } catch { } }); }
private void ItemSearch_clicked(object sender, AdapterView.ItemClickEventArgs e, Activity currentActivity) { androidGridView.ItemClick -= (sndr, argus) => ItemSearch_clicked(sndr, argus, currentActivity); try { if (gridViewCodeString[e.Position] == "BCK") { DashboardFragment objFragment = new DashboardFragment(); Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction(); tx.Replace(Resource.Id.m_main, objFragment, Constants.dashboard); tx.Commit(); } else if (gridViewCodeString[e.Position] == "NPR") { if (objSelectedItem == null) { objSelectedItem = new List <ItemPayloadModelWithBase64>(); } objSelectedItem.Add(new ItemPayloadModelWithBase64() { ItemName = gridViewString[e.Position], ItemCode = gridViewCodeString[e.Position], ItemIcon = BitmapHelpers.BitmapToBase64(gridViewImages[e.Position]), prdType = (ProductType)Convert.ToInt32(gridViewTypeCodeString[e.Position]) }); Bundle utilBundle = new Bundle(); utilBundle.PutString("siteparam", Newtonsoft.Json.JsonConvert.SerializeObject(objSelectedItem)); AddProductFragment objFragment = new AddProductFragment(); objFragment.Arguments = utilBundle; Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction(); tx.Replace(Resource.Id.m_main, objFragment, Constants.dashboard); tx.Commit(); } else { //Identification of parent selection if (gridViewCodeString[e.Position].Contains("Ø")) { objSelectedItem = null; } if (objSelectedItem == null) { objSelectedItem = new List <ItemPayloadModelWithBase64>(); } objSelectedItem.Add(new ItemPayloadModelWithBase64() { ItemName = gridViewString[e.Position], ItemCode = gridViewCodeString[e.Position], ItemIcon = BitmapHelpers.BitmapToBase64(gridViewImages[e.Position]), prdType = (ProductType)Convert.ToInt32(gridViewTypeCodeString[e.Position]) }); if (gridViewCodeString[e.Position].Contains("Ø")) { AddActivityFragment objFragment = new AddActivityFragment(); Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction(); tx.Replace(Resource.Id.m_main, objFragment, Constants.addactivity); tx.Commit(); } else { Bundle utilBundle = new Bundle(); if (objSelectedItem == null || objSelectedItem.Count() <= default(int)) { AddActivityFragment objFragment = new AddActivityFragment(); Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction(); tx.Replace(Resource.Id.m_main, objFragment, Constants.addactivity); tx.Commit(); } else if (objSelectedItem != null && objSelectedItem.Count() > default(int) && objSelectedItem.Count() <= 1) { utilBundle.PutString("siteparam", Newtonsoft.Json.JsonConvert.SerializeObject(objSelectedItem)); AddActivityFragment objFragment = new AddActivityFragment(); objFragment.Arguments = utilBundle; Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction(); tx.Replace(Resource.Id.m_main, objFragment, Constants.addactivity); tx.Commit(); } else if (objSelectedItem != null && objSelectedItem.Count() > 1) { utilBundle.PutString("siteparam", Newtonsoft.Json.JsonConvert.SerializeObject(objSelectedItem)); AddSelectedItemFragment objFragment = new AddSelectedItemFragment(); objFragment.Arguments = utilBundle; Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction(); tx.Replace(Resource.Id.m_main, objFragment, Constants.addactivity); tx.Commit(); } } } } catch (Exception ex) { currentActivity.RunOnUiThread(() => { Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity); alertDiag.SetTitle(Resource.String.DialogHeaderError); alertDiag.SetMessage(ex.Message); alertDiag.SetIcon(Resource.Drawable.alert); alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) => { androidGridView.ItemClick += (sndr, argus) => ItemSearch_clicked(sndr, argus, currentActivity); }); Dialog diag = alertDiag.Create(); diag.Show(); diag.SetCanceledOnTouchOutside(false); }); } }
protected void Send_Clicked(object sender, EventArgs e, Activity currentActivity, ViewGroup root) { button_chatbox_send.Click -= (sndr, argus) => Send_Clicked(sndr, argus, currentActivity, root); try { if (!string.IsNullOrEmpty(edittext_chatbox.Text.Trim())) { if (msg == null) { msg = new List <Message>(); } UserLoginInfo uobj = new UserLoginInfo(); try { objdb = new DBaseOperations(); var lstu = objdb.selectTable(); if (lstu != null && lstu.Count > default(int)) { uobj = lstu.FirstOrDefault(); } } catch { } var objmsg = new Message(); objmsg.message = edittext_chatbox.Text.Trim(); objmsg.createdAt = DateTime.Now; objmsg.sender = new UserLoginInfo(); objmsg.sender.EmailId = uobj.EmailId; objmsg.sender.GoodName = uobj.GoodName; if (!string.IsNullOrEmpty(uobj.ProfilePicture)) { objmsg.sender.ProfilePicture = uobj.ProfilePicture; } else { objmsg.sender.ProfilePicture = BitmapHelpers.BitmapToBase64(BitmapHelpers.GetBitmapFromResource(this.Activity.Resources, Resource.Drawable.chatbot)); } msg.Add(objmsg); this.MessageSetter(msg, currentActivity, root, (Android.Support.V4.App.Fragment)FragmentManager.FindFragmentByTag(Constants.chatbot)); var requestChatMsg = edittext_chatbox.Text.Trim(); edittext_chatbox.Text = string.Empty; ThreadPool.QueueUserWorkItem(state => { currentActivity.RunOnUiThread(() => this.ResponseChat(root, currentActivity, requestChatMsg)); }); } } catch (Exception ex) { currentActivity.RunOnUiThread(() => { Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity); alertDiag.SetTitle(Resource.String.DialogHeaderError); alertDiag.SetMessage(ex.Message); alertDiag.SetIcon(Resource.Drawable.alert); alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) => { //button_chatbox_send.Click += (sndr, argus) => Send_Clicked(sndr, argus, currentActivity, root); }); Dialog diag = alertDiag.Create(); diag.Show(); diag.SetCanceledOnTouchOutside(false); }); } }
public override void OnActivityResult(int requestCode, int resultCode, Intent data) { try { if (Build.VERSION.SdkInt >= Build.VERSION_CODES.M) { if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.WriteExternalStorage) != (int)Permission.Granted) { Android.Support.V4.App.ActivityCompat.RequestPermissions(this.Activity, new String[] { Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage }, 53); } else { if (requestCode == 102) { Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); Uri contentUri = Uri.FromFile(_file); mediaScanIntent.SetData(contentUri); this.Activity.SendBroadcast(mediaScanIntent); int height = profile_image0.Height; int width = Resources.DisplayMetrics.WidthPixels; using (Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height)) { profile_image0.RecycleBitmap(); profile_image0.SetImageBitmap(bitmap); try { this.SetProfileImageToNavMenuHeader(this.Activity, bitmap); } catch { } _profilepicbase64 = BitmapHelpers.BitmapToBase64(bitmap); try { objdb = new DBaseOperations(); var lstu = objdb.selectTable(); if (lstu != null && lstu.Count > default(int)) { var uobj = lstu.FirstOrDefault(); objdb.updateTable(new UserLoginInfo() { Id = uobj.Id, EmailId = uobj.EmailId, GoodName = uobj.GoodName, Password = uobj.Password, IsAdmin = uobj.IsAdmin, AuthToken = uobj.AuthToken, ProfilePicture = _profilepicbase64 }); } } catch { } } } } } else { if (requestCode == 102) { Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); Uri contentUri = Uri.FromFile(_file); mediaScanIntent.SetData(contentUri); this.Activity.SendBroadcast(mediaScanIntent); int height = profile_image0.Height; int width = Resources.DisplayMetrics.WidthPixels; using (Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height)) { profile_image0.RecycleBitmap(); profile_image0.SetImageBitmap(bitmap); try { this.SetProfileImageToNavMenuHeader(this.Activity, bitmap); } catch { } _profilepicbase64 = BitmapHelpers.BitmapToBase64(bitmap); try { objdb = new DBaseOperations(); var lstu = objdb.selectTable(); if (lstu != null && lstu.Count > default(int)) { var uobj = lstu.FirstOrDefault(); objdb.updateTable(new UserLoginInfo() { Id = uobj.Id, EmailId = uobj.EmailId, GoodName = uobj.GoodName, Password = uobj.Password, IsAdmin = uobj.IsAdmin, AuthToken = uobj.AuthToken, ProfilePicture = _profilepicbase64 }); } } catch { } } } } } 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) => { }); Dialog diag = alertDiag.Create(); diag.Show(); diag.SetCanceledOnTouchOutside(false); }); } }
//protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) public override void OnActivityResult(int requestCode, int resultCode, Intent data) { 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.App.ActivityCompat.RequestPermissions(this.Activity, new string[] { Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage }, 54); /*FragmentManager.FindFragmentById(Resource.Layout.fragment_content_addproduct).RequestPermissions(new string[] * { * Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage, * Manifest.Permission.ReadExternalStorage * }, 54);*/ } else { if (requestCode == 102) { Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); Uri contentUri = Uri.FromFile(_file); mediaScanIntent.SetData(contentUri); this.Activity.SendBroadcast(mediaScanIntent); int height = profile_image.Height; int width = Resources.DisplayMetrics.WidthPixels; //int width = profile_image.Width; using (Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height)) { profile_image.RecycleBitmap(); profile_image.SetImageBitmap(bitmap); _profilepicbase64 = BitmapHelpers.BitmapToBase64(bitmap); } } } } else { //if (requestCode == 102 && resultCode == (int)Result.Ok) if (requestCode == 102) { Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); Uri contentUri = Uri.FromFile(_file); mediaScanIntent.SetData(contentUri); this.Activity.SendBroadcast(mediaScanIntent); int height = profile_image.Height; int width = Resources.DisplayMetrics.WidthPixels; //int width = profile_image.Width; using (Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height)) { profile_image.RecycleBitmap(); profile_image.SetImageBitmap(bitmap); _profilepicbase64 = BitmapHelpers.BitmapToBase64(bitmap); } } } } 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) => { }); Dialog diag = alertDiag.Create(); diag.Show(); diag.SetCanceledOnTouchOutside(false); }); } }