Device provision response storing
This commit is contained in:
@@ -16,11 +16,11 @@ android {
|
|||||||
|
|
||||||
// dev - development, quality - qc, uat - User Acceptance Test, preprod - preproduction, prod - production
|
// dev - development, quality - qc, uat - User Acceptance Test, preprod - preproduction, prod - production
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "in.sminnovations.hpostesting.quality"
|
applicationId "in.sminnovations.hpostesting"
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 101
|
versionCode 102
|
||||||
versionName "2.1.101"
|
versionName "2.1.102"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,205 @@
|
|||||||
{
|
{
|
||||||
"project_info": {
|
"project_info": {
|
||||||
"project_number": "1004619739289",
|
"project_number": "650071678820",
|
||||||
"project_id": "hpos-qa",
|
"project_id": "hpos-af3cc",
|
||||||
"storage_bucket": "hpos-qa.appspot.com"
|
"storage_bucket": "hpos-af3cc.appspot.com"
|
||||||
},
|
},
|
||||||
"client": [
|
"client": [
|
||||||
{
|
{
|
||||||
"client_info": {
|
"client_info": {
|
||||||
"mobilesdk_app_id": "1:1004619739289:android:f669b47552748433e5c808",
|
"mobilesdk_app_id": "1:650071678820:android:f1435a1c07f710036c6471",
|
||||||
"android_client_info": {
|
"android_client_info": {
|
||||||
"package_name": "in.sminnovations.hposregistration.quality"
|
"package_name": "com.example.hposconsentform"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"oauth_client": [],
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
"api_key": [
|
"api_key": [
|
||||||
{
|
{
|
||||||
"current_key": "AIzaSyC4d4GhWHr_NMJAeBvnztQ_yQ3Qe9MAnLs"
|
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"services": {
|
"services": {
|
||||||
"appinvite_service": {
|
"appinvite_service": {
|
||||||
"other_platform_oauth_client": []
|
"other_platform_oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"client_info": {
|
"client_info": {
|
||||||
"mobilesdk_app_id": "1:1004619739289:android:8397cd1f0357bd89e5c808",
|
"mobilesdk_app_id": "1:650071678820:android:7865bef608cdee6f6c6471",
|
||||||
"android_client_info": {
|
"android_client_info": {
|
||||||
"package_name": "in.sminnovations.hpostesting.quality"
|
"package_name": "com.smi.counselling"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"oauth_client": [],
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
"api_key": [
|
"api_key": [
|
||||||
{
|
{
|
||||||
"current_key": "AIzaSyC4d4GhWHr_NMJAeBvnztQ_yQ3Qe9MAnLs"
|
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"services": {
|
"services": {
|
||||||
"appinvite_service": {
|
"appinvite_service": {
|
||||||
"other_platform_oauth_client": []
|
"other_platform_oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"client_info": {
|
||||||
|
"mobilesdk_app_id": "1:650071678820:android:2925e9ce3417d2386c6471",
|
||||||
|
"android_client_info": {
|
||||||
|
"package_name": "in.sminnovations.hemocube"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-srhm9spm9hjn4frcd3r6o02gdhdbtd15.apps.googleusercontent.com",
|
||||||
|
"client_type": 1,
|
||||||
|
"android_info": {
|
||||||
|
"package_name": "in.sminnovations.hemocube",
|
||||||
|
"certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"api_key": [
|
||||||
|
{
|
||||||
|
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": {
|
||||||
|
"appinvite_service": {
|
||||||
|
"other_platform_oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"client_info": {
|
||||||
|
"mobilesdk_app_id": "1:650071678820:android:7569c1cad4fc99916c6471",
|
||||||
|
"android_client_info": {
|
||||||
|
"package_name": "in.sminnovations.hposregistration"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-70kp5jvjda4r5diqch2kn4lc40p4f42g.apps.googleusercontent.com",
|
||||||
|
"client_type": 1,
|
||||||
|
"android_info": {
|
||||||
|
"package_name": "in.sminnovations.hposregistration",
|
||||||
|
"certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"api_key": [
|
||||||
|
{
|
||||||
|
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": {
|
||||||
|
"appinvite_service": {
|
||||||
|
"other_platform_oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"client_info": {
|
||||||
|
"mobilesdk_app_id": "1:650071678820:android:f96be19e5d43102b6c6471",
|
||||||
|
"android_client_info": {
|
||||||
|
"package_name": "in.sminnovations.hpostesting"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-l87dnr0bdj95get0khgnvfv2an1k6ogq.apps.googleusercontent.com",
|
||||||
|
"client_type": 1,
|
||||||
|
"android_info": {
|
||||||
|
"package_name": "in.sminnovations.hpostesting",
|
||||||
|
"certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"api_key": [
|
||||||
|
{
|
||||||
|
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": {
|
||||||
|
"appinvite_service": {
|
||||||
|
"other_platform_oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"client_info": {
|
||||||
|
"mobilesdk_app_id": "1:650071678820:android:a53292637abb7c0d6c6471",
|
||||||
|
"android_client_info": {
|
||||||
|
"package_name": "in.sminnovations.hpostesting.dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"api_key": [
|
||||||
|
{
|
||||||
|
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": {
|
||||||
|
"appinvite_service": {
|
||||||
|
"other_platform_oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
package com.example.hpostesting.data.api
|
package com.example.hpostesting.data.api
|
||||||
|
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
|
|
||||||
interface PropertyProvider {
|
interface PropertyProvider {
|
||||||
|
|
||||||
fun getProperty(key: String): String
|
fun getProperty(key: String): String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DeviceCommunicationHandler {
|
||||||
|
fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener)
|
||||||
|
}
|
||||||
|
|||||||
@@ -203,8 +203,7 @@ class DatabaseRepository @Inject constructor(
|
|||||||
return allDeviceDataList.find { it.deviceId == deviceId }
|
return allDeviceDataList.find { it.deviceId == deviceId }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun getDeviceResponse(data: DeviceData?): Response<String> {
|
||||||
override suspend fun getDeviceResponse(data: DeviceData): Response<String>? {
|
|
||||||
return try {
|
return try {
|
||||||
db.collection("devices").add(data!!).await()
|
db.collection("devices").add(data!!).await()
|
||||||
Response.Success(data.deviceProvisionResponse)
|
Response.Success(data.deviceProvisionResponse)
|
||||||
@@ -213,7 +212,22 @@ class DatabaseRepository @Inject constructor(
|
|||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
override suspend fun uploadDeviceId(data: DeviceData): Response<String>? {
|
||||||
|
return try {
|
||||||
|
db.collection("devices").add(data!!).await()
|
||||||
|
Response.Success(data.deviceId)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Firebase.crashlytics.recordException(e)
|
||||||
|
Response.Error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,8 @@ interface Repository {
|
|||||||
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean>
|
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean>
|
||||||
|
|
||||||
suspend fun getDeviceDataById(deviceId: String): DeviceData?
|
suspend fun getDeviceDataById(deviceId: String): DeviceData?
|
||||||
suspend fun getDeviceResponse(data: DeviceData): Response<String>?
|
suspend fun getDeviceResponse(data: DeviceData?): Response<String>
|
||||||
|
suspend fun uploadDeviceId(data: DeviceData): Response<String>?
|
||||||
abstract fun <UserData> addTestToDatabase(testDetails: UserData): Any
|
abstract fun <UserData> addTestToDatabase(testDetails: UserData): Any
|
||||||
// suspend fun addToDatabase(data: PatientDetails)
|
// suspend fun addToDatabase(data: PatientDetails)
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.Result
|
import com.example.hpostesting.data.Result
|
||||||
|
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.deviceprovision.ProvisionData
|
import com.example.hpostesting.data.model.deviceprovision.ProvisionData
|
||||||
import com.example.hpostesting.data.model.login.LoginRequest
|
import com.example.hpostesting.data.model.login.LoginRequest
|
||||||
import com.example.hpostesting.data.model.login.LoginResponse
|
import com.example.hpostesting.data.model.login.LoginResponse
|
||||||
@@ -32,6 +34,7 @@ import com.example.hpostesting.data.model.patient.UserData
|
|||||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||||
import com.example.hpostesting.presentation.KitScanActivity
|
import com.example.hpostesting.presentation.KitScanActivity
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
||||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||||
import com.example.hpostesting.presentation.assurance.AssuranceControlsActivity
|
import com.example.hpostesting.presentation.assurance.AssuranceControlsActivity
|
||||||
@@ -49,7 +52,9 @@ import com.google.gson.JsonSyntaxException
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||||
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import java.nio.charset.Charset
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
@@ -68,9 +73,10 @@ class HomeFragment : Fragment() {
|
|||||||
private val homeViewModel: HemoCubeViewModel by activityViewModels()
|
private val homeViewModel: HemoCubeViewModel by activityViewModels()
|
||||||
|
|
||||||
private var isTokenAvailable = false
|
private var isTokenAvailable = false
|
||||||
private var username:String =""
|
private var username: String = ""
|
||||||
private var passworD:String =""
|
private var passworD: String = ""
|
||||||
private var natsToken:String =""
|
private var natsToken: String = ""
|
||||||
|
private var deviceId: String = ""
|
||||||
|
|
||||||
|
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
@@ -120,7 +126,7 @@ class HomeFragment : Fragment() {
|
|||||||
binding.rvOrderOffline.adapter = adapter
|
binding.rvOrderOffline.adapter = adapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner){ deviceData->
|
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) { deviceData ->
|
||||||
val devicelist = mutableListOf<DeviceData>()
|
val devicelist = mutableListOf<DeviceData>()
|
||||||
if (deviceData != null) {
|
if (deviceData != null) {
|
||||||
devicelist.add(DeviceData(deviceData.deviceId))
|
devicelist.add(DeviceData(deviceData.deviceId))
|
||||||
@@ -134,6 +140,7 @@ class HomeFragment : Fragment() {
|
|||||||
loadUserData()
|
loadUserData()
|
||||||
setSearch()
|
setSearch()
|
||||||
checkForLocalDBData()
|
checkForLocalDBData()
|
||||||
|
getDeviceId()
|
||||||
checkForTokenAndUpdate()
|
checkForTokenAndUpdate()
|
||||||
} else {
|
} else {
|
||||||
binding.internetAvailableCL.visibility = View.GONE
|
binding.internetAvailableCL.visibility = View.GONE
|
||||||
@@ -206,19 +213,14 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForTokenAndUpdate() {
|
private fun checkForTokenAndUpdate() {
|
||||||
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||||
var password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
var password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||||
var userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
var userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||||
val deviceId = sharedPreference.getString(Constants.DEVICE_ID,"")
|
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
||||||
|
Log.e("idpass", userID)
|
||||||
if(userID.isEmpty() && password.isEmpty()){
|
Log.e("idpass", password)
|
||||||
if (deviceId != null) {
|
Log.e("idpass", deviceId)
|
||||||
fetchDeviceProvisionResponse(deviceId)
|
if (userID.isNotEmpty() && password.isNotEmpty()) {
|
||||||
}
|
|
||||||
userID = sharedPreference.getString("username",username).toString()
|
|
||||||
password = sharedPreference.getString("password",passworD).toString()
|
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
|
||||||
}else if (userID.isNotEmpty() && password.isNotEmpty()) {
|
|
||||||
if (accessToken.isEmpty()) {
|
if (accessToken.isEmpty()) {
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
} else {
|
} else {
|
||||||
@@ -231,7 +233,12 @@ class HomeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else if (deviceId.isNotEmpty()) {
|
||||||
|
fetchDeviceProvisionResponse()
|
||||||
|
userID = username
|
||||||
|
password = passworD
|
||||||
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
"Contact Help and get your device provision done",
|
"Contact Help and get your device provision done",
|
||||||
@@ -393,10 +400,12 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun fetchDeviceProvisionResponse(deviceId: String) {
|
private fun fetchDeviceProvisionResponse() {
|
||||||
val db = Firebase.firestore
|
val db = Firebase.firestore
|
||||||
|
val deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
||||||
val deviceRef = db.collection("devices").document(deviceId)
|
val deviceRef = db.collection("devices").document(deviceId)
|
||||||
|
|
||||||
|
|
||||||
deviceRef.get()
|
deviceRef.get()
|
||||||
.addOnSuccessListener { document ->
|
.addOnSuccessListener { document ->
|
||||||
if (document.exists()) {
|
if (document.exists()) {
|
||||||
@@ -411,15 +420,24 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
provisionData?.let { data ->
|
provisionData?.let { data ->
|
||||||
// Assuming 'data' has the fields 'username', 'password', and 'natsToken'
|
// Assuming 'data' has the fields 'username', 'password', and 'natsToken'
|
||||||
username = data.username.toString()
|
username = data.username.toString()
|
||||||
passworD = data.password.toString()
|
passworD = data.password.toString()
|
||||||
natsToken = data.natsToken.toString()
|
natsToken = data.natsToken.toString()
|
||||||
|
|
||||||
// Assuming 'sharedPreference' is correctly initialized SharedPreferences instance
|
// Assuming 'sharedPreference' is correctly initialized SharedPreferences instance
|
||||||
with(sharedPreference.edit()) {
|
with(sharedPreference.edit()) {
|
||||||
putString("username", username) // Replace "username_key" with your actual key for username
|
putString(
|
||||||
putString("password", passworD) // Replace "password_key" with your actual key for password
|
"username",
|
||||||
putString("natsToken", natsToken) // Replace "natsToken_key" with your actual key for NATS token
|
username
|
||||||
|
) // Replace "username_key" with your actual key for username
|
||||||
|
putString(
|
||||||
|
"password",
|
||||||
|
passworD
|
||||||
|
) // Replace "password_key" with your actual key for password
|
||||||
|
putString(
|
||||||
|
"natsToken",
|
||||||
|
natsToken
|
||||||
|
) // Replace "natsToken_key" with your actual key for NATS token
|
||||||
apply() // Don't forget to call apply() to save the changes
|
apply() // Don't forget to call apply() to save the changes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,16 +454,21 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
private fun parseDeviceProvisionResponse(responseString: String): ProvisionData? {
|
private fun parseDeviceProvisionResponse(responseString: String): ProvisionData? {
|
||||||
return try {
|
return try {
|
||||||
val gson = Gson()
|
val jsonObject = JSONObject(responseString)
|
||||||
val type = object : TypeToken<ProvisionData>() {}.type
|
|
||||||
gson.fromJson(responseString, type)
|
val credentials = jsonObject.getJSONObject("credentials")
|
||||||
} catch (e: JsonSyntaxException) {
|
val username = credentials.getString("username")
|
||||||
|
val password = credentials.getString("password")
|
||||||
|
|
||||||
|
val deviceUser = jsonObject.getJSONObject("device").getJSONObject("deviceUser")
|
||||||
|
val natsToken = deviceUser.getString("natsToken")
|
||||||
|
|
||||||
|
ProvisionData(username, password, natsToken)
|
||||||
|
} catch (e: JSONException) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun loadUserData() {
|
private fun loadUserData() {
|
||||||
try {
|
try {
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
||||||
@@ -828,4 +851,44 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private fun getDeviceId() {
|
||||||
|
val handler = activity as? DeviceCommunicationHandler
|
||||||
|
handler?.sendAndListenToDevice(
|
||||||
|
HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND,
|
||||||
|
object : UsbServiceListener {
|
||||||
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
|
data?.let {
|
||||||
|
val receivedData = String(it, Charset.forName("UTF-8"))
|
||||||
|
// Assuming the device ID is the full content of the received data. Adjust if needed.
|
||||||
|
deviceId =
|
||||||
|
extractDeviceId(receivedData) // Implement this method based on your data format.
|
||||||
|
if (deviceId.isNotEmpty()) {
|
||||||
|
// Store the deviceId in SharedPreferences
|
||||||
|
with(sharedPreference.edit()) {
|
||||||
|
putString(Constants.DEVICE_ID, deviceId)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
// Optionally, you can update UI or proceed with further logic now that you have the device ID
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
// Update your UI or trigger next steps here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUsbError(e: Exception?) {
|
||||||
|
// Handle USB communication error
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun extractDeviceId(receivedData: String): String {
|
||||||
|
// Example based on the format "SNS HPP1-3038 SNE"
|
||||||
|
val regex = "SNS (\\w+) SNE".toRegex()
|
||||||
|
val matchResult = regex.find(receivedData)
|
||||||
|
return matchResult?.groups?.get(1)?.value ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,8 +21,11 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.get
|
import androidx.core.view.get
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
|
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||||
@@ -31,7 +34,7 @@ import `in`.sminnovations.hpostesting.R
|
|||||||
import `in`.sminnovations.hpostesting.databinding.ActivityAutoDacBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityAutoDacBinding
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DeviceProvisionActivity : AppCompatActivity() {
|
class DeviceProvisionActivity : AppCompatActivity(), DeviceCommunicationHandler {
|
||||||
private lateinit var binding: ActivityAutoDacBinding
|
private lateinit var binding: ActivityAutoDacBinding
|
||||||
val viewModel: DeviceProvisionViewModel by viewModels()
|
val viewModel: DeviceProvisionViewModel by viewModels()
|
||||||
private var myMenu: Menu? = null
|
private var myMenu: Menu? = null
|
||||||
@@ -180,4 +183,8 @@ class DeviceProvisionActivity : AppCompatActivity() {
|
|||||||
viewModel.isServiceConnected = false
|
viewModel.isServiceConnected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener) {
|
||||||
|
mService.sendAndListenToHemoCube(command = HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND, listener)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -20,6 +21,7 @@ import com.example.hpostesting.presentation.UsbServiceListener
|
|||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
||||||
|
|
||||||
class DeviceProvisionFragment : Fragment() {
|
class DeviceProvisionFragment : Fragment() {
|
||||||
@@ -56,13 +58,13 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
viewModel.deviceData.observe(viewLifecycleOwner) {
|
|
||||||
currentDeviceData = it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun observeViewModel() {
|
private fun observeViewModel() {
|
||||||
|
viewModel.deviceData.observe(viewLifecycleOwner) {
|
||||||
|
currentDeviceData = it
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.deviceProvisionResponse.observe(viewLifecycleOwner) { response ->
|
viewModel.deviceProvisionResponse.observe(viewLifecycleOwner) { response ->
|
||||||
when (response) {
|
when (response) {
|
||||||
@@ -96,14 +98,16 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity, "Device registered successfully", Toast.LENGTH_LONG
|
activity, "Device registered successfully", Toast.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
|
|
||||||
response.data.data?.credentials?.username?.let { DeviceData(deviceId = it) }
|
|
||||||
?.let { viewModel.addDeviceId(it) }
|
|
||||||
viewModel.addDeviceProvisionDataToDb(
|
viewModel.addDeviceProvisionDataToDb(
|
||||||
DeviceData(
|
DeviceData(
|
||||||
deviceProvisionResponse = response.toString()
|
deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString(),
|
||||||
|
deviceProvisionResponse = response.data.data.toString()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
// viewModel.addDeviceId(DeviceData(deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()))
|
||||||
|
Log.e("idpass",response.toString())
|
||||||
|
Log.e("idpass",response.data.data?.credentials?.username.toString())
|
||||||
|
Log.e("idpass",deviceProvisionResponse)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity,
|
activity,
|
||||||
@@ -132,7 +136,13 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
viewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
|
if (result == "Success") {
|
||||||
|
Toast.makeText(
|
||||||
|
activity, "Device provision successfully uploaded to firebase", Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ class DeviceProvisionViewModel @Inject constructor(
|
|||||||
fun addDeviceId(data: DeviceData){
|
fun addDeviceId(data: DeviceData){
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try{
|
try{
|
||||||
val id = repository.getDeviceDataById(data.deviceId)
|
repository.uploadDeviceId(data)
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Successfully device Id uploaded to firebase")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Log.e("Testdb", "Exception during data upload: ${e.message}")
|
// Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||||
fireBaseUpload.postValue("Error")
|
fireBaseUpload.postValue("Error")
|
||||||
@@ -56,7 +56,7 @@ class DeviceProvisionViewModel @Inject constructor(
|
|||||||
when (val response = repository.getDeviceResponse(data)) {
|
when (val response = repository.getDeviceResponse(data)) {
|
||||||
is Response.Success -> {
|
is Response.Success -> {
|
||||||
// Log.i("Testdb", "Data uploaded to Firestore successfully")
|
// Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Successfully device response uploaded to firebase")
|
||||||
}
|
}
|
||||||
|
|
||||||
is Response.Error -> {
|
is Response.Error -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user