Skip to content

Commit

Permalink
TIQR-453: Open recent notification if available
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolnai committed Aug 29, 2024
1 parent 566ab1e commit 04af82c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/src/main/kotlin/nl/eduid/ActivityViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package nl.eduid

import android.content.Context
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import org.tiqr.data.repository.NotificationCacheRepository
import javax.inject.Inject

@HiltViewModel
class ActivityViewModel @Inject constructor(
private val notificationCacheRepository: NotificationCacheRepository
): ViewModel() {

fun getLastNotificationChallenge(context: Context): String? {
return notificationCacheRepository.getLastNotificationChallenge(context)
}

}
23 changes: 21 additions & 2 deletions app/src/main/kotlin/nl/eduid/MainComposeActivity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package nl.eduid

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint
import nl.eduid.graphs.MainGraph
Expand All @@ -14,12 +18,18 @@ import timber.log.Timber
@AndroidEntryPoint
class MainComposeActivity : ComponentActivity() {

internal val viewModel by viewModels<ActivityViewModel>()
private var navController: NavHostController? = null

override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
setContent {
EduidAppAndroidTheme {
MainGraph(navController = rememberNavController())
navController = rememberNavController().also {
MainGraph(navController = it)
}

}
}
}
Expand All @@ -29,5 +39,14 @@ class MainComposeActivity : ComponentActivity() {
if (intent != null && intent.action == Intent.ACTION_VIEW) {
Timber.d("Intent captured by MainComposeActivity ${this.hashCode()}: Received: ${intent.dataString}.")
}
if (intent?.dataString == null) {
viewModel.getLastNotificationChallenge(this)?.let { challenge ->
if (intent == null) {
intent = Intent()
}
intent.setData(Uri.parse(challenge))
navController?.navigate(Uri.parse(challenge))
}
}
}
}
}
15 changes: 11 additions & 4 deletions app/src/main/kotlin/nl/eduid/messaging/EduIdMessagingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import nl.eduid.R
import org.tiqr.data.repository.NotificationCacheRepository
import org.tiqr.data.repository.base.TokenRegistrarRepository
import timber.log.Timber
import javax.inject.Inject
Expand All @@ -33,13 +34,16 @@ class EduIdMessagingService : FirebaseMessagingService() {
private val scope = CoroutineScope(Dispatchers.IO + job)

@Inject
internal lateinit var repository: TokenRegistrarRepository
internal lateinit var tokenRegistrarRepository: TokenRegistrarRepository

@Inject
internal lateinit var notificationCacheRepository: NotificationCacheRepository

override fun onNewToken(token: String) {
super.onNewToken(token)

scope.launch {
repository.registerDeviceToken(token)
tokenRegistrarRepository.registerDeviceToken(token)
}
}

Expand Down Expand Up @@ -96,8 +100,11 @@ class EduIdMessagingService : FirebaseMessagingService() {
.setColor(resources.getColor(R.color.primaryColor))
.build()
.apply {
Timber.e("Sending notification")
notificationManager.notify(0, this)
val identifier = System.currentTimeMillis().toInt()
Timber.e("Sending notification with ID: $identifier")
val authenticationTimeout = message.data["authenticationTimeout"]?.toIntOrNull() ?: 150
notificationManager.notify(identifier, this)
notificationCacheRepository.saveLastNotificationData(challenge, authenticationTimeout, identifier)
}
}
}
Expand Down

0 comments on commit 04af82c

Please sign in to comment.