Skip to content

Commit

Permalink
Prep for release, also fixed a small error with notifiation sound on …
Browse files Browse the repository at this point in the history
…pull down. (#397)
  • Loading branch information
jorgeblacio authored Feb 5, 2019
1 parent de873d9 commit 2bb7f8d
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 59 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 46
versionName "0.16.4"
versionCode 47
versionName "0.16.5"
applicationId "com.criptext.mail"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class NotificationOpenMailbox(override val ctx: Context): CriptextNotification(c
.setGroupSummary(false)
.setSmallIcon(R.drawable.push_icon)
.setColor(Color.CYAN)
.setLargeIcon(Utility.getBitmapFromText(
pushData.title,
250,
250))
.setStyle(NotificationCompat.BigTextStyle().bigText(pushData.body))

return buildNotification(builder)
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/criptext/mail/push/PushController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class PushController(private val dataSource: PushDataSource, private val host: M

private fun parseNewOpenMailbox(pushData: Map<String, String>,
shouldPostNotification: Boolean): PushData.OpenMailbox {
val body = pushData["subject"] ?: ""
val title = pushData["name"] ?: ""
val body = pushData["body"] ?: ""
val title = pushData["title"] ?: ""

return PushData.OpenMailbox(title = title, body = body,
shouldPostNotification = shouldPostNotification,
Expand All @@ -64,8 +64,8 @@ class PushController(private val dataSource: PushDataSource, private val host: M

private fun parseLinkDevicePush(pushData: Map<String, String>,
shouldPostNotification: Boolean): PushData.LinkDevice {
val body = pushData["subject"] ?: ""
val title = pushData["name"] ?: ""
val body = pushData["body"] ?: ""
val title = pushData["title"] ?: ""
val deviceId = pushData["randomId"] ?: ""
val deviceType = pushData["deviceType"] ?: ""
val deviceName = pushData["deviceName"] ?: ""
Expand All @@ -79,8 +79,8 @@ class PushController(private val dataSource: PushDataSource, private val host: M

private fun parseSyncDevicePush(pushData: Map<String, String>,
shouldPostNotification: Boolean): PushData.SyncDevice {
val body = pushData["subject"] ?: ""
val title = pushData["name"] ?: ""
val body = pushData["body"] ?: ""
val title = pushData["title"] ?: ""
val randomId = pushData["randomId"] ?: ""
val deviceId = pushData["deviceId"] ?: ""
val deviceType = pushData["deviceType"] ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import com.criptext.mail.email_preview.EmailPreview
import com.criptext.mail.scenes.mailbox.data.MailboxAPIClient
import com.criptext.mail.scenes.mailbox.data.UpdateBannerData
import com.criptext.mail.signal.SignalClient
import com.criptext.mail.utils.EventHelper
import com.criptext.mail.utils.EventLoader
import com.criptext.mail.utils.UIMessage
import com.github.kittinunf.result.Result
import com.github.kittinunf.result.flatMap
import org.whispersystems.libsignal.DuplicateMessageException
import java.io.File
import com.squareup.picasso.Picasso
import android.graphics.Bitmap
import com.criptext.mail.api.Hosts
import com.criptext.mail.utils.EmailAddressUtils
import com.criptext.mail.utils.*


/**
Expand Down Expand Up @@ -57,7 +54,7 @@ class UpdateMailboxWorker(
return PushResult.UpdateMailbox.Failure(label, message, ex, pushData, shouldPostNotification)
}

private fun processFailure(failure: Result.Failure<Triple<List<EmailPreview>, UpdateBannerData?, List<DeviceInfo?>>,
private fun processFailure(failure: Result.Failure<EventHelperResultData,
Exception>): PushResult.UpdateMailbox {
return if (failure.error is EventHelper.NothingNewException)
PushResult.UpdateMailbox.Success(
Expand Down Expand Up @@ -109,7 +106,7 @@ class UpdateMailboxWorker(
PushResult.UpdateMailbox.SuccessAndRepeat(
mailboxLabel = label,
isManual = true,
mailboxThreads = operationResult.value.first,
mailboxThreads = operationResult.value.emailPreviews,
pushData = newData,
shouldPostNotification = shouldPostNotification,
senderImage = bm
Expand All @@ -118,7 +115,7 @@ class UpdateMailboxWorker(
PushResult.UpdateMailbox.Success(
mailboxLabel = label,
isManual = true,
mailboxThreads = operationResult.value.first,
mailboxThreads = operationResult.value.emailPreviews,
pushData = newData,
shouldPostNotification = shouldPostNotification,
senderImage = bm
Expand Down
21 changes: 7 additions & 14 deletions src/main/kotlin/com/criptext/mail/scenes/mailbox/MailboxScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.criptext.mail.scenes.mailbox
import android.content.Context
import android.media.AudioManager
import android.media.RingtoneManager
import android.os.Build
import android.os.Handler
import android.os.VibrationEffect
import android.os.Vibrator
import android.view.Gravity
import android.view.View
Expand Down Expand Up @@ -514,22 +516,13 @@ interface MailboxScene{
}

override fun showNotification() {
val am = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager?

when (am!!.ringerMode) {
AudioManager.RINGER_MODE_VIBRATE -> setNotification(false)
AudioManager.RINGER_MODE_NORMAL -> setNotification(true)
}
}

private fun setNotification(sound: Boolean){
val vibrate: Vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
vibrate.vibrate(400)
if(sound){
val defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val ringtone = RingtoneManager.getRingtone(context.applicationContext, defaultSound)
ringtone.play()
if (Build.VERSION.SDK_INT >= 26) {
vibrate.vibrate(VibrationEffect.createOneShot(400,10))
} else {
vibrate.vibrate(400)
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ class MailboxSceneController(private val scene: MailboxScene,
feedController.reloadFeeds()
dataSource.submitRequest(MailboxRequest.ResendEmails())
if(!model.threads.isEmpty()){
if(model.selectedLabel.text== Label.LABEL_INBOX && model.threads[0].unread){
if(resultData.shouldNotify){
scene.showNotification()
}
}
Expand Down Expand Up @@ -1043,7 +1043,8 @@ class MailboxSceneController(private val scene: MailboxScene,
syncEventsList = resultData.syncEventsList,
updateBannerData = resultData.updateBannerData,
isManual = resultData.isManual,
mailboxThreads = resultData.mailboxThreads
mailboxThreads = resultData.mailboxThreads,
shouldNotify = resultData.shouldNotify
)
handleSuccessfulMailboxUpdate(success)
dataSourceController.updateMailbox(model.selectedLabel)
Expand Down
23 changes: 16 additions & 7 deletions src/main/kotlin/com/criptext/mail/utils/EventHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ class EventHelper(private val db: EventLocalDB,
private var updateBannerData: UpdateBannerData? = null
private val linkDevicesEvents: MutableList<DeviceInfo?> = mutableListOf()
private var shouldCallAgain = false
private var shouldNotify = false

fun setupForMailbox(label: Label, threadCount: Int?){
this.label = label
loadedThreadsCount = threadCount
}

val processEvents: (Pair<List<Event>, Boolean>) -> Result<Triple<List<EmailPreview>, UpdateBannerData?, List<DeviceInfo?>>, Exception> = { events ->
val processEvents: (Pair<List<Event>, Boolean>) -> Result<EventHelperResultData, Exception> = { events ->
Result.of {

val shouldReload = processLowPreKeys(events.first).or(processNewEmails(events.first)).or(processTrackingUpdates(events.first))
Expand All @@ -63,8 +64,8 @@ class EventHelper(private val db: EventLocalDB,
.or(processThreadDeletedPermanently(events.first)).or(processLabelCreated(events.first))
.or(processOnError(events.first)).or(processEmailReadStatusChanged(events.first)).or(processUpdateBannerData(events.first))
.or(processLinkRequestEvents(events.first)).or(processSyncRequestEvents(events.first)).or(processProfilePicChangePeer(events.first))
Triple(reloadMailbox(shouldReload.or(acknowledgeEventsIgnoringErrors(eventsToAcknowldege))),
updateBannerData, linkDevicesEvents)
EventHelperResultData(reloadMailbox(shouldReload.or(acknowledgeEventsIgnoringErrors(eventsToAcknowldege))),
updateBannerData, linkDevicesEvents, shouldNotify)
}
}

Expand All @@ -85,6 +86,8 @@ class EventHelper(private val db: EventLocalDB,
if (cache.exists() && cache.isDirectory) {
FileUtils.deleteDir(cache)
}
if (acknoledgeEvents)
eventsToAcknowldege.addAll(eventIdsToAcknowledge)
}

return eventIdsToAcknowledge.isNotEmpty()
Expand Down Expand Up @@ -140,8 +143,10 @@ class EventHelper(private val db: EventLocalDB,
val deviceInfo = eventIdsToAcknowledge.map { it.second }
linkDevicesEvents.add(if(deviceInfo.isEmpty())
null
else
eventIdsToAcknowledge.map { it.second }.last()
else{
shouldNotify = true
eventIdsToAcknowledge.map { it.second }.last()
}
)

return eventIdsToAcknowledge.isNotEmpty()
Expand All @@ -162,8 +167,10 @@ class EventHelper(private val db: EventLocalDB,
val deviceInfo = eventIdsToAcknowledge.map { it.second }
linkDevicesEvents.add(if(deviceInfo.isEmpty())
null
else
eventIdsToAcknowledge.map { it.second }.last()
else {
shouldNotify = true
eventIdsToAcknowledge.map { it.second }.last()
}
)

return eventIdsToAcknowledge.isNotEmpty()
Expand All @@ -180,6 +187,7 @@ class EventHelper(private val db: EventLocalDB,
when(operation){
is Result.Success ->{
updateBannerDataList.add(operation.value)
shouldNotify = true
true
}
else -> false
Expand Down Expand Up @@ -210,6 +218,7 @@ class EventHelper(private val db: EventLocalDB,
{ (_, metadata) ->
try {
insertIncomingEmailTransaction(metadata)
shouldNotify = true
// insertion success, try to acknowledge it
true
} catch (ex: DuplicateMessageException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.criptext.mail.utils

import com.criptext.mail.api.models.DeviceInfo
import com.criptext.mail.email_preview.EmailPreview
import com.criptext.mail.scenes.mailbox.data.UpdateBannerData

data class EventHelperResultData(val emailPreviews: List<EmailPreview>, val updateBannerData: UpdateBannerData?,
val deviceInfo: List<DeviceInfo?>, val shouldNotify: Boolean)
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ sealed class GeneralResult {
sealed class UpdateMailbox : GeneralResult() {
abstract fun getDestinationMailbox(): Label
data class Success(
val shouldNotify: Boolean,
val mailboxLabel: Label,
val mailboxThreads: List<EmailPreview>?,
val updateBannerData: UpdateBannerData?,
Expand All @@ -47,6 +48,7 @@ sealed class GeneralResult {
}

data class SuccessAndRepeat(
val shouldNotify: Boolean,
val mailboxLabel: Label,
val mailboxThreads: List<EmailPreview>?,
val updateBannerData: UpdateBannerData?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import com.criptext.mail.email_preview.EmailPreview
import com.criptext.mail.scenes.mailbox.data.MailboxAPIClient
import com.criptext.mail.scenes.mailbox.data.UpdateBannerData
import com.criptext.mail.signal.SignalClient
import com.criptext.mail.utils.EventHelper
import com.criptext.mail.utils.EventLoader
import com.criptext.mail.utils.ServerCodes
import com.criptext.mail.utils.UIMessage
import com.criptext.mail.utils.*
import com.criptext.mail.utils.file.FileUtils
import com.criptext.mail.utils.generaldatasource.data.GeneralAPIClient
import com.criptext.mail.utils.generaldatasource.data.GeneralResult
Expand Down Expand Up @@ -68,14 +65,15 @@ class UpdateMailboxWorker(
else GeneralResult.UpdateMailbox.Failure(label, createErrorMessage(ex), ex)


private fun processFailure(failure: Result.Failure<Triple<List<EmailPreview>, UpdateBannerData?, List<DeviceInfo?>>, Exception>): GeneralResult.UpdateMailbox {
private fun processFailure(failure: Result.Failure<EventHelperResultData, Exception>): GeneralResult.UpdateMailbox {
return if (failure.error is EventHelper.NothingNewException)
GeneralResult.UpdateMailbox.Success(
mailboxLabel = label,
isManual = true,
mailboxThreads = null,
updateBannerData = null,
syncEventsList = listOf())
syncEventsList = listOf(),
shouldNotify = false)
else
catchException(failure.error)
}
Expand Down Expand Up @@ -103,17 +101,19 @@ class UpdateMailboxWorker(
GeneralResult.UpdateMailbox.SuccessAndRepeat(
mailboxLabel = label,
isManual = true,
mailboxThreads = finalResult.value.first,
updateBannerData = finalResult.value.second,
syncEventsList = finalResult.value.third
mailboxThreads = finalResult.value.emailPreviews,
updateBannerData = finalResult.value.updateBannerData,
syncEventsList = finalResult.value.deviceInfo,
shouldNotify = finalResult.value.shouldNotify
)
}else {
GeneralResult.UpdateMailbox.Success(
mailboxLabel = label,
isManual = true,
mailboxThreads = finalResult.value.first,
updateBannerData = finalResult.value.second,
syncEventsList = finalResult.value.third
mailboxThreads = finalResult.value.emailPreviews,
updateBannerData = finalResult.value.updateBannerData,
syncEventsList = finalResult.value.deviceInfo,
shouldNotify = finalResult.value.shouldNotify
)
}
}
Expand All @@ -126,15 +126,15 @@ class UpdateMailboxWorker(
TODO("CANCEL IS NOT IMPLEMENTED")
}

private fun workOperation() : Result<Triple<List<EmailPreview>, UpdateBannerData?, List<DeviceInfo?>>, Exception> {
private fun workOperation() : Result<EventHelperResultData, Exception> {
val requestEvents = EventLoader.getEvents(mailboxApiClient)
shouldCallAgain = (requestEvents as? Result.Success)?.value?.second ?: false
return requestEvents
.flatMap(eventHelper.processEvents)
}

private fun newRetryWithNewSessionOperation()
: Result<Triple<List<EmailPreview>, UpdateBannerData?, List<DeviceInfo?>>, Exception> {
: Result<EventHelperResultData, Exception> {
val refreshOperation = HttpErrorHandlingHelper.newRefreshSessionOperation(apiClient,
activeAccount, storage, accountDao)
.mapError(HttpErrorHandlingHelper.httpExceptionsToNetworkExceptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class MailboxControllerDataSourceEventsTest: MailboxControllerTest() {
mailboxLabel = model.selectedLabel,
isManual = false,
updateBannerData = null,
syncEventsList = listOf()))
syncEventsList = listOf(),
shouldNotify = false))

model.threads.size `should be` 20
verify { virtualListView.notifyDataSetChanged() }
Expand All @@ -137,7 +138,8 @@ class MailboxControllerDataSourceEventsTest: MailboxControllerTest() {
generalListenerSlot.captured(GeneralResult.UpdateMailbox.Success(mailboxThreads = null,
mailboxLabel = model.selectedLabel, isManual = false,
updateBannerData = null,
syncEventsList = listOf()))
syncEventsList = listOf(),
shouldNotify = false))

model.threads.size `should be` 40
verify(inverse = true) { virtualListView.notifyDataSetChanged() }
Expand All @@ -156,7 +158,8 @@ class MailboxControllerDataSourceEventsTest: MailboxControllerTest() {
generalListenerSlot.captured(GeneralResult.UpdateMailbox.Success(mailboxThreads = null,
mailboxLabel = model.selectedLabel, isManual = true,
updateBannerData = null,
syncEventsList = listOf()))
syncEventsList = listOf(),
shouldNotify = false))

verify { scene.clearRefreshing() }
}
Expand Down

0 comments on commit 2bb7f8d

Please sign in to comment.