Browse Source

added preferenceManager and screen one change

PankajBranch
Hemant Khadase 2 years ago
parent
commit
019205d375
11 changed files with 278 additions and 90 deletions
  1. +1
    -0
      app/src/main/AndroidManifest.xml
  2. +137
    -0
      app/src/main/java/com/nivesh/production/niveshfd/db/PreferenceManager.kt
  3. +30
    -0
      app/src/main/java/com/nivesh/production/niveshfd/interfaces/IPreferenceHelper.kt
  4. +2
    -1
      app/src/main/java/com/nivesh/production/niveshfd/model/FDInvestmentDetails.kt
  5. +6
    -0
      app/src/main/java/com/nivesh/production/niveshfd/ui/activity/NiveshFdMainActivity.kt
  6. +3
    -2
      app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepFiveNiveshFDFragment.kt
  7. +7
    -1
      app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepOneNiveshFDFragment.kt
  8. +0
    -62
      app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepTwoNiveshFDFragment.kt
  9. +86
    -0
      app/src/main/java/com/nivesh/production/niveshfd/util/Common.kt
  10. +6
    -15
      app/src/main/java/com/nivesh/production/niveshfd/viewModel/BajajFDViewModel.kt
  11. +0
    -9
      app/src/main/res/layout/fragment_niveshfd_step_one.xml

+ 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 <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />


+ 137
- 0
app/src/main/java/com/nivesh/production/niveshfd/db/PreferenceManager.kt View File

@ -0,0 +1,137 @@
package com.nivesh.production.niveshfd.db
import android.content.Context
import android.content.SharedPreferences
import com.nivesh.production.niveshfd.interfaces.IPreferenceHelper
open class PreferenceManager(context: Context) : IPreferenceHelper {
private val preferenceName = "NiveshFDSDK"
private var preferences: SharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE)
companion object {
const val KEY_USER_UID = "UserUid"
const val KEY_LOGIN_ROLE = "LoginRole"
const val KEY_SUB_BROKER_CODE = "SubBrokerCode"
const val KEY_LOGIN_PASSWORD = "LOGIN_PASSWORD"
const val KEY_CLIENT_UMS_ID = "UMS_Id"
const val KEY_CLIENT_CODE = "ClientCode"
const val KEY_GET_TOKEN = "GetToken"
const val CLIENT_LANGUAGE = "LANGUAGE"
}
override fun getLoginPasswordHash(): String {
return preferences[KEY_LOGIN_PASSWORD] ?: ""
}
override fun setLoginPasswordHash(appName: String) {
preferences[KEY_LOGIN_PASSWORD] = appName
}
override fun setUserUid(appName: Int) {
preferences[KEY_USER_UID] = appName
}
override fun getUserUid(): Int {
return preferences[KEY_USER_UID] ?: -1
}
override fun setLoginRole(appName: Int) {
preferences[KEY_LOGIN_ROLE] = appName
}
override fun getLoginRole(): Int {
return preferences[KEY_LOGIN_ROLE] ?: -1
}
override fun setSubBrokerID(appName: String) {
preferences[KEY_SUB_BROKER_CODE] = appName
}
override fun getSubBrokerID(): String {
return preferences[KEY_SUB_BROKER_CODE] ?: ""
}
override fun setClientUmsID(appName: String) {
preferences[KEY_CLIENT_UMS_ID] = appName
}
override fun getClientUmsID(): String {
return preferences[KEY_CLIENT_UMS_ID] ?: ""
}
override fun setClientCode(appName: String) {
preferences[KEY_CLIENT_CODE] = appName
}
override fun getClientCode(): String {
return preferences[KEY_CLIENT_CODE] ?: ""
}
override fun setToken(appName: String) {
preferences[KEY_GET_TOKEN] = appName
}
override fun getToken(): String {
return preferences[KEY_GET_TOKEN] ?: ""
}
override fun setLanguage(appName: String) {
preferences[CLIENT_LANGUAGE] = appName
}
override fun getLanguage(): String {
return preferences[CLIENT_LANGUAGE] ?: ""
}
override fun clearPrefs() {
preferences.edit().clear().apply()
}
}
/**
* SharedPreferences extension function, to listen the edit() and apply() fun calls
* on every SharedPreferences operation.
*/
private inline fun SharedPreferences.edit(operation: (SharedPreferences.Editor) -> Unit) {
val editor = this.edit()
operation(editor)
editor.apply()
}
/**
* puts a key value pair in shared prefs if doesn't exists, otherwise updates value on given [key]
*/
private operator fun SharedPreferences.set(key: String, value: Any?) {
when (value) {
is String? -> edit { it.putString(key, value) }
is Int -> edit { it.putInt(key, value) }
is Boolean -> edit { it.putBoolean(key, value) }
is Float -> edit { it.putFloat(key, value) }
is Long -> edit { it.putLong(key, value) }
else -> throw UnsupportedOperationException("Not yet implemented")
}
}
/**
* finds value on given key.
* [T] is the type of value
* @param defaultValue optional default value - will take null for strings, false for bool and -1 for numeric values if [defaultValue] is not specified
*/
private inline operator fun <reified T : Any> SharedPreferences.get(
key: String,
defaultValue: T? = null
): T? {
return when (T::class) {
String::class -> getString(key, defaultValue as? String) as T?
Int::class -> getInt(key, defaultValue as? Int ?: -1) as T?
Boolean::class -> getBoolean(key, defaultValue as? Boolean ?: false) as T?
Float::class -> getFloat(key, defaultValue as? Float ?: -1f) as T?
Long::class -> getLong(key, defaultValue as? Long ?: -1) as T?
else -> throw UnsupportedOperationException("Not yet implemented")
}
}

+ 30
- 0
app/src/main/java/com/nivesh/production/niveshfd/interfaces/IPreferenceHelper.kt View File

@ -0,0 +1,30 @@
package com.nivesh.production.niveshfd.interfaces
interface IPreferenceHelper {
fun getLoginPasswordHash(): String
fun setLoginPasswordHash(appName: String)
fun getUserUid(): Int
fun setUserUid(appName: Int)
fun getLoginRole(): Int
fun setLoginRole(appName: Int)
fun getSubBrokerID(): String
fun setSubBrokerID(appName: String)
fun getClientUmsID(): String
fun setClientUmsID(appName: String)
fun getClientCode(): String
fun setClientCode(appName: String)
fun setToken(appName: String)
fun getToken(): String
fun setLanguage(appName: String)
fun getLanguage(): String
fun clearPrefs()
}

+ 2
- 1
app/src/main/java/com/nivesh/production/niveshfd/model/FDInvestmentDetails.kt View File

@ -13,6 +13,7 @@ data class FDInvestmentDetails(
var Provider: String? = null, var Provider: String? = null,
var Source: String? = null, var Source: String? = null,
var Tenure: Int? = 0, var Tenure: Int? = 0,
var UniqueId: String? = ""
var UniqueId: String? = "",
var RenewOption : String = ""
) )

+ 6
- 0
app/src/main/java/com/nivesh/production/niveshfd/ui/activity/NiveshFdMainActivity.kt View File

@ -21,6 +21,7 @@ import com.nivesh.production.niveshfd.adapter.DisableAdapter
import com.nivesh.production.niveshfd.adapter.SectionsPagerAdapter import com.nivesh.production.niveshfd.adapter.SectionsPagerAdapter
import com.nivesh.production.niveshfd.api.ApiClient import com.nivesh.production.niveshfd.api.ApiClient
import com.nivesh.production.niveshfd.databinding.ActivityNiveshFdBinding import com.nivesh.production.niveshfd.databinding.ActivityNiveshFdBinding
import com.nivesh.production.niveshfd.db.PreferenceManager
import com.nivesh.production.niveshfd.model.* import com.nivesh.production.niveshfd.model.*
import com.nivesh.production.niveshfd.repositories.MainRepository import com.nivesh.production.niveshfd.repositories.MainRepository
import com.nivesh.production.niveshfd.ui.fragment.* import com.nivesh.production.niveshfd.ui.fragment.*
@ -79,6 +80,11 @@ class NiveshFdMainActivity : BaseActivity() {
setContentView(this.root) setContentView(this.root)
} }
// For Set Data
PreferenceManager( this@NiveshFdMainActivity).setSubBrokerID("")
// For Get Data
PreferenceManager(context = this@NiveshFdMainActivity).getSubBrokerID()
loginRole = 5 loginRole = 5
if (Common.isNetworkAvailable(this)) { if (Common.isNetworkAvailable(this)) {
getStepsCountApi() getStepsCountApi()


+ 3
- 2
app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepFiveNiveshFDFragment.kt View File

@ -55,6 +55,8 @@ class StepFiveNiveshFDFragment : Fragment() {
) )
binding.tvSuccessMessage.text = arrOfStr[1] binding.tvSuccessMessage.text = arrOfStr[1]
} }
finalizeFDApi()
finalizeKYCApi()
}else{ }else{
if (paymentReQueryResponse.Response.Message.isNotEmpty()) { if (paymentReQueryResponse.Response.Message.isNotEmpty()) {
if (paymentReQueryResponse.Response.Message.isNotEmpty()) { if (paymentReQueryResponse.Response.Message.isNotEmpty()) {
@ -71,8 +73,7 @@ class StepFiveNiveshFDFragment : Fragment() {
binding.tvRetry.visibility = View.VISIBLE binding.tvRetry.visibility = View.VISIBLE
binding.btnViewOrder.visibility = View.GONE binding.btnViewOrder.visibility = View.GONE
} }
finalizeFDApi()
finalizeKYCApi()
} }
private fun finalizeFDApi() { private fun finalizeFDApi() {


+ 7
- 1
app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepOneNiveshFDFragment.kt View File

@ -109,10 +109,15 @@ class StepOneNiveshFDFragment : Fragment() {
} }
// Maturity Options // Maturity Options
rgMaturity.text = getString(R.string.additionalDetailOne)
rgMaturity.text = "Total"
binding.radioGroup.setOnCheckedChangeListener { group, checkedId -> binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
rgMaturity = group.findViewById(checkedId) rgMaturity = group.findViewById(checkedId)
Log.e("Maturity", "-->" + rgMaturity.text) Log.e("Maturity", "-->" + rgMaturity.text)
if (rgMaturity.text.contains("credit")){
rgMaturity.text = "Total"
}else{
rgMaturity.text = "Principal"
}
} }
// Next Button // Next Button
@ -146,6 +151,7 @@ class StepOneNiveshFDFragment : Fragment() {
(activity as NiveshFdMainActivity).fdInvestmentDetails.CKYCNumber = "" (activity as NiveshFdMainActivity).fdInvestmentDetails.CKYCNumber = ""
(activity as NiveshFdMainActivity).fdInvestmentDetails.UniqueId = (activity as NiveshFdMainActivity).fdInvestmentDetails.UniqueId =
(activity as NiveshFdMainActivity).uniqueId (activity as NiveshFdMainActivity).uniqueId
(activity as NiveshFdMainActivity).fdInvestmentDetails.RenewOption = rgMaturity.text.toString()
(activity as NiveshFdMainActivity).createFDApplicantRequest.FDInvestmentDetails = (activity as NiveshFdMainActivity).createFDApplicantRequest.FDInvestmentDetails =
(activity as NiveshFdMainActivity).fdInvestmentDetails (activity as NiveshFdMainActivity).fdInvestmentDetails


+ 0
- 62
app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepTwoNiveshFDFragment.kt View File

@ -140,7 +140,6 @@ class StepTwoNiveshFDFragment : Fragment() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
removeError(binding.tlPanNumber) removeError(binding.tlPanNumber)
if (s.toString().trim().length == 10) { if (s.toString().trim().length == 10) {
panCheckApi()
checkFDCKYCApi() checkFDCKYCApi()
} }
} }
@ -1097,67 +1096,6 @@ class StepTwoNiveshFDFragment : Fragment() {
} }
private fun panCheckApi() {
val panCheck = PanCheckRequest()
panCheck.clientCode =
(activity as NiveshFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE
panCheck.subBrokerCode =
(activity as NiveshFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.sub_broker_code
panCheck.panNumber = binding.edtPANNumber.text.toString()
panCheck.mobileNumber = ""
(activity as NiveshFdMainActivity).viewModel.panCheck(panCheck, token, activity as NiveshFdMainActivity)
(activity as NiveshFdMainActivity).viewModel.getPanCheckMutableData.observe(viewLifecycleOwner) { response ->
when (response) {
is Resource.Success -> {
Log.e("panCheckApi ", " response -->$response")
val panCheckResponse =
Gson().fromJson(
response.data?.toString(),
PanCheckResponse::class.java
)
panCheckResponse.response.status_code.let { code ->
if (binding.tvPANVerify.visibility == View.GONE) {
binding.tvPANVerify.visibility = View.VISIBLE
}
when (code) {
200 -> {
binding.tvPANVerify.text = getString(R.string.verifiedText)
binding.tvPANVerify.setTextColor(
ContextCompat.getColor(
activity as NiveshFdMainActivity,
R.color.green
)
)
}
// 650 -> refreshToken()
else -> {
binding.tvPANVerify.text = getString(R.string.notVerifiedText)
binding.tvPANVerify.setTextColor(
ContextCompat.getColor(
activity as NiveshFdMainActivity,
R.color.red
)
)
}
}
}
}
is Resource.Error -> {
response.message?.let { message ->
showDialogValidation(activity as NiveshFdMainActivity, message)
}
}
is Resource.Loading -> {
}
is Resource.DataError -> {
}
}
}
}
private fun titleApi() { private fun titleApi() {
val getCodeRequest = GetCodeRequest() val getCodeRequest = GetCodeRequest()
getCodeRequest.ProductName = getString(R.string.bajajFD) getCodeRequest.ProductName = getString(R.string.bajajFD)


+ 86
- 0
app/src/main/java/com/nivesh/production/niveshfd/util/Common.kt View File

@ -1,9 +1,12 @@
package com.nivesh.production.niveshfd.util package com.nivesh.production.niveshfd.util
import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.AlertDialog import android.app.AlertDialog
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.net.ConnectivityManager import android.net.ConnectivityManager
@ -11,14 +14,20 @@ import android.net.NetworkCapabilities
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.provider.Settings import android.provider.Settings
import android.telephony.TelephonyManager
import android.text.TextUtils
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.core.app.ActivityCompat
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
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.nivesh.production.niveshfd.R import com.nivesh.production.niveshfd.R
import com.nivesh.production.niveshfd.db.PreferenceManager
import com.nivesh.production.niveshfd.interfaces.IPreferenceHelper
import com.nivesh.production.niveshfd.model.DeviceInfo
import com.nivesh.production.niveshfd.ui.activity.NiveshFdMainActivity import com.nivesh.production.niveshfd.ui.activity.NiveshFdMainActivity
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
import org.json.JSONObject import org.json.JSONObject
@ -274,6 +283,83 @@ class Common {
} }
@SuppressLint("HardwareIds")
fun getDeviceInfo(mContext: Context): DeviceInfo {
val preferenceHelper: IPreferenceHelper = PreferenceManager(mContext)
val deviceInfo = DeviceInfo()
var device_id: String? = ""
try {
val telephonyManager =
mContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
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_type = "Android"
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
)
}
// deviceInfo.device_id = device_id + "#" + preferenceHelper.getAppName()
deviceInfo.device_id_for_UMSId = device_id
// deviceInfo.sdk_version = com.nivesh.production.BuildConfig.VERSION_NAME
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
}
}
} catch (e: Exception) {
e.printStackTrace()
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
)
}
// deviceInfo.deviceId = device_id + "#" + preferenceHelper.getAppName()
deviceInfo.device_id_for_UMSId = device_id
}
return deviceInfo
}
} }
} }

+ 6
- 15
app/src/main/java/com/nivesh/production/niveshfd/viewModel/BajajFDViewModel.kt View File

@ -40,14 +40,7 @@ open class BajajFDViewModel(private val mainRepository: MainRepository) : ViewMo
} }
} }
val getFDKYCMutableData: MutableLiveData<Resource<JsonObject>> = MutableLiveData()
fun checkFDKYC(requestBody: CheckFDKYCRequest, token : String, activity: Activity) = viewModelScope.launch(handleError(activity)) {
if (Common.isNetworkAvailable(activity)) {
getFDKYCMutableData.postValue(Resource.Loading())
val response = mainRepository.checkFDKYCRequest(requestBody, token)
getFDKYCMutableData.postValue(handleResponse(response))
}
}
val getPaymentReQueryMutableData: MutableLiveData<Resource<JsonObject>> = MutableLiveData() val getPaymentReQueryMutableData: MutableLiveData<Resource<JsonObject>> = MutableLiveData()
fun getPaymentReQuery(requestBody: PaymentReQueryRequest, token : String, activity: Activity) = viewModelScope.launch(handleError(activity)) { fun getPaymentReQuery(requestBody: PaymentReQueryRequest, token : String, activity: Activity) = viewModelScope.launch(handleError(activity)) {
@ -124,14 +117,12 @@ open class BajajFDViewModel(private val mainRepository: MainRepository) : ViewMo
// Step 2 // Step 2
val getPanCheckMutableData: MutableLiveData<Resource<JsonObject>> = MutableLiveData()
fun panCheck(panCheck: PanCheckRequest, token: String, activity : Activity) = viewModelScope.launch(
handleError(activity)
) {
val getFDKYCMutableData: MutableLiveData<Resource<JsonObject>> = MutableLiveData()
fun checkFDKYC(requestBody: CheckFDKYCRequest, token : String, activity: Activity) = viewModelScope.launch(handleError(activity)) {
if (Common.isNetworkAvailable(activity)) { if (Common.isNetworkAvailable(activity)) {
getPanCheckMutableData.postValue(Resource.Loading())
val response = mainRepository.panCheck(panCheck, token)
getPanCheckMutableData.postValue(handleResponse(response))
getFDKYCMutableData.postValue(Resource.Loading())
val response = mainRepository.checkFDKYCRequest(requestBody, token)
getFDKYCMutableData.postValue(handleResponse(response))
} }
} }


+ 0
- 9
app/src/main/res/layout/fragment_niveshfd_step_one.xml View File

@ -222,15 +222,6 @@
android:text="@string/additionalDetailTwo" android:text="@string/additionalDetailTwo"
android:textSize="@dimen/text_size_12" /> android:textSize="@dimen/text_size_12" />
<RadioButton
android:id="@+id/rbAutoBoth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/black"
android:text="@string/additionalDetailThree"
android:textSize="@dimen/text_size_12" />
</RadioGroup> </RadioGroup>
<TextView <TextView


Loading…
Cancel
Save

Powered by TurnKey Linux.