private void Button_execute_all_Click(object sender, EventArgs e) { InterpretationInstance instance = session_listview_adapter[session_position]; List <NLQ> queries_to_execute = instance.session_queries.Where(x => x.query_type == SurveyHelper.QueryTypes.EDIT_RECORD || x.query_type == SurveyHelper.QueryTypes.ADD_RECORD || x.query_type == SurveyHelper.QueryTypes.DELETE_RECORD).ToList(); bool isSuccess = true; foreach (NLQ query in queries_to_execute) { isSuccess = SQLiteHelper.ExecuteNLQ(query); } if (isSuccess) { Toast.MakeText(Application.Context, $"All queries have executed successufully.", ToastLength.Long); } else if (!isSuccess) { Toast.MakeText(Application.Context, $"One or more queries have failed to execute.", ToastLength.Long); } }
private InterpretationInstance GetActiveSession() { foreach (InterpretationInstance session in sessions) { if (session.session_isOpen) { return(session); // potentially add checks for multiple open instances } } InterpretationInstance new_instance = new InterpretationInstance() { session_id = Guid.NewGuid().ToString(), survey_id = SurveyHelper.ActiveSurvey.survey_id, survey_name = SurveyHelper.ActiveSurvey.survey_name, session_datetime = DateTime.Now, session_isOpen = true }; sessions.Add(new_instance); return(new_instance); }
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { if (requestCode == VOICE) { if (resultCode == Result.Ok) { var matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults); if (matches.Count != 0) { // get an open session or create a new one InterpretationInstance working_instance = GetActiveSession(); working_instance.ProcessSpeech(matches[0], out NLQ current_query); // update the current query information display if (current_query != null) { UpdateCurrentQuery(current_query); } session_listview_adapter.NotifyDataSetChanged(); // update the list instance int index = sessions.FindIndex(x => x.session_id == working_instance.session_id); sessions[index] = working_instance; } else { textview_record_status.Text = "No speech was recognized."; } record_btn.Text = "Record"; } } base.OnActivityResult(requestCode, resultCode, data); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); // Get the control resources from the layout frame_home = FindViewById <FrameLayout>(Resource.Id.frame_home); frame_dashboard = FindViewById <FrameLayout>(Resource.Id.frame_dashboard); frame_log = FindViewById <RelativeLayout>(Resource.Id.frame_log); upload_btn = (Button)FindViewById(Resource.Id.dashboard_uploadBtn); record_btn = (Button)FindViewById(Resource.Id.dashboard_recordBtn); textview_status = FindViewById <TextView>(Resource.Id.dashboard_file_status); textview_record_status = FindViewById <TextView>(Resource.Id.dashboard_record_status); upload_btn.Click += Upload_btn_Click; record_btn.Click += Record_btn_Click; edittext_treeid = FindViewById <EditText>(Resource.Id.current_q_treeid_edittext); edittext_property = FindViewById <EditText>(Resource.Id.current_q_property_edittext); edittext_oldval = FindViewById <EditText>(Resource.Id.current_q_oldval_edittext); edittext_newval = FindViewById <EditText>(Resource.Id.current_q_newval_edittext); log_listview = FindViewById <ListView>(Resource.Id.log_listview); session_listview_adapter = new SessionAdapter(sessions); log_listview.Adapter = session_listview_adapter; log_listview.ItemClick += Log_listview_ItemClick; InterpretationInstance instance; NLQ query; string[] queryTypes = { "SESSION_START", "GET_TREE", "EDIT_PROPERTY", "SESION_END" }; Random rand = new Random(); for (int i = 0; i < 10; i++) { instance = new InterpretationInstance(); instance.survey_name = "BS5837 Test Survey"; instance.tree_id = "T" + rand.Next(1, 100).ToString(); instance.session_datetime = DateTime.Now; int count = 0; for (int j = 0; j < 4; j++) { query = new NLQ(); query.tree_id = instance.tree_id; query.query_type = queryTypes[count]; query.property_actioned = "Maturity"; query.property_val_old = "Young"; query.property_val_new = "Mature"; instance.session_queries.Add(query); count++; } sessions.Add(instance); } listview_detailed_log = FindViewById <ListView>(Resource.Id.detailed_listview); listview_detailed_log.ItemClick += Listview_detailed_log_ItemClick; button_execute_all = FindViewById <Button>(Resource.Id.button_exe_all); button_execute_all.Click += Button_execute_all_Click; textview_itemdetail_title = FindViewById <TextView>(Resource.Id.query_detail_name); textview_itemdetail_qtype = FindViewById <TextView>(Resource.Id.query_detail_querytype_val); edittext_itemdetail_prop = FindViewById <EditText>(Resource.Id.query_detail_property_val); edittext_itemdetail_oldval = FindViewById <EditText>(Resource.Id.query_detail_oldval_val); edittext_itemdetail_newval = FindViewById <EditText>(Resource.Id.query_detail_newval_val); button_itemdetail_save = FindViewById <Button>(Resource.Id.query_detail_save_button); button_itemdetail_save.Click += Button_itemdetail_save_Click; vf = FindViewById <ViewFlipper>(Resource.Id.viewflipper_logview); button_export = FindViewById <Button>(Resource.Id.button_export); button_export.Click += Button_export_Click; BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation); navigation.SetOnNavigationItemSelectedListener(this); }