@ -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,58 @@ 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.isValidIndividualPan
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.util.Constants.Companion.maxFileSize
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.*
class GetStartedFragment : BaseFragment ( ) {
class GetStartedFragment : BaseFragment ( ) {
private var _binding : FragmentGetStartedBinding ? = null
private var _binding : FragmentGetStartedBinding ? = null
@ -45,26 +73,23 @@ 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 firstDocUpload : Int = 3
private val secondDocUpload : Int = 4
private val mainARNPhotoUpload : Int = 2
private val mainEUINPhotoUpload : Int = 3
private var actionType : Int = - 1
private var actionType : Int = - 1
private var panString : String = ""
private var panString : String = ""
private var photoString : String = ""
private var docString : String = ""
private var docString2 : String = ""
private var panFileExt : String ? = ""
private var panFileExt : String ? = ""
private var photoFileExt : String ? = ""
private var doc1FileExt : String ? = ""
private var doc2fileExt : String ? = ""
private var docValue : String = ""
private var docValue : String = ""
private var uploadPosition = 0
private var isFront : Boolean = false
private var isFront : Boolean = false
private 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 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
@ -86,18 +111,8 @@ class GetStartedFragment : BaseFragment() {
private val requestGalleryPermission = registerForActivityResult (
private val requestGalleryPermission = registerForActivityResult (
ActivityResultContracts . RequestMultiplePermissions ( )
ActivityResultContracts . RequestMultiplePermissions ( )
) { permission - >
// if (!permission.containsValue(false)) {
) {
selectImageIntent ?. launch ( "image/*" )
selectImageIntent ?. launch ( "image/*" )
// } else {
// showDialogWithTwoButtons(
// (activity as SignUpActivity),
// getString(R.string.galleryPermission),
// getString(
// R.string.permissionsRequired
// )
// )
// }
}
}
override fun onCreateView (
override fun onCreateView (
@ -105,7 +120,6 @@ class GetStartedFragment : BaseFragment() {
container : ViewGroup ? ,
container : ViewGroup ? ,
savedInstanceState : Bundle ?
savedInstanceState : Bundle ?
) : View {
) : View {
// Inflate the layout for this fragment
_binding = FragmentGetStartedBinding . inflate ( inflater , container , false )
_binding = FragmentGetStartedBinding . inflate ( inflater , container , false )
return binding . root
return binding . root
}
}
@ -129,105 +143,77 @@ class GetStartedFragment : BaseFragment() {
return null
return null
}
}
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 ] )
}
@SuppressLint ( "SuspiciousIndentation" )
private fun init ( ) {
viewModel = ViewModelProvider (
( activity as SignUpActivity ) ,
OnBoardingModelProviderFactory ( MainRepository ( ApiClient . getApiClientOne ) )
) [ OnBoardingViewModel :: class . java ]
var docType = "I"
if ( arguments ?. getString ( "arnType" ) . equals ( "Associate" , true ) ) {
commonMethodForVisibility ( View . GONE )
docType = "N"
} else if ( arguments ?. getString ( "arnType" ) . equals ( "advisory" , true ) ) {
commonMethodForVisibility ( View . VISIBLE )
docType = "I"
}
}
return isCorrect
}
private fun init ( ) {
documentTypeAPI ( docType )
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 = '-'
binding . edtPassingAMFI . setOnClickListener {
Common . datePicker ( activity as SignUpActivity , binding . edtPassingAMFI )
}
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 . edtExpiryAMFI . setOnClickListener {
Common . datePicker ( activity as SignUpActivity , binding . edtExpiryAMFI )
}
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
selectImageIntent = registerForActivityResult ( ActivityResultContracts . GetContent ( ) )
{ uri : Uri ? - >
if ( uri ! = null ) {
bitmap = uriToBitmap ( uri )
uploadDocument ( uri , "g" )
}
}
}
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 . 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 ) {
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 + +
if ( s ?. length !! = = 7 ) {
apiAMFIDetail ( "ARN" , s . toString ( ) )
}
}
return digits
}
}
override fun afterTextChanged ( s : Editable ? ) { }
} )
} )
// 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 . ivInfo . setOnClickListener {
replaceFragment (
activity as BaseActivity ,
R . id . signUpContainer ,
QuestionsFragment ( ) ,
"GET STARTED" ,
true
)
}
binding . edtArnNumber . setOnItemClickListener { _ , _ , position , _ - >
if ( arnList ! = null & & arnList . size > 0 ) {
arnData = arnList [ position ]
if ( arnData . EUIN ! = null )
binding . edtEUINNumber . setText ( arnData . EUIN )
selectImageIntent = registerForActivityResult ( ActivityResultContracts . GetContent ( ) )
{ uri : Uri ? - >
if ( uri ! = null ) {
bitmap = uriToBitmap ( uri )
uploadDocument ( uri , "g" )
if ( arnData . ARNValidFrom ! = null )
binding . edtPassingAMFI . setText ( arnData . ARNValidFrom )
if ( arnData . ARNValidTill ! = null )
binding . edtExpiryAMFI . setText ( arnData . ARNValidTill )
} else {
binding . edtEUINNumber . setText ( "" )
binding . edtPassingAMFI . setText ( "" )
binding . edtExpiryAMFI . setText ( "" )
}
}
}
}
@ -241,58 +227,398 @@ class GetStartedFragment : BaseFragment() {
}
}
binding . btnNext . setOnClickListener {
binding . btnNext . setOnClickListener {
replaceFragment (
activity as BaseActivity ,
R . id . signUpContainer ,
AlmostThereFragment ( ) ,
"GET STARTED" ,
tru e
)
}
listArray . add ( "Aadhaar" )
listArray . add ( "Passport" )
listArray . add ( "Driving Licenses" )
listArray . add ( "Voter Id" )
val arrayAdapter = ArrayAdapter (
activity as SignUpActivity ,
androidx . appcompat . R . layout . support_simple_spinner_dropdown_item ,
listArray
)
binding . spDocType . setAdapter ( arrayAdapter )
if ( arguments ?. getString ( "arnType" ) . equals ( "Associate" , false ) ) {
val pt = PartnerRequest ( )
pt . Name = binding . edtFullNamePanCard . text . toString ( )
pt . PAN = binding . edtPanNumber . text . toString ( )
val fragmen t = AlmostThe reFragment ( )
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 . spDocType . setOnItemClickListener { _ , _ , position , _ - >
setVisibility ( listArray [ position ] )
} 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 ( isValidIndividualPan ( s . toString ( ) . trim ( ) ) ) {
binding . rlEUINUpload . visibility = View . GONE
} else {
binding . rlEUINUpload . visibility = View . VISIBLE
if ( ! TextUtils . isEmpty ( binding . edtEUINNumber . text ) ) {
binding . edtEUINNumberNF . setText ( binding . edtEUINNumber . text . toString ( ) )
binding . edtEUINNumber . 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 commonMethodForVisibility ( visibility : Int ) {
binding . edtArnNumber . visibility = visibility
binding . tlArnNumber . visibility = visibility
binding . edtEUINNumber . visibility = visibility
binding . tlArnNumber . visibility = visibility
binding . edtPassingAMFI . visibility = visibility
binding . tlPassingAMFI . visibility = visibility
binding . edtExpiryAMFI . visibility = visibility
binding . tlExpiryAMFI . visibility = visibility
}
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 = = getString ( R . string . successText ) ) {
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 )
}
}
apiAMFIDetail ( "Mobile" , arguments ?. getString ( "mobile" ) )
}
} catch ( e : Exception ) {
Log . e ( "checkPANError" , e . message . toString ( ) )
}
}
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 setUploadOption ( checked : Boolean ) {
isFront = checked
private fun apiAMFIDetail ( type : String , value : String ? ) {
val jsonObject = JSONObject ( )
val mediaType = "application/json; charset=utf-8" . toMediaType ( )
val 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
)
if ( res ! = null & & res . Result . data ! = null ) {
arnList . clear ( )
arnList = res . Result . data as ArrayList < DataX >
if ( res . Status = = getString ( R . string . successText ) ) {
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 )
}
setArnUploadVisibility ( View . GONE )
} else {
val 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 ) {
setArnUploadVisibility ( View . VISIBLE )
}
}
}
} catch ( e : Exception ) {
Log . e ( "check_error" , e . message . toString ( ) + "\n" + type + "\n" + value )
}
}
private fun setArnUploadVisibility ( visibility : Int ) {
binding . rlARNUpload . visibility = visibility
}
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 selectImage ( ) {
private fun selectImage ( ) {
@ -376,7 +702,8 @@ class GetStartedFragment : BaseFragment() {
}
}
private fun setVisibility ( s : String ) {
private fun setVisibility ( s : String ) {
if ( s . contains ( "Aadhaar" ) ) {
binding . llDoc . visibility = View . VISIBLE
if ( s . contains ( getString ( R . string . aadhaarText ) ) ) {
binding . txtFront . visibility = View . VISIBLE
binding . txtFront . visibility = View . VISIBLE
binding . uploadFront . visibility = View . VISIBLE
binding . uploadFront . visibility = View . VISIBLE
binding . txtBack . visibility = View . VISIBLE
binding . txtBack . visibility = View . VISIBLE
@ -475,61 +802,159 @@ 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 ( )
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 )
// 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 = ""
// }
// }
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 ) )
}
}
}
}
}
}
private fun apiUploadDocument ( ) {
if ( imageSelectedList ! = null & & imageSelectedList . size ! = 0 ) {
val 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 = = getString ( R . string . successText ) ) {
Toast . makeText ( activity as SignUpActivity , res . Message , Toast . LENGTH_LONG )
. show ( )
}
}
}
}
private fun prepareImagePart ( file : File , partName : String ) : MultipartBody . Part {
val requestBody : RequestBody =
file . asRequestBody ( "application/octet-stream" . toMediaTypeOrNull ( ) )
return MultipartBody . Part . createFormData (
"Files" ,
partName ,
requestBody
)
}
private fun setFrontHideVisible ( uri : Uri ) {
private fun setFrontHideVisible ( uri : Uri ) {
if ( isFront ) {
if ( isFront ) {
binding . uploadFront . visibility = View . GONE
binding . uploadFront . visibility = View . GONE