Bimba.git

commit 8fc7431eb7ebbf71d2bd1cb312b7000feae1d11b

Author: Adam <git@apiote.xyz>

show dialog after not getting location permission

 app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt | 14 
 app/src/main/res/values/strings.xml | 3 


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt
index 51cb36bc52d9201258e7e540598cd910b9f2caaa..eeece9a4a3c56b2e206fc1dc7da7742b93acb9a4 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt
@@ -10,6 +10,7 @@ import androidx.activity.OnBackPressedCallback
 import androidx.activity.result.ActivityResultLauncher
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.content.res.AppCompatResources
 import androidx.core.content.ContextCompat
 import androidx.core.content.edit
 import androidx.core.view.WindowCompat
@@ -21,6 +22,7 @@ import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
 import androidx.navigation.fragment.NavHostFragment
 import androidx.navigation.ui.setupWithNavController
 import com.google.android.material.bottomnavigation.BottomNavigationView
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
 import com.google.openlocationcode.OpenLocationCode
 import xyz.apiote.bimba.czwek.R
 import xyz.apiote.bimba.czwek.dashboard.ui.home.HomeFragment
@@ -37,6 +39,7 @@ 	private lateinit var binding: ActivityMainBinding
 	private lateinit var locationPermissionRequest: ActivityResultLauncher<Array<String>>
 
 	private lateinit var permissionAsker: Fragment
+	var locationPermissionDialogShown = false
 
 	override fun onCreate(savedInstanceState: Bundle?) {
 		super.onCreate(savedInstanceState)
@@ -118,8 +121,15 @@ 					}
 				}
 
 				else -> {
-					// todo(ux,ui) dialog
-					Toast.makeText(this, "No location access given", Toast.LENGTH_SHORT).show()
+					if (locationPermissionDialogShown) {
+						return@registerForActivityResult
+					}
+					MaterialAlertDialogBuilder(this).setIcon(AppCompatResources.getDrawable(this, R.drawable.error_gps))
+						.setTitle(getString(R.string.no_location_access))
+						.setMessage(getString(R.string.no_location_message))
+						.setPositiveButton(resources.getString(R.string.ok)) { _, _ ->}
+						.show()
+					locationPermissionDialogShown = true
 				}
 			}
 		}




diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 366e44ad629b6ee47e17bf3409aa8f01d0291896..c29273c10f337a92325bd503d2243d31bb529227 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -87,4 +87,7 @@ 	Cannot verify traffic server
 	<string name="stops_near_code">Stops near %1$s</string>
 	<string name="code_is_not_full">Code is not full</string>
 	<string name="choose_server">Choose server flavour</string>
+	<string name="ok">OK</string>
+	<string name="no_location_access">Location access not given</string>
+	<string name="no_location_message">Permission to use location is needed to find nearby stops and show current position on map. Other features will work without it.\nIt can be enabled and disabled in system settings any time.</string>
 </resources>
\ No newline at end of file