From 941ce87fd938188db5e0abf3a73fcfe671228a20 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Wed, 22 Aug 2018 20:07:41 +0200 Subject: [PATCH] Start adding random motivational tips to daily checkin. See #1007 --- Habitica/res/values/strings.xml | 4 ++++ .../habitica/receivers/NotificationPublisher.kt | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Habitica/res/values/strings.xml b/Habitica/res/values/strings.xml index c816ee130..85d9a4ca6 100644 --- a/Habitica/res/values/strings.xml +++ b/Habitica/res/values/strings.xml @@ -793,4 +793,8 @@ The more you add, the more you\'ll be rewarded. Even small habits add up to big change. Remember to check your tasks! There\'s lots of unlock and discover at you level up, so keep up with your tasks and have fun! + Use the mobile apps to set reminders for your tasks. + Add checklists to your To-Dos to multiply your rewards! + Complete all your Dailies to get a Perfect Day Buff that increases your Stats! + Occasionally re-evaluate your tasks to make sure they’re up-to-date! diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/receivers/NotificationPublisher.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/receivers/NotificationPublisher.kt index 01ab71631..775be7439 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/receivers/NotificationPublisher.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/receivers/NotificationPublisher.kt @@ -77,6 +77,7 @@ class NotificationPublisher : WakefulBroadcastReceiver() { val notification: Notification val builder = Notification.Builder(thisContext) builder.setContentTitle(thisContext.getString(R.string.reminder_title)) + builder.setContentText(getRandomDailyTip()) if (registrationDate != null) { val registrationCal = Calendar.getInstance() registrationCal.time = registrationDate @@ -119,6 +120,18 @@ class NotificationPublisher : WakefulBroadcastReceiver() { return notification } + private fun getRandomDailyTip(): String { + val thisContext = context ?: return "" + val index = Random().nextInt(4) + return when (index) { + 0 -> thisContext.getString(R.string.daily_tip_0) + 1 -> thisContext.getString(R.string.daily_tip_1) + 2 -> thisContext.getString(R.string.daily_tip_2) + 3 -> thisContext.getString(R.string.daily_tip_3) + else -> "" + } + } + companion object { var NOTIFICATION_ID = "notification-id"