Skip to content

Commit

Permalink
Merge pull request #366 from PeriodPals/chore/remove-annoying-toasts
Browse files Browse the repository at this point in the history
chore/remove-annoying-toasts : Remove useless toasts
  • Loading branch information
charliemangano authored Dec 20, 2024
2 parents f2ebde6 + 0062774 commit 4dd4e08
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 56 deletions.
12 changes: 1 addition & 11 deletions app/src/main/java/com/android/periodpals/ui/alert/AlertLists.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.android.periodpals.ui.alert

import android.content.Context
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -137,15 +135,7 @@ fun AlertListsScreen(
var productFilter by remember { mutableStateOf<Product?>(Product.NO_PREFERENCE) }
var urgencyFilter by remember { mutableStateOf<Urgency?>(null) }

authenticationViewModel.loadAuthenticationUserData(
onFailure = {
Handler(Looper.getMainLooper()).post { // used to show the Toast in the main thread
Toast.makeText(context, "Error loading your data! Try again later.", Toast.LENGTH_SHORT)
.show()
}
Log.d(TAG, "Authentication data is null")
},
)
authenticationViewModel.loadAuthenticationUserData()
userViewModel.loadUsers(
onSuccess = { Log.d(TAG, "loadUsers: Success") },
onFailure = { e: Exception -> Log.e(TAG, "loadUsers: Failure: $e") })
Expand Down
27 changes: 6 additions & 21 deletions app/src/main/java/com/android/periodpals/ui/alert/CreateAlert.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.android.periodpals.ui.alert

import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -96,23 +94,8 @@ fun CreateAlertScreen(
LaunchedEffect(Unit) {
gpsService.askPermissionAndStartUpdates() // Permission to access location
}
authenticationViewModel.loadAuthenticationUserData(
onFailure = {
Handler(Looper.getMainLooper()).post { // used to show the Toast in the main thread
Toast.makeText(context, "Error loading your data! Try again later.", Toast.LENGTH_SHORT)
.show()
}
Log.d(TAG, "Authentication data is null")
})
userViewModel.loadUser(
authenticationViewModel.authUserData.value!!.uid,
onFailure = {
Handler(Looper.getMainLooper()).post { // used to show the Toast in the main thread
Toast.makeText(context, "Error loading your data! Try again later.", Toast.LENGTH_SHORT)
.show()
}
Log.d(TAG, "User data is null")
})
authenticationViewModel.loadAuthenticationUserData()
userViewModel.loadUser(authenticationViewModel.authUserData.value!!.uid)

val name by remember { mutableStateOf(userViewModel.user.value?.name ?: "") }
val uid by remember { mutableStateOf(authenticationViewModel.authUserData.value!!.uid) }
Expand All @@ -126,7 +109,8 @@ fun CreateAlertScreen(
onTabSelect = { route -> navigationActions.navigateTo(route) },
tabList = LIST_TOP_LEVEL_DESTINATION,
selectedItem = navigationActions.currentRoute(),
networkChangeListener = networkChangeListener)
networkChangeListener = networkChangeListener,
)
},
containerColor = MaterialTheme.colorScheme.surface,
contentColor = MaterialTheme.colorScheme.onSurface,
Expand Down Expand Up @@ -205,7 +189,8 @@ fun CreateAlertScreen(
Toast.makeText(
context,
context.getString(R.string.create_alert_toast_successful_submission_message),
Toast.LENGTH_SHORT)
Toast.LENGTH_SHORT,
)
.show()
navigationActions.navigateTo(Screen.ALERT_LIST)
},
Expand Down
20 changes: 7 additions & 13 deletions app/src/main/java/com/android/periodpals/ui/map/Map.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.android.periodpals.ui.map

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.isSystemInDarkTheme
Expand Down Expand Up @@ -128,14 +126,7 @@ fun MapScreen(
var urgencyFilter by remember { mutableStateOf<Urgency?>(null) }

// Fetch alerts
authenticationViewModel.loadAuthenticationUserData(
onFailure = {
Handler(Looper.getMainLooper()).post {
Toast.makeText(context, "Error loading your data! Try again later.", Toast.LENGTH_SHORT)
.show()
}
Log.d(TAG, "Authentication data is null")
})
authenticationViewModel.loadAuthenticationUserData()
val uid by remember { mutableStateOf(authenticationViewModel.authUserData.value!!.uid) }
alertViewModel.setUserID(uid)

Expand Down Expand Up @@ -199,7 +190,8 @@ fun MapScreen(
onTabSelect = { route -> navigationActions.navigateTo(route) },
tabList = LIST_TOP_LEVEL_DESTINATION,
selectedItem = navigationActions.currentRoute(),
networkChangeListener = networkChangeListener)
networkChangeListener = networkChangeListener,
)
},
topBar = { TopAppBar(title = context.getString(R.string.map_screen_title)) },
floatingActionButton = {
Expand Down Expand Up @@ -250,7 +242,8 @@ fun MapScreen(
myUid = authUserData.uid,
palUid = alertViewModel.selectedAlert.value!!.uid,
myName = userViewModel.user.value!!.name,
palName = alertViewModel.selectedAlert.value!!.name)
palName = alertViewModel.selectedAlert.value!!.name,
)
Log.d(TAG, "Channel CID: $channelCid")
channelCid?.let {
val intent = ChannelActivity.getIntent(context, channelCid)
Expand All @@ -270,7 +263,8 @@ fun MapScreen(
},
onFailure = { e ->
Log.e(TAG, "deleteAlert: fail to delete alert: ${e.message}")
})
},
)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.android.periodpals.ui.profile

import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -91,14 +88,7 @@ fun ProfileScreen(
chatViewModel,
userState,
onSuccess = { Log.d(TAG, "User data loaded successfully") },
onFailure = { e: Exception ->
Log.d(TAG, "Error loading user data: $e")
Handler(Looper.getMainLooper()).post { // used to show the Toast in the main thread
Toast.makeText(context, "Error loading your data! Try again later.", Toast.LENGTH_SHORT)
.show()
}
},
)
onFailure = { Log.d(TAG, "Error loading user data: $it") })

// Only executed once
LaunchedEffect(Unit) { notificationService.askPermission() }
Expand Down

0 comments on commit 4dd4e08

Please sign in to comment.