|
@ -1,19 +1,25 @@ |
|
|
package com.nivesh.production.niveshfd.partnerOnBoarding.ui.fragments1 |
|
|
package com.nivesh.production.niveshfd.partnerOnBoarding.ui.fragments1 |
|
|
|
|
|
|
|
|
import android.Manifest |
|
|
import android.Manifest |
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
import android.app.Activity |
|
|
import android.app.Activity |
|
|
import android.content.DialogInterface |
|
|
import android.content.DialogInterface |
|
|
import android.content.pm.PackageManager |
|
|
import android.content.pm.PackageManager |
|
|
|
|
|
import android.database.Cursor |
|
|
import android.graphics.Bitmap |
|
|
import android.graphics.Bitmap |
|
|
import android.graphics.BitmapFactory |
|
|
import android.graphics.BitmapFactory |
|
|
|
|
|
import android.graphics.Color |
|
|
import android.net.Uri |
|
|
import android.net.Uri |
|
|
import android.os.Bundle |
|
|
import android.os.Bundle |
|
|
|
|
|
import android.provider.OpenableColumns |
|
|
|
|
|
import android.text.Editable |
|
|
|
|
|
import android.text.TextWatcher |
|
|
|
|
|
import android.util.Base64 |
|
|
|
|
|
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.Switch |
|
|
|
|
|
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 |
|
@ -21,24 +27,18 @@ 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.lifecycleScope |
|
|
import androidx.lifecycle.lifecycleScope |
|
|
import com.google.android.material.button.MaterialButton |
|
|
|
|
|
|
|
|
import com.nivesh.production.niveshfd.BuildConfig |
|
|
import com.nivesh.production.niveshfd.R |
|
|
import com.nivesh.production.niveshfd.R |
|
|
import com.nivesh.production.niveshfd.databinding.FragmentGetStartedBinding |
|
|
import com.nivesh.production.niveshfd.databinding.FragmentGetStartedBinding |
|
|
import com.nivesh.production.niveshfd.fd.db.PreferenceManager |
|
|
|
|
|
import com.nivesh.production.niveshfd.fd.ui.activity.BaseActivity |
|
|
import com.nivesh.production.niveshfd.fd.ui.activity.BaseActivity |
|
|
|
|
|
import com.nivesh.production.niveshfd.fd.util.Common |
|
|
|
|
|
import com.nivesh.production.niveshfd.fd.util.Common.Companion.getFileExtension |
|
|
import com.nivesh.production.niveshfd.fd.util.Common.Companion.showDialogWithTwoButtons |
|
|
import com.nivesh.production.niveshfd.fd.util.Common.Companion.showDialogWithTwoButtons |
|
|
|
|
|
import com.nivesh.production.niveshfd.fd.util.ImageUtil |
|
|
import com.nivesh.production.niveshfd.partnerOnBoarding.ui.activities1.SignUpActivity |
|
|
import com.nivesh.production.niveshfd.partnerOnBoarding.ui.activities1.SignUpActivity |
|
|
import java.io.File |
|
|
|
|
|
import java.io.FileDescriptor |
|
|
|
|
|
import java.io.IOException |
|
|
|
|
|
|
|
|
|
|
|
private const val ARG_PARAM1 = "param1" |
|
|
|
|
|
private const val ARG_PARAM2 = "param2" |
|
|
|
|
|
|
|
|
import java.io.* |
|
|
|
|
|
|
|
|
class GetStartedFragment : BaseFragment() { |
|
|
class GetStartedFragment : BaseFragment() { |
|
|
// TODO: Rename and change types of parameters |
|
|
|
|
|
private var param1: String? = null |
|
|
|
|
|
private var param2: String? = null |
|
|
|
|
|
private var _binding: FragmentGetStartedBinding? = null |
|
|
private var _binding: FragmentGetStartedBinding? = null |
|
|
private val binding get() = _binding!! |
|
|
private val binding get() = _binding!! |
|
|
private var latestTmpUri: Uri? = null |
|
|
private var latestTmpUri: Uri? = null |
|
@ -51,6 +51,19 @@ class GetStartedFragment : BaseFragment() { |
|
|
private val secondDocUpload: Int = 4 |
|
|
private val secondDocUpload: Int = 4 |
|
|
private var actionType: Int = -1 |
|
|
private var actionType: Int = -1 |
|
|
|
|
|
|
|
|
|
|
|
private var panString: String = "" |
|
|
|
|
|
private var photoString: String = "" |
|
|
|
|
|
private var docString: String = "" |
|
|
|
|
|
private var docString2: String = "" |
|
|
|
|
|
private var panFileExt: String? = "" |
|
|
|
|
|
private var photoFileExt: String? = "" |
|
|
|
|
|
private var doc1FileExt: String? = "" |
|
|
|
|
|
private var doc2fileExt: String? = "" |
|
|
|
|
|
private var docValue: String = "" |
|
|
|
|
|
private var uploadPosition = 0 |
|
|
|
|
|
|
|
|
|
|
|
private var isFront: Boolean = false |
|
|
|
|
|
|
|
|
private val listArray = ArrayList<String>() |
|
|
private val listArray = ArrayList<String>() |
|
|
private val permissions = arrayOf( |
|
|
private val permissions = arrayOf( |
|
|
Manifest.permission.READ_EXTERNAL_STORAGE, |
|
|
Manifest.permission.READ_EXTERNAL_STORAGE, |
|
@ -74,28 +87,24 @@ class GetStartedFragment : BaseFragment() { |
|
|
private val requestGalleryPermission = registerForActivityResult( |
|
|
private val requestGalleryPermission = registerForActivityResult( |
|
|
ActivityResultContracts.RequestMultiplePermissions() |
|
|
ActivityResultContracts.RequestMultiplePermissions() |
|
|
) { permission -> |
|
|
) { permission -> |
|
|
if (!permission.containsValue(false)) { |
|
|
|
|
|
selectImageIntent?.launch("image/*") |
|
|
|
|
|
} else { |
|
|
|
|
|
showDialogWithTwoButtons( |
|
|
|
|
|
(activity as SignUpActivity), |
|
|
|
|
|
getString(R.string.galleryPermission), |
|
|
|
|
|
getString( |
|
|
|
|
|
R.string.permissionsRequired |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
|
arguments?.let { |
|
|
|
|
|
param1 = it.getString(ARG_PARAM1) |
|
|
|
|
|
param2 = it.getString(ARG_PARAM2) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// if (!permission.containsValue(false)) { |
|
|
|
|
|
selectImageIntent?.launch("image/*") |
|
|
|
|
|
// } else { |
|
|
|
|
|
// showDialogWithTwoButtons( |
|
|
|
|
|
// (activity as SignUpActivity), |
|
|
|
|
|
// getString(R.string.galleryPermission), |
|
|
|
|
|
// getString( |
|
|
|
|
|
// R.string.permissionsRequired |
|
|
|
|
|
// ) |
|
|
|
|
|
// ) |
|
|
|
|
|
// } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { |
|
|
|
|
|
|
|
|
override fun onCreateView( |
|
|
|
|
|
inflater: LayoutInflater, |
|
|
|
|
|
container: ViewGroup?, |
|
|
|
|
|
savedInstanceState: Bundle? |
|
|
|
|
|
): View { |
|
|
// Inflate the layout for this fragment |
|
|
// Inflate the layout for this fragment |
|
|
_binding = FragmentGetStartedBinding.inflate(inflater, container, false) |
|
|
_binding = FragmentGetStartedBinding.inflate(inflater, container, false) |
|
|
return binding.root |
|
|
return binding.root |
|
@ -104,23 +113,6 @@ class GetStartedFragment : BaseFragment() { |
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
init() |
|
|
init() |
|
|
|
|
|
|
|
|
selectImageIntent = registerForActivityResult(ActivityResultContracts.GetContent()) |
|
|
|
|
|
{ uri: Uri? -> |
|
|
|
|
|
if (uri != null) { |
|
|
|
|
|
bitmap = uriToBitmap(uri) |
|
|
|
|
|
// uploadDocument(uri, "g") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
takeImageResult = |
|
|
|
|
|
registerForActivityResult(ActivityResultContracts.TakePicture()) { isSuccess -> |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
latestTmpUri?.let { uri -> |
|
|
|
|
|
// uploadDocument(uri, "c") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private fun uriToBitmap(selectedFileUri: Uri): Bitmap? { |
|
|
private fun uriToBitmap(selectedFileUri: Uri): Bitmap? { |
|
@ -137,8 +129,117 @@ 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 0 until s.length) { // 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 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private fun init() { |
|
|
private fun init() { |
|
|
|
|
|
|
|
|
|
|
|
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.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)) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// 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()) |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectImageIntent = registerForActivityResult(ActivityResultContracts.GetContent()) |
|
|
|
|
|
{ uri: Uri? -> |
|
|
|
|
|
if (uri != null) { |
|
|
|
|
|
bitmap = uriToBitmap(uri) |
|
|
|
|
|
uploadDocument(uri, "g") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
takeImageResult = |
|
|
|
|
|
registerForActivityResult(ActivityResultContracts.TakePicture()) { isSuccess -> |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
latestTmpUri?.let { uri -> |
|
|
|
|
|
uploadDocument(uri, "c") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
binding.btnNext.setOnClickListener { |
|
|
binding.btnNext.setOnClickListener { |
|
|
replaceFragment( |
|
|
replaceFragment( |
|
|
activity as BaseActivity, |
|
|
activity as BaseActivity, |
|
@ -154,19 +255,46 @@ class GetStartedFragment : BaseFragment() { |
|
|
listArray.add("Driving Licenses") |
|
|
listArray.add("Driving Licenses") |
|
|
listArray.add("Voter Id") |
|
|
listArray.add("Voter Id") |
|
|
|
|
|
|
|
|
val arrayAdapter = ArrayAdapter(activity as SignUpActivity, androidx.appcompat.R.layout.support_simple_spinner_dropdown_item,listArray) |
|
|
|
|
|
|
|
|
val arrayAdapter = ArrayAdapter( |
|
|
|
|
|
activity as SignUpActivity, |
|
|
|
|
|
androidx.appcompat.R.layout.support_simple_spinner_dropdown_item, |
|
|
|
|
|
listArray |
|
|
|
|
|
) |
|
|
binding.spDocType.setAdapter(arrayAdapter) |
|
|
binding.spDocType.setAdapter(arrayAdapter) |
|
|
|
|
|
|
|
|
binding.spDocType.setOnItemClickListener{ _, _, position, _ -> |
|
|
|
|
|
// setVisibility(listArray[position]) |
|
|
|
|
|
|
|
|
binding.spDocType.setOnItemClickListener { _, _, position, _ -> |
|
|
|
|
|
setVisibility(listArray[position]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
binding.uploadFront.setOnClickListener { |
|
|
binding.uploadFront.setOnClickListener { |
|
|
actionType = mainPANUpload |
|
|
actionType = mainPANUpload |
|
|
|
|
|
isFront = true |
|
|
|
|
|
selectImage() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
binding.mbUploadChangeFront.setOnClickListener { |
|
|
|
|
|
actionType = mainPANUpload |
|
|
|
|
|
isFront = true |
|
|
|
|
|
selectImage() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
binding.mbUploadChangeBack.setOnClickListener { |
|
|
|
|
|
actionType = mainPANUpload |
|
|
|
|
|
isFront = false |
|
|
|
|
|
selectImage() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
binding.uploadBack.setOnClickListener { |
|
|
|
|
|
actionType = mainPANUpload |
|
|
|
|
|
isFront = false |
|
|
selectImage() |
|
|
selectImage() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun setUploadOption(checked: Boolean) { |
|
|
|
|
|
isFront = checked |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private fun selectImage() { |
|
|
private fun selectImage() { |
|
|
val builder = AlertDialog.Builder( |
|
|
val builder = AlertDialog.Builder( |
|
|
activity as SignUpActivity |
|
|
activity as SignUpActivity |
|
@ -247,45 +375,116 @@ class GetStartedFragment : BaseFragment() { |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// private fun setVisibility(s: String) { |
|
|
|
|
|
// if(s.contains("Aadhaar")){ |
|
|
|
|
|
// binding.txtFront.visibility = View.VISIBLE |
|
|
|
|
|
// binding.uploadFront.visibility = View.VISIBLE |
|
|
|
|
|
// binding.txtBack.visibility = View.VISIBLE |
|
|
|
|
|
// binding.uploadViewBack.visibility = View.VISIBLE |
|
|
|
|
|
// }else{ |
|
|
|
|
|
// binding.txtFront.visibility = View.VISIBLE |
|
|
|
|
|
// binding.uploadFront.visibility = View.VISIBLE |
|
|
|
|
|
// binding.txtBack.visibility = View.GONE |
|
|
|
|
|
// binding.uploadViewBack.visibility = View.GONE |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
private fun setVisibility(s: String) { |
|
|
|
|
|
if (s.contains("Aadhaar")) { |
|
|
|
|
|
binding.txtFront.visibility = View.VISIBLE |
|
|
|
|
|
binding.uploadFront.visibility = View.VISIBLE |
|
|
|
|
|
binding.txtBack.visibility = View.VISIBLE |
|
|
|
|
|
binding.llBack.visibility = View.VISIBLE |
|
|
|
|
|
} else { |
|
|
|
|
|
binding.txtFront.visibility = View.VISIBLE |
|
|
|
|
|
binding.uploadFront.visibility = View.VISIBLE |
|
|
|
|
|
binding.txtBack.visibility = View.GONE |
|
|
|
|
|
binding.llBack.visibility = View.GONE |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getTmpFileUri(): Uri { |
|
|
|
|
|
val tmpFile = |
|
|
|
|
|
File.createTempFile("tmp_image_file", ".png", requireActivity().cacheDir).apply { |
|
|
|
|
|
createNewFile() |
|
|
|
|
|
deleteOnExit() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return FileProvider.getUriForFile( |
|
|
|
|
|
requireActivity(), BuildConfig.APPLICATION_ID.plus(".provider"), tmpFile |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private fun takeImage() { |
|
|
private fun takeImage() { |
|
|
lifecycleScope.launchWhenStarted { |
|
|
lifecycleScope.launchWhenStarted { |
|
|
getTmpFileUri().let { uri -> |
|
|
|
|
|
latestTmpUri = uri |
|
|
|
|
|
takeImageResult?.launch(uri) |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
getTmpFileUri().let { uri -> |
|
|
|
|
|
latestTmpUri = uri |
|
|
|
|
|
takeImageResult?.launch(uri) |
|
|
|
|
|
} |
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
Log.e("check_exception", e.message.toString()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// private fun uploadDocument(uri: Uri, type: String) { |
|
|
|
|
|
// when (actionType) { |
|
|
|
|
|
// mainPANUpload -> { |
|
|
|
|
|
// binding.ivPan.visibility = View.VISIBLE |
|
|
|
|
|
// val fileDir: File = requireActivity().cacheDir |
|
|
|
|
|
// val fileExtension = File(fileDir.toString().plus("/").plus(getFileName(uri))) |
|
|
|
|
|
// panFileExt = getFileExtension(getFileName(uri)) |
|
|
|
|
|
// val size: Double = Common.getFileSizeInMB(fileExtension.length()) |
|
|
|
|
|
// if (size < 5) { |
|
|
|
|
|
// if (type == "c") encodedPANBase64(fileExtension) |
|
|
|
|
|
// else panString = bitmap?.let { ImageUtil.convert(it) }.toString() |
|
|
|
|
|
// } else { |
|
|
|
|
|
// panString = "" |
|
|
|
|
|
// panFileExt = "" |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
@SuppressLint("Range") |
|
|
|
|
|
fun getFileName(uri: Uri): String { |
|
|
|
|
|
var result = "" |
|
|
|
|
|
if (uri.scheme == "content") { |
|
|
|
|
|
val cursor: Cursor = |
|
|
|
|
|
requireActivity().contentResolver.query(uri, null, null, null, null)!! |
|
|
|
|
|
cursor.use { cursor1 -> |
|
|
|
|
|
if (cursor1.moveToFirst()) { |
|
|
|
|
|
result = cursor1.getString(cursor1.getColumnIndex(OpenableColumns.DISPLAY_NAME)) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (result.isEmpty()) { |
|
|
|
|
|
result = uri.path!! |
|
|
|
|
|
val cut = result.lastIndexOf('/') |
|
|
|
|
|
if (cut != -1) { |
|
|
|
|
|
result = result.substring(cut + 1) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
|
private fun loadFile(file: File): ByteArray { |
|
|
|
|
|
val inputStream: InputStream = FileInputStream(file) |
|
|
|
|
|
val length = file.length() |
|
|
|
|
|
val bytes = ByteArray(length.toInt()) |
|
|
|
|
|
var offset = 0 |
|
|
|
|
|
var numRead = 0 |
|
|
|
|
|
while (offset < bytes.size && inputStream.read(bytes, offset, bytes.size - offset).also { |
|
|
|
|
|
numRead = it |
|
|
|
|
|
} >= 0) { |
|
|
|
|
|
offset += numRead |
|
|
|
|
|
} |
|
|
|
|
|
if (offset < bytes.size) { |
|
|
|
|
|
throw IOException("Could not completely read file " + file.name) |
|
|
|
|
|
} |
|
|
|
|
|
inputStream.close() |
|
|
|
|
|
return bytes |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun encodedPANBase64(fileName: File) { |
|
|
|
|
|
panString = try { |
|
|
|
|
|
val bytes: ByteArray = loadFile(fileName) |
|
|
|
|
|
Base64.encodeToString(bytes, Base64.DEFAULT).trim().replace("\n", "") |
|
|
|
|
|
.replace("\\s+", "") |
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
e.printStackTrace() |
|
|
|
|
|
"" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun uploadDocument(uri: Uri, type: String) { |
|
|
|
|
|
when (actionType) { |
|
|
|
|
|
mainPANUpload -> { |
|
|
|
|
|
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()) |
|
|
|
|
|
|
|
|
|
|
|
setFrontHideVisible(uri) |
|
|
|
|
|
if (size < 5) { |
|
|
|
|
|
if (type == "c") encodedPANBase64(fileExtension) |
|
|
|
|
|
else panString = bitmap?.let { ImageUtil.convert(it) }.toString() |
|
|
|
|
|
} else { |
|
|
|
|
|
panString = "" |
|
|
|
|
|
panFileExt = "" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// mainPhotoUpload -> { |
|
|
// mainPhotoUpload -> { |
|
|
// binding.ivPhotograph.visibility = View.VISIBLE |
|
|
// binding.ivPhotograph.visibility = View.VISIBLE |
|
|
// val fileDir: File = requireActivity().cacheDir |
|
|
// val fileDir: File = requireActivity().cacheDir |
|
@ -328,17 +527,22 @@ class GetStartedFragment : BaseFragment() { |
|
|
// doc2fileExt = "" |
|
|
// doc2fileExt = "" |
|
|
// } |
|
|
// } |
|
|
// } |
|
|
// } |
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
private fun getTmpFileUri(): Uri { |
|
|
|
|
|
val tmpFile = |
|
|
|
|
|
File.createTempFile("tmp_image_file", ".png", requireActivity().cacheDir).apply { |
|
|
|
|
|
createNewFile() |
|
|
|
|
|
deleteOnExit() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return FileProvider.getUriForFile( |
|
|
|
|
|
requireActivity(), PreferenceManager(activity as SignUpActivity).getAppId().plus(".provider"), tmpFile) |
|
|
|
|
|
|
|
|
private fun setFrontHideVisible(uri: Uri) { |
|
|
|
|
|
if (isFront) { |
|
|
|
|
|
binding.uploadFront.visibility = View.GONE |
|
|
|
|
|
binding.ivFrontLayer.setBackgroundColor(Color.parseColor("#99000000")) |
|
|
|
|
|
binding.ivFrontTik.setBackgroundResource(R.drawable.svg_tik) |
|
|
|
|
|
binding.mbUploadChangeFront.visibility = View.VISIBLE |
|
|
|
|
|
binding.ivFront.setImageURI(uri) |
|
|
|
|
|
} else { |
|
|
|
|
|
binding.uploadBack.visibility = View.GONE |
|
|
|
|
|
binding.ivBackLayer.setBackgroundColor(Color.parseColor("#99000000")) |
|
|
|
|
|
binding.ivBackTik.setBackgroundResource(R.drawable.svg_tik) |
|
|
|
|
|
binding.mbUploadChangeBack.visibility = View.VISIBLE |
|
|
|
|
|
binding.ivBack.setImageURI(uri) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |