Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and enhancements #1907

Merged
merged 3 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class NotificationService: UNNotificationServiceExtension {
}

private let notificationServiceAppGroup = UserDefaults(suiteName: "group.com.ruuvi.station.pnservice")
private let languageUDKey = "SettingsUserDegaults.languageUDKey"
private let notificationsBadgeCountUDKey = "SettingsUserDefaults.notificationsBadgeCount"

var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
Expand Down Expand Up @@ -60,6 +62,7 @@ class NotificationService: UNNotificationServiceExtension {
bestAttemptContent.body = sensorName
}
}
setAlertBadge(for: bestAttemptContent)

contentHandler(bestAttemptContent)
}
Expand Down Expand Up @@ -109,7 +112,6 @@ extension NotificationService {
return ""
}

let languageUDKey = "SettingsUserDegaults.languageUDKey"
let locale: Locale
if let languageCode = notificationServiceAppGroup?.string(forKey: languageUDKey) {
locale = Locale(identifier: languageCode)
Expand Down Expand Up @@ -152,4 +154,17 @@ extension NotificationService {
}
}
}

private func setAlertBadge(for content: UNMutableNotificationContent) {
let currentValue = notificationServiceAppGroup?
.integer(
forKey: notificationsBadgeCountUDKey
) ?? 0
notificationServiceAppGroup?
.set(
currentValue + 1,
forKey: notificationsBadgeCountUDKey
)
content.badge = (currentValue + 1) as NSNumber
}
}
20 changes: 19 additions & 1 deletion Apps/RuuviStation/Sources/Classes/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func applicationDidBecomeActive(_ application: UIApplication) {
resetNotificationsBadge()
appStateService.applicationDidBecomeActive(application)
}

Expand Down Expand Up @@ -215,10 +216,27 @@ extension AppDelegate {
if let viewModel = controller.viewModels.first(where: { viewModel in
viewModel.mac.value?.value == uuid || viewModel.luid.value == uuid.luid.any
}) {
controller.output.viewDidTriggerOpenCardImageView(for: viewModel)
controller.output.viewDidTriggerOpenSensorCardFromWidget(for: viewModel)
}
}

window?.makeKeyAndVisible()
}
}

// MARK: Notifications badge reset
extension AppDelegate {
private func resetNotificationsBadge() {
if #available(iOS 16.0, *) {
UNUserNotificationCenter.current().setBadgeCount(0) { [weak self] error in
guard error == nil else {
return
}
self?.settings.setNotificationsBadgeCount(value: 0)
}
} else {
settings.setNotificationsBadgeCount(value: 0)
UIApplication.shared.applicationIconBadgeNumber = 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@
openCardView(viewModel: viewModel, showCharts: false)
}

func viewDidTriggerOpenSensorCardFromWidget(for viewModel: CardsViewModel?) {
guard let viewModel else { return }
openCardView(
viewModel: viewModel,

Check warning on line 235 in Apps/RuuviStation/Sources/Classes/Presentation/Modules/Dashboard/Home/Presenter/DashboardPresenter.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
showCharts: settings.dashboardTapActionType == .chart
)
}

func viewDidTriggerDashboardCard(for viewModel: CardsViewModel) {
switch settings.dashboardTapActionType {
case .card:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ protocol DashboardViewOutput {
func viewDidTriggerMenu()
func viewDidTriggerBuySensors()
func viewDidTriggerOpenCardImageView(for viewModel: CardsViewModel?)
func viewDidTriggerOpenSensorCardFromWidget(for viewModel: CardsViewModel?)
func viewDidTriggerSettings(for viewModel: CardsViewModel)
func viewDidTriggerChart(for viewModel: CardsViewModel)
func viewDidTriggerChangeBackground(for viewModel: CardsViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RUAlertDetailsCellChildView: UIView {
let label = UILabel()
label.textAlignment = .left
label.numberOfLines = 0
label.textColor = .label
label.textColor = RuuviColor.textColor.color
label.font = UIFont.Muli(.regular, size: 14)
return label
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class TagSettingsAlertConfigCell: UITableViewCell {
let label = UILabel()
label.textAlignment = .left
label.numberOfLines = 0
label.textColor = .label
label.font = .systemFont(ofSize: 13)
label.textColor = RuuviColor.textColor.color.withAlphaComponent(0.6)
label.font = UIFont.Muli(.regular, size: 12)
return label
}()

Expand All @@ -50,8 +50,8 @@ class TagSettingsAlertConfigCell: UITableViewCell {
label.text = RuuviLocalization.off
label.textAlignment = .right
label.numberOfLines = 0
label.textColor = .label
label.font = .systemFont(ofSize: 14)
label.textColor = RuuviColor.textColor.color
label.font = UIFont.Muli(.regular, size: 14)
return label
}()

Expand Down Expand Up @@ -93,8 +93,8 @@ class TagSettingsAlertConfigCell: UITableViewCell {
let label = UILabel()
label.textAlignment = .left
label.numberOfLines = 0
label.textColor = .label
label.font = .systemFont(ofSize: 14)
label.textColor = RuuviColor.textColor.color
label.font = UIFont.Muli(.regular, size: 14)
return label
}()

Expand Down Expand Up @@ -149,7 +149,7 @@ extension TagSettingsAlertConfigCell {
noticeView.addSubview(noticeLabel)
noticeLabel.fillSuperview(padding: .init(
top: 8,
left: 8,
left: 12,
bottom: 8,
right: 8
))
Expand Down Expand Up @@ -261,7 +261,7 @@ extension TagSettingsAlertConfigCell {
additionalTextViewHiddenHeight.isActive = true

additionalTextView.addSubview(additionalTextLabel)
additionalTextLabel.fillSuperview(padding: .init(top: 0, left: 16, bottom: 0, right: 16))
additionalTextLabel.fillSuperview(padding: .init(top: 0, left: 14, bottom: 0, right: 16))

setCustomDescriptionView.delegate = self
alertLimitDescriptionView.delegate = self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import UIKit
import RuuviLocalization

class TagSettingsFooterCell: UITableViewCell {
private lazy var noteLabel: UILabel = {
let label = UILabel()
label.textAlignment = .left
label.numberOfLines = 0
label.textColor = .secondaryLabel
label.textColor = RuuviColor.textColor.color.withAlphaComponent(0.6)
label.font = UIFont.Muli(.regular, size: 12)
return label
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1676,10 +1676,10 @@ extension TagSettingsViewController {
let settingItem = TagSettingsItem(
createdCell: { [weak self] in
self?.movementAlertCell?
.setAlertAddtionalText(with: RuuviLocalization.TagSettings.Alerts.Movement.description)
.setNoticeText(with: RuuviLocalization.TagSettings.Alerts.Movement.description)
self?.movementAlertCell?.hideAlertRangeSetter()
self?.movementAlertCell?.hideNoticeView()
self?.movementAlertCell?.showAdditionalTextview()
self?.movementAlertCell?.showNoticeView()
self?.movementAlertCell?.hideAdditionalTextview()
self?.movementAlertCell?.delegate = self
self?.movementAlertCell?.disableEditing(
disable: disableMovement,
Expand Down Expand Up @@ -2801,9 +2801,9 @@ extension TagSettingsViewController {

moreInfoBatteryVoltageCell.bind(viewModel.batteryNeedsReplacement) { [weak self]
cell, needsReplacement in
guard let sSelf = self else { return }
let (status, color) = sSelf.formattedBatteryStatus(from: needsReplacement)
cell.configure(note: status, noteColor: color)
guard let sSelf = self else { return }
let (status, color) = sSelf.formattedBatteryStatus(from: needsReplacement)
cell.configure(note: status, noteColor: color)
}
}

Expand Down Expand Up @@ -3083,7 +3083,7 @@ extension TagSettingsViewController {
if let batteryLow {
// swiftlint:disable:next line_length
let batteryStatus = batteryLow ? "(\(RuuviLocalization.TagSettings.BatteryStatusLabel.Replace.message))" : "(\(RuuviLocalization.TagSettings.BatteryStatusLabel.Ok.message))"
let indicatorColor = batteryLow ? .red : RuuviColor.tintColor.color
let indicatorColor = batteryLow ? RuuviColor.orangeColor.color : RuuviColor.tintColor.color
return (status: batteryStatus, color: indicatorColor)
} else {
return (status: nil, color: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@ public protocol RuuviLocalSettings {

func syncDialogHidden(for luid: LocalIdentifier) -> Bool
func setSyncDialogHidden(for luid: LocalIdentifier)

func setNotificationsBadgeCount(value: Int)
func notificationsBadgeCount() -> Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,23 @@ final class RuuviLocalSettingsUserDefaults: RuuviLocalSettings {
}
}
}

private let notificationsBadgeCountUDKey = "SettingsUserDefaults.notificationsBadgeCount"
func setNotificationsBadgeCount(value: Int) {
notificationServiceAppGroup?
.set(
value,
forKey: notificationsBadgeCountUDKey
)
notificationServiceAppGroup?.synchronize()
}

func notificationsBadgeCount() -> Int {
return notificationServiceAppGroup?
.integer(
forKey: notificationsBadgeCountUDKey
) ?? 0
}
}

// swiftlint:enable type_body_length file_length
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public final class RuuviNotificationLocalImpl: NSObject, RuuviNotificationLocal
}
content.userInfo = [blast.uuidKey: uuid, blast.typeKey: BlastNotificationType.connection.rawValue]
content.categoryIdentifier = blast.id
setAlertBadge(for: content)

ruuviStorage.readOne(id(for: uuid)).on(success: { [weak self] ruuviTag in
guard let sSelf = self else { return }
Expand Down Expand Up @@ -171,6 +172,7 @@ public final class RuuviNotificationLocalImpl: NSObject, RuuviNotificationLocal
content.userInfo = [blast.uuidKey: uuid, blast.typeKey: BlastNotificationType.connection.rawValue]
content.categoryIdentifier = blast.id
content.title = title
setAlertBadge(for: content)

ruuviStorage.readOne(id(for: uuid)).on(success: { [weak self] ruuviTag in
guard let sSelf = self else { return }
Expand Down Expand Up @@ -218,6 +220,7 @@ public final class RuuviNotificationLocalImpl: NSObject, RuuviNotificationLocal
}
content.userInfo = [blast.uuidKey: uuid, blast.typeKey: BlastNotificationType.movement.rawValue]
content.categoryIdentifier = blast.id
setAlertBadge(for: content)

content.title = title

Expand Down Expand Up @@ -308,6 +311,7 @@ public extension RuuviNotificationLocalImpl {
content.title = title
content.userInfo = [lowHigh.uuidKey: uuid, lowHigh.typeKey: type.rawValue]
content.categoryIdentifier = lowHigh.id
setAlertBadge(for: content)

let body: String = switch type {
case .temperature:
Expand Down Expand Up @@ -663,6 +667,13 @@ extension RuuviNotificationLocalImpl: UNUserNotificationCenterDelegate {
to: shown
) ?? Date()
}

private func setAlertBadge(for content: UNMutableNotificationContent) {
let currentCount = settings.notificationsBadgeCount()
let newBadgeCount = currentCount + 1
content.badge = newBadgeCount as NSNumber
settings.setNotificationsBadgeCount(value: newBadgeCount)
}
}

extension NSObjectProtocol {
Expand Down
2 changes: 1 addition & 1 deletion station.localization
Loading