Skip to content

Commit

Permalink
feat: add accept logic in map
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarinibruno committed Dec 20, 2024
1 parent b9382d0 commit 04cb16e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/java/com/android/periodpals/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ fun PeriodPalsApp(
authenticationViewModel,
alertViewModel,
locationViewModel,
chatViewModel,
userViewModel,
navigationActions)
}
}
Expand Down
24 changes: 23 additions & 1 deletion app/src/main/java/com/android/periodpals/ui/map/Map.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.ContextCompat
import com.android.periodpals.BuildConfig
import com.android.periodpals.ChannelActivity
import com.android.periodpals.R
import com.android.periodpals.model.alert.Alert
import com.android.periodpals.model.alert.AlertViewModel
Expand All @@ -43,8 +44,10 @@ import com.android.periodpals.model.alert.stringToProduct
import com.android.periodpals.model.alert.stringToUrgency
import com.android.periodpals.model.alert.urgencyToPeriodPalsIcon
import com.android.periodpals.model.authentication.AuthenticationViewModel
import com.android.periodpals.model.chat.ChatViewModel
import com.android.periodpals.model.location.Location
import com.android.periodpals.model.location.LocationViewModel
import com.android.periodpals.model.user.UserViewModel
import com.android.periodpals.resources.C
import com.android.periodpals.services.GPSServiceImpl
import com.android.periodpals.ui.components.CONTENT
Expand Down Expand Up @@ -95,6 +98,8 @@ fun MapScreen(
authenticationViewModel: AuthenticationViewModel,
alertViewModel: AlertViewModel,
locationViewModel: LocationViewModel,
chatViewModel: ChatViewModel,
userViewModel: UserViewModel,
navigationActions: NavigationActions,
) {

Expand Down Expand Up @@ -234,7 +239,24 @@ fun MapScreen(
alertViewModel.selectAlert(alertViewModel.selectedAlert.value!!)
navigationActions.navigateTo(Screen.EDIT_ALERT)
},
onAcceptClick = { TODO("To be implemented") },
onAcceptClick = {
val authUserData = authenticationViewModel.authUserData.value
authUserData?.let {
Log.d(TAG, "Accepting alert from ${authUserData.uid}")
val channelCid =
chatViewModel.createChannel(
myUid = authUserData.uid,
palUid = alertViewModel.selectedAlert.value!!.uid,
myName = userViewModel.user.value!!.name,
palName = alertViewModel.selectedAlert.value!!.name
)
Log.d(TAG, "Channel CID: $channelCid")
channelCid?.let {
val intent = ChannelActivity.getIntent(context, channelCid)
context.startActivity(intent)
}
} ?: Toast.makeText(context, "Error: User data is not available", Toast.LENGTH_SHORT).show()
},
onResolveClick = {
alertViewModel.deleteAlert(
alertViewModel.selectedAlert.value!!.id,
Expand Down

0 comments on commit 04cb16e

Please sign in to comment.