diff --git a/app/src/main/java/com/nivesh/production/bajajfd/BajajApplication.kt b/app/src/main/java/com/nivesh/production/bajajfd/BajajApplication.kt index 8956025..50f4560 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/BajajApplication.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/BajajApplication.kt @@ -6,10 +6,12 @@ import android.content.Context class BajajApplication : Application() { private var mInstance: BajajApplication? = null // private val mRequestQueue: RequestQueue? = null - + companion object { + var appContext: Context? = null + } override fun onCreate() { super.onCreate() - mInstance = this; + mInstance = this appContext = applicationContext } @@ -17,15 +19,4 @@ class BajajApplication : Application() { fun getInstanceApp(): BajajApplication? { return mInstance } - - - companion object { - - lateinit var appContext: Context - - } - - - - } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/adapter/CustomerListAdapter.kt b/app/src/main/java/com/nivesh/production/bajajfd/adapter/CustomerListAdapter.kt index 73265b9..40e48d5 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/adapter/CustomerListAdapter.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/adapter/CustomerListAdapter.kt @@ -3,22 +3,20 @@ package com.nivesh.production.bajajfd.adapter import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Toast +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.google.android.material.switchmaterial.SwitchMaterial import com.nivesh.production.bajajfd.R import com.nivesh.production.bajajfd.model.GetCodes class CustomerListAdapter( - private val customerList: List? + private val customerList: MutableList? ) : RecyclerView.Adapter() { inner class BankListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val tvCustomerName: SwitchMaterial = itemView.findViewById(R.id.tvCustomerName) + val txtLabel: TextView = itemView.findViewById(R.id.txtLabel) } - private var checkedPosition: Int = -2 - - override fun onCreateViewHolder( parent: ViewGroup, viewType: Int @@ -35,22 +33,9 @@ class CustomerListAdapter( override fun onBindViewHolder(holder: BankListViewHolder, position: Int) { val cList = customerList?.get(position) if (cList != null) { - - holder.itemView.apply { - holder.tvCustomerName.text = cList.Label - setOnClickListener { - onItemClickListener?.let { - it(cList) - - Toast.makeText(context,cList.Value,Toast.LENGTH_SHORT).show() - - if (checkedPosition != holder.adapterPosition) { - notifyItemChanged(checkedPosition) - checkedPosition = holder.adapterPosition - - } - } - } + holder.txtLabel.text = cList.Label + holder.tvCustomerName.setOnCheckedChangeListener { _, isChecked -> + cList.isSelected = isChecked } } } @@ -59,17 +44,4 @@ class CustomerListAdapter( return customerList?.size!! } - private var onItemClickListener: ((GetCodes) -> Unit)? = null - - fun setOnItemClickListener(listener: (GetCodes) -> Unit) { - onItemClickListener = listener - } - - - fun getSelected(): GetCodes? { - return if (checkedPosition != -1) { - customerList?.get(checkedPosition) - } else null - } - } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/api/ApiClient.kt b/app/src/main/java/com/nivesh/production/bajajfd/api/ApiClient.kt index 2b88881..14f4d89 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/api/ApiClient.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/api/ApiClient.kt @@ -1,16 +1,21 @@ package com.nivesh.production.bajajfd.api - +import android.content.Context +import android.net.ConnectivityManager +import com.nivesh.production.bajajfd.BajajApplication +import com.nivesh.production.bajajfd.api.ApiClient.Companion.isNetworkAvailablee import com.nivesh.production.bajajfd.interfaces.ApiInterface import com.nivesh.production.bajajfd.util.Constants.Companion.BASE_URL import okhttp3.Interceptor import okhttp3.OkHttpClient +import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import java.io.IOException class ApiClient { - + val context = BajajApplication.appContext companion object { private val client by lazy { //lazy means we only initialize this here once @@ -32,40 +37,24 @@ class ApiClient { val getApiClient: ApiInterface by lazy { client.create(ApiInterface::class.java) } - - - - - class ConnectVerifierInterceptor : Interceptor { - override fun intercept(chain: Interceptor.Chain): okhttp3.Response { -// if (isNetworkAvailable(BaseActivity())) { -// // throw IOException("No Network Available!") -// -// } - - val request = chain.request() - return chain.proceed(request) - - - - - } - + fun isNetworkAvailablee(): Boolean { + val connectivityManager = + BajajApplication.appContext?.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager + return connectivityManager?.activeNetworkInfo?.isConnected == true } - - - } +} +class ConnectVerifierInterceptor : Interceptor { + override fun intercept(chain: Interceptor.Chain): okhttp3.Response { +// if (!isNetworkAvailablee()) { +// throw IOException("No Network Available!") +// } + val request = chain.request() + return chain.proceed(request) + } +} - - - - - - - -} \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/interfaces/ApiInterface.kt b/app/src/main/java/com/nivesh/production/bajajfd/interfaces/ApiInterface.kt index f8a0f7c..dc65119 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/interfaces/ApiInterface.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/interfaces/ApiInterface.kt @@ -28,7 +28,7 @@ interface ApiInterface { @POST("WebApi_Bajaj/api/DocumentsUpload") suspend fun documentsUpload( - @Body requestBody: RequestBody, + @Body requestBody: DocumentUpload, @Header("token") token: String ): Response diff --git a/app/src/main/java/com/nivesh/production/bajajfd/model/DocumentUpload.kt b/app/src/main/java/com/nivesh/production/bajajfd/model/DocumentUpload.kt index fd4ee1d..e0f8154 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/model/DocumentUpload.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/model/DocumentUpload.kt @@ -1,10 +1,10 @@ package com.nivesh.production.bajajfd.model data class DocumentUpload( - val Description: String? = null, - val DocumentType: String? = null, - val FDProvider: String? = null, - val ImageEncodeToBase64: String? = null, - val NiveshClientCode: String? = null, - val UniqueId: String? = null + var Description: String? = null, + var DocumentType: String? = null, + var FDProvider: String? = null, + var ImageEncodeToBase64: String? = null, + var NiveshClientCode: String? = null, + var UniqueId: String? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/model/GetCodes.kt b/app/src/main/java/com/nivesh/production/bajajfd/model/GetCodes.kt index e8c7329..6741a5c 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/model/GetCodes.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/model/GetCodes.kt @@ -2,7 +2,8 @@ package com.nivesh.production.bajajfd.model data class GetCodes( val Label: String, - val Value: String + val Value: String, + var isSelected : Boolean ) { override fun toString(): String { return Label diff --git a/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseX.kt b/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseX.kt index 0d08d82..06a1cde 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseX.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseX.kt @@ -2,7 +2,7 @@ package com.nivesh.production.bajajfd.model data class ResponseX( val Errors: List, - val GetCodesList: List, + val GetCodesList: MutableList, val Message: String, val Status: String, val StatusCode: Int diff --git a/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXX.kt b/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXX.kt index 4bacf38..95ae9ba 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXX.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXX.kt @@ -1,7 +1,7 @@ package com.nivesh.production.bajajfd.model data class ResponseXXXXXXXXXXXX( - val Errors: Any, + val Errors: List, val FDDataResponse: FDDataResponse, val Message: String, val Status: String, diff --git a/app/src/main/java/com/nivesh/production/bajajfd/model/UploadResponse.kt b/app/src/main/java/com/nivesh/production/bajajfd/model/UploadResponse.kt new file mode 100644 index 0000000..a9a1560 --- /dev/null +++ b/app/src/main/java/com/nivesh/production/bajajfd/model/UploadResponse.kt @@ -0,0 +1,5 @@ +package com.nivesh.production.bajajfd.model + +data class UploadResponse( + val Response: ResponseXXXXXXXXXXXX +) \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/repositories/MainRepository.kt b/app/src/main/java/com/nivesh/production/bajajfd/repositories/MainRepository.kt index 35b059f..8550104 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/repositories/MainRepository.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/repositories/MainRepository.kt @@ -26,8 +26,8 @@ class MainRepository constructor(private val apiInterface: ApiInterface) { suspend fun createFDKYCResponse(createFDRequest: CreateFDRequest, token: String) = apiInterface.createFDApp(createFDRequest, token) - suspend fun documentsUploadResponse(getRatesRequest: GetRatesRequest, token: String) = - apiInterface.getRates(getRatesRequest, token) + suspend fun documentsUploadResponse(getRatesRequest: DocumentUpload, token: String) = + apiInterface.documentsUpload(getRatesRequest, token) suspend fun saveFDOtherDataResponse(getRatesRequest: GetRatesRequest, token: String) = apiInterface.getRates(getRatesRequest, token) diff --git a/app/src/main/java/com/nivesh/production/bajajfd/ui/activity/BajajFdMainActivity.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/activity/BajajFdMainActivity.kt index 08dcfb6..9bb0340 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/ui/activity/BajajFdMainActivity.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/ui/activity/BajajFdMainActivity.kt @@ -108,42 +108,47 @@ class BajajFdMainActivity : BaseActivity(), BajajFDInterface { } private fun getStepsCountApi() { - val fdStepsCount = FDStepsCountRequest() - fdStepsCount.FDProvider = getString(com.nivesh.production.bajajfd.R.string.bajaj) - fdStepsCount.NiveshClientCode = "8872" - viewModel.getStepsCount(fdStepsCount, token) - viewModel.getStepsCountMutableData.observe(this) { response -> - when (response) { - is Resource.Success -> { - Log.e("response", "-->$response") - val stepsCountResponse: StepsCountResponse = - Gson().fromJson(response.data?.toString(), StepsCountResponse::class.java) - stepsCountResponse.Response.StatusCode.let { code -> - when (code) { - 200 -> { - stepCount = stepsCountResponse.Response.StepsCount - getClientDetailsApi(stepsCountResponse.Response.StepsCount) - } - 650 -> refreshToken(fdStepsCount) - else -> { - showDialogValidation( - this@BajajFdMainActivity, - stepsCountResponse.Response.Errors[0].ErrorMessage - ) - } - } - } - } - is Resource.Error -> { - response.message?.let { message -> - showDialogValidation(this@BajajFdMainActivity, message) - } - } - is Resource.Loading -> { - - } - } - } + if (Common.isNetworkAvailable(this)) { + val fdStepsCount = FDStepsCountRequest() + fdStepsCount.FDProvider = getString(com.nivesh.production.bajajfd.R.string.bajaj) + fdStepsCount.NiveshClientCode = "8872" + viewModel.getStepsCount(fdStepsCount, token) + viewModel.getStepsCountMutableData.observe(this) { response -> + when (response) { + is Resource.Success -> { + Log.e("response", "-->$response") + val stepsCountResponse: StepsCountResponse = + Gson().fromJson( + response.data?.toString(), + StepsCountResponse::class.java + ) + stepsCountResponse.Response.StatusCode.let { code -> + when (code) { + 200 -> { + stepCount = stepsCountResponse.Response.StepsCount + getClientDetailsApi(stepsCountResponse.Response.StepsCount) + } + 650 -> refreshToken(fdStepsCount) + else -> { + showDialogValidation( + this@BajajFdMainActivity, + stepsCountResponse.Response.Errors[0].ErrorMessage + ) + } + } + } + } + is Resource.Error -> { + response.message?.let { message -> + showDialogValidation(this@BajajFdMainActivity, message) + } + } + is Resource.Loading -> { + + } + } + } + } } private fun refreshToken(fdStepsCount: FDStepsCountRequest) { diff --git a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFourBajajFDFragment.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFourBajajFDFragment.kt index 7bb6e34..629f416 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFourBajajFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFourBajajFDFragment.kt @@ -24,6 +24,8 @@ class StepFourBajajFDFragment : BaseFragment() { private lateinit var stepFourBajajFDViewModel: StepFourBajajFDViewModel private var _binding: FragmentBajajfdStepFourBinding? = null private val binding get() = _binding!! + private lateinit var listOfCustomer: MutableList + private var selectedList: String = "" private var uniqueId: String? = "" private lateinit var bajajFDInterface: BajajFDInterface @@ -55,12 +57,24 @@ class StepFourBajajFDFragment : BaseFragment() { } binding.btnNext.setOnClickListener { + selectedList = "" + for (getCodes in listOfCustomer) { + if (getCodes.isSelected) { + selectedList = if (selectedList.isEmpty()) { + getCodes.Value + } else { + selectedList.plus(",").plus(getCodes.Value) + } + } + } + Log.e("selectedList", "-->$selectedList") if (binding.checkBox.isChecked) { - val saveFDOtherDataRequest = SaveFDOtherDataRequest() + val saveFDOtherDataRequest = SaveFDOtherDataRequest() saveFDOtherDataRequest.FDProvider = getString(R.string.bajaj) saveFDOtherDataRequest.UniqueId = uniqueId - saveFDOtherDataRequest.Values = "" - saveFDOtherDataRequest.NiveshClientCode = (activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE + saveFDOtherDataRequest.Values = selectedList + saveFDOtherDataRequest.NiveshClientCode = + (activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE bajajFDInterface.stepFourApi(saveFDOtherDataRequest) } else { showDialogValidation( @@ -70,18 +84,21 @@ class StepFourBajajFDFragment : BaseFragment() { } } - binding.btnBack.setOnClickListener{ + binding.btnBack.setOnClickListener { (activity as BajajFdMainActivity).binding.viewPager.currentItem = 2 } return root } - fun displayReceivedData(createFDApplicationResponse: CreateFDApplicationResponse) { - Log.e("createFDApplication", "Response-->"+createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId) - uniqueId = createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId - getFDDetailsApi(createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId) - customerListApi() + fun displayReceivedData(createFDApplicationResponse: CreateFDApplicationResponse) { + Log.e( + "createFDApplication", + "Response-->" + createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId + ) + uniqueId = createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId + getFDDetailsApi(createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId) + customerListApi() } @@ -103,7 +120,8 @@ class StepFourBajajFDFragment : BaseFragment() { when (code) { 200 -> { if (getCodeResponse.Response.GetCodesList.isNotEmpty()) { - setUpRecyclerView(getCodeResponse.Response.GetCodesList) + listOfCustomer = getCodeResponse.Response.GetCodesList + setUpRecyclerView(listOfCustomer) } } // 650 -> refreshToken() @@ -132,7 +150,7 @@ class StepFourBajajFDFragment : BaseFragment() { } - private fun setUpRecyclerView(getCustomerList: List) { + private fun setUpRecyclerView(getCustomerList: MutableList) { binding.rvTerms.layoutManager = LinearLayoutManager(activity as BajajFdMainActivity) val customerListAdapter = CustomerListAdapter(getCustomerList) @@ -146,7 +164,8 @@ class StepFourBajajFDFragment : BaseFragment() { if (Common.isNetworkAvailable(mActivity!!)) { val getFDDetailsRequest = GetFDDetailsRequest() getFDDetailsRequest.FDProvider = mActivity!!.getString(R.string.bajaj) - getFDDetailsRequest.NiveshClientCode = (mActivity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE + getFDDetailsRequest.NiveshClientCode = + (mActivity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE getFDDetailsRequest.UniqueId = uniqueId stepFourBajajFDViewModel.getFDDetails(getFDDetailsRequest, Constants.token) stepFourBajajFDViewModel.getFDDetailsMutableData.observe(viewLifecycleOwner) { response -> @@ -162,13 +181,15 @@ class StepFourBajajFDFragment : BaseFragment() { when (code) { 200 -> { binding.tvInvestedAmount.text = - getString(R.string.rs).plus(getFDDetailsResponse.Response.FDDataResponse.FDAmount.toString()) + getString(R.string.rs).plus(getFDDetailsResponse.Response.FDDataResponse.FDAmount.toString()) binding.tvTenure.text = - getFDDetailsResponse.Response.FDDataResponse.Tenure.toString().plus(" Months") + getFDDetailsResponse.Response.FDDataResponse.Tenure.toString() + .plus(" Months") binding.tvInterestPayout.text = getFDDetailsResponse.Response.FDDataResponse.Frequency binding.tvRateOfInterest.text = - getFDDetailsResponse.Response.FDDataResponse.RateOfInterest.toString().plus(" % p.a.") + getFDDetailsResponse.Response.FDDataResponse.RateOfInterest.toString() + .plus(" % p.a.") } // 650 -> refreshToken() else -> { diff --git a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepThreeBajajFDFragment.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepThreeBajajFDFragment.kt index afb0a16..e6dcb59 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepThreeBajajFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepThreeBajajFDFragment.kt @@ -1,13 +1,18 @@ package com.nivesh.production.bajajfd.ui.fragment import android.Manifest +import android.annotation.SuppressLint import android.app.ActionBar.LayoutParams import android.app.Dialog import android.content.pm.PackageManager +import android.database.Cursor import android.graphics.Bitmap import android.net.Uri import android.os.Bundle import android.provider.MediaStore +import android.provider.OpenableColumns +import android.text.Editable +import android.util.Base64 import android.util.Log import android.view.LayoutInflater import android.view.View @@ -16,6 +21,7 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.ImageView import android.widget.TextView +import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.core.app.ActivityCompat @@ -35,6 +41,9 @@ import com.nivesh.production.bajajfd.util.Constants import com.nivesh.production.bajajfd.util.Resource import com.nivesh.production.bajajfd.viewModel.StepThreeBajajFDViewModel import java.io.File +import java.io.FileInputStream +import java.io.IOException +import java.io.InputStream class StepThreeBajajFDFragment : BaseFragment() { @@ -47,6 +56,7 @@ class StepThreeBajajFDFragment : BaseFragment() { private lateinit var stepThreeBajajFDViewModel: StepThreeBajajFDViewModel private var uniqueId: String? = "" private lateinit var dialog: Dialog + private var front: String = "" companion object { fun getInstance(fdInterface: BajajFDInterface): StepThreeBajajFDFragment { @@ -71,7 +81,7 @@ class StepThreeBajajFDFragment : BaseFragment() { if (isSuccess) { latestTmpUri?.let { uri -> // binding.iv.setImageURI(uri) - uploadDocument() + uploadDocument(uri) } } } @@ -97,10 +107,11 @@ class StepThreeBajajFDFragment : BaseFragment() { stepThreeBajajFDViewModel = (activity as BajajFdMainActivity).stepThreeBajajFDViewModel binding.btnNext.setOnClickListener { - // if (validate()) { + if (validate()) { + // uploadDocApi() // - bajajFDInterface.stepThreeApi((activity as BajajFdMainActivity).createFDRequest) - // } + bajajFDInterface.stepThreeApi((activity as BajajFdMainActivity).createFDRequest) + } } binding.btnBack.setOnClickListener { (activity as BajajFdMainActivity).binding.viewPager.currentItem = 1 @@ -127,6 +138,30 @@ class StepThreeBajajFDFragment : BaseFragment() { return root } + @SuppressLint("Range") + fun getFileName(uri: Uri): String { + var result: String? = null + if (uri.scheme == "content") { + val cursor: Cursor = + requireActivity().getContentResolver().query(uri, null, null, null, null)!! + try { + if (cursor != null && cursor.moveToFirst()) { + result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)) + } + } finally { + cursor.close() + } + } + if (result == null) { + result = uri.path + val cut = result!!.lastIndexOf('/') + if (cut != -1) { + result = result.substring(cut + 1) + } + } + return result + } + private fun selectImage() { dialog = Dialog(activity as BajajFdMainActivity) dialog.setContentView(R.layout.camera_gallery_layout) @@ -222,9 +257,93 @@ class StepThreeBajajFDFragment : BaseFragment() { binding.btnAadhaarFrontUpload.visibility = View.VISIBLE } - private fun uploadDocument() { + private fun uploadDocument(uri: Uri) { if (Common.isNetworkAvailable(activity as BajajFdMainActivity)) { val documentUpload = DocumentUpload() + val value: Editable? = binding.spDocType.text + val file_dir:File = requireActivity().cacheDir + val file_ex = File(file_dir.toString().plus("/").plus(getFileName(uri))) + var file_path: File? = uri.path?.let { File(it) } + encodedFileToBase64(file_ex) + + Log.e("check_data_front", value.toString()+"\n"+front) +// documentUpload.DocumentType = + } + } + + private fun encodedFileToBase64(fileName: File?) { + front = try { + val bytes: ByteArray? = fileName?.let { loadFile(it) } + Base64.encodeToString(bytes, Base64.DEFAULT).trim { it <= ' ' } + .replace("\n".toRegex(), "").replace("\\s+".toRegex(), "") + } catch (e: Exception) { + e.printStackTrace() + "" + } + } + + @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 uploadDocApi(){ + if(Common.isNetworkAvailable((activity as BajajFdMainActivity))){ + val du = DocumentUpload() + du.Description = "PAN" + du.DocumentType = "PAN" + du.FDProvider = getString(R.string.bajaj) + du.ImageEncodeToBase64 = front //"data:image/png;base64" + du.NiveshClientCode = (activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE + du.UniqueId = uniqueId + stepThreeBajajFDViewModel.documentsUpload(du,Constants.token) + stepThreeBajajFDViewModel.getDocumentUploadMutableData.observe(viewLifecycleOwner){ response -> + when (response){ + is Resource.Success ->{ + Log.e("response", "-->$response") + val getUploadResponse: UploadResponse = + Gson().fromJson(response.data?.toString(),UploadResponse::class.java) + getUploadResponse.Response.StatusCode.let { code -> + when (code) { + 200 -> { + Log.e("check_upload_res",response.message.toString()) + } + // 650 -> refreshToken() + else -> { + Common.showDialogValidation( + activity as BajajFdMainActivity, + getUploadResponse.Response.Message + ) + } + } + } + } + + is Resource.Error -> { + response.message?.let { message -> + Common.showDialogValidation(activity as BajajFdMainActivity, message) + } + } + is Resource.Loading -> { + + } + } + } + } } @@ -286,7 +405,7 @@ class StepThreeBajajFDFragment : BaseFragment() { private fun validate(): Boolean { - return false + return true } private fun takeImage() { @@ -313,7 +432,6 @@ class StepThreeBajajFDFragment : BaseFragment() { } - override fun onDestroyView() { super.onDestroyView() _binding = null diff --git a/app/src/main/java/com/nivesh/production/bajajfd/util/Common.kt b/app/src/main/java/com/nivesh/production/bajajfd/util/Common.kt index 18cb165..405c1ad 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/util/Common.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/util/Common.kt @@ -19,6 +19,7 @@ import com.nivesh.production.bajajfd.R import com.nivesh.production.bajajfd.ui.activity.BaseActivity import retrofit2.HttpException import java.io.IOException +import java.net.SocketTimeoutException import java.text.SimpleDateFormat import java.util.* import java.util.regex.Matcher @@ -113,6 +114,7 @@ class Common { fun showDialogValidation(activity: Activity?, message: CharSequence?) { val builder = AlertDialog.Builder(activity) builder.setMessage(message) + builder.setCancelable(false) if (activity != null) { builder.setPositiveButton(activity.getString(R.string.ok)) { dialogInterface, _ -> dialogInterface.dismiss() @@ -201,13 +203,11 @@ class Common { return when (t) { is IOException -> Resource.Error("Response : " + t.message.plus(" Cause: " + t.cause)) is HttpException -> Resource.Error("Response : " + t.message.plus(" Cause: " + t.cause)) + is SocketTimeoutException -> Resource.Error("Response : " + t.message.plus(" Cause: " + t.cause)) else -> Resource.Error(t.localizedMessage?.toString() ?: "") } } return Resource.Error(response.message()) } - } - - } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/BajajFDViewModel.kt b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/BajajFDViewModel.kt index e26e127..1b703fb 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/BajajFDViewModel.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/BajajFDViewModel.kt @@ -1,5 +1,6 @@ package com.nivesh.production.bajajfd.viewModel +import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -18,6 +19,7 @@ class BajajFDViewModel(private val mainRepository: MainRepository) : ViewModel() fun getStepsCount(requestBody: FDStepsCountRequest, token: String) = viewModelScope.launch { getStepsCountMutableData.postValue(Resource.Loading()) val response = mainRepository.getStepsCountResponse(requestBody, token) + Log.e("response", "-->"+response) getStepsCountMutableData.postValue(handleRatesResponse(response)) } diff --git a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepThreeBajajFDViewModel.kt b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepThreeBajajFDViewModel.kt index 1162885..65b7ecf 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepThreeBajajFDViewModel.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepThreeBajajFDViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.google.gson.JsonObject +import com.nivesh.production.bajajfd.model.DocumentUpload import com.nivesh.production.bajajfd.model.GetCodeRequest import com.nivesh.production.bajajfd.model.GetRatesRequest import com.nivesh.production.bajajfd.repositories.MainRepository @@ -13,13 +14,6 @@ import kotlinx.coroutines.launch class StepThreeBajajFDViewModel(private val mainRepository: MainRepository) : ViewModel() { - private val getRatesMutableData: MutableLiveData> = MutableLiveData() - fun documentsUpload(getRatesRequest: GetRatesRequest, token: String) = viewModelScope.launch { - getRatesMutableData.postValue(Resource.Loading()) - val response = mainRepository.documentsUploadResponse(getRatesRequest, token) - getRatesMutableData.postValue(handleRatesResponse(response)) - } - val getTitleMutableData: MutableLiveData> = MutableLiveData() fun titleApi(getCodeRequest: GetCodeRequest, token: String) = viewModelScope.launch { getTitleMutableData.postValue(Resource.Loading()) @@ -27,5 +21,12 @@ class StepThreeBajajFDViewModel(private val mainRepository: MainRepository) : Vi getTitleMutableData.postValue(handleRatesResponse(response)) } + val getDocumentUploadMutableData: MutableLiveData> = MutableLiveData() + fun documentsUpload(documentUpload: DocumentUpload, token: String) = viewModelScope.launch { + getDocumentUploadMutableData.postValue(Resource.Loading()) + val response = mainRepository.documentsUploadResponse(documentUpload, token) + getDocumentUploadMutableData.postValue(handleRatesResponse(response)) + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/item_customer_list_preview.xml b/app/src/main/res/layout/item_customer_list_preview.xml index 1531c6e..f2ae760 100644 --- a/app/src/main/res/layout/item_customer_list_preview.xml +++ b/app/src/main/res/layout/item_customer_list_preview.xml @@ -1,20 +1,9 @@ - - - + android:layout_height="wrap_content"> - \ No newline at end of file diff --git a/app/src/main/res/values-hi-rIN/strings.xml b/app/src/main/res/values-hi-rIN/strings.xml index 8d1dde6..53064ea 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -237,9 +237,11 @@ Non Senior Citizen Add New Account - OK + OK Cancel Aadhar + + Select Option Gallery Camera PaymentMode diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d4243c5..0027640 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -237,7 +237,7 @@ Non Senior Citizen Add New Account - OK + OK Cancel Aadhar