Exemplo n.º 1
0
        private string getSubtitle(PassportFormField field, PassportSuitableElement documentRequiredType, string value, int availableDocumentTypesCount)
        {
            if (field.RequiredType.Type is PassportElementTypePhoneNumber)
            {
                var element = field.AvailableElements.GetElementForType(field.RequiredType.Type);
                value = getTextForElement(element);
            }
            else if (field.RequiredType.Type is PassportElementTypeEmailAddress)
            {
                var element = field.AvailableElements.GetElementForType(field.RequiredType.Type);
                value = getTextForElement(element);
            }
            else
            {
                var builder = new StringBuilder();

                if (documentRequiredType != null)
                {
                    var documentRequiredTypeValue = field.AvailableElements.GetElementForType(documentRequiredType?.Type);
                    if (availableDocumentTypesCount > 1)
                    {
                        builder.Append(GetTextForType(documentRequiredType.Type));
                    }
                    else if (documentRequiredTypeValue == null)
                    {
                        builder.Append(Strings.Resources.PassportDocuments);
                    }
                }

                if (field.RequiredType.Type is PassportElementTypePersonalDetails)
                {
                    if (!field.IsDocumentOnly)
                    {
                        var element = field.AvailableElements.GetElementForType(field.RequiredType.Type);
                        if (builder.Length > 0)
                        {
                            builder.Append(", ");
                        }

                        builder.Append(getTextForElement(element));
                    }
                    if (documentRequiredType != null)
                    {
                        var element = field.AvailableElements.GetElementForType(documentRequiredType.Type);
                        if (builder.Length > 0)
                        {
                            builder.Append(", ");
                        }

                        builder.Append(getTextForElement(element));
                    }
                }
                else if (field.RequiredType.Type is PassportElementTypeAddress)
                {
                    if (!field.IsDocumentOnly)
                    {
                        var element = field.AvailableElements.GetElementForType(field.RequiredType.Type);
                        if (builder.Length > 0)
                        {
                            builder.Append(", ");
                        }

                        builder.Append(getTextForElement(element));
                    }
                }

                value = builder.ToString();
            }



            bool isError = false;

            var errors          = !field.IsDocumentOnly ? field.AvailableElements.GetErrorsForType(field.RequiredType.Type).ToList() : null;
            var documentsErrors = documentRequiredType != null?field.AvailableElements.GetErrorsForType(documentRequiredType.Type).ToList() : null;

            if (errors != null && errors.Count > 0 || documentsErrors != null && documentsErrors.Count > 0)
            {
                value = null;
                if (!field.IsDocumentOnly)
                {
                    value = errors[0].Message;
                }
                if (value == null)
                {
                    value = documentsErrors[0].Message;
                }
                isError = true;
            }

            //Dictionary<String, String> errors = !field.GetHashCode ? errorsMap.get(getNameForType(requiredType.type)) : null;
            //Dictionary<String, String> documentsErrors = documentRequiredType != null ? errorsMap.get(getNameForType(documentRequiredType.type)) : null;
            //if (errors != null && errors.size() > 0 || documentsErrors != null && documentsErrors.size() > 0)
            //{
            //    value = null;
            //    if (!documentOnly)
            //    {
            //        value = mainErrorsMap.get(getNameForType(requiredType.type));
            //    }
            //    if (value == null)
            //    {
            //        value = mainErrorsMap.get(getNameForType(documentRequiredType.type));
            //    }
            //    isError = true;
            //}
            else
            {
                if (field.RequiredType.Type is PassportElementTypePersonalDetails)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        if (documentRequiredType == null)
                        {
                            value = Strings.Resources.PassportPersonalDetailsInfo;
                        }
                        else
                        {
                            //if (currentActivityType == TYPE_MANAGE)
                            //{
                            //    value = Strings.Resources.PassportDocuments;
                            //}
                            //else
                            {
                                if (availableDocumentTypesCount == 1)
                                {
                                    if (documentRequiredType.Type is PassportElementTypePassport)
                                    {
                                        value = Strings.Resources.PassportIdentityPassport;
                                    }
                                    else if (documentRequiredType.Type is PassportElementTypeInternalPassport)
                                    {
                                        value = Strings.Resources.PassportIdentityInternalPassport;
                                    }
                                    else if (documentRequiredType.Type is PassportElementTypeDriverLicense)
                                    {
                                        value = Strings.Resources.PassportIdentityDriverLicence;
                                    }
                                    else if (documentRequiredType.Type is PassportElementTypeIdentityCard)
                                    {
                                        value = Strings.Resources.PassportIdentityID;
                                    }
                                }
                                else
                                {
                                    value = Strings.Resources.PassportIdentityDocumentInfo;
                                }
                            }
                        }
                    }
                }
                else if (field.RequiredType.Type is PassportElementTypeAddress)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        if (documentRequiredType == null)
                        {
                            value = Strings.Resources.PassportAddressNoUploadInfo;
                        }
                        else
                        {
                            //if (currentActivityType == TYPE_MANAGE)
                            //{
                            //    value = Strings.Resources.PassportDocuments;
                            //}
                            //else
                            {
                                if (availableDocumentTypesCount == 1)
                                {
                                    if (documentRequiredType.Type is PassportElementTypeRentalAgreement)
                                    {
                                        value = Strings.Resources.PassportAddAgreementInfo;
                                    }
                                    else if (documentRequiredType.Type is PassportElementTypeUtilityBill)
                                    {
                                        value = Strings.Resources.PassportAddBillInfo;
                                    }
                                    else if (documentRequiredType.Type is PassportElementTypePassportRegistration)
                                    {
                                        value = Strings.Resources.PassportAddPassportRegistrationInfo;
                                    }
                                    else if (documentRequiredType.Type is PassportElementTypeTemporaryRegistration)
                                    {
                                        value = Strings.Resources.PassportAddTemporaryRegistrationInfo;
                                    }
                                    else if (documentRequiredType.Type is PassportElementTypeBankStatement)
                                    {
                                        value = Strings.Resources.PassportAddBankInfo;
                                    }
                                }
                                else
                                {
                                    value = Strings.Resources.PassportAddressInfo;
                                }
                            }
                        }
                    }
                }
                else if (field.RequiredType.Type is PassportElementTypePhoneNumber)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        value = Strings.Resources.PassportPhoneInfo;
                    }
                }
                else if (field.RequiredType.Type is PassportElementTypeEmailAddress)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        value = Strings.Resources.PassportEmailInfo;
                    }
                }
            }

            return(value);
        }
Exemplo n.º 2
0
        private void SetupFormField(TextBlock title, TextBlock subtitle, PassportFormField field)
        {
            int availableDocumentTypesCount = field.DocumentTypes != null ? field.DocumentTypes.Count : 0;

            //TextDetailSecureCell view = new TextDetailSecureCell(context);
            //view.setBackgroundDrawable(Theme.getSelectorDrawable(true));
            if (field.RequiredType.Type is PassportElementTypePersonalDetails)
            {
                String label;
                if (field.DocumentTypes == null || field.DocumentTypes.IsEmpty())
                {
                    label = Strings.Resources.PassportPersonalDetails;
                }
                else if (field.IsDocumentOnly && field.DocumentTypes.Count == 1)
                {
                    label = GetTextForType(field.DocumentTypes[0].Type);
                }
                else if (field.IsDocumentOnly && field.DocumentTypes.Count == 2)
                {
                    label = string.Format(Strings.Resources.PassportTwoDocuments, GetTextForType(field.DocumentTypes[0].Type), GetTextForType(field.DocumentTypes[1].Type));
                }
                else
                {
                    label = Strings.Resources.PassportIdentityDocument;
                }

                title.Text = label;
            }
            else if (field.RequiredType.Type is PassportElementTypeAddress)
            {
                String label;
                if (field.DocumentTypes == null || field.DocumentTypes.IsEmpty())
                {
                    label = Strings.Resources.PassportAddress;
                }
                else if (field.IsDocumentOnly && field.DocumentTypes.Count == 1)
                {
                    label = GetTextForType(field.DocumentTypes[0].Type);
                }
                else if (field.IsDocumentOnly && field.DocumentTypes.Count == 2)
                {
                    label = string.Format(Strings.Resources.PassportTwoDocuments, GetTextForType(field.DocumentTypes[0].Type), GetTextForType(field.DocumentTypes[1].Type));
                }
                else
                {
                    label = Strings.Resources.PassportResidentialAddress;
                }

                title.Text = label;
            }
            else if (field.RequiredType.Type is PassportElementTypePhoneNumber)
            {
                title.Text = Strings.Resources.PassportPhone;
            }
            else if (field.RequiredType.Type is PassportElementTypeEmailAddress)
            {
                title.Text = Strings.Resources.PassportEmail;
            }

            PassportSuitableElement documentsType = null;

            if (field.DocumentTypes != null && field.DocumentTypes.Count > 0)
            {
                bool found = false;
                for (int a = 0, count = field.DocumentTypes.Count; a < count; a++)
                {
                    var documentType = field.DocumentTypes[a];
                    //typesValues.put(documentType, new HashMap<>());
                    //documentsToTypesLink.put(documentType, requiredType);
                    if (!found)
                    {
                        var documentValue = field.AvailableElements.GetElementForType(documentType.Type);
                        if (documentValue != null)
                        {
                            //if (documentValue.data != null)
                            //{
                            //    documentJson = decryptData(documentValue.data.data, decryptValueSecret(documentValue.data.secret, documentValue.data.data_hash), documentValue.data.data_hash);
                            //}
                            documentsType = documentType;
                            found         = true;
                        }
                    }
                }
                if (documentsType == null)
                {
                    documentsType = field.DocumentTypes[0];
                }
            }

            subtitle.Text = getSubtitle(field, documentsType, string.Empty, availableDocumentTypesCount);
        }