Browse Source

refresh token

Manoj 2 years ago
parent
commit
46d82c215f
15 changed files with 626 additions and 13 deletions
  1. +4
    -0
      app/build.gradle
  2. +1
    -0
      app/src/main/AndroidManifest.xml
  3. +5
    -0
      app/src/main/java/com/nivesh/production/bajajfd/interfaces/ApiInterface.kt
  4. +5
    -0
      app/src/main/java/com/nivesh/production/bajajfd/repositories/MainRepository.kt
  5. +9
    -5
      app/src/main/java/com/nivesh/production/bajajfd/ui/activity/BajajFdMainActivity.kt
  6. +131
    -6
      app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepThreeBajajFDFragment.kt
  7. +2
    -2
      app/src/main/java/com/nivesh/production/bajajfd/util/Common.kt
  8. +10
    -0
      app/src/main/java/com/nivesh/production/bajajfd/util/Constants.kt
  9. +141
    -0
      app/src/main/java/com/nivesh/production/bajajfd/util/EncryptionDecryption.kt
  10. +50
    -0
      app/src/main/java/com/nivesh/production/bajajfd/util/ProgressUtil.kt
  11. +65
    -0
      app/src/main/java/com/nivesh/production/bajajfd/util/SharedPrefrenceDataMethods.kt
  12. +169
    -0
      app/src/main/java/com/nivesh/production/bajajfd/util/Utility.kt
  13. +21
    -0
      app/src/main/java/com/nivesh/production/bajajfd/util/Utils_Functions.kt
  14. +1
    -0
      app/src/main/java/com/nivesh/production/bajajfd/viewModel/BajajFDViewModel.kt
  15. +12
    -0
      app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepThreeBajajFDViewModel.kt

+ 4
- 0
app/build.gradle View File

@ -1,6 +1,7 @@
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'org.jetbrains.kotlin.android' id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
} }
android { android {
@ -73,4 +74,7 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:2.5.3" implementation "androidx.navigation:navigation-fragment-ktx:2.5.3"
implementation "androidx.navigation:navigation-ui-ktx:2.5.3" implementation "androidx.navigation:navigation-ui-ktx:2.5.3"
//Preference
implementation 'androidx.preference:preference:1.2.0'
} }

+ 1
- 0
app/src/main/AndroidManifest.xml View File

@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>


+ 5
- 0
app/src/main/java/com/nivesh/production/bajajfd/interfaces/ApiInterface.kt View File

@ -166,4 +166,9 @@ interface ApiInterface {
@Header("token") token: String @Header("token") token: String
): Response<JsonObject> ): Response<JsonObject>
@POST("GetToken_V2")
suspend fun freshToken(
@Body requestBody: RequestBody
):Response<JsonObject>
} }

+ 5
- 0
app/src/main/java/com/nivesh/production/bajajfd/repositories/MainRepository.kt View File

@ -1,7 +1,9 @@
package com.nivesh.production.bajajfd.repositories package com.nivesh.production.bajajfd.repositories
import com.google.gson.JsonObject
import com.nivesh.production.bajajfd.interfaces.ApiInterface import com.nivesh.production.bajajfd.interfaces.ApiInterface
import com.nivesh.production.bajajfd.model.* import com.nivesh.production.bajajfd.model.*
import okhttp3.RequestBody
class MainRepository constructor(private val apiInterface: ApiInterface) { class MainRepository constructor(private val apiInterface: ApiInterface) {
suspend fun getRatesResponse(getRatesRequest: GetRatesRequest, token: String) = suspend fun getRatesResponse(getRatesRequest: GetRatesRequest, token: String) =
@ -92,4 +94,7 @@ class MainRepository constructor(private val apiInterface: ApiInterface) {
suspend fun bankValidationApiRequest(bankValidationApiRequest: BankValidationApiRequest, token: String) = suspend fun bankValidationApiRequest(bankValidationApiRequest: BankValidationApiRequest, token: String) =
apiInterface.bankValidationApi(bankValidationApiRequest, token) apiInterface.bankValidationApi(bankValidationApiRequest, token)
suspend fun freshToken(body: RequestBody) =
apiInterface.freshToken(body)
} }

+ 9
- 5
app/src/main/java/com/nivesh/production/bajajfd/ui/activity/BajajFdMainActivity.kt View File

@ -29,6 +29,7 @@ import com.nivesh.production.bajajfd.util.Common.Companion.getDate
import com.nivesh.production.bajajfd.util.Common.Companion.selectedShape import com.nivesh.production.bajajfd.util.Common.Companion.selectedShape
import com.nivesh.production.bajajfd.util.Common.Companion.showDialogValidation import com.nivesh.production.bajajfd.util.Common.Companion.showDialogValidation
import com.nivesh.production.bajajfd.util.Constants.Companion.token import com.nivesh.production.bajajfd.util.Constants.Companion.token
import com.nivesh.production.bajajfd.util.ProgressUtil
import com.nivesh.production.bajajfd.util.Resource import com.nivesh.production.bajajfd.util.Resource
import com.nivesh.production.bajajfd.viewModel.* import com.nivesh.production.bajajfd.viewModel.*
@ -87,6 +88,7 @@ class BajajFdMainActivity : BaseActivity() {
private fun getStepsCountApi() { private fun getStepsCountApi() {
if (Common.isNetworkAvailable(this)) { if (Common.isNetworkAvailable(this)) {
ProgressUtil.showLoading(this)
val fdStepsCount = FDStepsCountRequest() val fdStepsCount = FDStepsCountRequest()
fdStepsCount.FDProvider = getString(R.string.bajaj) fdStepsCount.FDProvider = getString(R.string.bajaj)
fdStepsCount.NiveshClientCode = "8872" fdStepsCount.NiveshClientCode = "8872"
@ -123,7 +125,7 @@ class BajajFdMainActivity : BaseActivity() {
} }
} }
is Resource.Loading -> { is Resource.Loading -> {
ProgressUtil.hideLoading()
} }
is Resource.DataError -> { is Resource.DataError -> {
@ -140,6 +142,7 @@ class BajajFdMainActivity : BaseActivity() {
private fun getClientDetailsApi(stepsCount: Int) { private fun getClientDetailsApi(stepsCount: Int) {
if (Common.isNetworkAvailable(this@BajajFdMainActivity)) { if (Common.isNetworkAvailable(this@BajajFdMainActivity)) {
ProgressUtil.showLoading(this)
val getClientDetailsRequest = getClientDetailsRequest() val getClientDetailsRequest = getClientDetailsRequest()
getClientDetailsRequest.client_code = "8872" getClientDetailsRequest.client_code = "8872"
getClientDetailsRequest.AppOrWeb = getString(R.string.app) getClientDetailsRequest.AppOrWeb = getString(R.string.app)
@ -194,7 +197,7 @@ class BajajFdMainActivity : BaseActivity() {
} }
} }
is Resource.Loading -> { is Resource.Loading -> {
ProgressUtil.hideLoading()
} }
is Resource.DataError -> { is Resource.DataError -> {
@ -294,6 +297,7 @@ class BajajFdMainActivity : BaseActivity() {
private fun checkFDCKYCApi() { private fun checkFDCKYCApi() {
if (Common.isNetworkAvailable(this@BajajFdMainActivity)) { if (Common.isNetworkAvailable(this@BajajFdMainActivity)) {
ProgressUtil.showLoading(this)
if (getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CM_MOBILE?.isNotEmpty()!! && getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_DOB?.isNotEmpty()!! && getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_PAN?.isNotEmpty()!! && getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE?.isNotEmpty()!!) { if (getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CM_MOBILE?.isNotEmpty()!! && getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_DOB?.isNotEmpty()!! && getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_PAN?.isNotEmpty()!! && getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE?.isNotEmpty()!!) {
val checkFDKYCRequest = CheckFDKYCRequest() val checkFDKYCRequest = CheckFDKYCRequest()
checkFDKYCRequest.Mobile = checkFDKYCRequest.Mobile =
@ -337,7 +341,7 @@ class BajajFdMainActivity : BaseActivity() {
} }
} }
is Resource.Loading -> { is Resource.Loading -> {
ProgressUtil.hideLoading()
} }
is Resource.DataError -> { is Resource.DataError -> {
@ -426,6 +430,7 @@ class BajajFdMainActivity : BaseActivity() {
fun paymentReQueryApi() { fun paymentReQueryApi() {
if (Common.isNetworkAvailable(this)) { if (Common.isNetworkAvailable(this)) {
ProgressUtil.showLoading(this)
val paymentReQueryRequest = PaymentReQueryRequest() val paymentReQueryRequest = PaymentReQueryRequest()
paymentReQueryRequest.UniqueId = uniqueId paymentReQueryRequest.UniqueId = uniqueId
paymentReQueryRequest.NiveshClientCode = paymentReQueryRequest.NiveshClientCode =
@ -466,7 +471,7 @@ class BajajFdMainActivity : BaseActivity() {
} }
} }
is Resource.Loading -> { is Resource.Loading -> {
ProgressUtil.hideLoading()
} }
is Resource.DataError -> { is Resource.DataError -> {
@ -475,5 +480,4 @@ class BajajFdMainActivity : BaseActivity() {
} }
} }
} }
} }

+ 131
- 6
app/src/main/java/com/nivesh/production/bajajfd/ui/fragment/StepThreeBajajFDFragment.kt View File

@ -24,6 +24,7 @@ import androidx.core.content.FileProvider
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonObject
import com.nivesh.production.bajajfd.BuildConfig import com.nivesh.production.bajajfd.BuildConfig
import com.nivesh.production.bajajfd.R import com.nivesh.production.bajajfd.R
import com.nivesh.production.bajajfd.api.ApiClient import com.nivesh.production.bajajfd.api.ApiClient
@ -32,12 +33,26 @@ import com.nivesh.production.bajajfd.model.*
import com.nivesh.production.bajajfd.repositories.MainRepository import com.nivesh.production.bajajfd.repositories.MainRepository
import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity
import com.nivesh.production.bajajfd.ui.providerfactory.StepThreeModelProviderFactory import com.nivesh.production.bajajfd.ui.providerfactory.StepThreeModelProviderFactory
import com.nivesh.production.bajajfd.util.Common
import com.nivesh.production.bajajfd.util.*
import com.nivesh.production.bajajfd.util.Common.Companion.getFileExtension import com.nivesh.production.bajajfd.util.Common.Companion.getFileExtension
import com.nivesh.production.bajajfd.util.Constants
import com.nivesh.production.bajajfd.util.ImageUtil
import com.nivesh.production.bajajfd.util.Resource
import com.nivesh.production.bajajfd.util.Constants.Companion.GetFreshToken_V2_Encrypt
import com.nivesh.production.bajajfd.util.Constants.Companion.KEY_LOGINTYPE
import com.nivesh.production.bajajfd.util.Constants.Companion.KEY_LOGINUSER_CODE
import com.nivesh.production.bajajfd.util.Constants.Companion.KEY_LOGIN_EMAIL
import com.nivesh.production.bajajfd.util.Constants.Companion.KEY_LOGIN_PASSWORD
import com.nivesh.production.bajajfd.util.Constants.Companion.KEY_LOGIN_SOCIALID
import com.nivesh.production.bajajfd.util.SharedPrefrenceDataMethods.Companion.getLoginPassword
import com.nivesh.production.bajajfd.util.Utility.Companion.convert_sha256
import com.nivesh.production.bajajfd.util.Utility.Companion.convert_sha256_2X
import com.nivesh.production.bajajfd.util.Utility.Companion.getDeviceInfo
import com.nivesh.production.bajajfd.util.Utils_Functions.Companion.getCurrentDateStamp
import com.nivesh.production.bajajfd.viewModel.StepThreeBajajFDViewModel import com.nivesh.production.bajajfd.viewModel.StepThreeBajajFDViewModel
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import java.io.* import java.io.*
@ -72,6 +87,11 @@ class StepThreeBajajFDFragment : BaseFragment() {
private val check = arrayOf<CharSequence>("Take Photo", "Choose from Gallery", "Cancel") private val check = arrayOf<CharSequence>("Take Photo", "Choose from Gallery", "Cancel")
private var strToken: String? = null
private var strTimeStamp: String? = null
private var str2Hash: String? = null
private var strDeviceID: String? = null
private val requestPermission = registerForActivityResult( private val requestPermission = registerForActivityResult(
ActivityResultContracts.RequestPermission() ActivityResultContracts.RequestPermission()
) { isGranted: Boolean -> ) { isGranted: Boolean ->
@ -135,6 +155,7 @@ class StepThreeBajajFDFragment : BaseFragment() {
} }
var uploadPosition = 0 var uploadPosition = 0
for (entry in mapImage.iterator()) { for (entry in mapImage.iterator()) {
ProgressUtil.showLoading(activity as BajajFdMainActivity)
uploadPosition++ uploadPosition++
uploadDocApi(entry.key, entry.value, uploadPosition) uploadDocApi(entry.key, entry.value, uploadPosition)
} }
@ -403,6 +424,7 @@ class StepThreeBajajFDFragment : BaseFragment() {
activity as BajajFdMainActivity activity as BajajFdMainActivity
) )
stepThreeBajajFDViewModel.getDocumentUploadMutableData.observe(viewLifecycleOwner) { response -> stepThreeBajajFDViewModel.getDocumentUploadMutableData.observe(viewLifecycleOwner) { response ->
ProgressUtil.hideLoading()
when (response) { when (response) {
is Resource.Success -> { is Resource.Success -> {
Log.e("UploadImage", "Response-->" + response.data.toString()) Log.e("UploadImage", "Response-->" + response.data.toString())
@ -421,7 +443,7 @@ class StepThreeBajajFDFragment : BaseFragment() {
createFDApi((activity as BajajFdMainActivity).createFDRequest) createFDApi((activity as BajajFdMainActivity).createFDRequest)
} }
} }
// 650 -> refreshToken()
650 -> refreshToken()
else -> { else -> {
Common.showDialogValidation( Common.showDialogValidation(
activity as BajajFdMainActivity, activity as BajajFdMainActivity,
@ -438,7 +460,7 @@ class StepThreeBajajFDFragment : BaseFragment() {
} }
} }
is Resource.Loading -> { is Resource.Loading -> {
ProgressUtil.hideLoading()
} }
is Resource.DataError -> { is Resource.DataError -> {
@ -447,6 +469,109 @@ class StepThreeBajajFDFragment : BaseFragment() {
} }
} }
private fun refreshToken() {
if (Common.isNetworkAvailable(activity as BajajFdMainActivity)) {
var jsonObject: JSONObject? = null
try {
jsonObject = JSONObject()
jsonObject.put(
"Email_Mob",
SharedPrefrenceDataMethods.getLoginEmail(KEY_LOGIN_EMAIL, activity)
)
jsonObject.put(
"Uid",
SharedPrefrenceDataMethods.getLoginUserCode(KEY_LOGINUSER_CODE, activity)
)
jsonObject.put(
"Soc_Id",
SharedPrefrenceDataMethods.getLoginSOCIALID(KEY_LOGIN_SOCIALID, activity)
)
val ed = EncryptionDecryption()
val decryptString = ed.decrypt(
getLoginPassword(
KEY_LOGIN_PASSWORD,
activity
)
)
val strsha256hex_password: String? = decryptString?.let { convert_sha256(it) }
Log.e(
"Scheme",
"LoginEmail -> " + SharedPrefrenceDataMethods.getLoginEmail(
KEY_LOGIN_EMAIL,
activity
).toString() + ", convert_sha256-> " + strsha256hex_password
)
strTimeStamp = getCurrentDateStamp()
Log.e("Scheme_strTimeStamp", "-> $strTimeStamp")
if (SharedPrefrenceDataMethods.getLogin_Type(KEY_LOGINTYPE, activity)
.equals("EMAIL", ignoreCase = true)
) {
str2Hash = convert_sha256_2X(strsha256hex_password + strTimeStamp)
Log.e("Scheme_Convert_str2Hash", "-> $str2Hash")
} else {
str2Hash = ""
}
val deviceInfo: DeviceInfo = getDeviceInfo(activity as BajajFdMainActivity)
strDeviceID = java.lang.String.valueOf(deviceInfo.device_id)
Log.e("Scheme_strDeviceID", "-> $strDeviceID")
jsonObject.put("DeviceId", strDeviceID)
Log.e(
"FreshToken_Request",
"URL_API -> " + GetFreshToken_V2_Encrypt.toString() + " JsonData-> " + jsonObject.toString() + ", Header-> " + "time_stamp :" + strTimeStamp.toString() + ", Password :" + str2Hash
)
} catch (e: Exception) {
e.printStackTrace()
}
val json = ""
val JSON : MediaType = "application/json; charset=utf-8".toMediaType()
val jsonBody: RequestBody = json.toRequestBody(JSON)
stepThreeBajajFDViewModel.getFreshToken(
jsonBody,
Constants.token,
activity as BajajFdMainActivity
)
stepThreeBajajFDViewModel.getFreshTokenMutableData.observe(viewLifecycleOwner) { response ->
when (response) {
is Resource.Success -> {
var jsonObject1: JsonObject = response.data!!
if (jsonObject1.has("Token")) {
strToken = jsonObject1.get("Token").toString()
strToken = jsonObject1.get("Token").toString()
Log.e("Scheme", "Token-> $strToken")
SharedPrefrenceDataMethods.setToken(activity, strToken)
}
}
is Resource.Error -> {
response.message?.let { message ->
Common.showDialogValidation(activity as BajajFdMainActivity, message)
}
}
is Resource.Loading -> {
}
is Resource.DataError -> {
}
}
}
}
}
private fun createFDApi(data: CreateFDRequest) { private fun createFDApi(data: CreateFDRequest) {
stepThreeBajajFDViewModel.createFDApi( stepThreeBajajFDViewModel.createFDApi(
data, data,


+ 2
- 2
app/src/main/java/com/nivesh/production/bajajfd/util/Common.kt View File

@ -12,6 +12,7 @@ import android.provider.ContactsContract
import android.text.format.DateFormat import android.text.format.DateFormat
import android.util.Log import android.util.Log
import android.util.Patterns import android.util.Patterns
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.textfield.MaterialAutoCompleteTextView import com.google.android.material.textfield.MaterialAutoCompleteTextView
import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
@ -103,7 +104,7 @@ class Common {
if (textInputLayout.error != null) { if (textInputLayout.error != null) {
textInputLayout.error = null textInputLayout.error = null
if (textInputLayout.isErrorEnabled) { if (textInputLayout.isErrorEnabled) {
textInputLayout.isErrorEnabled = false;
textInputLayout.isErrorEnabled = false
} }
} }
} }
@ -272,6 +273,5 @@ class Common {
"" ""
} }
} }
} }
} }

+ 10
- 0
app/src/main/java/com/nivesh/production/bajajfd/util/Constants.kt View File

@ -5,5 +5,15 @@ class Constants() {
companion object { companion object {
const val BASE_URL = "https://providential.in/WebApi_Bajaj/api/" const val BASE_URL = "https://providential.in/WebApi_Bajaj/api/"
const val token = "636F8F63-06C4-4D95-8562-392B34025FB0" const val token = "636F8F63-06C4-4D95-8562-392B34025FB0"
const val passphrase = "bml2ZXNo"
const val KEY_LOGIN_EMAIL = "LOGIN_EMAIL"
const val KEY_LOGINUSER_CODE = "LOGINUSER_CODE"
const val KEY_LOGIN_SOCIALID = "KEY_LOGIN_SOCIALID"
const val KEY_LOGIN_PASSWORD = "LOGIN_PASSWORD"
const val KEY_LOGINTYPE = "LOGINTYPE"
const val KEY_VERSION_CODE = "Version Code"
const val KEY_GCM_APP_ID = "Gcm App Id"
val GetFreshToken_V2_Encrypt: String = BASE_URL + "GetToken_V2"
} }
} }

+ 141
- 0
app/src/main/java/com/nivesh/production/bajajfd/util/EncryptionDecryption.kt View File

@ -0,0 +1,141 @@
package com.nivesh.production.bajajfd.util
import android.annotation.SuppressLint
import android.util.Base64
import android.util.Log
import com.nivesh.production.bajajfd.util.Constants.Companion.passphrase
import java.security.InvalidAlgorithmParameterException
import java.security.InvalidKeyException
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.text.SimpleDateFormat
import java.util.*
import javax.crypto.*
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
class EncryptionDecryption {
val TAG = "Crypto"
private var aesCipher: Cipher? = null
private var secretKey: SecretKey? = null
private var ivParameterSpec: IvParameterSpec? = null
private val CIPHER_TRANSFORMATION = "AES/CBC/PKCS5Padding"
private val CIPHER_ALGORITHM = "AES"
// Replace me with a 16-byte key, share between Java and C#
private val rawSecretKey = byteArrayOf(
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
)
private val MESSAGEDIGEST_ALGORITHM = "MD5"
@SuppressLint("NotConstructor")
fun EncryptionDecryption() {
val passwordKey =
encodeDigest(passphrase) //new NativeClass().localName(KeyConstant.passphrase));
try {
aesCipher = Cipher.getInstance(CIPHER_TRANSFORMATION)
} catch (e: NoSuchAlgorithmException) {
Log.e(TAG, "No such algorithm $CIPHER_ALGORITHM", e)
} catch (e: NoSuchPaddingException) {
Log.e(TAG, "No such padding PKCS5", e)
}
secretKey = SecretKeySpec(passwordKey, CIPHER_ALGORITHM)
ivParameterSpec = IvParameterSpec(rawSecretKey)
}
fun encryptAsBase64(dataToEncrypt: String): String? {
var dataToEncrypt = dataToEncrypt
val dateFormat = SimpleDateFormat("SSS", Locale.US)
dataToEncrypt = dataToEncrypt + dateFormat.format(Date())
val encryptedData = encrypt(dataToEncrypt.toByteArray())
return Base64.encodeToString(encryptedData, Base64.DEFAULT)
}
// public String decrypt(String textToDecrypt) throws Exception {
//
//
// //SecretKeySpec skeySpec = new SecretKeySpec(getRaw(plainText, AESSalt), "AES");
// //Cipher cipher = Cipher.getInstance(cypherInstance);
// //cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(initializationVector.getBytes()));
// byte[] decrypted = aesCipher.doFinal(encryted_bytes);
// return new String(decrypted, "UTF-8");
// }
// public String decrypt(String textToDecrypt) throws Exception {
//
//
// //SecretKeySpec skeySpec = new SecretKeySpec(getRaw(plainText, AESSalt), "AES");
// //Cipher cipher = Cipher.getInstance(cypherInstance);
// //cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(initializationVector.getBytes()));
// byte[] decrypted = aesCipher.doFinal(encryted_bytes);
// return new String(decrypted, "UTF-8");
// }
fun decrypt(encryptString: String?): String? {
var decryptedData = ""
try {
aesCipher!!.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec)
} catch (e: InvalidKeyException) {
Log.e(TAG, "Invalid key", e)
return null
} catch (e: InvalidAlgorithmParameterException) {
Log.e(TAG, "Invalid algorithm $CIPHER_ALGORITHM", e)
return null
}
val decryptBytes: ByteArray
try {
val encryted_bytes = Base64.decode(encryptString, Base64.DEFAULT)
decryptBytes = aesCipher!!.doFinal(encryted_bytes)
decryptedData = String(decryptBytes)
decryptedData = decryptedData.substring(0, decryptedData.length - 3)
} catch (e: IllegalBlockSizeException) {
Log.e(TAG, "Illegal block size", e)
return null
} catch (e: BadPaddingException) {
Log.e(TAG, "Bad padding", e)
return null
} catch (e: Exception) {
e.printStackTrace()
}
return decryptedData
}
fun encrypt(clearData: ByteArray?): ByteArray? {
try {
aesCipher!!.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec)
} catch (e: InvalidKeyException) {
Log.e(TAG, "Invalid key", e)
return null
} catch (e: InvalidAlgorithmParameterException) {
Log.e(TAG, "Invalid algorithm $CIPHER_ALGORITHM", e)
return null
}
val encryptedData: ByteArray
encryptedData = try {
aesCipher!!.doFinal(clearData)
} catch (e: IllegalBlockSizeException) {
Log.e(TAG, "Illegal block size", e)
return null
} catch (e: BadPaddingException) {
Log.e(TAG, "Bad padding", e)
return null
}
return encryptedData
}
private fun encodeDigest(text: String): ByteArray? {
val digest: MessageDigest
try {
digest = MessageDigest.getInstance(MESSAGEDIGEST_ALGORITHM)
return digest.digest(text.toByteArray())
} catch (e: NoSuchAlgorithmException) {
Log.e(TAG, "No such algorithm $MESSAGEDIGEST_ALGORITHM", e)
}
return null
}
}

+ 50
- 0
app/src/main/java/com/nivesh/production/bajajfd/util/ProgressUtil.kt View File

@ -0,0 +1,50 @@
package com.nivesh.production.bajajfd.util
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.util.Log
import android.view.Window
import android.widget.ProgressBar
@SuppressLint("StaticFieldLeak")
object ProgressUtil{
private lateinit var dialogBuilder: AlertDialog.Builder
private lateinit var alertDialog: AlertDialog
private lateinit var pDialog: ProgressBar
fun showLoading(ctx: Context){
// instantiating the lateint objects
dialogBuilder= AlertDialog.Builder(ctx)
pDialog= ProgressBar(ctx)
// setting up the dialog
dialogBuilder.setCancelable(false)
dialogBuilder.setView(pDialog)
alertDialog=dialogBuilder.create()
// magic of transparent background goes here
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// setting the alertDialog's BackgroundDrawable as the color resource of any color with 1% opacity
alertDialog.window?.setBackgroundDrawable(ColorDrawable(Color.parseColor("#00141414")))
// finally displaying the Alertdialog containging the ProgressBar
alertDialog.show()
}
fun hideLoading(){
try {
if(alertDialog.isShowing){
alertDialog.dismiss()
}
} catch (e: UninitializedPropertyAccessException) {
Log.e("TAG","AlertDialog UninitializedPropertyAccessException")
}
}
}

+ 65
- 0
app/src/main/java/com/nivesh/production/bajajfd/util/SharedPrefrenceDataMethods.kt View File

@ -0,0 +1,65 @@
package com.nivesh.production.bajajfd.util
import android.content.Context
import androidx.preference.PreferenceManager
class SharedPrefrenceDataMethods {
companion object {
fun getLoginEmail(Name: String?, context: Context?): String? {
val preferences = context?.let {
PreferenceManager.getDefaultSharedPreferences(
it
)
}
return preferences?.getString(Name, "")
}
fun getLoginUserCode(Name: String?, context: Context?): String? {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
return preferences?.getString(Name, "")
}
fun setLogin_SOCIALID(json: String?, context: Context?, Name: String?) {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
val editor = preferences?.edit()
editor?.putString(Name, json)
editor?.apply()
}
fun getLoginSOCIALID(Name: String?, context: Context?): String? {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
return preferences?.getString(Name, "")
}
fun getLoginPassword(Name: String?, context: Context?): String? {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
return preferences?.getString(Name, "")
}
fun getLogin_Type(Name: String?, context: Context?): String? {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
return preferences?.getString(Name, "")
}
fun getVersionCode(Name: String?, context: Context?): String? {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
return preferences?.getString(Name, "")
}
fun getGcmAppId(Name: String?, context: Context?): String? {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
return preferences?.getString(Name, "")
}
fun setToken(context: Context?, token: String?) {
val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
val editor = preferences?.edit()
editor?.putString("token", token)
editor?.apply()
}
}
}

+ 169
- 0
app/src/main/java/com/nivesh/production/bajajfd/util/Utility.kt View File

@ -0,0 +1,169 @@
package com.nivesh.production.bajajfd.util
import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.provider.Settings
import android.telephony.TelephonyManager
import android.text.TextUtils
import android.util.Log
import androidx.core.app.ActivityCompat
import com.nivesh.production.bajajfd.model.DeviceInfo
import java.nio.charset.StandardCharsets
import java.security.MessageDigest
import java.util.*
class Utility {
companion object{
fun convert_sha256(rawString: String): String {
return try {
val digest = MessageDigest.getInstance("SHA-256")
var hash = ByteArray(0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
hash = digest.digest(rawString.toByteArray(StandardCharsets.UTF_8))
}
val hexString = StringBuilder()
for (i in hash.indices) {
val hex = Integer.toHexString(0xff and hash[i].toInt())
if (hex.length == 1) hexString.append('0')
hexString.append(hex)
}
hexString.toString().uppercase(Locale.getDefault())
} catch (ex: Exception) {
throw RuntimeException(ex)
}
}
fun convert_sha256_2X(rawString: String): String {
return try {
val digest = MessageDigest.getInstance("SHA-256")
var hash = ByteArray(0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
hash = digest.digest(rawString.toByteArray(StandardCharsets.UTF_8))
}
val hexString = java.lang.StringBuilder()
for (i in hash.indices) {
val hex = Integer.toHexString(0xff and hash[i].toInt())
if (hex.length == 1) hexString.append('0')
hexString.append(hex)
}
hexString.toString()
} catch (ex: java.lang.Exception) {
throw java.lang.RuntimeException(ex)
}
}
@SuppressLint("HardwareIds")
fun getDeviceInfo(mContext: Context): DeviceInfo {
val deviceInfo = DeviceInfo()
var device_id: String? = ""
try {
val telephonyManager =
mContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
deviceInfo.app_version = (
SharedPrefrenceDataMethods.getVersionCode(
Constants.KEY_VERSION_CODE,
mContext
)
)
deviceInfo.device_model = (if (TextUtils.isEmpty(Build.DEVICE)) "" else Build.DEVICE)
deviceInfo.device_os_version = (if (TextUtils.isEmpty(Build.VERSION.RELEASE)) "" else Build.VERSION.RELEASE)
deviceInfo.device_name = (if (TextUtils.isEmpty(Build.PRODUCT)) "" else Build.PRODUCT)
deviceInfo.device_token = (
if (TextUtils.isEmpty(
SharedPrefrenceDataMethods.getGcmAppId(
Constants.KEY_GCM_APP_ID,
mContext
)
)
) "" else SharedPrefrenceDataMethods.getGcmAppId(
Constants.KEY_GCM_APP_ID,
mContext
)
)
deviceInfo.device_type = ("Android")
// Hemant Code Added start 28-10-2020
if (ActivityCompat.checkSelfPermission(
mContext,
Manifest.permission.READ_PHONE_STATE
) != PackageManager.PERMISSION_GRANTED
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
device_id = telephonyManager.imei
if (device_id == null) {
device_id =
if (TextUtils.isEmpty(Build.getSerial())) "" else Build.getSerial()
}
} else {
device_id = telephonyManager.deviceId
if (device_id == null) {
device_id =
if (TextUtils.isEmpty(Build.SERIAL)) "" else Build.SERIAL
}
}
} else {
device_id = telephonyManager.deviceId
if (device_id == null) {
device_id = if (TextUtils.isEmpty(Build.SERIAL)) "" else Build.SERIAL
}
}
if (device_id == null || device_id.isEmpty() || device_id.equals(
"unknown",
ignoreCase = true
)
) {
device_id = if (TextUtils.isEmpty(
Settings.Secure.getString(
mContext.contentResolver,
Settings.Secure.ANDROID_ID
)
)
) "" else Settings.Secure.getString(
mContext.contentResolver,
Settings.Secure.ANDROID_ID
)
}
Log.e("device_id", "-> $device_id")
// Hemant changes 07-11-2019 start commented and Added 12-12-2019
// deviceInfo.device_id = (device_id + "#" + com.nivesh.production.util.Utility.getFlavor())
// Hemant changes 07-11-2019 end commented and Added 12-12-2019
// Hemant changes 07-11-2019 start added and commented 12-12-2019
deviceInfo.device_id_for_UMSId = (device_id)
// deviceInfo.setDeviceId(device_id);
// Hemant changes 07-11-2019 end added and commented 12-12-2019
} catch (e: java.lang.Exception) {
e.printStackTrace()
// Hemant changes 07-11-2019 start Added 28-10-2020
if (device_id == null || device_id.isEmpty() || device_id.equals(
"unknown",
ignoreCase = true
)
) {
device_id = if (TextUtils.isEmpty(
Settings.Secure.getString(
mContext.contentResolver,
Settings.Secure.ANDROID_ID
)
)
) "" else Settings.Secure.getString(
mContext.contentResolver,
Settings.Secure.ANDROID_ID
)
}
Log.e("device_id", "-> $device_id")
// deviceInfo.setDeviceId(device_id + "#" + com.nivesh.production.util.Utility.getFlavor())
deviceInfo.device_id_for_UMSId = (device_id)
// Hemant changes 07-11-2019 end Added 28-10-2020
}
return deviceInfo
}
}
}

+ 21
- 0
app/src/main/java/com/nivesh/production/bajajfd/util/Utils_Functions.kt View File

@ -0,0 +1,21 @@
package com.nivesh.production.bajajfd.util
import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.*
class Utils_Functions {
companion object{
fun getCurrentDateStamp(): String? {
val d = Date()
@SuppressLint("SimpleDateFormat") val simpleDateFormat =
SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val dateStr = simpleDateFormat.format(d)
val output = d.time / 1000L
val str = java.lang.Long.toString(output)
return d.time.toString()
}
}
}

+ 1
- 0
app/src/main/java/com/nivesh/production/bajajfd/viewModel/BajajFDViewModel.kt View File

@ -11,6 +11,7 @@ import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity
import com.nivesh.production.bajajfd.util.Common import com.nivesh.production.bajajfd.util.Common
import com.nivesh.production.bajajfd.util.Common.Companion.handleError import com.nivesh.production.bajajfd.util.Common.Companion.handleError
import com.nivesh.production.bajajfd.util.Common.Companion.handleResponse import com.nivesh.production.bajajfd.util.Common.Companion.handleResponse
import com.nivesh.production.bajajfd.util.ProgressUtil
import com.nivesh.production.bajajfd.util.Resource import com.nivesh.production.bajajfd.util.Resource
import kotlinx.coroutines.launch import kotlinx.coroutines.launch


+ 12
- 0
app/src/main/java/com/nivesh/production/bajajfd/viewModel/StepThreeBajajFDViewModel.kt View File

@ -14,6 +14,7 @@ import com.nivesh.production.bajajfd.util.Common
import com.nivesh.production.bajajfd.util.Common.Companion.handleResponse import com.nivesh.production.bajajfd.util.Common.Companion.handleResponse
import com.nivesh.production.bajajfd.util.Resource import com.nivesh.production.bajajfd.util.Resource
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import okhttp3.RequestBody
class StepThreeBajajFDViewModel(private val mainRepository: MainRepository) : ViewModel() { class StepThreeBajajFDViewModel(private val mainRepository: MainRepository) : ViewModel() {
@ -50,4 +51,15 @@ class StepThreeBajajFDViewModel(private val mainRepository: MainRepository) : Vi
} }
} }
val getFreshTokenMutableData: MutableLiveData<Resource<JsonObject>> = MutableLiveData()
fun getFreshToken(body: RequestBody, token: String, activity: Activity) = viewModelScope.launch(
Common.handleError(activity)
) {
if (Common.isNetworkAvailable(activity)) {
getFreshTokenMutableData.postValue(Resource.Loading())
val response = mainRepository.freshToken(body)
getFreshTokenMutableData.postValue(handleResponse(response))
}
}
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.