Skip to content

Commit

Permalink
gps problem dialog issue resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
nawinkhatiwada committed Dec 30, 2019
1 parent d819068 commit fa7104b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LocationFragment private constructor() : BaseFragment() {
isObserverAdded = true
}
locationManager?.getLocation()
}
}
}

override fun onLocationChanged(location: Location?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class LocationManager private constructor(

private fun permissionGranted(alreadyHadPermission: Boolean) {
locationListener?.onPermissionGranted(alreadyHadPermission)
gpsProvider.get()
// gpsProvider.get()
}

private fun onPermissionGrantedFailed() {
Expand Down
31 changes: 21 additions & 10 deletions library/src/main/java/com/androidbolts/library/gps/GpsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.annotation.SuppressLint
import android.app.Dialog
import android.content.IntentSender
import android.location.Location
import android.os.Handler
import android.os.CountDownTimer
import android.os.Looper
import android.util.Log
import android.view.View
Expand Down Expand Up @@ -38,6 +38,7 @@ internal class GpsManager private constructor() : GpsProvider() {
private var mLocationSettingsRequest: LocationSettingsRequest? = null
private var dialog: AlertDialog? = null
private var mRequestingLocationUpdates: Boolean = false
private var timer: CountDownTimer ?= null

companion object {
private var gpsManager: GpsManager? = null
Expand Down Expand Up @@ -117,6 +118,7 @@ internal class GpsManager private constructor() : GpsProvider() {
getPrefs()?.setLocationModel(locationModel)
}
if (isLocationAvailable()) {
timer?.cancel()
dismissDialog()
}

Expand Down Expand Up @@ -208,12 +210,22 @@ internal class GpsManager private constructor() : GpsProvider() {
val negButton = dialog?.getButton(Dialog.BUTTON_NEGATIVE)
posButton?.visibility = View.GONE
negButton?.visibility = View.GONE
if (getTimeOut() != TIME_OUT_NONE) {
Handler().postDelayed({
posButton?.visibility = View.VISIBLE
negButton?.visibility = View.VISIBLE
updateDialog()
}, getTimeOut())
if (getTimeOut() != TIME_OUT_NONE && mCurrentLocation == null) {
timer = object :CountDownTimer(getTimeOut(), 1000){
override fun onFinish() {
if(mCurrentLocation == null) {
posButton?.visibility = View.VISIBLE
negButton?.visibility = View.VISIBLE
updateDialog()
}else {
dismissDialog()
}
}

override fun onTick(running: Long) {
}
}
timer?.start()
}
}
dialog?.let { loadingDialog ->
Expand All @@ -228,9 +240,8 @@ internal class GpsManager private constructor() : GpsProvider() {
}

private fun updateDialog() {
dialog?.findViewById<TextView>(R.id.title)?.text = "Gps problem"
dialog?.findViewById<TextView>(R.id.message)?.text =
"We couldn't fetch your current location."
dialog?.findViewById<TextView>(R.id.title)?.text = getContext()?.getString(R.string.gps_problem)
dialog?.findViewById<TextView>(R.id.message)?.text =getContext()?.getString(R.string.gps_problem_desc)
dialog?.findViewById<ProgressBar>(R.id.progress_circular)?.visibility = View.GONE
}

Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">library</string>
<string name="gps_problem" >Gps problem</string>
<string name="gps_problem_desc" >We couldn\'t fetch your current location.</string>
</resources>

0 comments on commit fa7104b

Please sign in to comment.