79298215

Date: 2024-12-20 19:24:15
Score: 2
Natty:
Report link

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()
}
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (1): Good morning
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: developer_petit