public void RenderInputs(LinearLayout inputsLayout, FormParameter formParameter, List <FormInputManager> inputsManager) { var orderedInputs = formParameter.Form.InputFields.OrderBy(a => a.OrderIndex).ToList(); inputsManager.Clear(); foreach (var input in orderedInputs) { if (!input.Hidden) { var label = new TextView(Application.Context) { Text = input.Label.Humanize(LetterCasing.Sentence), LayoutParameters = inputsLayout.MatchParentWrapContent() }; this.ManagersCollection.StyleRegister.ApplyStyle("TextView", label); inputsLayout.AddView(label); } var manager = this.ManagersCollection.InputManagerCollection.GetManager(input.Type); var view = manager.GetView(input.CustomProperties, this); if (view.LayoutParameters == null) { view.LayoutParameters = inputsLayout.MatchParentWrapContent(); } var value = formParameter.Parameters?.SingleOrDefault(a => a.Key.ToLower().Equals(input.Id.ToLower())).Value; if (value != null) { manager.SetValue(value); } inputsManager.Add(new FormInputManager(input, manager, view)); if (input.Hidden) { view.Visibility = ViewStates.Gone; } inputsLayout.AddView(view); } }
public override View GetView(int position, View convertView, ViewGroup parent) { PropertyInfo[] properties = null; var view = (ViewGroup)convertView; var viewHolder = new ListViewHolder { Objects = new List <View>() }; if (view == null) { view = new LinearLayout(parent.Context) { Orientation = Orientation.Vertical }; var param = view.MatchParentWrapContent(); var orderedOutputs = this.OutputFieldProperty.OrderBy(a => a.OrderIndex); foreach (var output in orderedOutputs) { if (!output.Hidden) { object value; if (this.ObjectList[position].GetType() == typeof(JObject)) { var jsonObj = this.ObjectList[position] as JObject; value = jsonObj?.GetValue(output.Id.ToLower()); } else { var propertyInfo = this.ObjectList[position].GetType().GetProperty(output.Id); value = propertyInfo?.GetValue(this.ObjectList[position], null); } if (value != null) { var manager = this.MyFormHandler.ManagersCollection.OutputManagerCollection.GetManager(output.Type); var outputView = manager.GetView(output, value, this.MyFormHandler, null, null); view.AddView(outputView, param); viewHolder.Objects.Add(outputView); } } } view.LayoutParameters = param; view.Tag = viewHolder; this.MyFormHandler.ManagersCollection.StyleRegister.ApplyStyle("ListViewItem", view); } return(view); }
private View RenderForm(FormParameter formParameter, string submitAction) { var scroll = new NestedScrollView(Application.Context); var linearLayout = new LinearLayout(Application.Context) { Orientation = Orientation.Vertical }; if (formParameter != null) { InvokeForm.Response result = null; var inputsManager = new List <FormInputManager>(); var resultLayout = new LinearLayout(Application.Context) { Orientation = Orientation.Vertical, LayoutParameters = linearLayout.MatchParentWrapContent() }; if (formParameter.Form.InputFields.Count > 0) { var inputsLayout = new LinearLayout(Application.Context) { Orientation = Orientation.Vertical }; this.RenderInputs(inputsLayout, formParameter, inputsManager); if (formParameter.Form.InputFields.Count(a => !a.Hidden) > 0) { this.ManagersCollection.StyleRegister.ApplyStyle("FormLayout", inputsLayout); var submitLabel = "Submit"; var submitbuttonlabel = formParameter.Form.CustomProperties?.GetCustomProperty <string>("submitButtonLabel"); if (!string.IsNullOrEmpty(submitbuttonlabel)) { submitLabel = submitbuttonlabel; } var btn = new Button(Application.Context) { Text = submitLabel, LayoutParameters = inputsLayout.MatchParentWrapContent() }; this.ManagersCollection.StyleRegister.ApplyStyle("Button SubmitButton", btn); inputsLayout.AddView(btn); btn.Click += async(sender, args) => { try { result = await this.SubmitFormAsync(resultLayout, formParameter.Form, inputsManager); if (submitAction == FormLinkActions.OpenModal && result != null) { this.FormWrapper.CloseForm(); } else { this.RenderOutput(resultLayout, result, formParameter.Form, inputsManager); } } catch (Exception ex) { Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show(); } }; } linearLayout.AddView(inputsLayout); } // run on response handled events EventsManager.OnFormLoadedEvent(formParameter); if (formParameter.Form.PostOnLoad || submitAction == FormLinkActions.Run) { try { var taskToRun = Task.Run(() => this.SubmitFormAsync(resultLayout, formParameter.Form, inputsManager, formParameter.Form.PostOnLoadValidation)); result = taskToRun.Result; } catch (AggregateException ex) { ex.ThrowInnerException(); } if (submitAction == FormLinkActions.Run) { this.FormWrapper.CloseForm(); return(null); } this.RenderOutput(resultLayout, result, formParameter.Form, inputsManager); } this.ManagersCollection.StyleRegister.ApplyStyle("ResultsLayout", resultLayout); linearLayout.AddView(resultLayout); scroll.AddView(linearLayout, scroll.MatchParentWrapContent()); } return(scroll); }