From 63fd4b6da87921e9586a82528d02676402e221cd Mon Sep 17 00:00:00 2001 From: Hemant Khadase Date: Tue, 3 Jan 2023 19:33:31 +0530 Subject: [PATCH 1/5] added manoj's code --- .../production/bajajfd/BajajApplication.kt | 8 +- .../production/bajajfd/api/ApiClient.kt | 31 +++- .../bajajfd/interfaces/ApiInterface.kt | 2 +- .../bajajfd/model/DocumentUpload.kt | 12 +- .../bajajfd/model/ResponseXXXXXXXXXXXX.kt | 2 +- .../bajajfd/model/UploadResponse.kt | 5 + .../bajajfd/repositories/MainRepository.kt | 4 +- .../ui/activity/BajajFdMainActivity.kt | 77 +++++----- .../ui/fragment/StepThreeBajajFDFragment.kt | 132 +++++++++++++++++- .../nivesh/production/bajajfd/util/Common.kt | 8 +- .../bajajfd/viewModel/BajajFDViewModel.kt | 2 + .../viewModel/StepThreeBajajFDViewModel.kt | 15 +- 12 files changed, 231 insertions(+), 67 deletions(-) create mode 100644 app/src/main/java/com/nivesh/production/bajajfd/model/UploadResponse.kt 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 22e3de5..50f4560 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/BajajApplication.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/BajajApplication.kt @@ -1,14 +1,18 @@ package com.nivesh.production.bajajfd import android.app.Application +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 } @Synchronized 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 aaa5a11..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,13 +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 @@ -17,7 +25,7 @@ class ApiClient { //see the body of response //create client for retrofit val client = OkHttpClient.Builder() - .addInterceptor(logging) + .addInterceptor(ConnectVerifierInterceptor()) .retryOnConnectionFailure(true) .build() Retrofit.Builder() @@ -29,5 +37,24 @@ class ApiClient { val getApiClient: ApiInterface by lazy { client.create(ApiInterface::class.java) } + fun isNetworkAvailablee(): Boolean { + val connectivityManager = + BajajApplication.appContext?.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager + return connectivityManager?.activeNetworkInfo?.isConnected == true + } } -} \ No newline at end of file + +} + + + +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) + } +} + 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/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/StepThreeBajajFDFragment.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepThreeBajajFDFragment.kt index afb0a16..b368669 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 791ce18..8f27b88 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 @@ -9,6 +9,7 @@ import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.os.Build import android.provider.ContactsContract +import android.util.Log import android.util.Patterns import com.google.android.material.textfield.MaterialAutoCompleteTextView import com.google.android.material.textfield.TextInputEditText @@ -16,8 +17,11 @@ import com.google.android.material.textfield.TextInputLayout import com.google.gson.JsonObject import com.nivesh.production.bajajfd.R import com.nivesh.production.bajajfd.ui.activity.BaseActivity +import okhttp3.Interceptor.* import retrofit2.HttpException +import retrofit2.Response import java.io.IOException +import java.net.SocketTimeoutException import java.text.SimpleDateFormat import java.util.* import java.util.regex.Matcher @@ -195,13 +199,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 From 0323379e9a63d299f8f5501321fdf95ac04cab0f Mon Sep 17 00:00:00 2001 From: Hemant Khadase Date: Tue, 3 Jan 2023 20:48:48 +0530 Subject: [PATCH 2/5] completed stepfour coding --- .../bajajfd/adapter/CustomerListAdapter.kt | 36 +++++------------- .../production/bajajfd/model/GetCodes.kt | 3 +- .../production/bajajfd/model/ResponseX.kt | 2 +- .../ui/fragment/StepFourBajajFDFragment.kt | 21 +++++++++-- .../ui/fragment/StepThreeBajajFDFragment.kt | 4 +- .../nivesh/production/bajajfd/util/Common.kt | 1 + .../res/layout/item_customer_list_preview.xml | 37 ++++++++++--------- app/src/main/res/values-hi-rIN/strings.xml | 4 +- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 56 insertions(+), 54 deletions(-) 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 3681c93..1083c34 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 @@ -1,21 +1,24 @@ package com.nivesh.production.bajajfd.adapter +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +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 + var mExpandedPosition = -1 override fun onCreateViewHolder( @@ -34,18 +37,10 @@ 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) - if (checkedPosition != holder.adapterPosition) { - notifyItemChanged(checkedPosition) - checkedPosition = holder.adapterPosition - - } - } - } + holder.txtLabel.text = cList.Label + holder.tvCustomerName.setOnCheckedChangeListener { _, isChecked -> + cList.isSelected = isChecked + Log.e("isSelected","-->"+cList.isSelected) } } } @@ -54,17 +49,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/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/ui/fragment/StepFourBajajFDFragment.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFourBajajFDFragment.kt index 74f02dd..a6489fc 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 @@ -25,6 +25,9 @@ class StepFourBajajFDFragment : BaseFragment() { private var _binding: FragmentBajajfdStepFourBinding? = null private val binding get() = _binding!! private var uniqueId: String? = "" + private lateinit var listOfCustomer: MutableList + var selectedList : String = "" + private lateinit var bajajFDInterface: BajajFDInterface @@ -55,11 +58,22 @@ class StepFourBajajFDFragment : BaseFragment() { } binding.btnNext.setOnClickListener { + for (getCodes in listOfCustomer){ + if (getCodes.isSelected){ + if (selectedList.isEmpty()){ + selectedList = getCodes.Value + }else{ + selectedList = selectedList.plus(",").plus(getCodes.Value) + } + } + } + Log.e("selectedList", "-->$selectedList") if (binding.checkBox.isChecked) { + val saveFDOtherDataRequest = SaveFDOtherDataRequest() saveFDOtherDataRequest.FDProvider = getString(R.string.bajaj) saveFDOtherDataRequest.UniqueId = uniqueId - saveFDOtherDataRequest.Values = "" + saveFDOtherDataRequest.Values = selectedList saveFDOtherDataRequest.NiveshClientCode = (activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE bajajFDInterface.stepFourApi(saveFDOtherDataRequest) } else { @@ -103,7 +117,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 +147,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) 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 b368669..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 @@ -108,9 +108,9 @@ class StepThreeBajajFDFragment : BaseFragment() { binding.btnNext.setOnClickListener { if (validate()) { - uploadDocApi() + // uploadDocApi() // - // bajajFDInterface.stepThreeApi((activity as BajajFdMainActivity).createFDRequest) + bajajFDInterface.stepThreeApi((activity as BajajFdMainActivity).createFDRequest) } } binding.btnBack.setOnClickListener { 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 8f27b88..7716ed0 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 @@ -111,6 +111,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() 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 2fff86b..ea3e1ab 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,21 @@ - + + + + + + + + + + + - + - + 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 From 14f72f3c9f97465c6a9d338116b7fdd762741b6a Mon Sep 17 00:00:00 2001 From: Hemant Khadase Date: Tue, 3 Jan 2023 20:55:15 +0530 Subject: [PATCH 3/5] updated code --- .../bajajfd/adapter/CustomerListAdapter.kt | 5 -- .../ui/fragment/StepFourBajajFDFragment.kt | 50 +++++++++++-------- .../nivesh/production/bajajfd/util/Common.kt | 3 -- .../res/layout/item_customer_list_preview.xml | 13 ----- 4 files changed, 28 insertions(+), 43 deletions(-) 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 1083c34..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 @@ -1,6 +1,5 @@ package com.nivesh.production.bajajfd.adapter -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -18,9 +17,6 @@ class CustomerListAdapter( val txtLabel: TextView = itemView.findViewById(R.id.txtLabel) } - var mExpandedPosition = -1 - - override fun onCreateViewHolder( parent: ViewGroup, viewType: Int @@ -40,7 +36,6 @@ class CustomerListAdapter( holder.txtLabel.text = cList.Label holder.tvCustomerName.setOnCheckedChangeListener { _, isChecked -> cList.isSelected = isChecked - Log.e("isSelected","-->"+cList.isSelected) } } } 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 a6489fc..8735f74 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,10 +24,9 @@ class StepFourBajajFDFragment : BaseFragment() { private lateinit var stepFourBajajFDViewModel: StepFourBajajFDViewModel private var _binding: FragmentBajajfdStepFourBinding? = null private val binding get() = _binding!! - private var uniqueId: String? = "" private lateinit var listOfCustomer: MutableList - var selectedList : String = "" - + private var selectedList: String = "" + private var uniqueId: String? = "" private lateinit var bajajFDInterface: BajajFDInterface @@ -58,23 +57,24 @@ class StepFourBajajFDFragment : BaseFragment() { } binding.btnNext.setOnClickListener { - for (getCodes in listOfCustomer){ - if (getCodes.isSelected){ - if (selectedList.isEmpty()){ - selectedList = getCodes.Value - }else{ - selectedList = selectedList.plus(",").plus(getCodes.Value) + 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 = selectedList - saveFDOtherDataRequest.NiveshClientCode = (activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE + saveFDOtherDataRequest.NiveshClientCode = + (activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE bajajFDInterface.stepFourApi(saveFDOtherDataRequest) } else { showDialogValidation( @@ -84,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() } @@ -159,7 +162,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 -> @@ -175,13 +179,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/util/Common.kt b/app/src/main/java/com/nivesh/production/bajajfd/util/Common.kt index 7716ed0..2616268 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 @@ -9,7 +9,6 @@ import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.os.Build import android.provider.ContactsContract -import android.util.Log import android.util.Patterns import com.google.android.material.textfield.MaterialAutoCompleteTextView import com.google.android.material.textfield.TextInputEditText @@ -17,9 +16,7 @@ import com.google.android.material.textfield.TextInputLayout import com.google.gson.JsonObject import com.nivesh.production.bajajfd.R import com.nivesh.production.bajajfd.ui.activity.BaseActivity -import okhttp3.Interceptor.* import retrofit2.HttpException -import retrofit2.Response import java.io.IOException import java.net.SocketTimeoutException import java.text.SimpleDateFormat 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 ea3e1ab..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,16 +1,4 @@ - - - - - - - - - - - - - From 0f6c54fe7aa17b5b1dd4894b7e6f108348e94f79 Mon Sep 17 00:00:00 2001 From: Hemant Khadase Date: Wed, 4 Jan 2023 15:39:55 +0530 Subject: [PATCH 4/5] changes done --- .../production/bajajfd/api/ApiClient.kt | 48 ++-- .../bajajfd/interfaces/ApiInterface.kt | 2 +- .../bajajfd/interfaces/BajajFDInterface.kt | 2 +- .../bajajfd/model/ResponseXXXXXXXXXXXXX.kt | 8 + .../bajajfd/model/SaveFDOtherDataResponse.kt | 5 + .../bajajfd/repositories/MainRepository.kt | 4 +- .../ui/activity/BajajFdMainActivity.kt | 222 ++++++++++++------ .../ui/fragment/StepFiveBajajFDFragment.kt | 16 +- .../ui/fragment/StepFourBajajFDFragment.kt | 16 +- .../ui/fragment/StepOneBajajFDFragment.kt | 2 +- .../ui/fragment/StepTwoBajajFDFragment.kt | 12 +- .../nivesh/production/bajajfd/util/Common.kt | 13 + .../bajajfd/viewModel/BajajFDViewModel.kt | 26 +- .../viewModel/StepFiveBajajFDViewModel.kt | 10 + .../viewModel/StepFourBajajFDViewModel.kt | 8 +- app/src/main/res/layout/row_fd_pay.xml | 43 ++++ app/src/main/res/values-hi-rIN/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 18 files changed, 302 insertions(+), 139 deletions(-) create mode 100644 app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXXX.kt create mode 100644 app/src/main/java/com/nivesh/production/bajajfd/model/SaveFDOtherDataResponse.kt create mode 100644 app/src/main/res/layout/row_fd_pay.xml 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 14f4d89..a537cf0 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,21 +1,20 @@ 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 +import java.security.KeyStore +import java.util.* +import java.util.concurrent.TimeUnit +import javax.net.ssl.* class ApiClient { val context = BajajApplication.appContext + companion object { private val client by lazy { //lazy means we only initialize this here once @@ -24,10 +23,31 @@ class ApiClient { logging.setLevel(HttpLoggingInterceptor.Level.BODY) //see the body of response //create client for retrofit + + val trustManagerFactory: TrustManagerFactory = + TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) + trustManagerFactory.init(null as KeyStore?) + val trustManagers: Array = trustManagerFactory.getTrustManagers() + check(!(trustManagers.size != 1 || trustManagers[0] !is X509TrustManager)) { + "Unexpected default trust managers:" + Arrays.toString( + trustManagers + ) + } + val trustManager: X509TrustManager = trustManagers[0] as X509TrustManager + val sslContext = SSLContext.getInstance("SSL") + sslContext.init(null, arrayOf(trustManager), null) + val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory + val client = OkHttpClient.Builder() - .addInterceptor(ConnectVerifierInterceptor()) + .addInterceptor(logging) + .sslSocketFactory(sslSocketFactory, trustManager) .retryOnConnectionFailure(true) + .callTimeout(2, TimeUnit.MINUTES) + .connectTimeout(20, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) .build() + Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) @@ -37,24 +57,10 @@ class ApiClient { val getApiClient: ApiInterface by lazy { client.create(ApiInterface::class.java) } - 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) - } -} 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 dc65119..c253c17 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 @@ -34,7 +34,7 @@ interface ApiInterface { @POST("WebApi_Bajaj/api/SaveFDOtherData") suspend fun saveFDOtherData( - @Body requestBody: RequestBody, + @Body requestBody: SaveFDOtherDataRequest, @Header("token") token: String ): Response diff --git a/app/src/main/java/com/nivesh/production/bajajfd/interfaces/BajajFDInterface.kt b/app/src/main/java/com/nivesh/production/bajajfd/interfaces/BajajFDInterface.kt index d827306..2238ef6 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/interfaces/BajajFDInterface.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/interfaces/BajajFDInterface.kt @@ -7,5 +7,5 @@ interface BajajFDInterface { fun stepOneApi(data: String?) fun stepTwoApi(data: CreateFDRequest) fun stepThreeApi(data: CreateFDRequest) - fun stepFourApi(data: SaveFDOtherDataRequest) + fun stepFourApi(data: SaveFDOtherDataRequest, payUrl: String, value: String) } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXXX.kt b/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXXX.kt new file mode 100644 index 0000000..d140607 --- /dev/null +++ b/app/src/main/java/com/nivesh/production/bajajfd/model/ResponseXXXXXXXXXXXXX.kt @@ -0,0 +1,8 @@ +package com.nivesh.production.bajajfd.model + +data class ResponseXXXXXXXXXXXXX( + val Errors: List, + val Message: String, + val Status: String, + val StatusCode: Int +) \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/model/SaveFDOtherDataResponse.kt b/app/src/main/java/com/nivesh/production/bajajfd/model/SaveFDOtherDataResponse.kt new file mode 100644 index 0000000..d1cd6f4 --- /dev/null +++ b/app/src/main/java/com/nivesh/production/bajajfd/model/SaveFDOtherDataResponse.kt @@ -0,0 +1,5 @@ +package com.nivesh.production.bajajfd.model + +data class SaveFDOtherDataResponse( + val Response: ResponseXXXXXXXXXXXXX +) \ 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 8550104..0b1ba2c 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 @@ -29,8 +29,8 @@ class MainRepository constructor(private val apiInterface: ApiInterface) { suspend fun documentsUploadResponse(getRatesRequest: DocumentUpload, token: String) = apiInterface.documentsUpload(getRatesRequest, token) - suspend fun saveFDOtherDataResponse(getRatesRequest: GetRatesRequest, token: String) = - apiInterface.getRates(getRatesRequest, token) + suspend fun saveFDOtherDataResponse(getRatesRequest: SaveFDOtherDataRequest, token: String) = + apiInterface.saveFDOtherData(getRatesRequest, token) suspend fun getFDDetailsResponse(getRatesRequest: GetFDDetailsRequest, token: String) = apiInterface.getFDDetails(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 9bb0340..2982565 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 @@ -1,12 +1,20 @@ package com.nivesh.production.bajajfd.ui.activity +import android.annotation.SuppressLint +import android.app.Dialog +import android.graphics.Bitmap import android.graphics.drawable.Drawable import android.os.Bundle import android.util.Log +import android.view.WindowManager +import android.webkit.WebView +import android.webkit.WebViewClient +import android.widget.TextView import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import androidx.viewpager.widget.ViewPager import com.google.gson.Gson +import com.nivesh.production.bajajfd.R import com.nivesh.production.bajajfd.adapter.SectionsPagerAdapter import com.nivesh.production.bajajfd.api.ApiClient import com.nivesh.production.bajajfd.databinding.ActivityBajajFdBinding @@ -46,7 +54,7 @@ class BajajFdMainActivity : BaseActivity(), BajajFDInterface { var getClientDetailsResponse: getClientDetailsResponse private var stepCount: Int = 0 - private lateinit var sectionsPagerAdapter : SectionsPagerAdapter + private lateinit var sectionsPagerAdapter: SectionsPagerAdapter private lateinit var fragments: Array override fun onCreate(savedInstanceState: Bundle?) { @@ -108,53 +116,51 @@ class BajajFdMainActivity : BaseActivity(), BajajFDInterface { } private fun getStepsCountApi() { - 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 -> { - - } - } - } - } + if (Common.isNetworkAvailable(this)) { + val fdStepsCount = FDStepsCountRequest() + fdStepsCount.FDProvider = getString(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) { - if (Common.isNetworkAvailable(this@BajajFdMainActivity)) { - } } @@ -162,20 +168,20 @@ class BajajFdMainActivity : BaseActivity(), BajajFDInterface { if (Common.isNetworkAvailable(this@BajajFdMainActivity)) { val getClientDetailsRequest = getClientDetailsRequest() getClientDetailsRequest.client_code = "8872" - getClientDetailsRequest.AppOrWeb = getString(com.nivesh.production.bajajfd.R.string.app) + getClientDetailsRequest.AppOrWeb = getString(R.string.app) getClientDetailsRequest.sub_broker_code = "1038" val userRequest = UserRequest() userRequest.UID = 19060 userRequest.IPAddress = "" - userRequest.Source = getString(com.nivesh.production.bajajfd.R.string.source) - userRequest.AppOrWeb = getString(com.nivesh.production.bajajfd.R.string.app) + userRequest.Source = getString(R.string.source) + userRequest.AppOrWeb = getString(R.string.app) userRequest.LoggedInRoleId = 5 val deviceInfo = DeviceInfo() deviceInfo.device_id = "" deviceInfo.device_id_for_UMSId = "" - deviceInfo.device_type = getString(com.nivesh.production.bajajfd.R.string.app) + deviceInfo.device_type = getString(R.string.app) deviceInfo.device_model = "" deviceInfo.device_token = "" deviceInfo.device_name = "" @@ -388,29 +394,23 @@ class BajajFdMainActivity : BaseActivity(), BajajFDInterface { // step 2 response override fun stepTwoApi(data: CreateFDRequest) { - Log.e("stepTwoApi", " response ---> $data") - // if (stepCount == 4) { - // go to step 3 image Upload - // binding.viewPager.currentItem = 2 - // } else { - // call create fd api bypass step 3 - createFDApi(data, 2, "2") - // } + Log.e("stepTwoApi", " response ---> " + Gson().toJson(data)) + createFDApi(data, 2, "2") } // step 3 response override fun stepThreeApi(data: CreateFDRequest) { - Log.e("stepThreeApi", " response ---> $data") + Log.e("stepThreeApi", " response --->" + Gson().toJson(data)) // call create fd api createFDApi(data, 3, "3") } // step 4 response - override fun stepFourApi(data: SaveFDOtherDataRequest) { - Log.e("stepFourApi", " response ---> $data") - // binding.viewPager.currentItem = 4 - + override fun stepFourApi(data: SaveFDOtherDataRequest, payUrl: String, value: String) { + Log.e("stepFourApi", " response ---> " + Gson().toJson(data)) + // binding.viewPager.currentItem = 4 + saveFDOtherData(data, payUrl, value) } private fun createFDApi(data: CreateFDRequest, currentItem: Int, step: String) { @@ -430,16 +430,19 @@ class BajajFdMainActivity : BaseActivity(), BajajFDInterface { when (code) { 200 -> { binding.viewPager.currentItem = currentItem - if (step == "2"){ + if (step == "2") { val stepThreeBajajFDFragment: StepThreeBajajFDFragment = sectionsPagerAdapter.getRegisteredFragment(currentItem) as StepThreeBajajFDFragment - stepThreeBajajFDFragment.displayReceivedData(createFDApplicationResponse) + stepThreeBajajFDFragment.displayReceivedData( + createFDApplicationResponse + ) + } else { + val stepFourFDFragment: StepFourBajajFDFragment = + sectionsPagerAdapter.getRegisteredFragment(currentItem) as StepFourBajajFDFragment + stepFourFDFragment.displayReceivedData( + createFDApplicationResponse + ) } - else{ - val stepFourFDFragment: StepFourBajajFDFragment = - sectionsPagerAdapter.getRegisteredFragment(currentItem) as StepFourBajajFDFragment - stepFourFDFragment.displayReceivedData(createFDApplicationResponse) - } } // 650 -> refreshToken() else -> { @@ -464,4 +467,87 @@ class BajajFdMainActivity : BaseActivity(), BajajFDInterface { } } } + + private fun saveFDOtherData(data: SaveFDOtherDataRequest, payUrl: String, value: String) { + if (Common.isNetworkAvailable(this)) { + viewModel.saveFDOtherData(data, token) + viewModel.getFDOtherMutableData.observe(this) { response -> + when (response) { + is Resource.Success -> { + Log.e("response", "-->" + response.data.toString()) + val saveFDOtherDataResponse: SaveFDOtherDataResponse = + Gson().fromJson( + response.data?.toString(), + SaveFDOtherDataResponse::class.java + ) + saveFDOtherDataResponse.Response.StatusCode.let { code -> + when (code) { + 200 -> { + paymentDialog(payUrl, value) + } + // 650 -> refreshToken() + else -> { + showDialogValidation( + this@BajajFdMainActivity, + saveFDOtherDataResponse.Response.Errors[0].ErrorMessage + ) + } + } + } + } + + is Resource.Error -> { + response.message?.let { message -> + showDialogValidation(this@BajajFdMainActivity, message) + } + } + is Resource.Loading -> { + + } + } + } + } + } + + @SuppressLint("SetJavaScriptEnabled") + fun paymentDialog(payUrl: String, value: String) { + Log.e("payUrl", "-->$payUrl") + Log.e("value", "-->$value") + val dialogWebView = Dialog(this@BajajFdMainActivity) + dialogWebView.setContentView(R.layout.row_fd_pay) + dialogWebView.setCancelable(true) + + val tvCancel = dialogWebView.findViewById(R.id.tvCancel) + tvCancel.setOnClickListener { + dialogWebView.dismiss() + } + + val lp = WindowManager.LayoutParams() + lp.copyFrom(dialogWebView.window?.attributes) + lp.width = WindowManager.LayoutParams.MATCH_PARENT + lp.height = WindowManager.LayoutParams.MATCH_PARENT + dialogWebView.window?.attributes = lp + val wVPay = dialogWebView.findViewById(R.id.wVPay) + wVPay.webViewClient = MyWebViewClient() + wVPay.settings.javaScriptEnabled = true + wVPay.settings.domStorageEnabled = true + wVPay.loadUrl(payUrl) + dialogWebView.show() + } + + class MyWebViewClient : WebViewClient() { + override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { + super.onPageStarted(view, url, favicon) + Log.e("onPageStarted", "-->$url") + if (url.isNotEmpty() && url.contains("CustomerPaymentResponse")) { + + } + } + + override fun onPageFinished(view: WebView, url: String) { + super.onPageFinished(view, url) + } + + } + } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFiveBajajFDFragment.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFiveBajajFDFragment.kt index 654ce7d..4186ee3 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFiveBajajFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepFiveBajajFDFragment.kt @@ -8,30 +8,27 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import com.nivesh.production.bajajfd.interfaces.BajajFDInterface import com.nivesh.production.bajajfd.databinding.FragmentBajajfdStepFiveBinding +import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity import com.nivesh.production.bajajfd.viewModel.StepFiveBajajFDViewModel class StepFiveBajajFDFragment : Fragment() { - private lateinit var stepFourViewModel: StepFiveBajajFDViewModel + private lateinit var stepFiveBajajFDViewModel: StepFiveBajajFDViewModel private var _binding: FragmentBajajfdStepFiveBinding? = null private val binding get() = _binding!! private lateinit var bajajFDInterface: BajajFDInterface companion object { fun getInstance(fdInterface: BajajFDInterface): StepFiveBajajFDFragment { - val stepFourFragment = StepFiveBajajFDFragment() - stepFourFragment.setApi(fdInterface) - return stepFourFragment + val stepFiveFragment = StepFiveBajajFDFragment() + stepFiveFragment.setApi(fdInterface) + return stepFiveFragment } } - private fun setApi(bajajFDInterfaces: BajajFDInterface) { + fun setApi(bajajFDInterfaces: BajajFDInterface) { bajajFDInterface = bajajFDInterfaces } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -40,6 +37,7 @@ class StepFiveBajajFDFragment : Fragment() { _binding = FragmentBajajfdStepFiveBinding.inflate(inflater, container, false) val root = binding.root + stepFiveBajajFDViewModel= (activity as BajajFdMainActivity).stepFiveBajajFDViewModel // val textView: TextView = binding.sectionLabel // stepFourViewModel.text.observe(viewLifecycleOwner) { 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 8735f74..60a5e1d 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 @@ -26,7 +26,9 @@ class StepFourBajajFDFragment : BaseFragment() { private val binding get() = _binding!! private lateinit var listOfCustomer: MutableList private var selectedList: String = "" - private var uniqueId: String? = "" + private var uniqueId: String = "" + private var payUrl : String = "" + private var Value : String = "" private lateinit var bajajFDInterface: BajajFDInterface @@ -75,7 +77,7 @@ class StepFourBajajFDFragment : BaseFragment() { saveFDOtherDataRequest.Values = selectedList saveFDOtherDataRequest.NiveshClientCode = (activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE - bajajFDInterface.stepFourApi(saveFDOtherDataRequest) + bajajFDInterface.stepFourApi(saveFDOtherDataRequest, payUrl, Value) } else { showDialogValidation( activity as BajajFdMainActivity, @@ -92,10 +94,6 @@ class StepFourBajajFDFragment : BaseFragment() { fun displayReceivedData(createFDApplicationResponse: CreateFDApplicationResponse) { - Log.e( - "createFDApplication", - "Response-->" + createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId - ) uniqueId = createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId getFDDetailsApi(createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId) customerListApi() @@ -188,12 +186,14 @@ class StepFourBajajFDFragment : BaseFragment() { binding.tvRateOfInterest.text = getFDDetailsResponse.Response.FDDataResponse.RateOfInterest.toString() .plus(" % p.a.") + payUrl = getFDDetailsResponse.Response.FDDataResponse.PaymentUrl + Value = getFDDetailsResponse.Response.FDDataResponse.Value } // 650 -> refreshToken() else -> { showDialogValidation( activity as BajajFdMainActivity, - getFDDetailsResponse.Response.Message + getFDDetailsResponse.Response.Errors[0].ErrorMessage ) } } @@ -216,6 +216,6 @@ class StepFourBajajFDFragment : BaseFragment() { override fun onDestroyView() { super.onDestroyView() - _binding = null + // _binding = null } } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepOneBajajFDFragment.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepOneBajajFDFragment.kt index b6e6484..d902315 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepOneBajajFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepOneBajajFDFragment.kt @@ -505,6 +505,6 @@ class StepOneBajajFDFragment : BaseFragment() { override fun onDestroyView() { super.onDestroyView() - _binding = null + // _binding = null } } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepTwoBajajFDFragment.kt b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepTwoBajajFDFragment.kt index 8218885..4637d23 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepTwoBajajFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepTwoBajajFDFragment.kt @@ -35,6 +35,7 @@ import com.nivesh.production.bajajfd.util.Common.Companion.commonErrorMethod import com.nivesh.production.bajajfd.util.Common.Companion.commonSpinnerErrorMethod import com.nivesh.production.bajajfd.util.Common.Companion.getDate import com.nivesh.production.bajajfd.util.Common.Companion.isIndianMobileNo +import com.nivesh.production.bajajfd.util.Common.Companion.isMinor import com.nivesh.production.bajajfd.util.Common.Companion.isValidEmail import com.nivesh.production.bajajfd.util.Common.Companion.isValidName import com.nivesh.production.bajajfd.util.Common.Companion.isValidPan @@ -1784,7 +1785,14 @@ class StepTwoBajajFDFragment : BaseFragment() { binding.tlPinCode, getString(R.string.validPinCode) ) - } else if ((activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.ClientBanklist?.isEmpty()!! && binding.edtIFSC.text.toString() + }else if (binding.edtNomineeDOB.text.toString().isNotEmpty() && isMinor(binding.edtNomineeDOB.text.toString())){ + commonErrorMethod( + binding.edtGuardianName, + binding.tlGuardianName, + getString(R.string.validGuardianDetails) + ) + } + else if ((activity as BajajFdMainActivity).getClientDetailsResponse.ObjectResponse?.ClientBanklist?.isEmpty()!! && binding.edtIFSC.text.toString() .isEmpty() ) { // EditText commonErrorAutoCompleteMethod( @@ -1831,7 +1839,7 @@ class StepTwoBajajFDFragment : BaseFragment() { override fun onDestroyView() { super.onDestroyView() - _binding = null + // _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 2616268..9e980ec 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 @@ -9,6 +9,7 @@ import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.os.Build import android.provider.ContactsContract +import android.text.format.DateFormat import android.util.Patterns import com.google.android.material.textfield.MaterialAutoCompleteTextView import com.google.android.material.textfield.TextInputEditText @@ -203,5 +204,17 @@ class Common { } return Resource.Error(response.message()) } + + fun isMinor(date: String): Boolean { + val simpleDateFormat = SimpleDateFormat("yyyy-mm-dd") + val dt1: Date = simpleDateFormat.parse(date) + val year: Int = DateFormat.format("yyyy", dt1).toString().toInt() + val month: Int = DateFormat.format("mm", dt1).toString().toInt() + val day = DateFormat.format("dd", dt1).toString().toInt() + val userAge: Calendar = GregorianCalendar(year, month, day) + val minAdultAge: Calendar = GregorianCalendar() + minAdultAge.add(Calendar.YEAR, -18) + return minAdultAge.before(userAge) + } } } \ 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 1b703fb..a659e8c 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 @@ -5,9 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.google.gson.JsonObject -import com.nivesh.production.bajajfd.model.CreateFDRequest -import com.nivesh.production.bajajfd.model.FDStepsCountRequest -import com.nivesh.production.bajajfd.model.getClientDetailsRequest +import com.nivesh.production.bajajfd.model.* import com.nivesh.production.bajajfd.repositories.MainRepository import com.nivesh.production.bajajfd.util.Common.Companion.handleRatesResponse import com.nivesh.production.bajajfd.util.Resource @@ -38,21 +36,11 @@ class BajajFDViewModel(private val mainRepository: MainRepository) : ViewModel() getFDResponseMutableData.postValue(handleRatesResponse(response)) } -// private fun handleRatesResponse(response: retrofit2.Response): Resource { -// try { -// if ( response.isSuccessful && response.body() != null) { -// response.body()?.let { resultResponse -> -// return Resource.Success(resultResponse) -// } -// } -// } catch (t: Throwable) { -// 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)) -// else -> Resource.Error(t.localizedMessage?.toString() ?: "") -// } -// } -// return Resource.Error(response.message()) -// } + val getFDOtherMutableData: MutableLiveData> = MutableLiveData() + fun saveFDOtherData(getRatesRequest: SaveFDOtherDataRequest, token: String) = viewModelScope.launch { + getFDOtherMutableData.postValue(Resource.Loading()) + val response = mainRepository.saveFDOtherDataResponse(getRatesRequest, token) + getFDOtherMutableData.postValue(handleRatesResponse(response)) + } } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFiveBajajFDViewModel.kt b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFiveBajajFDViewModel.kt index 509c598..0484681 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFiveBajajFDViewModel.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFiveBajajFDViewModel.kt @@ -1,7 +1,17 @@ package com.nivesh.production.bajajfd.viewModel +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import androidx.lifecycle.ViewModel +import com.nivesh.production.bajajfd.databinding.FragmentBajajfdStepFiveBinding +import com.nivesh.production.bajajfd.databinding.FragmentBajajfdStepFourBinding +import com.nivesh.production.bajajfd.interfaces.BajajFDInterface import com.nivesh.production.bajajfd.repositories.MainRepository +import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity +import com.nivesh.production.bajajfd.ui.fragment.StepFiveBajajFDFragment +import com.nivesh.production.bajajfd.ui.fragment.StepFourBajajFDFragment class StepFiveBajajFDViewModel (private val mainRepository: MainRepository) : ViewModel() { diff --git a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFourBajajFDViewModel.kt b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFourBajajFDViewModel.kt index e68bff9..f7acd5b 100644 --- a/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFourBajajFDViewModel.kt +++ b/app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepFourBajajFDViewModel.kt @@ -28,13 +28,7 @@ class StepFourBajajFDViewModel(private val mainRepository: MainRepository) : Vie getFDDetailsMutableData.postValue(handleRatesResponse(response)) } - private val getRatesMutableData: MutableLiveData> = MutableLiveData() - fun saveFDOtherData(getRatesRequest: GetRatesRequest, token: String) = viewModelScope.launch { - getRatesMutableData.postValue(Resource.Loading()) - val response = mainRepository.saveFDOtherDataResponse(getRatesRequest, token) - getRatesMutableData.postValue(handleRatesResponse(response)) - } - + val getRatesMutableData: MutableLiveData> = MutableLiveData() fun updateFDPaymentStatus(getRatesRequest: GetRatesRequest, token: String) = viewModelScope.launch { getRatesMutableData.postValue(Resource.Loading()) diff --git a/app/src/main/res/layout/row_fd_pay.xml b/app/src/main/res/layout/row_fd_pay.xml new file mode 100644 index 0000000..a255157 --- /dev/null +++ b/app/src/main/res/layout/row_fd_pay.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + \ 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 53064ea..86039fa 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -247,5 +247,7 @@ PaymentMode CustomerCategory PAY + Payment + Please enter Guardian Details \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0027640..7311f62 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -247,6 +247,8 @@ PaymentMode CustomerCategory PAY + Payment + Please enter Guardian Details Aadhaar Card From 38f8420ed4b2077f74a386d36cdc65e43baf1b97 Mon Sep 17 00:00:00 2001 From: Hemant Khadase Date: Wed, 4 Jan 2023 16:35:54 +0530 Subject: [PATCH 5/5] added minor changes --- .../ui/fragment/StepThreeBajajFDFragment.kt | 239 +++++++++--------- 1 file changed, 122 insertions(+), 117 deletions(-) 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 e6dcb59..e57c40a 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 @@ -6,28 +6,19 @@ 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 import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import android.widget.ImageView -import android.widget.TextView -import android.widget.Toast +import android.widget.* import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.core.content.FileProvider -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import com.google.gson.Gson import com.nivesh.production.bajajfd.BuildConfig @@ -54,9 +45,18 @@ class StepThreeBajajFDFragment : BaseFragment() { private lateinit var bajajFDInterface: BajajFDInterface private lateinit var stepThreeBajajFDViewModel: StepThreeBajajFDViewModel - private var uniqueId: String? = "" + private lateinit var dialog: Dialog + private var takeImageResult: ActivityResultLauncher? = null + private var selectImageIntent: ActivityResultLauncher? = null + private val mapImage: HashMap = HashMap() + private var front: String = "" + private var fileExt: String? = "" + private var uniqueId: String? = "" + private var selectedImage: String? = "" + private var checkPANUploadFile: Boolean? = false + private var checkPhotoUploadFile: Boolean? = false companion object { fun getInstance(fdInterface: BajajFDInterface): StepThreeBajajFDFragment { @@ -70,22 +70,6 @@ class StepThreeBajajFDFragment : BaseFragment() { bajajFDInterface = bajajFDInterfaces } - private val selectImageIntent = registerForActivityResult(ActivityResultContracts.GetContent()) - { uri -> - val bitmap: Bitmap = MediaStore.Images.Media.getBitmap(context?.contentResolver, uri) - binding.iv.setImageBitmap(bitmap) - } - - private val takeImageResult = - registerForActivityResult(ActivityResultContracts.TakePicture()) { isSuccess -> - if (isSuccess) { - latestTmpUri?.let { uri -> -// binding.iv.setImageURI(uri) - uploadDocument(uri) - } - } - } - private val requestPermission = registerForActivityResult( ActivityResultContracts.RequestPermission() ) { isGranted: Boolean -> @@ -106,19 +90,61 @@ class StepThreeBajajFDFragment : BaseFragment() { val root = binding.root stepThreeBajajFDViewModel = (activity as BajajFdMainActivity).stepThreeBajajFDViewModel + selectImageIntent = registerForActivityResult(ActivityResultContracts.GetContent()) + { uri: Uri? -> + if (uri != null) { + uploadDocument(uri) + } + } + + takeImageResult = + registerForActivityResult(ActivityResultContracts.TakePicture()) { isSuccess -> + if (isSuccess) { + latestTmpUri?.let { uri -> + uploadDocument(uri) + } + } + } + binding.btnNext.setOnClickListener { if (validate()) { - // uploadDocApi() - // - bajajFDInterface.stepThreeApi((activity as BajajFdMainActivity).createFDRequest) + var uploadPosition = 0 + for (entry in mapImage.iterator()) { + uploadPosition++ + if (entry.key.contains("Main ")) { + uploadDocApi(entry.key.replace("Main ", ""), entry.value, uploadPosition) + } else { + uploadDocApi(entry.key, entry.value, uploadPosition) + } + } } } binding.btnBack.setOnClickListener { (activity as BajajFdMainActivity).binding.viewPager.currentItem = 1 } + binding.btnPANUpload.setOnClickListener { + checkPANUploadFile = true + checkPhotoUploadFile = false + selectImage("PAN") + } + + binding.btnPhotoUpload.setOnClickListener { + checkPhotoUploadFile = true + checkPANUploadFile = false + selectImage("Photograph") + } + binding.btnAadhaarFrontUpload.setOnClickListener { - selectImage() + checkPANUploadFile = false + checkPhotoUploadFile = false + selectImage(binding.spDocType.text.toString()) + } + + binding.btnAadhaarBackUpload.setOnClickListener { + checkPANUploadFile = false + checkPhotoUploadFile = false + selectImage(binding.spDocType.text.toString()) } binding.spDocType.onItemClickListener = @@ -140,21 +166,19 @@ class StepThreeBajajFDFragment : BaseFragment() { @SuppressLint("Range") fun getFileName(uri: Uri): String { - var result: String? = null + var result = "" 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)) + requireActivity().contentResolver.query(uri, null, null, null, null)!! + cursor.use { cursor1 -> + if (cursor1.moveToFirst()) { + result = cursor1.getString(cursor1.getColumnIndex(OpenableColumns.DISPLAY_NAME)) } - } finally { - cursor.close() } } - if (result == null) { - result = uri.path - val cut = result!!.lastIndexOf('/') + if (result.isEmpty()) { + result = uri.path!! + val cut = result.lastIndexOf('/') if (cut != -1) { result = result.substring(cut + 1) } @@ -162,7 +186,8 @@ class StepThreeBajajFDFragment : BaseFragment() { return result } - private fun selectImage() { + private fun selectImage(fileType: String) { + selectedImage = fileType dialog = Dialog(activity as BajajFdMainActivity) dialog.setContentView(R.layout.camera_gallery_layout) val ivCut: ImageView = dialog.findViewById(R.id.ivCut) @@ -175,55 +200,31 @@ class StepThreeBajajFDFragment : BaseFragment() { tvGallery.setOnClickListener { dialog.cancel() - when { - ContextCompat.checkSelfPermission( - activity as BajajFdMainActivity, - Manifest.permission.READ_EXTERNAL_STORAGE - ) == PackageManager.PERMISSION_GRANTED -> { - selectImageIntent.launch("image/*") - } - - ActivityCompat.shouldShowRequestPermissionRationale( - activity as BajajFdMainActivity, + val permission = ContextCompat.checkSelfPermission( + activity as BajajFdMainActivity, + Manifest.permission.READ_EXTERNAL_STORAGE + ) + if (permission == PackageManager.PERMISSION_GRANTED) { + selectImageIntent?.launch("image/*") + } else { + requestPermission.launch( Manifest.permission.READ_EXTERNAL_STORAGE - ) -> { - requestPermission.launch( - Manifest.permission.READ_EXTERNAL_STORAGE - ) - } - - else -> { - requestPermission.launch( - Manifest.permission.READ_EXTERNAL_STORAGE - ) - } + ) } } tvCamera.setOnClickListener { dialog.cancel() - when { - ContextCompat.checkSelfPermission( - activity as BajajFdMainActivity, - Manifest.permission.CAMERA - ) == PackageManager.PERMISSION_GRANTED -> { - takeImage() - } - - ActivityCompat.shouldShowRequestPermissionRationale( - activity as BajajFdMainActivity, + val permission = ContextCompat.checkSelfPermission( + activity as BajajFdMainActivity, + Manifest.permission.CAMERA + ) + if (permission == PackageManager.PERMISSION_GRANTED) { + takeImage() + } else { + requestPermission.launch( Manifest.permission.CAMERA - ) -> { - requestPermission.launch( - Manifest.permission.CAMERA - ) - } - - else -> { - requestPermission.launch( - Manifest.permission.CAMERA - ) - } + ) } } @@ -231,13 +232,6 @@ class StepThreeBajajFDFragment : BaseFragment() { dialog.window?.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT) } - private fun checkCameraStoragePermission( - permission: String, - selectImageIntent: ActivityResultLauncher - ) { - TODO("Not yet implemented") - } - private fun setOtherUploadLayout(itemName: String) { binding.tvAadhaarFront.text = itemName.plus(" Front *") if (binding.tvAadhaarBack.visibility == View.VISIBLE) binding.tvAadhaarBack.visibility = @@ -259,15 +253,15 @@ class StepThreeBajajFDFragment : BaseFragment() { 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 = + val fileDir: File = requireActivity().cacheDir + val fileExtension = File(fileDir.toString().plus("/").plus(getFileName(uri))) + fileExt = fileExtension.extension + encodedFileToBase64(fileExtension) + if (checkPANUploadFile == true || checkPhotoUploadFile == true) { + mapImage["Main ".plus(selectedImage)] = front + } else { + selectedImage?.let { mapImage.put(it, front) } + } } } @@ -283,7 +277,7 @@ class StepThreeBajajFDFragment : BaseFragment() { } @Throws(IOException::class) - private fun loadFile(file: File): ByteArray? { + private fun loadFile(file: File): ByteArray { val inputStream: InputStream = FileInputStream(file) val length = file.length() val bytes = ByteArray(length.toInt()) @@ -301,26 +295,38 @@ class StepThreeBajajFDFragment : BaseFragment() { return bytes } - private fun uploadDocApi(){ - if(Common.isNetworkAvailable((activity as BajajFdMainActivity))){ + private fun uploadDocApi(key: String, imageBase64: String, uploadPosition: Int) { + if (Common.isNetworkAvailable((activity as BajajFdMainActivity))) { val du = DocumentUpload() - du.Description = "PAN" - du.DocumentType = "PAN" + du.Description = key + du.DocumentType = key 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.ImageEncodeToBase64 = + "data:image/" + "." + fileExt + ";base64,".plus(imageBase64) //"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") + stepThreeBajajFDViewModel.documentsUpload(du, Constants.token) + + stepThreeBajajFDViewModel.getDocumentUploadMutableData.observe(viewLifecycleOwner) { response -> + when (response) { + is Resource.Success -> { + Log.e("UploadImage", "Response-->"+response.data.toString()) val getUploadResponse: UploadResponse = - Gson().fromJson(response.data?.toString(),UploadResponse::class.java) + Gson().fromJson(response.data?.toString(), UploadResponse::class.java) getUploadResponse.Response.StatusCode.let { code -> when (code) { 200 -> { - Log.e("check_upload_res",response.message.toString()) + Log.e("check_upload_res", response.message.toString()) + if (uploadPosition == mapImage.size) { + Toast.makeText( + requireActivity(), + "".plus(mapImage.size.toString() + " Last Image Uploaded ") + + uploadPosition, + Toast.LENGTH_LONG + ).show() + bajajFDInterface.stepThreeApi((activity as BajajFdMainActivity).createFDRequest) + } } // 650 -> refreshToken() else -> { @@ -343,7 +349,6 @@ class StepThreeBajajFDFragment : BaseFragment() { } } } - } } @@ -412,7 +417,7 @@ class StepThreeBajajFDFragment : BaseFragment() { lifecycleScope.launchWhenStarted { getTmpFileUri().let { uri -> latestTmpUri = uri - takeImageResult.launch(uri) + takeImageResult?.launch(uri) } } } @@ -438,6 +443,6 @@ class StepThreeBajajFDFragment : BaseFragment() { } fun displayReceivedData(createFDApplicationResponse: CreateFDApplicationResponse) { - uniqueId = createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId + uniqueId = createFDApplicationResponse.Response.FDCreationDetailsResponse.UniqueId } } \ No newline at end of file