From 3d1b26f290fba4e7dd826f3c02a6846619fd5747 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 8 Aug 2019 12:57:10 +0200 Subject: [PATCH] Fix issue with monthly dailies. Fixes #1195 --- Habitica/res/values/strings.xml | 2 +- .../ui/activities/TaskFormActivity.kt | 2 +- .../tasks/form/TaskSchedulingControls.kt | 80 +++++++++++-------- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/Habitica/res/values/strings.xml b/Habitica/res/values/strings.xml index fe30e4047..aa72ceb1f 100644 --- a/Habitica/res/values/strings.xml +++ b/Habitica/res/values/strings.xml @@ -589,7 +589,7 @@ Reload Content Set Dailies default to ‘due’ tab With this option set, the Dailies tasks will default to ‘due’ instead of ‘all’ - "Repeats %1$s every %2$s %3$s %4$s" + "Repeats %1$s every %2$s%3$s %4$s" Your device does not have any of the supported payment methods. Please use the habitica website if you want to purchase gems. Your device does not have any of the supported payment methods. Please use the habitica website if you want to purchase a subscription. diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/TaskFormActivity.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/TaskFormActivity.kt index 724643033..3b31c57a6 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/TaskFormActivity.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/TaskFormActivity.kt @@ -338,12 +338,12 @@ class TaskFormActivity : BaseActivity() { } Task.TYPE_DAILY -> { taskSchedulingControls.startDate = task.startDate ?: Date() - taskSchedulingControls.frequency = task.frequency ?: Task.FREQUENCY_DAILY taskSchedulingControls.everyX = task.everyX ?: 1 task.repeat?.let { taskSchedulingControls.weeklyRepeat = it } taskSchedulingControls.daysOfMonth = task.getDaysOfMonth() taskSchedulingControls.weeksOfMonth = task.getWeeksOfMonth() habitAdjustPositiveStreakView.setText((task.streak ?: 0).toString()) + taskSchedulingControls.frequency = task.frequency ?: Task.FREQUENCY_DAILY } Task.TYPE_TODO -> taskSchedulingControls.dueDate = task.dueDate Task.TYPE_REWARD -> rewardValueFormView.value = task.value diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt index eda51ed14..65d163cf7 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt @@ -3,6 +3,8 @@ package com.habitrpg.android.habitica.ui.views.tasks.form import android.app.DatePickerDialog import android.content.Context import android.content.DialogInterface +import android.icu.text.MessageFormat +import android.os.Build import android.text.TextUtils import android.util.AttributeSet import android.view.View @@ -288,52 +290,62 @@ class TaskSchedulingControls @JvmOverloads constructor( var frequencyQualifier = "" when (frequency) { - "daily" -> frequencyQualifier = "day(s)" - "weekly" -> frequencyQualifier = "week(s)" - "monthly" -> frequencyQualifier = "month(s)" - "yearly" -> frequencyQualifier = "year(s)" + "daily" -> frequencyQualifier = if (everyX == 1) "day" else "days" + "weekly" -> frequencyQualifier = if (everyX == 1) "week" else "weeks" + "monthly" -> frequencyQualifier = if (everyX == 1) "month" else "months" + "yearly" -> frequencyQualifier = if (everyX == 1) "year" else "years" } - var weekdays: String - val weekdayStrings = ArrayList() - if (weeklyRepeat.m) { - weekdayStrings.add("Monday") - } - if (weeklyRepeat.t) { - weekdayStrings.add("Tuesday") - } - if (weeklyRepeat.w) { - weekdayStrings.add("Wednesday") - } - if (weeklyRepeat.th) { - weekdayStrings.add("Thursday") - } - if (weeklyRepeat.f) { - weekdayStrings.add("Friday") - } - if (weeklyRepeat.s) { - weekdayStrings.add("Saturday") - } - if (weeklyRepeat.su) { - weekdayStrings.add("Sunday") - } - weekdays = " on " + TextUtils.join(", ", weekdayStrings) - if (frequency != "weekly") { - weekdays = "" + var weekdays = if (frequency == "weekly") { + val weekdayStrings = ArrayList() + if (weeklyRepeat.m) { + weekdayStrings.add("Monday") + } + if (weeklyRepeat.t) { + weekdayStrings.add("Tuesday") + } + if (weeklyRepeat.w) { + weekdayStrings.add("Wednesday") + } + if (weeklyRepeat.th) { + weekdayStrings.add("Thursday") + } + if (weeklyRepeat.f) { + weekdayStrings.add("Friday") + } + if (weeklyRepeat.s) { + weekdayStrings.add("Saturday") + } + if (weeklyRepeat.su) { + weekdayStrings.add("Sunday") + } + " on " + TextUtils.join(", ", weekdayStrings) + } else { + "" } if (frequency == "monthly") { - weekdays = if (daysOfMonth != null) { + weekdays = if (daysOfMonth?.isNotEmpty() == true) { val date = startDateCalendar.get(Calendar.DATE) - " on the $date" + val formattedDate = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + val formatter = MessageFormat("{0,ordinal}", Locale.getDefault()) + formatter.format(arrayOf(date)) + } else date.toString() + " on the $formattedDate" } else { val week = startDateCalendar.get(Calendar.WEEK_OF_MONTH) + val formattedWeek = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + val formatter = MessageFormat("{0,ordinal}", Locale.getDefault()) + formatter.format(arrayOf(week)) + } else week.toString() val dayLongName = startDateCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()) - " on the $week week on $dayLongName" + " on the $formattedWeek week on $dayLongName" } } - val summary = resources.getString(R.string.repeat_summary, frequency, everyX.toString(), frequencyQualifier, weekdays) + val everyXString = if (everyX == 1) "" else "$everyX " + + val summary = resources.getString(R.string.repeat_summary, frequency, everyXString, frequencyQualifier, weekdays) summaryTextView.text = summary } } \ No newline at end of file