Skip to content

Commit

Permalink
Merge pull request wordpress-mobile#18753 from wordpress-mobile/featu…
Browse files Browse the repository at this point in the history
…re/18429-reminders-settings-ui-sync

Blogging Prompts: Add syncing reminder UI with remote prompts schedule
  • Loading branch information
dvdchr authored May 30, 2022
2 parents 91eb454 + 62a5afd commit 6590dcc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ public class BloggingPromptSettings: NSManagedObject {
reminderDays?.configure(with: remoteSettings.reminderDays)
}

func reminderTimeDate() -> Date? {
guard let reminderTime = reminderTime else {
return nil
}
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH.mm"
return dateFormatter.date(from: reminderTime)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,21 @@ public class BloggingPromptSettingsReminderDays: NSManagedObject {
self.sunday = remoteReminderDays.sunday
}

func getActiveWeekdays() -> [BloggingRemindersScheduler.Weekday] {
return [
sunday,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday
].enumerated().compactMap { (index: Int, isReminderActive: Bool) in
guard isReminderActive else {
return nil
}
return BloggingRemindersScheduler.Weekday(rawValue: index)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ class BloggingRemindersScheduler {
case .weekDaysWithTime(let daysWithTime):
return daysWithTime.time
default:
return Calendar.current.date(from: DateComponents(calendar: Calendar.current, hour: Weekday.defaultHour, minute: 0)) ?? Date()
let settings = BloggingPromptsService(blog: blog)?.localSettings
let defaultTime = Calendar.current.date(from: DateComponents(calendar: Calendar.current, hour: Weekday.defaultHour, minute: 0)) ?? Date()

if FeatureFlag.bloggingPrompts.enabled, settings?.promptRemindersEnabled ?? false {
return settings?.reminderTimeDate() ?? defaultTime
} else {
return defaultTime
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,16 @@ class BloggingRemindersFlowSettingsViewController: UIViewController {
}()
self.delegate = delegate

let settings = BloggingPromptsService(blog: blog)?.localSettings
scheduler = try BloggingRemindersScheduler()

switch self.scheduler.schedule(for: blog) {
case .none:
previousWeekdays = []
if FeatureFlag.bloggingPrompts.enabled, settings?.promptRemindersEnabled ?? false {
previousWeekdays = settings?.reminderDays?.getActiveWeekdays() ?? []
} else {
previousWeekdays = []
}
case .weekdays(let scheduledWeekdays):
previousWeekdays = scheduledWeekdays
}
Expand Down

0 comments on commit 6590dcc

Please sign in to comment.