Problem solved. I removed the viewmodel and replaced it with the following code
override fun doWork(): Result {
val sharedPreferences = applicationContext.getSharedPreferences("AppPrefs", Context.MODE_PRIVATE)
val lastIndex = sharedPreferences.getInt("lastIndex", -1)
val phrases = listOf(
"Hello!", "Good morning!", "How are you?", "Nice to meet you!", "Good luck!",
"See you soon!", "Take care!", "Have a great day!", "Welcome!", "Congratulations!",
"Happy Birthday!", "Safe travels!", "Enjoy your meal!", "Sweet dreams!", "Get well soon!",
"Well done!", "Thank you!", "I love you!", "Good night!", "Goodbye!"
)
val nextIndex = (lastIndex + 1) % phrases.size
val nextPhrase = phrases[nextIndex]
val editor = sharedPreferences.edit()
editor.putInt("lastIndex", nextIndex)
editor.apply()
sendNotification(nextPhrase)
return Result.success()
}