Skip to content

Commit c94d659

Browse files
authored
Merge pull request #551 from jorgeblacio/link_cancel
Implemented link and sync cancel, as well as some bug fuxes.
2 parents 4cc2c7b + d067b70 commit c94d659

File tree

53 files changed

+458
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+458
-138
lines changed

src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
</service>
150150
<service android:name=".push.services.NewMailActionService" />
151151
<service android:name=".push.services.SyncDeviceActionService" />
152+
<service android:name=".push.services.HeaderActionService" />
152153

153154
<meta-data
154155
android:name="io.fabric.ApiKey"

src/main/kotlin/com/criptext/mail/BaseActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {
263263
activityMessage = null
264264
}
265265

266+
override fun onPause() {
267+
super.onPause()
268+
controller.onPause()
269+
}
270+
266271
override fun onStop() {
267272
handler.removeCallbacksAndMessages(null)
268273
mFirebaseAnalytics = null

src/main/kotlin/com/criptext/mail/androidui/CriptextNotification.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.annotation.RequiresApi
1212
import androidx.core.app.NotificationCompat
1313
import com.criptext.mail.R
1414
import com.criptext.mail.push.PushData
15+
import com.criptext.mail.push.services.HeaderActionService
1516
import com.criptext.mail.push.services.NewMailActionService
1617

1718
/**
@@ -56,6 +57,18 @@ abstract class CriptextNotification(open val ctx: Context) {
5657
else -> "DEFAULT_CHANNEL"
5758
}
5859
}
60+
61+
fun getNotificationId(action: String): Int {
62+
return when(action){
63+
ACTION_OPEN -> OPEN_ID
64+
ACTION_INBOX -> INBOX_ID
65+
ACTION_LINK_DEVICE -> LINK_DEVICE_ID
66+
ACTION_SYNC_DEVICE -> LINK_DEVICE_ID
67+
ACTION_ERROR -> ERROR_ID
68+
ACTION_JOB_BACKUP -> JOB_BACKUP_ID
69+
else -> -1
70+
}
71+
}
5972
}
6073

6174
abstract fun buildNotification(builder: NotificationCompat.Builder): Notification
@@ -82,12 +95,10 @@ abstract class CriptextNotification(open val ctx: Context) {
8295
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
8396
.setGroup(group)
8497

85-
if(channelId == CHANNEL_ID_NEW_EMAIL) {
86-
val deleteAction = Intent(ctx, NewMailActionService::class.java)
87-
deleteAction.action = NewMailActionService.DELETE
88-
val deletePendingIntent = PendingIntent.getService(ctx, INBOX_ID, deleteAction,0)
89-
builder.setDeleteIntent(deletePendingIntent)
90-
}
98+
val deleteAction = Intent(ctx, HeaderActionService::class.java)
99+
deleteAction.action = group
100+
val deletePendingIntent = PendingIntent.getService(ctx, getNotificationId(group), deleteAction,0)
101+
builder.setDeleteIntent(deletePendingIntent)
91102

92103
if(pendingIntent != null) builder.setContentIntent(pendingIntent)
93104

src/main/kotlin/com/criptext/mail/db/ComposerLocalDB.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class ComposerLocalDB(val contactDao: ContactDao, val emailDao: EmailDao, val fi
138138
headers = emailContent.second),
139139
totalEmails = getEmailCount(emailsInSelectedLabel, emails.size, selectedLabel),
140140
hasFiles = totalFiles > 0,
141-
allFilesAreInline = files.filter { it.cid != null }.size == totalFiles,
141+
allFilesAreInline = files.filter { it.cid != null && it.cid != "" }.size == totalFiles,
142142
headerData = headerData.distinctBy { it.name }
143143
)
144144
}

src/main/kotlin/com/criptext/mail/db/EventLocalDB.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class EventLocalDB(private val db: AppDatabase, private val filesDir: File, priv
383383
headers = emailContent.second),
384384
totalEmails = emails.size,
385385
hasFiles = totalFiles > 0,
386-
allFilesAreInline = files.filter { it.cid != null }.size == totalFiles,
386+
allFilesAreInline = files.filter { it.cid != null && it.cid != "" }.size == totalFiles,
387387
headerData = headerData.distinctBy { it.name }
388388
)
389389
}

src/main/kotlin/com/criptext/mail/db/MailboxLocalDB.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ interface MailboxLocalDB {
548548
headers = emailContent.second),
549549
totalEmails = getEmailCount(emailsInSelectedLabel, emails.size, selectedLabel),
550550
hasFiles = totalFiles > 0,
551-
allFilesAreInline = files.filter { it.cid != null }.size == totalFiles,
551+
allFilesAreInline = files.filter { it.cid != null && it.cid != "" }.size == totalFiles,
552552
headerData = headerData.distinctBy { it.name }
553553
)
554554
}

src/main/kotlin/com/criptext/mail/db/SearchLocalDB.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ interface SearchLocalDB{
134134
headers = emailContent.second),
135135
totalEmails = emails.size,
136136
hasFiles = totalFiles > 0,
137-
allFilesAreInline = files.filter { it.cid != null }.size == totalFiles,
137+
allFilesAreInline = files.filter { it.cid != null && it.cid != "" }.size == totalFiles,
138138
headerData = headerData.distinctBy { it.name }
139139
)
140140
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.criptext.mail.push.services
2+
3+
import android.app.IntentService
4+
import android.content.Intent
5+
import com.criptext.mail.androidui.CriptextNotification
6+
import com.criptext.mail.db.KeyValueStorage
7+
import com.criptext.mail.db.models.ActiveAccount
8+
import com.criptext.mail.db.models.Contact
9+
10+
11+
class HeaderActionService : IntentService("Header Action Service") {
12+
13+
public override fun onHandleIntent(intent: Intent?) {
14+
val storage = KeyValueStorage.SharedPrefs(this)
15+
val activeAccount = ActiveAccount.loadFromStorage(storage)!!
16+
val data = getIntentData(intent, activeAccount.recipientId)
17+
18+
19+
when (data.action){
20+
CriptextNotification.ACTION_INBOX -> storage.putInt(KeyValueStorage.StringKey.NewMailNotificationCount, 0)
21+
CriptextNotification.ACTION_LINK_DEVICE,
22+
CriptextNotification.ACTION_SYNC_DEVICE -> storage.putInt(KeyValueStorage.StringKey.SyncNotificationCount, 0)
23+
CriptextNotification.ACTION_JOB_BACKUP -> storage.putInt(KeyValueStorage.StringKey.CloudBackupNotificationCount, 0)
24+
else -> {}
25+
}
26+
}
27+
28+
private fun getIntentData(intent: Intent?, activeRecipientId: String): IntentData {
29+
val action = intent!!.action ?: ""
30+
val notificationId = intent.getIntExtra("notificationId", 0)
31+
val metadataKey = intent.getLongExtra("metadataKey", 0)
32+
val recipientId = intent.getStringExtra("account") ?: activeRecipientId
33+
val domain = intent.getStringExtra("domain") ?: Contact.mainDomain
34+
return IntentData(action, metadataKey, notificationId, recipientId, domain)
35+
}
36+
37+
private data class IntentData(val action: String, val metadataKey: Long, val notificationId: Int,
38+
val recipientId: String, val domain: String)
39+
}

src/main/kotlin/com/criptext/mail/push/workers/GetPushEmailWorker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class GetPushEmailWorker(
129129
val files = fullEmail.files
130130
newData["preview"] = email.preview
131131
newData["subject"] = email.subject
132-
newData["hasInlineImages"] = (files.firstOrNull { it.cid != null } != null).toString()
132+
newData["hasInlineImages"] = (files.firstOrNull { it.cid != null && it.cid != "" } != null).toString()
133133
newData["name"] = dbEvents.getFromContactByEmailId(email.id)[0].name
134134
newData["email"] = dbEvents.getFromContactByEmailId(email.id)[0].email
135135
val emailAddress = newData["email"]

src/main/kotlin/com/criptext/mail/scenes/SceneController.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ abstract class SceneController {
2828
*/
2929
abstract fun onResume(activityMessage: ActivityMessage?): Boolean
3030

31+
/**
32+
* Called during the host activity's `onStop()`. This where your controller's "teardown" code
33+
* should go.
34+
*/
35+
abstract fun onPause()
36+
3137
/**
3238
* Called during the host activity's `onStop()`. This where your controller's "teardown" code
3339
* should go.

0 commit comments

Comments
 (0)