-
Notifications
You must be signed in to change notification settings - Fork 10
[BM-667] Feedback - baby device side #263
base: BM-667_User_feedback
Are you sure you want to change the base?
[BM-667] Feedback - baby device side #263
Conversation
Added checking the frequency of feedback requests Added sending feedback requests with the notifications Added tests
@@ -47,6 +47,11 @@ class BabyMonitorMessagingService : FirebaseMessagingService() { | |||
message.data | |||
) | |||
NotificationType.LOW_BATTERY_NOTIFICATION -> handleLowBatteryNotification(message.data) | |||
NotificationType.CRY_NOTIFICATION_WITH_FEEDBACK_REQUEST, | |||
NotificationType.NOISE_NOTIFICATION_WITH_FEEDBACK_REQUEST -> { | |||
// TODO handle notification with feedback request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment contains text that has been defined as forbidden in detekt. |
@@ -15,14 +17,30 @@ class NotifyBabyEventUseCase( | |||
private val babyEvents: PublishSubject<BabyEvent> = PublishSubject.create() | |||
|
|||
private fun fetchClientsAndPostNotification(babyEvent: BabyEvent): Completable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function fetchClientsAndPostNotification appears to be too complex. |
Timber.d("Notification posted: $response.") | ||
} | ||
.ignoreElement() | ||
} | ||
|
||
private fun updateFeedbackData(notificationData: NotificationData) { | ||
feedbackFrequencyUseCase.notificationSent() | ||
if (notificationData.feedbackRecordingFile.isNotEmpty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multi-line if statement was found that does not have braces. These should be added to improve readability. |
private fun updateFeedbackData(notificationData: NotificationData) { | ||
feedbackFrequencyUseCase.notificationSent() | ||
if (notificationData.feedbackRecordingFile.isNotEmpty()) | ||
feedbackFrequencyUseCase.feedbackRequestSent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing { … } |
title: String, | ||
text: String, | ||
notificationType: NotificationType | ||
notificationData: NotificationData | ||
): Single<Response> { | ||
return checkIdCall(firebaseToken) | ||
.flatMap { isAndroid -> | ||
return@flatMap notificationCall( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expression with labels increase complexity and affect maintainability. |
Timber.d("Sound Db: $decibels") | ||
return@fromCallable decibels.roundToInt() | ||
Timber.d("Max Db: $maxDecibels") | ||
return@fromCallable maxDecibels?.roundToInt() ?: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expression with labels increase complexity and affect maintainability. |
} | ||
|
||
private fun mapToDecibels(shorts: List<Short>): Double { | ||
var totalSquared = 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected indentation (7) (it should be 8) |
@@ -26,10 +29,11 @@ class RecordingController @Inject constructor( | |||
.map { | |||
val data = when { | |||
isMachineLearningWithEnoughData(it) -> RecordingData.MachineLearning( | |||
it.first.takeLast(MachineLearning.DATA_SIZE * 2).toByteArray(), | |||
it.first.takeLast(FeedbackController.DATA_SIZE * 2).toByteArray(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This expression contains a magic number. Consider defining it to a well named constant. |
it.second.takeLast(MachineLearning.DATA_SIZE).toShortArray() | ||
) | ||
isNoiseDetectionWithEnoughData(it) -> RecordingData.NoiseDetection( | ||
it.first.takeLast(FeedbackController.DATA_SIZE * 2).toByteArray(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This expression contains a magic number. Consider defining it to a well named constant. |
) = Single.fromCallable { | ||
// TODO add metadata to the recordings (should be consulted with ML dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment contains text that has been defined as forbidden in detekt. |
.subscribeOn(Schedulers.io()) | ||
.subscribeBy( | ||
onSuccess = { savedRecordingData -> | ||
Timber.i("Recording saved: ${savedRecordingData.fileName}" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace String concatenation with Timber’s string formatting |
.subscribeOn(Schedulers.io()) | ||
.subscribeBy( | ||
onSuccess = { savedRecordingData -> | ||
Timber.i("Recording saved: ${savedRecordingData.fileName}" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple occurrences of the same string literal within a single file detected. |
.subscribeBy( | ||
onSuccess = { savedRecordingData -> | ||
Timber.i("Recording saved: ${savedRecordingData.fileName}" + | ||
" should ask for feedback: ${savedRecordingData.shouldAskForFeedback}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple occurrences of the same string literal within a single file detected. |
.subscribeOn(Schedulers.io()) | ||
.subscribeBy( | ||
onSuccess = { savedRecordingData -> | ||
Timber.i("Recording saved: ${savedRecordingData.fileName}" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace String concatenation with Timber’s string formatting |
@@ -23,9 +24,9 @@ class NotifyLowBatteryUseCaseTest { | |||
notifyLowBatteryUseCase.notifyLowBattery(title, text) | |||
|
|||
verify(notificationSender).broadcastNotificationToFcm( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected indentation (11) (it should be 12) |
JaCoCO Code Coverage 20.09% ✅
APK file size
Number of method references
Generated by 🚫 Danger |
fun shouldAskForFeedback(): Boolean { | ||
val currentCounter = sharedPreferences.getInt(NOTIFICATION_COUNTER_KEY, 0) | ||
val lastFeedbackTimestamp = sharedPreferences.getLong(FEEDBACK_TIMESTAMP_KEY, 0) | ||
return enoughTimePassed(lastFeedbackTimestamp) && currentCounter > NO_FEEDBACK_COUNTER_LIMIT | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it could be modeled with rx. Something like this, perhaps?
fun feedbackRecordings(recordings: Observable<Recording>) =
Observable.interval(DELAY_HOURS, TimeUnit.HOURS)
.withLatestFrom(recordings) { _, recording -> recording }
Task
Description
Added checking the frequency of feedback requests
Added sending feedback requests with the notifications
Added tests