Skip to content

Commit 3ac43eb

Browse files
committed
Fixing and reorganizing to address lint issues
1 parent 8d8bd3a commit 3ac43eb

File tree

10 files changed

+428
-397
lines changed

10 files changed

+428
-397
lines changed

legacy/common/src/main/java/com/fsck/k9/notification/K9NotificationActionCreator.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ internal class K9NotificationActionCreator(
8080
}
8181

8282
override fun createDismissAllMessagesPendingIntent(account: LegacyAccountDto): PendingIntent {
83-
val intent = NotificationActionService.createDismissAllMessagesIntent(context, account).apply {
83+
val intent = NotificationActionIntents.createDismissAllMessagesIntent(context, account).apply {
8484
data = Uri.parse("data:,dismissAll/${account.uuid}/${System.currentTimeMillis()}")
8585
}
8686
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
8787
}
8888

8989
override fun createDismissMessagePendingIntent(messageReference: MessageReference): PendingIntent {
90-
val intent = NotificationActionService.createDismissMessageIntent(context, messageReference).apply {
90+
val intent = NotificationActionIntents.createDismissMessageIntent(context, messageReference).apply {
9191
data = Uri.parse("data:,dismiss/${messageReference.toIdentityString()}")
9292
}
9393
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
@@ -101,7 +101,7 @@ internal class K9NotificationActionCreator(
101101
}
102102

103103
override fun createMarkMessageAsReadPendingIntent(messageReference: MessageReference): PendingIntent {
104-
val intent = NotificationActionService.createMarkMessageAsReadIntent(context, messageReference).apply {
104+
val intent = NotificationActionIntents.createMarkMessageAsReadIntent(context, messageReference).apply {
105105
data = Uri.parse("data:,markAsRead/${messageReference.toIdentityString()}")
106106
}
107107
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
@@ -113,7 +113,7 @@ internal class K9NotificationActionCreator(
113113
): PendingIntent {
114114
val accountUuid = account.uuid
115115
val intent =
116-
NotificationActionService.createMarkAllAsReadIntent(context, accountUuid, messageReferences).apply {
116+
NotificationActionIntents.createMarkAllAsReadIntent(context, accountUuid, messageReferences).apply {
117117
data = Uri.parse("data:,markAllAsRead/$accountUuid/${System.currentTimeMillis()}")
118118
}
119119
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
@@ -144,7 +144,7 @@ internal class K9NotificationActionCreator(
144144
}
145145

146146
private fun createDeleteServicePendingIntent(messageReference: MessageReference): PendingIntent {
147-
val intent = NotificationActionService.createDeleteMessageIntent(context, messageReference).apply {
147+
val intent = NotificationActionIntents.createDeleteMessageIntent(context, messageReference).apply {
148148
data = Uri.parse("data:,delete/${messageReference.toIdentityString()}")
149149
}
150150
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
@@ -181,14 +181,14 @@ internal class K9NotificationActionCreator(
181181
): PendingIntent {
182182
val accountUuid = account.uuid
183183
val intent =
184-
NotificationActionService.createDeleteAllMessagesIntent(context, accountUuid, messageReferences).apply {
184+
NotificationActionIntents.createDeleteAllMessagesIntent(context, accountUuid, messageReferences).apply {
185185
data = Uri.parse("data:,deleteAll/$accountUuid/${System.currentTimeMillis()}")
186186
}
187187
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
188188
}
189189

190190
override fun createArchiveMessagePendingIntent(messageReference: MessageReference): PendingIntent {
191-
val intent = NotificationActionService.createArchiveMessageIntent(context, messageReference).apply {
191+
val intent = NotificationActionIntents.createArchiveMessageIntent(context, messageReference).apply {
192192
data = Uri.parse("data:,archive/${messageReference.toIdentityString()}")
193193
}
194194
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
@@ -198,21 +198,21 @@ internal class K9NotificationActionCreator(
198198
account: LegacyAccountDto,
199199
messageReferences: List<MessageReference>,
200200
): PendingIntent {
201-
val intent = NotificationActionService.createArchiveAllIntent(context, account, messageReferences).apply {
201+
val intent = NotificationActionIntents.createArchiveAllIntent(context, account, messageReferences).apply {
202202
data = Uri.parse("data:,archiveAll/${account.uuid}/${System.currentTimeMillis()}")
203203
}
204204
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
205205
}
206206

207207
override fun createMarkMessageAsSpamPendingIntent(messageReference: MessageReference): PendingIntent {
208-
val intent = NotificationActionService.createMarkMessageAsSpamIntent(context, messageReference).apply {
208+
val intent = NotificationActionIntents.createMarkMessageAsSpamIntent(context, messageReference).apply {
209209
data = Uri.parse("data:,spam/${messageReference.toIdentityString()}")
210210
}
211211
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
212212
}
213213

214214
override fun createMarkMessageAsStarPendingIntent(messageReference: MessageReference): PendingIntent {
215-
val intent = NotificationActionService.createMarkMessageAsStarIntent(context, messageReference).apply {
215+
val intent = NotificationActionIntents.createMarkMessageAsStarIntent(context, messageReference).apply {
216216
data = Uri.parse("data:,star/${messageReference.toIdentityString()}")
217217
}
218218
return PendingIntentCompat.getService(context, 0, intent, FLAG_UPDATE_CURRENT, false)!!
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.fsck.k9.notification
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import app.k9mail.legacy.message.controller.MessageReference
6+
import com.fsck.k9.controller.MessageReferenceHelper
7+
import net.thunderbird.core.android.account.LegacyAccountDto
8+
9+
internal const val ACTION_MARK_AS_READ = "ACTION_MARK_AS_READ"
10+
internal const val ACTION_DELETE = "ACTION_DELETE"
11+
internal const val ACTION_ARCHIVE = "ACTION_ARCHIVE"
12+
internal const val ACTION_SPAM = "ACTION_SPAM"
13+
internal const val ACTION_STAR = "ACTION_STAR"
14+
internal const val ACTION_DISMISS = "ACTION_DISMISS"
15+
internal const val EXTRA_ACCOUNT_UUID = "accountUuid"
16+
internal const val EXTRA_MESSAGE_REFERENCE = "messageReference"
17+
internal const val EXTRA_MESSAGE_REFERENCES = "messageReferences"
18+
19+
object NotificationActionIntents {
20+
fun createMarkMessageAsReadIntent(context: Context, messageReference: MessageReference): Intent {
21+
return Intent(context, NotificationActionService::class.java).apply {
22+
action = ACTION_MARK_AS_READ
23+
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
24+
putExtra(EXTRA_MESSAGE_REFERENCES, arrayListOf(messageReference.toIdentityString()))
25+
}
26+
}
27+
28+
fun createMarkAllAsReadIntent(
29+
context: Context,
30+
accountUuid: String,
31+
messageReferences: List<MessageReference>,
32+
): Intent {
33+
return Intent(context, NotificationActionService::class.java).apply {
34+
action = ACTION_MARK_AS_READ
35+
putExtra(EXTRA_ACCOUNT_UUID, accountUuid)
36+
putExtra(
37+
EXTRA_MESSAGE_REFERENCES,
38+
MessageReferenceHelper.toMessageReferenceStringList(messageReferences),
39+
)
40+
}
41+
}
42+
43+
fun createDismissMessageIntent(context: Context, messageReference: MessageReference): Intent {
44+
return Intent(context, NotificationActionService::class.java).apply {
45+
action = ACTION_DISMISS
46+
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
47+
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
48+
}
49+
}
50+
51+
fun createDismissAllMessagesIntent(context: Context, account: LegacyAccountDto): Intent {
52+
return Intent(context, NotificationActionService::class.java).apply {
53+
action = ACTION_DISMISS
54+
putExtra(EXTRA_ACCOUNT_UUID, account.uuid)
55+
}
56+
}
57+
58+
fun createDeleteMessageIntent(context: Context, messageReference: MessageReference): Intent {
59+
return Intent(context, NotificationActionService::class.java).apply {
60+
action = ACTION_DELETE
61+
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
62+
putExtra(EXTRA_MESSAGE_REFERENCES, arrayListOf(messageReference.toIdentityString()))
63+
}
64+
}
65+
66+
fun createDeleteAllMessagesIntent(
67+
context: Context,
68+
accountUuid: String,
69+
messageReferences: List<MessageReference>,
70+
): Intent {
71+
return Intent(context, NotificationActionService::class.java).apply {
72+
action = ACTION_DELETE
73+
putExtra(EXTRA_ACCOUNT_UUID, accountUuid)
74+
putExtra(
75+
EXTRA_MESSAGE_REFERENCES,
76+
MessageReferenceHelper.toMessageReferenceStringList(messageReferences),
77+
)
78+
}
79+
}
80+
81+
fun createArchiveMessageIntent(context: Context, messageReference: MessageReference): Intent {
82+
return Intent(context, NotificationActionService::class.java).apply {
83+
action = ACTION_ARCHIVE
84+
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
85+
putExtra(EXTRA_MESSAGE_REFERENCES, arrayListOf(messageReference.toIdentityString()))
86+
}
87+
}
88+
89+
fun createArchiveAllIntent(
90+
context: Context,
91+
account: LegacyAccountDto,
92+
messageReferences: List<MessageReference>,
93+
): Intent {
94+
return Intent(context, NotificationActionService::class.java).apply {
95+
action = ACTION_ARCHIVE
96+
putExtra(EXTRA_ACCOUNT_UUID, account.uuid)
97+
putExtra(
98+
EXTRA_MESSAGE_REFERENCES,
99+
MessageReferenceHelper.toMessageReferenceStringList(messageReferences),
100+
)
101+
}
102+
}
103+
104+
fun createMarkMessageAsSpamIntent(context: Context, messageReference: MessageReference): Intent {
105+
return Intent(context, NotificationActionService::class.java).apply {
106+
action = ACTION_SPAM
107+
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
108+
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
109+
}
110+
}
111+
112+
fun createMarkMessageAsStarIntent(context: Context, messageReference: MessageReference): Intent {
113+
return Intent(context, NotificationActionService::class.java).apply {
114+
action = ACTION_STAR
115+
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
116+
putExtra(EXTRA_MESSAGE_REFERENCES, arrayListOf(messageReference.toIdentityString()))
117+
}
118+
}
119+
}

legacy/core/src/main/java/com/fsck/k9/notification/NotificationActionService.kt

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fsck.k9.notification
22

33
import android.app.Service
4-
import android.content.Context
54
import android.content.Intent
65
import android.os.IBinder
76
import app.k9mail.legacy.message.controller.MessageReference
@@ -157,122 +156,4 @@ class NotificationActionService : Service() {
157156
messagingController.cancelNotificationsForAccount(account)
158157
}
159158
}
160-
161-
companion object {
162-
private const val ACTION_MARK_AS_READ = "ACTION_MARK_AS_READ"
163-
private const val ACTION_DELETE = "ACTION_DELETE"
164-
private const val ACTION_ARCHIVE = "ACTION_ARCHIVE"
165-
private const val ACTION_SPAM = "ACTION_SPAM"
166-
private const val ACTION_STAR = "ACTION_STAR"
167-
private const val ACTION_DISMISS = "ACTION_DISMISS"
168-
private const val EXTRA_ACCOUNT_UUID = "accountUuid"
169-
private const val EXTRA_MESSAGE_REFERENCE = "messageReference"
170-
private const val EXTRA_MESSAGE_REFERENCES = "messageReferences"
171-
172-
fun createMarkMessageAsReadIntent(context: Context, messageReference: MessageReference): Intent {
173-
return Intent(context, NotificationActionService::class.java).apply {
174-
action = ACTION_MARK_AS_READ
175-
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
176-
putExtra(EXTRA_MESSAGE_REFERENCES, createSingleItemArrayList(messageReference))
177-
}
178-
}
179-
180-
fun createMarkAllAsReadIntent(
181-
context: Context,
182-
accountUuid: String,
183-
messageReferences: List<MessageReference>,
184-
): Intent {
185-
return Intent(context, NotificationActionService::class.java).apply {
186-
action = ACTION_MARK_AS_READ
187-
putExtra(EXTRA_ACCOUNT_UUID, accountUuid)
188-
putExtra(
189-
EXTRA_MESSAGE_REFERENCES,
190-
MessageReferenceHelper.toMessageReferenceStringList(messageReferences),
191-
)
192-
}
193-
}
194-
195-
fun createDismissMessageIntent(context: Context, messageReference: MessageReference): Intent {
196-
return Intent(context, NotificationActionService::class.java).apply {
197-
action = ACTION_DISMISS
198-
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
199-
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
200-
}
201-
}
202-
203-
fun createDismissAllMessagesIntent(context: Context, account: LegacyAccountDto): Intent {
204-
return Intent(context, NotificationActionService::class.java).apply {
205-
action = ACTION_DISMISS
206-
putExtra(EXTRA_ACCOUNT_UUID, account.uuid)
207-
}
208-
}
209-
210-
fun createDeleteMessageIntent(context: Context, messageReference: MessageReference): Intent {
211-
return Intent(context, NotificationActionService::class.java).apply {
212-
action = ACTION_DELETE
213-
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
214-
putExtra(EXTRA_MESSAGE_REFERENCES, createSingleItemArrayList(messageReference))
215-
}
216-
}
217-
218-
fun createDeleteAllMessagesIntent(
219-
context: Context,
220-
accountUuid: String,
221-
messageReferences: List<MessageReference>,
222-
): Intent {
223-
return Intent(context, NotificationActionService::class.java).apply {
224-
action = ACTION_DELETE
225-
putExtra(EXTRA_ACCOUNT_UUID, accountUuid)
226-
putExtra(
227-
EXTRA_MESSAGE_REFERENCES,
228-
MessageReferenceHelper.toMessageReferenceStringList(messageReferences),
229-
)
230-
}
231-
}
232-
233-
fun createArchiveMessageIntent(context: Context, messageReference: MessageReference): Intent {
234-
return Intent(context, NotificationActionService::class.java).apply {
235-
action = ACTION_ARCHIVE
236-
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
237-
putExtra(EXTRA_MESSAGE_REFERENCES, createSingleItemArrayList(messageReference))
238-
}
239-
}
240-
241-
fun createArchiveAllIntent(
242-
context: Context,
243-
account: LegacyAccountDto,
244-
messageReferences: List<MessageReference>,
245-
): Intent {
246-
return Intent(context, NotificationActionService::class.java).apply {
247-
action = ACTION_ARCHIVE
248-
putExtra(EXTRA_ACCOUNT_UUID, account.uuid)
249-
putExtra(
250-
EXTRA_MESSAGE_REFERENCES,
251-
MessageReferenceHelper.toMessageReferenceStringList(messageReferences),
252-
)
253-
}
254-
}
255-
256-
fun createMarkMessageAsSpamIntent(context: Context, messageReference: MessageReference): Intent {
257-
return Intent(context, NotificationActionService::class.java).apply {
258-
action = ACTION_SPAM
259-
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
260-
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
261-
}
262-
}
263-
264-
fun createMarkMessageAsStarIntent(context: Context, messageReference: MessageReference): Intent {
265-
return Intent(context, NotificationActionService::class.java).apply {
266-
action = ACTION_STAR
267-
putExtra(EXTRA_ACCOUNT_UUID, messageReference.accountUuid)
268-
putExtra(EXTRA_MESSAGE_REFERENCES, createSingleItemArrayList(messageReference))
269-
}
270-
}
271-
272-
private fun createSingleItemArrayList(messageReference: MessageReference): ArrayList<String> {
273-
return ArrayList<String>(1).apply {
274-
add(messageReference.toIdentityString())
275-
}
276-
}
277-
}
278159
}

0 commit comments

Comments
 (0)