Skip to content

Commit 4d1cf58

Browse files
enedclaude
andcommitted
chore: standardize code formatting and improve example app structure
- Fix Kotlin package naming to follow conventions (dev.fluttercommunity.workmanager.example) - Use shorthand dot notation in AndroidManifest.xml for cleaner configuration - Apply ktlint and swiftlint formatting fixes across all platforms - Remove trailing whitespace from Swift files 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent 72a86a3 commit 4d1cf58

File tree

10 files changed

+85
-76
lines changed

10 files changed

+85
-76
lines changed

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
55

66
<application
7-
android:name="dev.fluttercommunity.workmanager_example.ExampleApplication"
7+
android:name=".ExampleApplication"
88
android:icon="@mipmap/ic_launcher"
99
android:label="workmanager_example">
1010
<activity
11-
android:name="dev.fluttercommunity.workmanager_example.MainActivity"
11+
android:name=".MainActivity"
1212
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1313
android:hardwareAccelerated="true"
1414
android:launchMode="singleTop"

example/android/app/src/main/kotlin/dev/fluttercommunity/workmanager_example/ExampleApplication.kt renamed to example/android/app/src/main/kotlin/dev/fluttercommunity/workmanager/example/ExampleApplication.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
1-
package dev.fluttercommunity.workmanager_example
1+
package dev.fluttercommunity.workmanager.example
22

33
import android.app.NotificationChannel
44
import android.app.NotificationManager
55
import android.os.Build
6-
import dev.fluttercommunity.workmanager.LoggingDebugHandler
76
import dev.fluttercommunity.workmanager.NotificationDebugHandler
87
import dev.fluttercommunity.workmanager.WorkmanagerDebug
98
import io.flutter.app.FlutterApplication
109

1110
class ExampleApplication : FlutterApplication() {
12-
1311
override fun onCreate() {
1412
super.onCreate()
1513

1614
// Create custom notification channel for debug notifications
1715
val debugChannelId = "workmanager_debug"
1816
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
19-
val channel = NotificationChannel(
20-
debugChannelId,
21-
"Workmanager Example Debug",
22-
NotificationManager.IMPORTANCE_DEFAULT
23-
).apply {
24-
description = "Debug notifications for background tasks in example app"
25-
}
26-
17+
val channel =
18+
NotificationChannel(
19+
debugChannelId,
20+
"Workmanager Example Debug",
21+
NotificationManager.IMPORTANCE_DEFAULT,
22+
).apply {
23+
description = "Debug notifications for background tasks in example app"
24+
}
25+
2726
val notificationManager = getSystemService(NotificationManager::class.java)
2827
notificationManager.createNotificationChannel(channel)
2928
}
3029

3130
// EXAMPLE: Enable debug handlers for background tasks
3231
// Choose one of the following options:
33-
32+
3433
// Option 1: Custom notification handler using our custom channel
35-
WorkmanagerDebug.setCurrent(NotificationDebugHandler(
36-
channelId = debugChannelId,
37-
channelName = "Workmanager Example Debug",
38-
groupKey = "workmanager_example_group"
39-
))
40-
34+
WorkmanagerDebug.setCurrent(
35+
NotificationDebugHandler(
36+
channelId = debugChannelId,
37+
channelName = "Workmanager Example Debug",
38+
groupKey = "workmanager_example_group",
39+
),
40+
)
41+
4142
// Option 2: Default notification handler (creates and uses default channel)
4243
// WorkmanagerDebug.setCurrent(NotificationDebugHandler())
43-
44+
4445
// Option 3: Logging-based debug handler (writes to system log)
4546
// WorkmanagerDebug.setCurrent(LoggingDebugHandler())
46-
47+
4748
// Note: For Android 13+, the app needs to request POST_NOTIFICATIONS permission
4849
// at runtime from the Flutter side or in the first activity
4950
}
50-
}
51+
}

example/android/app/src/main/kotlin/dev/fluttercommunity/workmanager_example/MainActivity.kt renamed to example/android/app/src/main/kotlin/dev/fluttercommunity/workmanager/example/MainActivity.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.fluttercommunity.workmanager_example
1+
package dev.fluttercommunity.workmanager.example
22

33
import android.Manifest
44
import android.content.pm.PackageManager
@@ -14,18 +14,18 @@ class MainActivity : FlutterActivity() {
1414

1515
override fun onStart() {
1616
super.onStart()
17-
17+
1818
// Request notification permission for Android 13+ (API 33+)
1919
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
2020
if (ContextCompat.checkSelfPermission(
2121
this,
22-
Manifest.permission.POST_NOTIFICATIONS
22+
Manifest.permission.POST_NOTIFICATIONS,
2323
) != PackageManager.PERMISSION_GRANTED
2424
) {
2525
ActivityCompat.requestPermissions(
2626
this,
2727
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
28-
NOTIFICATION_PERMISSION_REQUEST_CODE
28+
NOTIFICATION_PERMISSION_REQUEST_CODE,
2929
)
3030
}
3131
}
@@ -34,10 +34,10 @@ class MainActivity : FlutterActivity() {
3434
override fun onRequestPermissionsResult(
3535
requestCode: Int,
3636
permissions: Array<out String>,
37-
grantResults: IntArray
37+
grantResults: IntArray,
3838
) {
3939
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
40-
40+
4141
if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE) {
4242
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
4343
// Permission granted - debug notifications will work
@@ -48,4 +48,4 @@ class MainActivity : FlutterActivity() {
4848
}
4949
}
5050
}
51-
}
51+
}

example/ios/Runner/AppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import workmanager_apple
2424

2525
// EXAMPLE: Enable debug notifications for background tasks
2626
// Uncomment one of the following lines to enable debug output:
27-
27+
2828
// Option 1: Notification-based debug handler (shows debug info as notifications)
2929
WorkmanagerDebug.setCurrent(NotificationDebugHandler())
30-
30+
3131
// Option 2: Logging-based debug handler (writes to system log)
3232
// WorkmanagerDebug.setCurrent(LoggingDebugHandler())
3333

workmanager_android/android/src/main/kotlin/dev/fluttercommunity/workmanager/BackgroundWorker.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package dev.fluttercommunity.workmanager
33
import android.content.Context
44
import android.os.Handler
55
import android.os.Looper
6-
import android.util.Log
76
import androidx.concurrent.futures.CallbackToFutureAdapter
87
import androidx.work.ListenableWorker
98
import androidx.work.WorkerParameters
@@ -127,7 +126,10 @@ class BackgroundWorker(
127126
stopEngine(null)
128127
}
129128

130-
private fun stopEngine(result: Result?, errorMessage: String? = null) {
129+
private fun stopEngine(
130+
result: Result?,
131+
errorMessage: String? = null,
132+
) {
131133
val fetchDuration = System.currentTimeMillis() - startTime
132134

133135
val taskInfo =
@@ -141,17 +143,19 @@ class BackgroundWorker(
141143
TaskResult(
142144
success = result is Result.Success,
143145
duration = fetchDuration,
144-
error = when (result) {
145-
is Result.Failure -> errorMessage ?: "Task failed"
146-
else -> null
147-
},
146+
error =
147+
when (result) {
148+
is Result.Failure -> errorMessage ?: "Task failed"
149+
else -> null
150+
},
148151
)
149152

150-
val status = when (result) {
151-
is Result.Success -> TaskStatus.COMPLETED
152-
is Result.Retry -> TaskStatus.RESCHEDULED
153-
else -> TaskStatus.FAILED
154-
}
153+
val status =
154+
when (result) {
155+
is Result.Success -> TaskStatus.COMPLETED
156+
is Result.Retry -> TaskStatus.RESCHEDULED
157+
else -> TaskStatus.FAILED
158+
}
155159
WorkmanagerDebug.onTaskStatusUpdate(applicationContext, taskInfo, status, taskResult)
156160

157161
// No result indicates we were signalled to stop by WorkManager. The result is already

workmanager_android/android/src/main/kotlin/dev/fluttercommunity/workmanager/NotificationDebugHandler.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ import kotlin.random.Random
1414
/**
1515
* A debug handler that shows notifications for task events.
1616
* Note: You need to ensure your app has notification permissions.
17-
*
17+
*
1818
* @param channelId Custom notification channel ID (defaults to "WorkmanagerDebugChannelId")
1919
* @param channelName Custom notification channel name (defaults to "Workmanager Debug")
2020
* @param groupKey Custom notification group key for grouping notifications (optional)
2121
*/
2222
class NotificationDebugHandler(
2323
private val channelId: String = "WorkmanagerDebugChannelId",
2424
private val channelName: String = "Workmanager Debug",
25-
private val groupKey: String? = null
25+
private val groupKey: String? = null,
2626
) : WorkmanagerDebug() {
2727
private val isUsingDefaultChannel = channelId == "WorkmanagerDebugChannelId"
28+
2829
companion object {
2930
private val debugDateFormatter =
3031
DateFormat.getTimeInstance(DateFormat.SHORT)
@@ -131,19 +132,20 @@ class NotificationDebugHandler(
131132
createNotificationChannel(notificationManager)
132133
}
133134

134-
val notificationBuilder = NotificationCompat
135-
.Builder(context, channelId)
136-
.setContentTitle(title)
137-
.setContentText(contentText)
138-
.setStyle(
139-
NotificationCompat
140-
.BigTextStyle()
141-
.bigText(contentText),
142-
).setSmallIcon(android.R.drawable.stat_notify_sync)
143-
.setPriority(NotificationCompat.PRIORITY_LOW)
135+
val notificationBuilder =
136+
NotificationCompat
137+
.Builder(context, channelId)
138+
.setContentTitle(title)
139+
.setContentText(contentText)
140+
.setStyle(
141+
NotificationCompat
142+
.BigTextStyle()
143+
.bigText(contentText),
144+
).setSmallIcon(android.R.drawable.stat_notify_sync)
145+
.setPriority(NotificationCompat.PRIORITY_LOW)
144146

145147
// Add group key if specified
146-
groupKey?.let {
148+
groupKey?.let {
147149
notificationBuilder.setGroup(it)
148150
}
149151

workmanager_android/android/src/main/kotlin/dev/fluttercommunity/workmanager/WorkManagerUtils.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,14 @@ class WorkManagerWrapper(
135135
?: defaultOneOffExistingWorkPolicy,
136136
oneOffTaskRequest,
137137
)
138-
139-
val taskInfo = TaskDebugInfo(
140-
taskName = request.taskName,
141-
uniqueName = request.uniqueName,
142-
inputData = request.inputData?.filterNotNullKeys(),
143-
startTime = System.currentTimeMillis(),
144-
)
138+
139+
val taskInfo =
140+
TaskDebugInfo(
141+
taskName = request.taskName,
142+
uniqueName = request.uniqueName,
143+
inputData = request.inputData?.filterNotNullKeys(),
144+
startTime = System.currentTimeMillis(),
145+
)
145146
WorkmanagerDebug.onTaskStatusUpdate(context, taskInfo, TaskStatus.SCHEDULED)
146147
} catch (e: Exception) {
147148
throw e
@@ -186,13 +187,14 @@ class WorkManagerWrapper(
186187
?: defaultPeriodExistingWorkPolicy,
187188
periodicTaskRequest,
188189
)
189-
190-
val taskInfo = TaskDebugInfo(
191-
taskName = request.taskName,
192-
uniqueName = request.uniqueName,
193-
inputData = request.inputData?.filterNotNullKeys(),
194-
startTime = System.currentTimeMillis(),
195-
)
190+
191+
val taskInfo =
192+
TaskDebugInfo(
193+
taskName = request.taskName,
194+
uniqueName = request.uniqueName,
195+
inputData = request.inputData?.filterNotNullKeys(),
196+
startTime = System.currentTimeMillis(),
197+
)
196198
WorkmanagerDebug.onTaskStatusUpdate(context, taskInfo, TaskStatus.SCHEDULED)
197199
}
198200

workmanager_apple/ios/Classes/BackgroundWorker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class BackgroundWorker {
135135
let fetchResult: UIBackgroundFetchResult
136136
let status: TaskStatus
137137
let errorMessage: String?
138-
138+
139139
switch taskResult {
140140
case .success(let wasSuccessful):
141141
if wasSuccessful {

workmanager_apple/ios/Classes/NotificationDebugHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class NotificationDebugHandler: WorkmanagerDebug {
1515
private let successEmoji = ""
1616
private let failureEmoji = ""
1717
private let stopEmoji = "⏹️"
18-
18+
1919
private let categoryIdentifier: String?
2020
private let threadIdentifier: String?
2121

@@ -71,12 +71,12 @@ public class NotificationDebugHandler: WorkmanagerDebug {
7171
content.title = title
7272
content.body = body
7373
content.sound = .default
74-
74+
7575
// Set category identifier if specified
7676
if let categoryIdentifier = categoryIdentifier {
7777
content.categoryIdentifier = categoryIdentifier
7878
}
79-
79+
8080
// Set thread identifier if specified for grouping
8181
if let threadIdentifier = threadIdentifier {
8282
content.threadIdentifier = threadIdentifier

workmanager_apple/ios/Classes/WorkmanagerPlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public class WorkmanagerPlugin: FlutterPluginAppLifeCycleDelegate, FlutterPlugin
172172
inputData: request.inputData as? [String: Any],
173173
delaySeconds: delaySeconds
174174
)
175-
175+
176176
let taskInfo = TaskDebugInfo(
177177
taskName: request.taskName,
178178
uniqueName: request.uniqueName,
@@ -195,7 +195,7 @@ public class WorkmanagerPlugin: FlutterPluginAppLifeCycleDelegate, FlutterPlugin
195195
taskIdentifier: request.uniqueName,
196196
earliestBeginInSeconds: initialDelaySeconds
197197
)
198-
198+
199199
let taskInfo = TaskDebugInfo(
200200
taskName: request.taskName,
201201
uniqueName: request.uniqueName,

0 commit comments

Comments
 (0)