@ -1,3 +1,5 @@
@file : Suppress ( "SENSELESS_COMPARISON" )
package com.nivesh.production.partnerOnBoarding.ui.fragments
package com.nivesh.production.partnerOnBoarding.ui.fragments
import android.Manifest
import android.Manifest
@ -11,32 +13,57 @@ import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.Color
import android.net.Uri
import android.net.Uri
import android.os.Bundle
import android.os.Bundle
import android.provider.MediaStore
import android.provider.OpenableColumns
import android.provider.OpenableColumns
import android.text.Editable
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.text.TextWatcher
import android.util.Base64
import android.util.Base64
import android.util.Log
import android.util.Log
import android.view.LayoutInflater
import android.view.LayoutInflater
import android.view.View
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AlertDialog
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.content.FileProvider
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.lifecycleScope
import com.google.android.material.textfield.MaterialAutoCompleteTextView
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.google.gson.Gson
import com.nivesh.production.partnerOnBoarding.BuildConfig
import com.nivesh.production.partnerOnBoarding.BuildConfig
import com.nivesh.production.partnerOnBoarding.R
import com.nivesh.production.partnerOnBoarding.R
import com.nivesh.production.partnerOnBoarding.api.ApiClient
import com.nivesh.production.partnerOnBoarding.databinding.FragmentGetStartedBinding
import com.nivesh.production.partnerOnBoarding.databinding.FragmentGetStartedBinding
import com.nivesh.production.partnerOnBoarding.model.DataX
import com.nivesh.production.partnerOnBoarding.model.request.PartnerRequest
import com.nivesh.production.partnerOnBoarding.model.response.*
import com.nivesh.production.partnerOnBoarding.providerfactory.OnBoardingModelProviderFactory
import com.nivesh.production.partnerOnBoarding.repositories.MainRepository
import com.nivesh.production.partnerOnBoarding.ui.activities.BaseActivity
import com.nivesh.production.partnerOnBoarding.ui.activities.BaseActivity
import com.nivesh.production.partnerOnBoarding.ui.activities.SignUpActivity
import com.nivesh.production.partnerOnBoarding.ui.activities.SignUpActivity
import com.nivesh.production.partnerOnBoarding.util.Common
import com.nivesh.production.partnerOnBoarding.util.*
import com.nivesh.production.partnerOnBoarding.util.Common.Companion.getFileExtension
import com.nivesh.production.partnerOnBoarding.util.Common.Companion.getFileExtension
import com.nivesh.production.partnerOnBoarding.util.Common.Companion.showDialogValidation
import com.nivesh.production.partnerOnBoarding.util.Common.Companion.showDialogWithTwoButtons
import com.nivesh.production.partnerOnBoarding.util.Common.Companion.showDialogWithTwoButtons
import com.nivesh.production.partnerOnBoarding.util.ImageUtil
import com.nivesh.production.partnerOnBoarding.viewModels.OnBoardingViewModel
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import java.io.*
import java.io.*
import java.util.*
import kotlin.collections.ArrayList
class GetStartedFragment : BaseFragment ( ) {
class GetStartedFragment : BaseFragment ( ) {
private var _binding : FragmentGetStartedBinding ? = null
private var _binding : FragmentGetStartedBinding ? = null
@ -45,9 +72,10 @@ class GetStartedFragment : BaseFragment() {
private var takeImageResult : ActivityResultLauncher < Uri > ? = null
private var takeImageResult : ActivityResultLauncher < Uri > ? = null
private var selectImageIntent : ActivityResultLauncher < String > ? = null
private var selectImageIntent : ActivityResultLauncher < String > ? = null
private var bitmap : Bitmap ? = null
private var bitmap : Bitmap ? = null
private var isPanVerify : Boolean = false
private val mainPANUpload : Int = 1
private val mainPANUpload : Int = 1
private val mainPhotoUpload : Int = 2
private val firstDoc Upload: Int = 3
private val mainARN PhotoUpload : Int = 2
private val mainEUINPhoto Upload: Int = 3
private val secondDocUpload : Int = 4
private val secondDocUpload : Int = 4
private var actionType : Int = - 1
private var actionType : Int = - 1
@ -63,8 +91,21 @@ class GetStartedFragment : BaseFragment() {
private var uploadPosition = 0
private var uploadPosition = 0
private var isFront : Boolean = false
private var isFront : Boolean = false
private var preSelectedDate = ""
private var preSelectedDate2 = ""
var year = 0
var month = 0
var day = 0
private var cal = Calendar . getInstance ( )
lateinit var viewModel : OnBoardingViewModel
private lateinit var listOfDocType : List < Data >
private var imageSelectedList = ArrayList < File > ( )
private var arnList = ArrayList < DataX > ( )
private lateinit var arnData : DataX
private lateinit var panRes : PANResponse
private var isCharacterTotalCountReach = false
private val MaxFileSize = 5
private val listArray = ArrayList < String > ( )
private val permissions = arrayOf (
private val permissions = arrayOf (
Manifest . permission . READ_EXTERNAL_STORAGE ,
Manifest . permission . READ_EXTERNAL_STORAGE ,
Manifest . permission . WRITE_EXTERNAL_STORAGE
Manifest . permission . WRITE_EXTERNAL_STORAGE
@ -146,82 +187,52 @@ class GetStartedFragment : BaseFragment() {
return isCorrect
return isCorrect
}
}
@SuppressLint ( "SuspiciousIndentation" )
private fun init ( ) {
private fun init ( ) {
viewModel = ViewModelProvider (
( activity as SignUpActivity ) ,
OnBoardingModelProviderFactory ( MainRepository ( ApiClient . getApiClientOne ) )
) [ OnBoardingViewModel :: class . java ]
var total_SYMBOLS : Int = 14
var TOTAL_DIGITS : Int = 12 // max numbers of digits in pattern: 0000 x 4
var DIVIDER_MODULO : Int = 4 // means divider position is every 5th symbol beginning with 1
var DIVIDER_POSITION : Int = DIVIDER_MODULO - 1 ; // means divider position is every 4th symbol beginning with 0
var DIVIDER : Char = '-'
var docType = "I"
if ( arguments ?. getString ( "arnType" ) . equals ( "Associate" , true ) ) {
binding . edtArnNumber . visibility = View . GONE
binding . tlArnNumber . visibility = View . GONE
binding . edtEUINNumber . addTextChangedListener ( object : TextWatcher {
override fun beforeTextChanged ( s : CharSequence ? , start : Int , count : Int , after : Int ) { }
override fun onTextChanged ( s : CharSequence ? , start : Int , before : Int , count : Int ) { }
override fun afterTextChanged ( s : Editable ) {
if ( ! isInputCorrect ( s , total_SYMBOLS , DIVIDER_MODULO , DIVIDER ) ) {
s . replace ( 0 , s . length , buildCorrectString ( getDigitArray ( s , TOTAL_DIGITS ) , DIVIDER_POSITION , DIVIDER ) )
}
}
binding . edtEUINNumber . visibility = View . GONE
binding . tlArnNumber . visibility = View . GONE
private fun isInputCorrect (
s : Editable ,
totalSymbols : Int ,
dividerModulo : Int ,
divider : Char
) : Boolean {
var isCorrect = s . length < = totalSymbols // check size of entered string
for ( i in s . indices ) { // check that every element is right
isCorrect = if ( i > 0 & & ( i + 1 ) % dividerModulo = = 0 ) {
isCorrect and ( divider = = s [ i ] )
} else {
isCorrect and Character . isDigit ( s [ i ] )
}
}
return isCorrect
}
binding . edtPassingAMFI . visibility = View . GONE
binding . tlPassingAMFI . visibility = View . GONE
private fun buildCorrectString (
digits : CharArray ,
dividerPosition : Int ,
divider : Char
) : String {
val formatted = StringBuilder ( )
for ( i in digits . indices ) {
if ( digits [ i ] . code ! = 0 ) {
formatted . append ( digits [ i ] )
if ( i > 0 & & i < digits . size - 1 & & ( i + 1 ) % dividerPosition = = 0 ) {
formatted . append ( divider )
}
}
}
return formatted . toString ( )
}
binding . edtExpiryAMFI . visibility = View . GONE
binding . tlExpiryAMFI . visibility = View . GONE
docType = "N"
private fun getDigitArray ( s : Editable , size : Int ) : CharArray {
val digits = CharArray ( size )
var index = 0
var i = 0
while ( i < s . length & & index < size ) {
val current = s [ i ]
if ( Character . isDigit ( current ) ) {
digits [ index ] = current
index + +
}
i + +
}
return digits
}
} else if ( arguments ?. getString ( "arnType" ) . equals ( "advisory" , true ) ) {
binding . edtArnNumber . visibility = View . VISIBLE
binding . tlArnNumber . visibility = View . VISIBLE
} )
binding . edtEUINNumber . visibility = View . VISIBLE
binding . tlArnNumber . visibility = View . VISIBLE
// binding.edtEUINNumber.doAfterTextChanged {
// val formattedText = binding.edtEUINNumber.toString().replace(" ", "").chunked(4).joinToString("/")
// if (formattedText != binding.edtEUINNumber.toString()) {
// binding.edtEUINNumber.setText(formattedText)
// binding.edtEUINNumber.setSelection(binding.edtEUINNumber.length())
// }
// }
binding . edtPassingAMFI . visibility = View . VISIBLE
binding . tlPassingAMFI . visibility = View . VISIBLE
binding . edtExpiryAMFI . visibility = View . VISIBLE
binding . tlExpiryAMFI . visibility = View . VISIBLE
docType = "I"
}
documentTypeAPI ( docType )
binding . edtPassingAMFI . setOnClickListener {
Common . datePicker ( activity as SignUpActivity , binding . edtPassingAMFI )
}
binding . edtExpiryAMFI . setOnClickListener {
Common . datePicker ( activity as SignUpActivity , binding . edtExpiryAMFI )
}
selectImageIntent = registerForActivityResult ( ActivityResultContracts . GetContent ( ) )
selectImageIntent = registerForActivityResult ( ActivityResultContracts . GetContent ( ) )
{ uri : Uri ? - >
{ uri : Uri ? - >
@ -231,64 +242,495 @@ class GetStartedFragment : BaseFragment() {
}
}
}
}
takeImageResult =
registerForActivityResult ( ActivityResultContracts . TakePicture ( ) ) { isSuccess - >
if ( isSuccess ) {
latestTmpUri ?. let { uri - >
uploadDocument ( uri , "c" )
}
binding . edtArnNumber . addTextChangedListener ( object : TextWatcher {
override fun beforeTextChanged ( s : CharSequence ? , start : Int , count : Int , after : Int ) { }
override fun onTextChanged ( s : CharSequence ? , start : Int , before : Int , count : Int ) {
if ( s ?. length !! = = 7 ) {
apiAMFIDetail ( "ARN" , s . toString ( ) )
}
}
}
}
binding . btnNext . setOnClickListener {
override fun afterTextChanged ( s : Editable ? ) { }
} )
binding . ivInfo . setOnClickListener {
replaceFragment (
replaceFragment (
activity as BaseActivity ,
activity as BaseActivity ,
R . id . signUpContainer ,
R . id . signUpContainer ,
AlmostThere Fragment( ) ,
Questions Fragment( ) ,
"GET STARTED" ,
"GET STARTED" ,
true
true
)
)
}
}
listArray . add ( "Aadhaar" )
listArray . add ( "Passport" )
listArray . add ( "Driving Licenses" )
listArray . add ( "Voter Id" )
binding . edtArnNumber . setOnItemClickListener { _ , _ , position , _ - >
if ( arnList ! = null & & arnList . size > 0 ) {
arnData = arnList [ position ]
if ( arnData . EUIN ! = null )
binding . edtEUINNumber . setText ( arnData . EUIN )
val arrayAdapter = ArrayAdapter (
activity as SignUpActivity ,
androidx . appcompat . R . layout . support_simple_spinner_dropdown_item ,
listArray
)
binding . spDocType . setAdapter ( arrayAdapter )
if ( arnData . ARNValidFrom ! = null )
binding . edtPassingAMFI . setText ( arnData . ARNValidFrom )
binding . spDocType . setOnItemClickListener { _ , _ , position , _ - >
setVisibility ( listArray [ position ] )
if ( arnData . ARNValidTill ! = null )
binding . edtExpiryAMFI . setText ( arnData . ARNValidTill )
} else {
binding . edtEUINNumber . setText ( "" )
binding . edtPassingAMFI . setText ( "" )
binding . edtExpiryAMFI . setText ( "" )
}
}
takeImageResult =
registerForActivityResult ( ActivityResultContracts . TakePicture ( ) ) { isSuccess - >
if ( isSuccess ) {
latestTmpUri ?. let { uri - >
uploadDocument ( uri , "c" )
}
}
}
binding . btnNext . setOnClickListener {
// apiUploadDocument()
if ( arguments ?. getString ( "arnType" ) . equals ( "Associate" , false ) ) {
val pt = PartnerRequest ( )
pt . Name = binding . edtFullNamePanCard . text . toString ( )
pt . PAN = binding . edtPanNumber . text . toString ( )
val fragment = AlmostThereFragment ( )
val bundle = Bundle ( )
bundle . putSerializable ( "Inputvalue" , pt )
bundle . putSerializable ( "arnData" , arnData )
bundle . putSerializable ( "PANDATA" , panRes )
bundle . putString ( "mobile" , arguments ?. getString ( "mobile" ) )
fragment . arguments = bundle
replaceFragment (
activity as BaseActivity ,
R . id . signUpContainer ,
fragment ,
"GET STARTED" ,
true
)
} else if ( arguments ?. getString ( "arnType" ) . equals ( "advisory" , false ) ) {
if ( validation ( ) ) {
val pt = PartnerRequest ( )
pt . ARNNumber = binding . edtArnNumber . text . toString ( )
pt . EUINNumber = binding . edtEUINNumber . text . toString ( )
pt . DateOfExpiryAMFICertificate = binding . edtExpiryAMFI . text . toString ( )
pt . Name = binding . edtFullNamePanCard . text . toString ( )
pt . PAN = binding . edtPanNumber . text . toString ( )
pt . DateOfPassingAMFICertificate = binding . edtPassingAMFI . text . toString ( )
val fragment = AlmostThereFragment ( )
val bundle = Bundle ( )
bundle . putSerializable ( "Inputvalue" , pt )
bundle . putSerializable ( "arnData" , arnData )
bundle . putSerializable ( "PANDATA" , panRes )
bundle . putString ( "mobile" , arguments ?. getString ( "mobile" ) )
fragment . arguments = bundle
replaceFragment (
activity as BaseActivity ,
R . id . signUpContainer ,
fragment ,
"GET STARTED" ,
true
)
}
}
}
}
binding . uploadFront . setOnClickListener {
binding . uploadFront . setOnClickListener {
actionType = mainPANUpload
actionType = mainPANUpload
isFront = true
isFront = true
selectImage ( )
if ( docValue . isNotBlank ( ) & & docValue . isNotEmpty ( ) ) {
selectImage ( )
} else {
showDialogValidation (
activity as SignUpActivity ,
resources . getString ( R . string . selectAddressProof )
)
}
}
}
binding . mbUploadChangeFront . setOnClickListener {
binding . mbUploadChangeFront . setOnClickListener {
actionType = mainPANUpload
actionType = mainPANUpload
isFront = true
isFront = true
selectImage ( )
if ( docValue . isNotBlank ( ) & & docValue . isNotEmpty ( ) ) {
selectImage ( )
} else {
showDialogValidation (
activity as SignUpActivity ,
resources . getString ( R . string . selectAddressProof )
)
}
}
}
binding . mbUploadChangeBack . setOnClickListener {
binding . mbUploadChangeBack . setOnClickListener {
actionType = mainPANUpload
actionType = mainPANUpload
isFront = false
isFront = false
selectImage ( )
if ( docValue . isNotBlank ( ) & & docValue . isNotEmpty ( ) ) {
selectImage ( )
} else {
showDialogValidation (
activity as SignUpActivity ,
resources . getString ( R . string . selectAddressProof )
)
}
}
}
binding . uploadBack . setOnClickListener {
binding . uploadBack . setOnClickListener {
actionType = mainPANUpload
actionType = mainPANUpload
isFront = false
isFront = false
if ( docValue . isNotBlank ( ) & & docValue . isNotEmpty ( ) ) {
selectImage ( )
} else {
showDialogValidation (
activity as SignUpActivity ,
resources . getString ( R . string . selectAddressProof )
)
}
}
binding . rlARNUpload . setOnClickListener {
actionType = mainARNPhotoUpload
selectImage ( )
}
binding . rlEUINUpload . setOnClickListener {
actionType = mainEUINPhotoUpload
selectImage ( )
selectImage ( )
}
}
binding . edtPanNumber . addTextChangedListener ( object : TextWatcher {
override fun onTextChanged ( s : CharSequence ? , start : Int , before : Int , count : Int ) {
Common . removeError ( binding . tlPanNumber )
if ( s . toString ( ) . length > 3 & & s . toString ( ) [ 3 ] ! = 'P' ) {
binding . rlEUINUpload . visibility = View . VISIBLE
if ( ! TextUtils . isEmpty ( binding . edtEUINNumber . text ) ) {
binding . edtEUINNumberNF . setText ( binding . edtEUINNumber . text . toString ( ) )
binding . edtEUINNumber . visibility = View . GONE
}
} else if ( s . toString ( ) . length > 3 & & s . toString ( ) [ 3 ] = = 'P' ) {
binding . rlEUINUpload . visibility = View . GONE
}
if ( s . toString ( ) . trim ( ) . length > = 10 & & ! isPanVerify ) {
apiPANVerify ( s . toString ( ) . trim ( ) )
} else if ( s . toString ( ) . trim ( ) . length < 10 & & ! isPanVerify ) {
binding . edtPanNumber . setCompoundDrawablesWithIntrinsicBounds (
0 ,
0 ,
0 ,
0
)
binding . edtFullNamePanCard . setText ( "" )
} else if ( s . toString ( ) . length < 10 ) {
isPanVerify = false
binding . edtPanNumber . setCompoundDrawablesWithIntrinsicBounds (
0 ,
0 ,
0 ,
0
)
}
else {
binding . edtPanNumber . setCompoundDrawablesWithIntrinsicBounds (
0 ,
0 ,
R . drawable . svg_pan_verified ,
0
)
}
}
override fun afterTextChanged ( s : Editable ? ) { }
override fun beforeTextChanged ( s : CharSequence ? , start : Int , count : Int , after : Int ) { }
} )
binding . spDocType . onItemClickListener =
AdapterView . OnItemClickListener { parent , _ , position , _ - >
val getCodes : Data = parent . getItemAtPosition ( position ) as Data
imageSelectedList . clear ( )
docValue = getCodes . DocumentType
setVisibility ( listOfDocType [ position ] . DocumentType )
}
}
private fun documentTypeAPI ( docType : String ) {
try {
ProgressUtil . showLoading ( activity as SignUpActivity )
( activity as SignUpActivity ) . viewModelOne . getDocumentType (
"3" , //Currently it is static
docType ,
Constants . BASE_URL_COMMON + "User/GetAllDocumentsType" ,
( activity as SignUpActivity )
)
ProgressUtil . hideLoading ( )
( activity as SignUpActivity ) . viewModelOne . getDocumentTypeMutableData . observe (
viewLifecycleOwner
) { response - >
val res : DocumentTypeResponse =
Gson ( ) . fromJson (
response ?. data . toString ( ) ,
DocumentTypeResponse :: class . java
)
Log . e ( "checkDocRes" , res . toString ( ) )
if ( res . Status = = "success" ) {
listOfDocType = res . Result . Data
if ( listOfDocType . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as SignUpActivity ,
android . R . layout . simple_list_item_1 ,
listOfDocType
)
binding . spDocType . setAdapter ( adapter )
}
}
//TODO: Check AMFI Data Available or not
apiAMFIDetail ( "Mobile" , arguments ?. getString ( "mobile" ) )
// apiAMFIDetail("Mobile", "1722651388")
}
} catch ( e : Exception ) {
// ProgressUtil.hideLoading()
Log . e ( "checkPANError" , e . message . toString ( ) )
}
}
private fun prepareImagePart ( file : File , partName : String ) : MultipartBody . Part {
var requestBody : RequestBody =
file . asRequestBody ( "application/octet-stream" . toMediaTypeOrNull ( ) )
return MultipartBody . Part . createFormData (
"Files" ,
partName ,
requestBody
)
}
private fun apiUploadDocument ( ) {
if ( imageSelectedList ! = null & & imageSelectedList . size ! = 0 ) {
var part = ArrayList < MultipartBody . Part > ( )
imageSelectedList . forEachIndexed { index , element - >
if ( index = = 0 ) {
part . add ( prepareImagePart ( element , "front" ) )
} else {
part . add ( prepareImagePart ( element , "back" ) )
}
}
( activity as SignUpActivity ) . viewModelOne . getDocumentUpload (
part ,
3 ,
5 ,
8 ,
( activity as SignUpActivity )
)
( activity as SignUpActivity ) . viewModelOne . getDocumentUploadMutableData . observe (
viewLifecycleOwner
) { response - >
Log . e ( "check_upload_res" , response . toString ( ) )
val res : DocumentUploadResponse =
Gson ( ) . fromJson (
response ?. data . toString ( ) ,
DocumentUploadResponse :: class . java
)
if ( res . Status = = "success" ) {
Toast . makeText ( activity as SignUpActivity , res . Message , Toast . LENGTH_LONG )
. show ( )
}
}
}
}
private fun apiPANVerify ( pan : String ) {
try {
ProgressUtil . showLoading ( activity as SignUpActivity )
( activity as SignUpActivity ) . viewModelOne . getPANDetail (
pan ,
Constants . BASE_URL_COMMON + "User/GetPANDetail" ,
( activity as SignUpActivity )
)
( activity as SignUpActivity ) . viewModelOne . getPANDetailMutableData . observe (
viewLifecycleOwner
) { response - >
ProgressUtil . hideLoading ( )
val res : PANResponse =
Gson ( ) . fromJson (
response ?. data . toString ( ) ,
PANResponse :: class . java
)
panRes = res
isPanVerify = if ( res . Status = = "success" ) {
binding . edtPanNumber . setCompoundDrawablesWithIntrinsicBounds (
0 ,
0 ,
R . drawable . svg_pan_verified ,
0
)
binding . edtFullNamePanCard . setText ( res . Result . data . FullName )
true
} else {
commonErrorMethod (
binding . edtPanNumber ,
binding . tlPanNumber ,
getString ( R . string . invalidPAN )
)
}
}
} catch ( e : Exception ) {
ProgressUtil . hideLoading ( )
Log . e ( "checkPANError" , e . message . toString ( ) )
}
}
private fun apiAMFIDetail ( type : String , value : String ? ) {
var jsonObject = JSONObject ( )
val mediaType = "application/json; charset=utf-8" . toMediaType ( )
var body : RequestBody
try {
jsonObject . put ( type , value )
body = jsonObject . toString ( ) . toRequestBody ( mediaType )
( activity as SignUpActivity ) . viewModelOne . getAMFIDetail (
body ,
"" ,
( activity as SignUpActivity )
)
( activity as SignUpActivity ) . viewModelOne . getAMFIDetailMutableData . observe (
viewLifecycleOwner
) { response - >
val res : GetAMFIDetailResponse =
Gson ( ) . fromJson (
response ?. data . toString ( ) ,
GetAMFIDetailResponse :: class . java
)
//TODO: Need to set up Data if not null
if ( res ! = null & & res . Result . data ! = null ) {
arnList . clear ( )
arnList = res . Result . data as ArrayList < DataX >
if ( res . Status = = "success" ) {
if ( type = = "ARN" ) {
if ( arnList . size > 0 ) {
arnData = arnList [ 0 ]
if ( arnData . EUIN ! = null )
binding . edtEUINNumber . setText ( arnData . EUIN )
if ( arnData . ARNValidFrom ! = null )
binding . edtPassingAMFI . setText ( arnData . ARNValidFrom )
if ( arnData . ARNValidTill ! = null )
binding . edtExpiryAMFI . setText ( arnData . ARNValidTill )
}
setARNEUIN ( View . GONE )
} else {
var adapter = ArrayAdapter (
( activity as SignUpActivity ) ,
androidx . appcompat . R . layout . support_simple_spinner_dropdown_item ,
arnList
)
binding . edtArnNumber . setAdapter ( adapter )
}
} else if ( type = = "ARN" & & binding . edtArnNumber . text . length > = 7 ) {
setARNEUIN ( View . VISIBLE )
}
}
}
} catch ( e : Exception ) {
Log . e ( "check_error" , e . message . toString ( ) + "\n" + type + "\n" + value )
}
}
private fun setARNEUIN ( visibility : Int ) {
binding . rlARNUpload . visibility = visibility
// binding.rlEUINUpload.visibility = visibility
// if(visibility==View.VISIBLE) binding.tlEUINNumber.visibility = View.GONE
// else binding.tlEUINNumber.visibility = View.VISIBLE
}
private fun commonErrorMethod (
inputText : TextInputEditText ,
inputError : TextInputLayout ,
strMessage : String
) : Boolean {
inputText . requestFocus ( )
inputError . error = strMessage
return false
}
private fun commonErrorMethodAutoComplete (
inputText : MaterialAutoCompleteTextView ,
inputError : TextInputLayout ,
strMessage : String
) : Boolean {
inputText . requestFocus ( )
inputError . error = strMessage
return false
}
private fun validation ( ) : Boolean {
return if ( binding . edtArnNumber . text . toString ( ) . isEmpty ( ) ) {
commonErrorMethodAutoComplete (
binding . edtArnNumber ,
binding . tlArnNumber ,
getString ( R . string . pleaseArnNum )
)
} else if ( binding . edtEUINNumber . text . toString ( ) . isEmpty ( ) ) {
commonErrorMethod (
binding . edtEUINNumber ,
binding . tlEUINNumber ,
getString ( R . string . pleaseEuinNum )
)
} else if ( binding . edtPassingAMFI . text . toString ( ) . isEmpty ( ) ) {
commonErrorMethod (
binding . edtPassingAMFI ,
binding . tlPassingAMFI ,
getString ( R . string . pleasePassingCertificate )
)
} else if ( binding . edtExpiryAMFI . text . toString ( ) . isEmpty ( ) ) {
commonErrorMethod (
binding . edtExpiryAMFI ,
binding . tlExpiryAMFI ,
getString ( R . string . pleaseExpirCertificate )
)
} else if ( binding . edtPanNumber . text . toString ( ) . isEmpty ( ) ) {
commonErrorMethod (
binding . edtPanNumber ,
binding . tlPanNumber ,
getString ( R . string . emptyPAN )
)
} else if ( binding . edtFullNamePanCard . text . toString ( ) . isEmpty ( ) ) {
commonErrorMethod (
binding . edtFullNamePanCard ,
binding . tlFullNamePanCard ,
getString ( R . string . full_name_as_on_pan_card )
)
} else if ( imageSelectedList = = null & & imageSelectedList . size = = 0 ) {
showDialogValidation (
( activity as SignUpActivity ) ,
resources . getString ( R . string . selectAddressProof )
)
false
} else {
true
}
}
}
private fun setUploadOption ( checked : Boolean ) {
private fun setUploadOption ( checked : Boolean ) {
@ -376,6 +818,7 @@ class GetStartedFragment : BaseFragment() {
}
}
private fun setVisibility ( s : String ) {
private fun setVisibility ( s : String ) {
binding . llDoc . visibility = View . VISIBLE
if ( s . contains ( "Aadhaar" ) ) {
if ( s . contains ( "Aadhaar" ) ) {
binding . txtFront . visibility = View . VISIBLE
binding . txtFront . visibility = View . VISIBLE
binding . uploadFront . visibility = View . VISIBLE
binding . uploadFront . visibility = View . VISIBLE
@ -475,58 +918,105 @@ class GetStartedFragment : BaseFragment() {
val size : Double = Common . getFileSizeInMB ( fileExtension . length ( ) )
val size : Double = Common . getFileSizeInMB ( fileExtension . length ( ) )
setFrontHideVisible ( uri )
setFrontHideVisible ( uri )
if ( size < 5 ) {
if ( type = = "c" ) encodedPANBase64 ( fileExtension )
else panString = bitmap ?. let { ImageUtil . convert ( it ) } . toString ( )
if ( size < MaxFileSize ) {
if ( type = = "c" ) {
encodedPANBase64 ( fileExtension )
if ( isFront ) imageSelectedList . add ( 0 , fileExtension )
else imageSelectedList . add ( 1 , fileExtension )
} else {
val bitmap : Bitmap =
MediaStore . Images . Media . getBitmap ( context ?. contentResolver , uri )
val fileName : String = System . currentTimeMillis ( ) . toString ( )
val file = File ( fileDir , fileName . plus ( ".png" ) )
val fOut = FileOutputStream ( file )
bitmap . compress ( Bitmap . CompressFormat . PNG , 100 , fOut )
fOut . flush ( )
fOut . close ( )
if ( file . exists ( ) ) encodedPANBase64 ( file )
if ( isFront ) imageSelectedList . add ( 0 , file )
else imageSelectedList . add ( 1 , file )
Log . e ( "check_panString" , panString + "\n" + bitmap . toString ( ) )
}
} else {
} else {
panString = ""
panString = ""
panFileExt = ""
panFileExt = ""
showDialogValidation ( activity , getString ( R . string . fileSizeCant ) )
}
}
}
}
mainARNPhotoUpload - > {
val fileDir : File = ( activity as SignUpActivity ) . cacheDir
val fileExtension = File ( fileDir . toString ( ) . plus ( "/" ) . plus ( getFileName ( uri ) ) )
panFileExt = getFileExtension ( getFileName ( uri ) )
val size : Double = Common . getFileSizeInMB ( fileExtension . length ( ) )
binding . ivARNUpload . setImageURI ( uri )
if ( size < MaxFileSize ) {
if ( type = = "c" ) {
encodedPANBase64 ( fileExtension )
imageSelectedList . add ( 2 , fileExtension )
} else {
val bitmap : Bitmap =
MediaStore . Images . Media . getBitmap ( context ?. contentResolver , uri )
val fileName : String = System . currentTimeMillis ( ) . toString ( )
// mainPhotoUpload -> {
// binding.ivPhotograph.visibility = View.VISIBLE
// val fileDir: File = requireActivity().cacheDir
// val fileExtension = File(fileDir.toString().plus("/").plus(getFileName(uri)))
// photoFileExt = getFileExtension(getFileName(uri))
// val size: Double = Common.getFileSizeInMB(fileExtension.length())
// if (size < 5) {
// if (type == "c") encodedPhotoBase64(fileExtension)
// else photoString = bitmap?.let { ImageUtil.convert(it) }.toString()
// } else {
// photoString = ""
// photoFileExt = ""
// }
// }
// firstDocUpload -> {
// binding.ivAadharFront.visibility = View.VISIBLE
// val fileDir: File = requireActivity().cacheDir
// val fileExtension = File(fileDir.toString().plus("/").plus(getFileName(uri)))
// doc1FileExt = getFileExtension(getFileName(uri))
// val size: Double = Common.getFileSizeInMB(fileExtension.length())
// if (size < 5) {
// if (type == "c") encodedUpload1Base64(fileExtension)
// else docString = bitmap?.let { ImageUtil.convert(it) }.toString()
// } else {
// docString = ""
// doc1FileExt = ""
// }
// }
// else -> {
// binding.ivAadharBack.visibility = View.VISIBLE
// val fileDir: File = requireActivity().cacheDir
// val fileExtension = File(fileDir.toString().plus("/").plus(getFileName(uri)))
// doc2fileExt = getFileExtension(getFileName(uri))
// val size: Double = Common.getFileSizeInMB(fileExtension.length())
// if (size < 5) {
// if (type == "c") encodedFileToBase64(fileExtension)
// else docString2 = bitmap?.let { ImageUtil.convert(it) }.toString()
// } else {
// docString2 = ""
// doc2fileExt = ""
// }
// }
val file = File ( fileDir , fileName . plus ( ".png" ) )
val fOut = FileOutputStream ( file )
bitmap . compress ( Bitmap . CompressFormat . PNG , 100 , fOut )
fOut . flush ( )
fOut . close ( )
if ( file . exists ( ) ) encodedPANBase64 ( file )
imageSelectedList . add ( 2 , file )
Log . e ( "check_panString" , panString + "\n" + bitmap . toString ( ) )
}
} else {
panString = ""
panFileExt = ""
showDialogValidation ( activity , getString ( R . string . fileSizeCant ) )
}
}
mainEUINPhotoUpload - > {
val fileDir : File = ( activity as SignUpActivity ) . cacheDir
val fileExtension = File ( fileDir . toString ( ) . plus ( "/" ) . plus ( getFileName ( uri ) ) )
panFileExt = getFileExtension ( getFileName ( uri ) )
val size : Double = Common . getFileSizeInMB ( fileExtension . length ( ) )
binding . ivEUINUpload . setImageURI ( uri )
if ( size < MaxFileSize ) {
if ( type = = "c" ) {
encodedPANBase64 ( fileExtension )
imageSelectedList . add ( 3 , fileExtension )
} else {
val bitmap : Bitmap =
MediaStore . Images . Media . getBitmap ( context ?. contentResolver , uri )
val fileName : String = System . currentTimeMillis ( ) . toString ( )
val file = File ( fileDir , fileName . plus ( ".png" ) )
val fOut = FileOutputStream ( file )
bitmap . compress ( Bitmap . CompressFormat . PNG , 100 , fOut )
fOut . flush ( )
fOut . close ( )
if ( file . exists ( ) ) encodedPANBase64 ( file )
imageSelectedList . add ( 3 , file )
Log . e ( "check_panString" , panString + "\n" + bitmap . toString ( ) )
}
} else {
panString = ""
panFileExt = ""
showDialogValidation ( activity , getString ( R . string . fileSizeCant ) )
}
}
}
}
}
}