Skip to content

Commit

Permalink
Merge pull request #47 from CathalOConnorRH/dev
Browse files Browse the repository at this point in the history
Merge from Dev to Main for release 1.0
  • Loading branch information
CathalOConnorRH authored Apr 30, 2024
2 parents 629f78b + f840fb5 commit 7f123c2
Show file tree
Hide file tree
Showing 40 changed files with 569 additions and 959 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ dependencies {
implementation ("com.squareup.moshi:moshi-kotlin:1.15.1")

implementation ("com.jakewharton.timber:timber:5.0.1")

}
implementation ("me.saket.swipe:swipe:1.3.0")
}
11 changes: 0 additions & 11 deletions app/src/main/java/ie/coconnor/mobileappdev/Atrraction.kt

This file was deleted.

8 changes: 0 additions & 8 deletions app/src/main/java/ie/coconnor/mobileappdev/Attractions.kt

This file was deleted.

102 changes: 42 additions & 60 deletions app/src/main/java/ie/coconnor/mobileappdev/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package ie.coconnor.mobileappdev

import android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.annotation.SuppressLint
Expand All @@ -11,10 +12,9 @@ import android.content.Intent
import android.content.IntentSender
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.speech.tts.TextToSpeech
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -43,23 +43,26 @@ import androidx.navigation.navArgument
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.android.gms.common.api.ResolvableApiException
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingClient
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.LocationSettingsRequest
import com.google.android.gms.location.LocationSettingsResponse
import com.google.android.gms.location.Priority
import com.google.android.gms.location.SettingsClient
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.tasks.Task
import dagger.hilt.android.AndroidEntryPoint
import ie.coconnor.mobileappdev.models.AuthState
import ie.coconnor.mobileappdev.models.Constants.BACKGROUND_LOCATION_PERMISSION_REQUEST_CODE
import ie.coconnor.mobileappdev.models.Constants.Geofencing.LOCATION_FASTEST_INTERVAL
import ie.coconnor.mobileappdev.models.Constants.Geofencing.LOCATION_INTERVAL
import ie.coconnor.mobileappdev.models.Constants.Geofencing.REQUEST_CHECK_SETTINGS
import ie.coconnor.mobileappdev.models.Constants.Geofencing.REQUEST_CODE
import ie.coconnor.mobileappdev.models.Constants.LOCATION_PERMISSION_REQUEST_CODE
import ie.coconnor.mobileappdev.models.DataProvider
import ie.coconnor.mobileappdev.models.auth.AuthState
import ie.coconnor.mobileappdev.models.auth.AuthViewModel
import ie.coconnor.mobileappdev.models.auth.DataProvider
import ie.coconnor.mobileappdev.models.locations.LocationDetailsViewModel
import ie.coconnor.mobileappdev.models.locations.LocationsViewModel
import ie.coconnor.mobileappdev.models.plan.PlanViewModel
Expand All @@ -72,8 +75,7 @@ import ie.coconnor.mobileappdev.ui.login.LoginScreen
import ie.coconnor.mobileappdev.ui.navigation.BottomBar
import ie.coconnor.mobileappdev.ui.navigation.Destinations
import ie.coconnor.mobileappdev.ui.plan.PlanScreen
import ie.coconnor.mobileappdev.ui.screens.SettingsScreen
import ie.coconnor.mobileappdev.ui.screens.TestScreen
import ie.coconnor.mobileappdev.ui.settings.SettingsScreen
import ie.coconnor.mobileappdev.ui.theme.MobileAppDevTheme
import ie.coconnor.mobileappdev.utils.SharedPref
import ie.coconnor.mobileappdev.utils.UIThemeController
Expand All @@ -93,7 +95,7 @@ class MainActivity : ComponentActivity() {

private lateinit var fusedLocationClient: FusedLocationProviderClient
lateinit var geofencingClient: GeofencingClient
// private val geofenceList = mutableListOf<Geofence>()
private val geofenceList = mutableListOf<Geofence>()

private val geofencePendingIntent: PendingIntent by lazy {
val intent = Intent(this, GeofenceBroadcastReceiver::class.java)
Expand All @@ -106,7 +108,7 @@ class MainActivity : ComponentActivity() {
}


// lateinit var textToSpeech: TextToSpeech
lateinit var textToSpeech: TextToSpeech


@OptIn(ExperimentalPermissionsApi::class)
Expand All @@ -119,21 +121,33 @@ class MainActivity : ComponentActivity() {
Timber.plant(Timber.DebugTree())
}

// textToSpeech.language = Locale.US

textToSpeech = TextToSpeech(this) {status ->
if (status == TextToSpeech.SUCCESS){
Timber.tag("TAG").d("TextToSpeech Initialization Success")
// textToSpeech.speak("test text to speech", TextToSpeech.QUEUE_FLUSH, null, null)

}else{
Timber.tag("TAG").d("TextToSpeech Initialization Failed")
}
}

Timber.tag(TAG).i("Creating geofence client")
geofencingClient = LocationServices.getGeofencingClient(this)
//check permission
if (ActivityCompat.checkSelfPermission(
this,
android.Manifest.permission.ACCESS_FINE_LOCATION
ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
) {
currentLocation()
} else {
ActivityCompat.requestPermissions(
this,
arrayOf(
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
ACCESS_FINE_LOCATION,
ACCESS_BACKGROUND_LOCATION
),
REQUEST_CODE
)
Expand All @@ -159,9 +173,8 @@ class MainActivity : ComponentActivity() {
// )
// window.setTitle("Test")
createLocationRequest()
// createGeofence()
// println(sharedPref.getDarkMode())
// UIThemeController.updateUITheme(sharedPref.getDarkMode())
// createGeofence()

setContent {
val isDarkMode by UIThemeController.isDarkMode.collectAsState()
MobileAppDevTheme (darkTheme = isDarkMode){
Expand All @@ -188,7 +201,7 @@ class MainActivity : ComponentActivity() {
Box(
modifier = Modifier.padding(paddingValues)
) {
NavigationGraph(navController = navController, authViewModel = authViewModel, tourViewModel = tourViewModel, locationDetailsViewModel = locationDetailsViewModel, planViewModel, sharedPref = sharedPref)
NavigationGraph(navController = navController, authViewModel = authViewModel, tourViewModel = tourViewModel, locationDetailsViewModel = locationDetailsViewModel, planViewModel, sharedPref = sharedPref, geofencingClient)
}
}
}
Expand All @@ -201,11 +214,11 @@ class MainActivity : ComponentActivity() {
ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
}

private fun openApplicationSettings() {
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", packageName, null)).also {
startActivity(it)
}
}
// private fun openApplicationSettings() {
// Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", packageName, null)).also {
// startActivity(it)
// }
// }

private fun decideCurrentPermissionStatus(locationPermissionsGranted: Boolean,
shouldShowPermissionRationale: Boolean): String {
Expand Down Expand Up @@ -247,7 +260,7 @@ class MainActivity : ComponentActivity() {
val locationRequest = LocationRequest.create().apply {
interval = LOCATION_INTERVAL
fastestInterval = LOCATION_FASTEST_INTERVAL
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
Priority.PRIORITY_HIGH_ACCURACY
}

val builder = LocationSettingsRequest.Builder()
Expand Down Expand Up @@ -276,7 +289,7 @@ class MainActivity : ComponentActivity() {
}
}
}
// private fun createGeofence(){
// private fun createGeofence(){
// geofenceList.add(
// Geofence.Builder()
// .setRequestId("entry.key")
Expand Down Expand Up @@ -310,7 +323,7 @@ class MainActivity : ComponentActivity() {
// addGeofences(geofenceList)
// }.build()
// }
//

private fun checkBackGroundLocationPermission(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
(ContextCompat.checkSelfPermission(
Expand All @@ -336,6 +349,7 @@ class MainActivity : ComponentActivity() {
private fun checkAndRequestLocationPermissions() {
if (checkLocationPermission()) {
if (checkBackGroundLocationPermission()){
Timber.tag(TAG).i("Start Location Service")
startLocationService()
}else{
requestBackGroundLocationPermission()
Expand Down Expand Up @@ -403,43 +417,15 @@ class MainActivity : ComponentActivity() {
}
}


//@Composable
//fun getPermissions(){
// val lifecycleOwner = LocalLifecycleOwner.current
// val permissionState = rememberMultiplePermissionsState(permissions = listOf(
// ACCESS_COARSE_LOCATION,
// ACCESS_FINE_LOCATION
// ))
//
// DisposableEffect(key1 = lifecycleOwner) {
// val observer = LifecycleEventObserver{ source, event ->
// when (event) {
// Lifecycle.Event.ON_START -> {
// permissionState.launchMultiplePermissionRequest()
// }
//
// else -> {
//
// }
// }
//
// }
// lifecycleOwner.lifecycle.addObserver(observer)
// onDispose {
// lifecycleOwner.lifecycle.removeObserver(observer)
// }
// }
//}

@Composable
fun NavigationGraph(navController: NavHostController,
authViewModel: AuthViewModel,
tourViewModel: LocationsViewModel,
locationDetailsViewModel: LocationDetailsViewModel,
planViewModel: PlanViewModel,
sharedPref: SharedPref) {
var startDestination = Destinations.TestScreen.route
sharedPref: SharedPref,
geoFencingClient: GeofencingClient) {
var startDestination = Destinations.LocationsScreen.route

if (DataProvider.authState == AuthState.SignedOut)
{
Expand All @@ -454,19 +440,15 @@ fun NavigationGraph(navController: NavHostController,
}
// composable(Destinations.PlanScreenWithId.route + "/{location}", arguments = listOf(navArgument("location") { type = NavType.StringType })
composable(Destinations.PlanScreen.route ) {
PlanScreen(planViewModel, navController, sharedPref)
}

composable(Destinations.TestScreen.route) {
TestScreen(navController)
PlanScreen(planViewModel, navController, geoFencingClient)
}
composable(Destinations.SettingsScreen.route) {
SettingsScreen(navController, authViewModel)
}
composable(Destinations.LocationDetailsScreen.route + "/{location}", arguments = listOf(navArgument("location") { type = NavType.StringType })
) { backStackEntry ->
val location = backStackEntry.arguments?.getString("location")
LocationDetailsScreen(navController, locationDetailsViewModel, location)
LocationDetailsScreen(locationDetailsViewModel, location)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Constants {
const val EMAIL_ALREADY_IN_USE = "ERROR_EMAIL_ALREADY_IN_USE"
}
object Geofencing {
const val RADIUS = 20f
const val RADIUS = 70f
const val REQUEST_CODE = 200
const val REQUEST_CHECK_SETTINGS = 101
const val LOCATION_INTERVAL = 100L
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ie.coconnor.mobileappdev
package ie.coconnor.mobileappdev.models.auth


import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import ie.coconnor.mobileappdev.models.DataProvider
import ie.coconnor.mobileappdev.models.Response
import ie.coconnor.mobileappdev.repository.AuthRepository
import com.google.android.gms.auth.api.identity.SignInClient
import com.google.android.gms.auth.api.identity.SignInCredential
import dagger.hilt.android.lifecycle.HiltViewModel
import ie.coconnor.mobileappdev.models.Response
import ie.coconnor.mobileappdev.repository.AuthRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package ie.coconnor.mobileappdev.models
package ie.coconnor.mobileappdev.models.auth


import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.google.firebase.auth.FirebaseUser
import ie.coconnor.mobileappdev.models.FirebaseSignInResponse
import ie.coconnor.mobileappdev.models.OneTapSignInResponse
import ie.coconnor.mobileappdev.models.Response.Success
import ie.coconnor.mobileappdev.models.SignOutResponse

enum class AuthState {
Authenticated, SignedIn, SignedOut;
Expand All @@ -31,7 +34,7 @@ object DataProvider {
private set

fun updateAuthState(user: FirebaseUser?) {
this.user = user
DataProvider.user = user
isAuthenticated = user != null
isAnonymous = user?.isAnonymous ?: false

Expand All @@ -43,13 +46,13 @@ object DataProvider {
}

fun getDisplayName(user: FirebaseUser?): String{
this.user = user
DataProvider.user = user
val displayName = user!!.displayName
return displayName.toString()
}

fun getProfilePhoto(user: FirebaseUser?): String{
this.user = user
DataProvider.user = user
val photoUrl = user!!.photoUrl
return photoUrl.toString().replace("s96", "s250")
}
Expand Down
Loading

0 comments on commit 7f123c2

Please sign in to comment.