Skip to content

Commit f51bec9

Browse files
committed
wear: initialize wear listener in onCreate
1 parent debca50 commit f51bec9

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

wearapp/src/fullgms/java/com/thewizrd/simpleweather/setup/SetupSyncActivity.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ class SetupSyncActivity : UserLocaleActivity() {
3737

3838
private lateinit var binding: ActivitySetupSyncBinding
3939

40-
private val wearListenerMgr = WearableListenerManager(this,
41-
WearBroadcastReceiver(),
42-
IntentFilter().apply {
43-
addAction(WearableHelper.IsSetupPath)
44-
addAction(WearableHelper.LocationPath)
45-
addAction(WearableHelper.SettingsPath)
46-
addAction(WearableHelper.WeatherPath)
47-
addAction(WearableHelper.ErrorPath)
48-
}
49-
)
40+
private lateinit var wearListenerMgr: WearableListenerManager
5041

5142
override fun enableLocaleChangeListener(): Boolean {
5243
return false
5344
}
5445

5546
override fun onCreate(savedInstanceState: Bundle?) {
5647
super.onCreate(savedInstanceState)
57-
5848
AnalyticsLogger.logEvent("$TAG: onCreate")
5949

50+
wearListenerMgr = WearableListenerManager(this, WearBroadcastReceiver(),
51+
IntentFilter().apply {
52+
addAction(WearableHelper.IsSetupPath)
53+
addAction(WearableHelper.LocationPath)
54+
addAction(WearableHelper.SettingsPath)
55+
addAction(WearableHelper.WeatherPath)
56+
addAction(WearableHelper.ErrorPath)
57+
}
58+
)
59+
6060
binding = ActivitySetupSyncBinding.inflate(layoutInflater)
6161
setContentView(binding.root)
6262

wearapp/src/main/java/com/thewizrd/simpleweather/main/MainActivity.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@ class MainActivity : UserLocaleActivity() {
4747
private const val TAG = "MainActivity"
4848
}
4949

50-
private val wearListenerMgr =
51-
WearableListenerManager(this, WearableSyncReceiver(), IntentFilter().apply {
52-
addAction(ACTION_OPENONPHONE)
53-
addAction(ACTION_REQUESTSETUPSTATUS)
54-
addAction(ACTION_UPDATECONNECTIONSTATUS)
55-
}
56-
)
50+
private lateinit var wearListenerMgr: WearableListenerManager
5751

5852
// View Models
5953
private val wNowViewModel: WeatherNowViewModel by viewModels()
@@ -73,6 +67,13 @@ class MainActivity : UserLocaleActivity() {
7367
super.onCreate(savedInstanceState)
7468
AnalyticsLogger.logEvent("$TAG: onCreate")
7569

70+
wearListenerMgr =
71+
WearableListenerManager(this, WearableSyncReceiver(), IntentFilter().apply {
72+
addAction(ACTION_OPENONPHONE)
73+
addAction(ACTION_REQUESTSETUPSTATUS)
74+
addAction(ACTION_UPDATECONNECTIONSTATUS)
75+
})
76+
7677
locationPermissionLauncher = LocationPermissionLauncher(
7778
this,
7879
locationCallback = { granted ->
@@ -103,6 +104,7 @@ class MainActivity : UserLocaleActivity() {
103104
}
104105

105106
override fun onStart() {
107+
wearListenerMgr.onStart()
106108
super.onStart()
107109

108110
lifecycleScope.launch {
@@ -151,10 +153,12 @@ class MainActivity : UserLocaleActivity() {
151153
override fun onResume() {
152154
super.onResume()
153155
AnalyticsLogger.logEvent("$TAG: onResume")
156+
wearListenerMgr.onResume()
154157
}
155158

156159
override fun onPause() {
157160
AnalyticsLogger.logEvent("$TAG: onPause")
161+
wearListenerMgr.onPause()
158162
super.onPause()
159163
}
160164

0 commit comments

Comments
 (0)