location changes is done in home fragment,for to pass the ip address in login screen, and device id fetching from local file also added
This commit is contained in:
@@ -54,33 +54,33 @@ import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
|||||||
import com.example.hpostesting.encryption.Encryption
|
import com.example.hpostesting.encryption.Encryption
|
||||||
import com.example.hpostesting.presentation.KitScanActivity
|
import com.example.hpostesting.presentation.KitScanActivity
|
||||||
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.assurance.AssuranceControlsActivity
|
import com.example.hpostesting.presentation.assurance.AssuranceControlsActivity
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
import com.example.hpostesting.presentation.utils.DeviceCommunicationHandler
|
import com.example.hpostesting.presentation.utils.DeviceCommunicationHandler
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.util.Result
|
||||||
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
|
||||||
import com.google.firebase.firestore.Query
|
|
||||||
import com.google.firebase.firestore.ktx.firestore
|
import com.google.firebase.firestore.ktx.firestore
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import com.google.firebase.perf.ktx.performance
|
|
||||||
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 kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
import java.nio.charset.Charset
|
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.Locale
|
import java.util.Locale
|
||||||
|
import java.util.Scanner
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
@@ -251,6 +251,7 @@ class HomeFragment : Fragment() {
|
|||||||
// loadUserData()
|
// loadUserData()
|
||||||
//setSearch()
|
//setSearch()
|
||||||
checkForLocalDBData()
|
checkForLocalDBData()
|
||||||
|
|
||||||
if (Constants.MOLBIO_INTEGRATION) {
|
if (Constants.MOLBIO_INTEGRATION) {
|
||||||
checkForTokenAndUpdate()
|
checkForTokenAndUpdate()
|
||||||
}
|
}
|
||||||
@@ -354,7 +355,9 @@ class HomeFragment : Fragment() {
|
|||||||
Log.d("istoken", isTokenAvailable.toString())
|
Log.d("istoken", isTokenAvailable.toString())
|
||||||
if (!isTokenAvailable) {
|
if (!isTokenAvailable) {
|
||||||
Log.d("istoken1", isTokenAvailable.toString())
|
Log.d("istoken1", isTokenAvailable.toString())
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
callLogin(userID, password)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//isTokenAvailable = true
|
//isTokenAvailable = true
|
||||||
|
|
||||||
@@ -362,7 +365,8 @@ class HomeFragment : Fragment() {
|
|||||||
Log.d("istoken7", isTokenAvailable.toString())
|
Log.d("istoken7", isTokenAvailable.toString())
|
||||||
if (isTokenExpired(accessToken)) {
|
if (isTokenExpired(accessToken)) {
|
||||||
Log.d("istoken8", isTokenAvailable.toString())
|
Log.d("istoken8", isTokenAvailable.toString())
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
callLogin(userID, password)
|
||||||
|
// hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
//hemoCubeViewModel.startPeriodicCheckUpdate()
|
//hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||||
}else{
|
}else{
|
||||||
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
||||||
@@ -380,14 +384,17 @@ class HomeFragment : Fragment() {
|
|||||||
val credentials = decryptedMessage.split("\n")
|
val credentials = decryptedMessage.split("\n")
|
||||||
userID = credentials[0]
|
userID = credentials[0]
|
||||||
password = credentials[1]
|
password = credentials[1]
|
||||||
|
deviceId = credentials[0]
|
||||||
// Toast.makeText(context, "DECRYPTED: $credentials", Toast.LENGTH_SHORT).show()
|
// Toast.makeText(context, "DECRYPTED: $credentials", Toast.LENGTH_SHORT).show()
|
||||||
if (!isTokenAvailable) {
|
if (!isTokenAvailable) {
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
callLogin(userID, password)
|
||||||
|
//hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
}
|
}
|
||||||
else if (isTokenAvailable) {
|
else if (isTokenAvailable) {
|
||||||
//hemoCubeViewModel.startPeriodicCheckUpdate()
|
//hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||||
if (isTokenExpired(accessToken)) {
|
if (isTokenExpired(accessToken)) {
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
callLogin(userID, password)
|
||||||
|
// hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
}else{
|
}else{
|
||||||
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
||||||
}
|
}
|
||||||
@@ -621,6 +628,19 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun callLogin(userID: String, password: String) {
|
||||||
|
if(DataHolder.ipAddress == "0.0"){
|
||||||
|
getPublicIpAddr { ipAddress ->
|
||||||
|
if(ipAddress != "fail"){
|
||||||
|
DataHolder.ipAddress = ipAddress
|
||||||
|
}
|
||||||
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun isTokenExpired(token: String): Boolean {
|
private fun isTokenExpired(token: String): Boolean {
|
||||||
if (token.isNotEmpty()) {
|
if (token.isNotEmpty()) {
|
||||||
@@ -654,13 +674,14 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createLoginRequestData(userID: String, password: String): LoginRequest {
|
private fun createLoginRequestData(userID: String, password: String): LoginRequest {
|
||||||
|
|
||||||
val pInfo = requireActivity().packageManager.getPackageInfo(
|
val pInfo = requireActivity().packageManager.getPackageInfo(
|
||||||
requireActivity().packageName, 0
|
requireActivity().packageName, 0
|
||||||
)
|
)
|
||||||
val version = pInfo.versionName
|
val version = pInfo.versionName
|
||||||
var labname = sharedPreference.getString(Constants.LABNAME,"")
|
var labname = sharedPreference.getString(Constants.LABNAME,"")
|
||||||
return LoginRequest(
|
return LoginRequest(
|
||||||
password = password, serialNumber = userID, username = userID, version = version, lab = labname,location = DataHolder.location.toString()
|
password = password, serialNumber = userID, username = userID, version = version, lab = labname,location = DataHolder.ipAddress.toString()
|
||||||
)
|
)
|
||||||
}//latitude = DataHolder.location!!.latitude.toString(), longitude = DataHolder.location!!.longitude.toString(), location = DataHolder.location.toString()
|
}//latitude = DataHolder.location!!.latitude.toString(), longitude = DataHolder.location!!.longitude.toString(), location = DataHolder.location.toString()
|
||||||
|
|
||||||
@@ -676,7 +697,7 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
|
private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
|
||||||
return DeviceUpdateRequest(
|
return DeviceUpdateRequest(
|
||||||
serial_no = sharedPreference.getString(Constants.DEVICE_ID, "")
|
serial_no = deviceId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,7 +817,8 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
if (!isTokenAvailable) {
|
if (!isTokenAvailable) {
|
||||||
Log.d("istoken0", isTokenAvailable.toString())
|
Log.d("istoken0", isTokenAvailable.toString())
|
||||||
hemoCubeViewModel.login(createLoginRequestData(username, password))
|
callLogin(username, password)
|
||||||
|
//hemoCubeViewModel.login(createLoginRequestData(username, password))
|
||||||
}
|
}
|
||||||
|
|
||||||
} ?: Log.e("fetchDeviceCredentials", "Failed to parse device data.")
|
} ?: Log.e("fetchDeviceCredentials", "Failed to parse device data.")
|
||||||
@@ -1487,6 +1509,33 @@ class HomeFragment : Fragment() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private fun getPublicIpAddr(callback: (String) -> Unit) {
|
||||||
|
try {
|
||||||
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
val url = URL("https://api.ipify.org")
|
||||||
|
val conn = url.openConnection() as HttpURLConnection
|
||||||
|
try {
|
||||||
|
conn.connect()
|
||||||
|
if (conn.responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
val scanner = Scanner(conn.inputStream)
|
||||||
|
scanner.useDelimiter("\\A")
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
val ipAddress = scanner.next()
|
||||||
|
Log.d("ipaddress",DataHolder.ipAddress)
|
||||||
|
callback(ipAddress)
|
||||||
|
}else{
|
||||||
|
callback("fail")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
conn.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (e: Exception){
|
||||||
|
Log.e("home",e.toString())
|
||||||
|
callback("fail")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class LoginFragment : Fragment() {
|
|||||||
getPublicIpAddr { ipAddress ->
|
getPublicIpAddr { ipAddress ->
|
||||||
DataHolder.ipAddress = ipAddress
|
DataHolder.ipAddress = ipAddress
|
||||||
}
|
}
|
||||||
|
Log.d("ipaddress",DataHolder.ipAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPublicIpAddr { ipAddress ->
|
// getPublicIpAddr { ipAddress ->
|
||||||
@@ -112,6 +113,7 @@ class LoginFragment : Fragment() {
|
|||||||
|
|
||||||
if (loginId.isNotBlank() && password.isNotBlank()) {
|
if (loginId.isNotBlank() && password.isNotBlank()) {
|
||||||
performLogin(loginId, password)
|
performLogin(loginId, password)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (loginId.isBlank()) {
|
if (loginId.isBlank()) {
|
||||||
binding.loginId.error = R.string.enter_proper_login_id.toString()
|
binding.loginId.error = R.string.enter_proper_login_id.toString()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import android.content.Intent
|
|||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.text.method.ScrollingMovementMethod
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -73,6 +74,7 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
binding.btnSubmit.visibility = View.GONE
|
binding.btnSubmit.visibility = View.GONE
|
||||||
|
binding.tvSubtitle4.movementMethod = ScrollingMovementMethod()
|
||||||
listenToHemoCube()
|
listenToHemoCube()
|
||||||
getDeviceId()
|
getDeviceId()
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="Start"
|
android:text="Start"
|
||||||
|
android:scrollbars="vertical"
|
||||||
android:textColor="@color/red"
|
android:textColor="@color/red"
|
||||||
android:textSize="22sp"
|
android:textSize="22sp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user