Skip to content

Commit

Permalink
Merge pull request #38 from rfcx/feature/CA-2119-handle-error-while-l…
Browse files Browse the repository at this point in the history
…ocation-notfound

CA-2119 - Show message dialog if cannot get location after 30 seconds.
  • Loading branch information
jingjoeh authored Mar 24, 2020
2 parents 6be0475 + 9873be3 commit 61a0ebd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/org/rfcx/ranger/view/report/ReportActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.view.MenuItem
import android.view.View
import android.widget.ScrollView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -44,6 +45,7 @@ import java.io.File
import java.io.IOException
import java.util.*
import org.rfcx.ranger.databinding.ActivityReportBinding
import kotlin.concurrent.timerTask


class ReportActivity : BaseReportImageActivity(), OnMapReadyCallback {
Expand All @@ -59,6 +61,8 @@ class ReportActivity : BaseReportImageActivity(), OnMapReadyCallback {
private var lastLocation: Location? = null
private val analytics by lazy { Analytics(this) }

private val waitingForLocationTimer: Timer = Timer()

private lateinit var binding: ActivityReportBinding

private fun bitmapDescriptorFromVector(context: Context, vectorResId: Int): BitmapDescriptor? {
Expand Down Expand Up @@ -127,6 +131,7 @@ class ReportActivity : BaseReportImageActivity(), OnMapReadyCallback {
supportFragmentManager.beginTransaction().remove(it).commitAllowingStateLoss()
}
stopPlaying()
waitingForLocationTimer.cancel()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down Expand Up @@ -215,14 +220,31 @@ class ReportActivity : BaseReportImageActivity(), OnMapReadyCallback {
if (isDestroyed) return
locationManager?.removeUpdates(locationListener)
locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager?
waitingForLocationTimer.schedule(timerTask {
if (lastLocation == null) {
runOnUiThread {
showLocationMessageError(getString(R.string.in_air_plane_mode))
AlertDialog.Builder(this@ReportActivity)
.setTitle(null)
.setMessage("${getString(R.string.in_air_plane_mode)}. ${getString(R.string.please_try_again_later)}")
.setCancelable(true)
.setPositiveButton(R.string.button_ok) { dialog, _ ->
dialog.dismiss()
finish()
}.show()
}
}
}, 30 * 1000) // waiting for 30 sec if cannot get location show error
try {
locationManager?.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5 * 1000L, 0f, locationListener)
lastLocation = locationManager?.getLastKnownLocation(LocationManager.GPS_PROVIDER)
showLocationFinding()
lastLocation?.let { markRangerLocation(it) }
} catch (ex: SecurityException) {
showLocationMessageError(getString(R.string.in_air_plane_mode))
ex.printStackTrace()
} catch (ex: IllegalArgumentException) {
showLocationMessageError(getString(R.string.in_air_plane_mode))
ex.printStackTrace()
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
<string name="password_changed_successfully">La contraseña ha sido cambiada con éxito.</string>
<string name="something_is_wrong">Algo salió mal. Por favor, inténtelo de nuevo más tarde.</string>
<string name="account">Cuenta</string>
<string name="please_try_again_later">inténtelo de nuevo más tarde</string>

<string name="change_profile_photo">Cambio de perfil de fotos</string>
<string name="edit_profile">Editar perfil</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
<string name="password_changed_successfully">Password telah berhasil diubah.</string>
<string name="something_is_wrong">Ada yang salah. Silakan coba lagi nanti.</string>
<string name="account">Akun</string>
<string name="please_try_again_later">Silakan coba lagi nanti</string>

<string name="change_profile_photo">Ganti foto profil</string>
<string name="edit_profile">Sunting profil</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
<string name="profile_feedback_label">Terugkoppeling</string>
<string name="profile_rate_app_label">Beoordeel de app</string>
<string name="save_changed">Wijzigingen opslaan</string>
<string name="please_try_again_later">Probeer het later opnieuw.</string>

<string name="feedback_submitted">Terugkoppeling ingediend. Bedankt voor je tijd :)</string>
<string name="feedback_submission_failed">Indienen van gebruikersfeedback mislukt! Probeer het opnieuw.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
<string name="password_changed_successfully">A senha foi alterada com sucesso.</string>
<string name="something_is_wrong">Algo deu errado. Por favor, tente novamente mais tarde.</string>
<string name="account">Conta</string>
<string name="please_try_again_later">tente novamente mais tarde.</string>

<string name="change_profile_photo">Alterar foto do perfil</string>
<string name="edit_profile">Editar Perfil</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-th/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<string name="password_changed_successfully">การเปลี่ยนรหัสผ่านสำเร็จ</string>
<string name="something_is_wrong">มีบางอย่างผิดพลาด กรุณาลองใหม่อีกครั้ง</string>
<string name="account">บัญชีผู้ใช้</string>
<string name="please_try_again_later">มีบางอย่างผิดพลาด กรุณาลองใหม่อีกครั้ง</string>

<string name="change_profile_photo">เปลี่ยนรูปโปรไฟล์</string>
<string name="edit_profile">แก้ไขโปรไฟล์</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
<string name="profile_feedback_label">Feedback</string>
<string name="profile_rate_app_label">Rate the app</string>
<string name="save_changed">Save Changes</string>
<string name="please_try_again_later">Please try again later</string>

<string name="feedback_submitted">Feedback submitted. Thank you for your time :)</string>
<string name="feedback_submission_failed">Feedback submission failed! Please try again.</string>
Expand Down

0 comments on commit 61a0ebd

Please sign in to comment.