Result screen stuck, issue is solves
This commit is contained in:
@@ -13,15 +13,16 @@
|
|||||||
|
|
||||||
package com.example.hpostesting.presentation.dashboard.ui
|
package com.example.hpostesting.presentation.dashboard.ui
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Context.WIFI_SERVICE
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.location.Location
|
import android.location.Location
|
||||||
import android.location.LocationListener
|
import android.location.LocationListener
|
||||||
import android.location.LocationManager
|
import android.location.LocationManager
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.wifi.WifiManager
|
import android.net.NetworkInfo
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@@ -30,21 +31,25 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.ContextCompat.getSystemService
|
import androidx.core.content.ContextCompat.getSystemService
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.google.android.gms.location.FusedLocationProviderClient
|
||||||
|
import com.google.android.gms.location.LocationCallback
|
||||||
|
import com.google.android.gms.location.LocationRequest
|
||||||
|
import com.google.android.gms.location.LocationResult
|
||||||
|
import com.google.android.gms.location.LocationServices
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentLoginBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentLoginBinding
|
||||||
import kotlinx.coroutines.Dispatchers
|
import java.net.NetworkInterface
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.net.HttpURLConnection
|
|
||||||
import java.net.URL
|
|
||||||
import java.util.Scanner
|
|
||||||
|
|
||||||
|
|
||||||
class LoginFragment : Fragment() {
|
class LoginFragment : Fragment() {
|
||||||
|
private val LOCATION_PERMISSION_REQUEST_CODE = 1001
|
||||||
|
private lateinit var locationManager: LocationManager
|
||||||
var latitude = 0.0
|
var latitude = 0.0
|
||||||
var longitude = 0.0
|
var longitude = 0.0
|
||||||
var TAG = "LoginFragmentCheck"
|
var TAG = "LoginFragmentCheck"
|
||||||
@@ -65,7 +70,31 @@ class LoginFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
init()
|
init()
|
||||||
checkLocation()
|
locationManager = requireActivity().getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||||
|
|
||||||
|
// Check for location permission
|
||||||
|
if (ContextCompat.checkSelfPermission(requireContext(),
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(requireContext(),
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// Permission is not granted, request it
|
||||||
|
ActivityCompat.requestPermissions(requireActivity(),
|
||||||
|
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION),
|
||||||
|
LOCATION_PERMISSION_REQUEST_CODE)
|
||||||
|
} else {
|
||||||
|
// Permission is granted, fetch location
|
||||||
|
checkLocation()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNetworkProviderAvailable()) {
|
||||||
|
Toast.makeText(requireContext(), "Network provider is available", Toast.LENGTH_SHORT).show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(requireContext(), "Network provider is not available", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isNetworkProviderAvailable(): Boolean {
|
||||||
|
|
||||||
|
return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||||
}
|
}
|
||||||
private fun init() {
|
private fun init() {
|
||||||
if (isUserLoggedIn()) {
|
if (isUserLoggedIn()) {
|
||||||
@@ -129,49 +158,52 @@ class LoginFragment : Fragment() {
|
|||||||
/** Check if we can get our location */
|
/** Check if we can get our location */
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun checkLocation() {
|
fun checkLocation() {
|
||||||
// Get the location manager
|
|
||||||
val locationManager = requireActivity().getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
val locationManager = requireActivity().getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||||
val locationProviderWifi = LocationManager.NETWORK_PROVIDER
|
val locationProviderWifi = LocationManager.NETWORK_PROVIDER
|
||||||
val locationProviderGPS = LocationManager.GPS_PROVIDER
|
val locationProviderGPS = LocationManager.FUSED_PROVIDER
|
||||||
val locationListenerNetwork: LocationListener
|
val locationListenerNetwork: LocationListener
|
||||||
val locationListenerGPS: LocationListener
|
val locationListenerGPS: LocationListener
|
||||||
var gps_enabled = false
|
var gps_enabled = false
|
||||||
var network_enabled = false
|
var network_enabled = false
|
||||||
|
Log.d(TAG,"PRoveider"+locationManager.allProviders.toString())
|
||||||
|
//check wifi
|
||||||
|
|
||||||
//check wifi
|
//check wifi
|
||||||
val connectivityManager = requireActivity().getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
val connectivityManager = requireActivity().getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
val mWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
|
val mWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
|
||||||
|
|
||||||
if (mWifi!!.isConnected) {
|
if (mWifi!!.isConnected) {
|
||||||
Log.d(TAG, "Wifi connected")
|
Log.d(TAG, "Wifi connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check gps and wifi availability
|
||||||
|
|
||||||
//check gps and wifi availability
|
//check gps and wifi availability
|
||||||
try {
|
try {
|
||||||
gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: java.lang.Exception) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
network_enabled =
|
||||||
} catch (ex: Exception) {
|
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||||
|
} catch (ex: java.lang.Exception) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gps_enabled) {
|
if (!gps_enabled) {
|
||||||
Log.d(TAG, "GPS: Missing")
|
Log.d(TAG, "GPS: Missing")
|
||||||
}else{
|
|
||||||
// getPublicIpAddr { ipAddress ->
|
|
||||||
// // Do something with the ipAddress
|
|
||||||
// Log.d(TAG, "GPS: PRESENT"+ipAddress)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
if (!network_enabled) {
|
if (!network_enabled) {
|
||||||
Log.d(TAG, "Network: Missing")
|
Log.d(TAG, "Network: Missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Location change listeners */
|
||||||
|
|
||||||
/* Location change listeners */try {
|
/* Location change listeners */try {
|
||||||
Log.d(TAG, "GPS: PRESENT TRy")
|
|
||||||
// Define a listener that responds to gps location updates
|
// Define a listener that responds to gps location updates
|
||||||
locationListenerGPS = object : LocationListener {
|
locationListenerGPS = object : LocationListener {
|
||||||
override fun onLocationChanged(location: Location) {
|
override fun onLocationChanged(location: Location) {
|
||||||
Log.d(TAG, "GPS: PRESENT loc")
|
|
||||||
Log.d(
|
Log.d(
|
||||||
TAG,
|
TAG,
|
||||||
"GPS: Latitude: " + location.latitude + ", Longitude = " + location.longitude
|
"GPS: Latitude: " + location.latitude + ", Longitude = " + location.longitude
|
||||||
@@ -179,22 +211,27 @@ class LoginFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
|
override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
|
||||||
Log.d(TAG, "GP location found 1")
|
Log.d(TAG, "GPS location found 1")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onProviderEnabled(provider: String) {
|
override fun onProviderEnabled(provider: String) {
|
||||||
Log.d(TAG, "GP location found 2")
|
Log.d(TAG, "GPS location found 2")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onProviderDisabled(provider: String) {
|
override fun onProviderDisabled(provider: String) {
|
||||||
Log.d(TAG, "GP location found 3")
|
Log.d(TAG, "GPS location found 3")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
locationManager.requestLocationUpdates(locationProviderGPS, 0, 0f, locationListenerGPS)
|
locationManager.requestLocationUpdates(
|
||||||
Log.d(TAG, "GPS: PRESENT Req")
|
locationProviderGPS,
|
||||||
} catch (e: Exception) {
|
0,
|
||||||
Log.e(TAG, "Location Exception: " + e.message)
|
0f,
|
||||||
|
locationListenerGPS
|
||||||
|
)
|
||||||
|
} catch (e: java.lang.Exception) {
|
||||||
|
Log.e(TAG, "Location Exception GPS: " + e.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Define a listener that responds to wifi location updates
|
// Define a listener that responds to wifi location updates
|
||||||
locationListenerNetwork = object : LocationListener {
|
locationListenerNetwork = object : LocationListener {
|
||||||
@@ -223,8 +260,22 @@ class LoginFragment : Fragment() {
|
|||||||
0f,
|
0f,
|
||||||
locationListenerNetwork
|
locationListenerNetwork
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
Log.e(TAG, "NW Location Exception: " + e.message)
|
Log.e(TAG, "Location Exception: " + e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) {
|
||||||
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// Permission granted, fetch location
|
||||||
|
checkLocation()
|
||||||
|
} else {
|
||||||
|
// Permission denied
|
||||||
|
Toast.makeText(requireContext(), "Location permission denied", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fun getPublicIpAddr(callback: (String) -> Unit) {
|
// fun getPublicIpAddr(callback: (String) -> Unit) {
|
||||||
|
|||||||
@@ -245,24 +245,24 @@ class HemoCubeFragment : Fragment() {
|
|||||||
} else {
|
} else {
|
||||||
handleReadingFinish()
|
handleReadingFinish()
|
||||||
}
|
}
|
||||||
// hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
// if (result == "Success") {
|
if (result == "Success") {
|
||||||
// uploadedToCloud = true
|
uploadedToCloud = true
|
||||||
// var accessToken = sharedPreferences.getString(Constants.ACCESS_TOKEN, "").toString()
|
var accessToken = sharedPreferences.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||||
// showToast(R.string.test_upload)
|
showToast(R.string.test_upload)
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
// if (result == "Local") {
|
if (result == "Local") {
|
||||||
// showToast(R.string.internt_not_local)
|
showToast(R.string.internt_not_local)
|
||||||
// startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
||||||
// }
|
}
|
||||||
// if (result == "Error") {
|
if (result == "Error") {
|
||||||
// showToast(R.string.error_local)
|
showToast(R.string.error_local)
|
||||||
// startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// binding.progressBar.visibility = View.GONE
|
binding.progressBar.visibility = View.GONE
|
||||||
// }
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID, ""))
|
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID, ""))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user