125 version, net kit button issue resolved
This commit is contained in:
@@ -42,7 +42,7 @@ object DataHolder {
|
||||
var district: String = ""
|
||||
var quickCapture:Boolean = false
|
||||
var location: UserData.Location? = null
|
||||
var ipAddress: String =""
|
||||
var ipAddress: String ="0.0"
|
||||
var testExp: Boolean = true
|
||||
var hemocubeResult: Double? = null
|
||||
}
|
||||
@@ -51,7 +51,7 @@ import java.util.Locale
|
||||
import kotlin.math.max
|
||||
|
||||
class KitScanActivity : AppCompatActivity(), IDcsSdkApiDelegate {
|
||||
|
||||
private var fromWhere = "Home"
|
||||
private val TAG = "KitScanActivity"
|
||||
private lateinit var binding: ActivityKitScanBinding
|
||||
|
||||
@@ -134,6 +134,7 @@ class KitScanActivity : AppCompatActivity(), IDcsSdkApiDelegate {
|
||||
sharedPreference = this.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
setContentView(binding.root)
|
||||
binding.toolbar.title = "Kit Serial Number"
|
||||
fromWhere = intent.getStringExtra("fromWhere").toString()
|
||||
val maxTest = if(sharedPreference.getString(Constants.CUVETTE_SIZE, "10mm").toString() == "2mm"){
|
||||
Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE
|
||||
}else{
|
||||
@@ -363,22 +364,23 @@ class KitScanActivity : AppCompatActivity(), IDcsSdkApiDelegate {
|
||||
}
|
||||
|
||||
private fun moveToNext() {
|
||||
if(fromWhere == "Main"){
|
||||
DataHolder.deviceType.observe(this) { deviceType ->
|
||||
when (deviceType) {
|
||||
Constants.DEVICE_TYPE_HEMOCUBE -> {
|
||||
val i = Intent(applicationContext, HemocubeActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
DataHolder.deviceType.observe(this) { deviceType ->
|
||||
when (deviceType) {
|
||||
Constants.DEVICE_TYPE_HEMOCUBE -> {
|
||||
val i = Intent(applicationContext, HemocubeActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
Constants.DEVICE_TYPE_TEST_RIGHT -> {
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
Constants.DEVICE_TYPE_TEST_RIGHT -> {
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
Constants.DEVICE_TYPE_TRUEHEME -> {
|
||||
val i = Intent(applicationContext, HemocubeActivity::class.java)
|
||||
startActivity(i)
|
||||
Constants.DEVICE_TYPE_TRUEHEME -> {
|
||||
val i = Intent(applicationContext, HemocubeActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +220,7 @@ class MainActivity : AppCompatActivity() {
|
||||
binding.cvItem1.setOnClickListener {
|
||||
DataHolder.selectedTestType = TestType.SICKLECERT
|
||||
val i = Intent(applicationContext, KitScanActivity::class.java)
|
||||
i.putExtra("fromWhere","Main")
|
||||
startActivity(i)
|
||||
finish()
|
||||
}
|
||||
@@ -227,6 +228,7 @@ class MainActivity : AppCompatActivity() {
|
||||
binding.cvItem2.setOnClickListener {
|
||||
DataHolder.selectedTestType = TestType.SICKLEFIND
|
||||
val i = Intent(applicationContext, KitScanActivity::class.java)
|
||||
i.putExtra("fromWhere","Main")
|
||||
startActivity(i)
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.DataHolder
|
||||
@@ -73,10 +74,9 @@ import com.google.firebase.perf.ktx.performance
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.ResponseBody
|
||||
import org.json.JSONObject
|
||||
import java.io.BufferedOutputStream
|
||||
@@ -90,7 +90,6 @@ import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.Scanner
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
import kotlin.properties.Delegates
|
||||
@@ -140,7 +139,7 @@ class HomeFragment : Fragment() {
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
deleteIncompleteRegistrations(userData)
|
||||
}
|
||||
getLocationIP()
|
||||
// getLocationIP()
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
deleteHemoCubeIncompleteRegistrations(userData)
|
||||
if (userData.isNotEmpty()) {
|
||||
@@ -236,7 +235,9 @@ class HomeFragment : Fragment() {
|
||||
// putInt(Constants.KIT_COUNT, 0)
|
||||
// apply()
|
||||
// }
|
||||
startActivity(Intent(requireContext(), KitScanActivity::class.java))
|
||||
val intent = Intent(requireContext(), KitScanActivity::class.java)
|
||||
intent.putExtra("fromWhere","Home")
|
||||
startActivity(intent)
|
||||
// requireActivity().finish()
|
||||
}
|
||||
binding.btnQuickCapture.setOnClickListener {
|
||||
@@ -260,19 +261,29 @@ class HomeFragment : Fragment() {
|
||||
checkNetworkStatus()
|
||||
|
||||
}
|
||||
private fun getLocationIP() {
|
||||
if(isInternetAvailable(requireContext())) {
|
||||
getPublicIpAddr { ipAddress ->
|
||||
if(ipAddress != "fail"){
|
||||
DataHolder.ipAddress = ipAddress
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.IP_ADDRESS, ipAddress)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// private fun getLocationIP() {
|
||||
// try {
|
||||
// if (isInternetAvailable(requireContext())) {
|
||||
// getPublicIpAddr { ipAddress ->
|
||||
// if (ipAddress != "fail") {
|
||||
// DataHolder.ipAddress = ipAddress
|
||||
// with(sharedPreference.edit()) {
|
||||
// putString(Constants.IP_ADDRESS, ipAddress)
|
||||
// apply()
|
||||
// }
|
||||
// } else {
|
||||
// Log.e("Home", "Failed to get public IP address")
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// Log.e("Home", "Internet is not available")
|
||||
// }
|
||||
// } catch (e: UnknownHostException) {
|
||||
// Log.e("Home", "UnknownHostException: Unable to resolve host. Network might be unavailable or DNS server is not reachable", e)
|
||||
// } catch (e: Exception) {
|
||||
// Log.e("Home", "Network Problem", e)
|
||||
// }
|
||||
// }
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
private fun checkNetworkStatus() {
|
||||
@@ -690,9 +701,10 @@ class HomeFragment : Fragment() {
|
||||
requireActivity().packageName, 0
|
||||
)
|
||||
val version = pInfo.versionName
|
||||
var labname = sharedPreference.getString(Constants.LABNAME,"")
|
||||
val labname = sharedPreference.getString(Constants.CENTER_NAME,"")
|
||||
val ip = sharedPreference.getString(Constants.IP_ADDRESS,"")
|
||||
return LoginRequest(
|
||||
location = DataHolder.ipAddress, password = password, serialNumber = userID, username = userID, version = version, lab = labname
|
||||
location = ip, password = password, serialNumber = userID, username = userID, version = version, lab = labname
|
||||
)
|
||||
}
|
||||
private fun createCheckUpdateRequestData(): CheckUpdateRequest {
|
||||
@@ -1527,34 +1539,64 @@ class HomeFragment : Fragment() {
|
||||
super.onDestroy()
|
||||
|
||||
}
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
private fun getPublicIpAddr(callback: (String) -> Unit) {
|
||||
try {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
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)
|
||||
val inputStream = conn.inputStream
|
||||
val ipAddress = inputStream.bufferedReader().use { it.readText() }
|
||||
inputStream.close()
|
||||
withContext(Dispatchers.Main) {
|
||||
callback(ipAddress)
|
||||
}else{
|
||||
}
|
||||
} else {
|
||||
withContext(Dispatchers.Main) {
|
||||
callback("fail")
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
conn.disconnect()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("getPublicIpAddr", e.toString())
|
||||
withContext(Dispatchers.Main) {
|
||||
callback("fail")
|
||||
}
|
||||
}
|
||||
}catch (e: Exception){
|
||||
Log.e("home",e.toString())
|
||||
callback("fail")
|
||||
}
|
||||
}
|
||||
// @OptIn(DelicateCoroutinesApi::class)
|
||||
// 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")
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun callLogin(userID: String, password: String) {
|
||||
if(DataHolder.ipAddress == "0.0"){
|
||||
@@ -1586,7 +1628,7 @@ class HomeFragment : Fragment() {
|
||||
|
||||
return diffMillis / (60 * 1000) // Convert milliseconds to minutes
|
||||
}
|
||||
fun isInternetAvailable(context: Context): Boolean {
|
||||
private fun isInternetAvailable(context: Context): Boolean {
|
||||
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
val network = connectivityManager.activeNetwork ?: return false
|
||||
|
||||
@@ -77,12 +77,12 @@ class LoginFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
init()
|
||||
|
||||
if(isInternetAvailable()){
|
||||
getPublicIpAddr { ipAddress ->
|
||||
DataHolder.ipAddress = ipAddress
|
||||
}
|
||||
Log.d("ipaddress",DataHolder.ipAddress)
|
||||
}
|
||||
// if(isInternetAvailable()){
|
||||
// getPublicIpAddr { ipAddress ->
|
||||
// DataHolder.ipAddress = ipAddress
|
||||
// }
|
||||
// Log.d("ipaddress",DataHolder.ipAddress)
|
||||
// }
|
||||
setupAutoCompleteTextView()
|
||||
//checkLocation()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user