Skip to content

Commit 057a77a

Browse files
committed
fix: changing volume with rotating crown freeze
1 parent 2ea50be commit 057a77a

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

wear/src/main/java/com/matejdro/wearmusiccenter/watch/communication/PhoneConnection.kt

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import android.net.Uri
66
import android.os.Handler
77
import android.os.Looper
88
import androidx.lifecycle.MutableLiveData
9-
import com.google.android.gms.wearable.*
9+
import com.google.android.gms.wearable.CapabilityClient
10+
import com.google.android.gms.wearable.CapabilityInfo
11+
import com.google.android.gms.wearable.DataClient
12+
import com.google.android.gms.wearable.DataEvent
13+
import com.google.android.gms.wearable.DataEventBuffer
14+
import com.google.android.gms.wearable.DataItem
15+
import com.google.android.gms.wearable.Wearable
1016
import com.matejdro.wearmusiccenter.R
1117
import com.matejdro.wearmusiccenter.common.CommPaths
1218
import com.matejdro.wearmusiccenter.common.buttonconfig.ButtonInfo
@@ -17,11 +23,22 @@ import com.matejdro.wearmusiccenter.proto.MusicState
1723
import com.matejdro.wearmusiccenter.proto.Notification
1824
import com.matejdro.wearmusiccenter.watch.util.launchWithErrorHandling
1925
import com.matejdro.wearutils.coroutines.await
20-
import com.matejdro.wearutils.lifecycle.*
21-
import com.matejdro.wearutils.messages.*
26+
import com.matejdro.wearutils.lifecycle.ListenableLiveData
27+
import com.matejdro.wearutils.lifecycle.LiveDataLifecycleCombiner
28+
import com.matejdro.wearutils.lifecycle.LiveDataLifecycleListener
29+
import com.matejdro.wearutils.lifecycle.Resource
30+
import com.matejdro.wearutils.lifecycle.SingleLiveEvent
31+
import com.matejdro.wearutils.messages.getByteArrayAsset
32+
import com.matejdro.wearutils.messages.getNearestNodeId
33+
import com.matejdro.wearutils.messages.sendMessageToNearestClient
2234
import com.matejdro.wearutils.miscutils.BitmapUtils
2335
import dagger.hilt.android.qualifiers.ApplicationContext
24-
import kotlinx.coroutines.*
36+
import kotlinx.coroutines.CoroutineScope
37+
import kotlinx.coroutines.Dispatchers
38+
import kotlinx.coroutines.Job
39+
import kotlinx.coroutines.NonCancellable
40+
import kotlinx.coroutines.cancel
41+
import kotlinx.coroutines.withContext
2542
import java.lang.ref.WeakReference
2643
import java.nio.ByteBuffer
2744
import java.util.concurrent.atomic.AtomicBoolean
@@ -149,18 +166,20 @@ class PhoneConnection @Inject constructor(@ApplicationContext private val contex
149166
return@launchWithErrorHandling
150167
}
151168

152-
sendingVolume = true
153-
154-
messageClient.sendMessageToNearestClient(
155-
nodeClient,
156-
CommPaths.MESSAGE_CHANGE_VOLUME,
157-
FloatPacker.packFloat(newVolume)
158-
)
159-
}
169+
try {
170+
sendingVolume = true
160171

161-
sendingVolume = false
162-
if (nextVolume >= 0) {
163-
sendVolume(nextVolume)
172+
messageClient.sendMessageToNearestClient(
173+
nodeClient,
174+
CommPaths.MESSAGE_CHANGE_VOLUME,
175+
FloatPacker.packFloat(newVolume)
176+
)
177+
} finally {
178+
sendingVolume = false
179+
if (nextVolume >= 0) {
180+
sendVolume(nextVolume)
181+
}
182+
}
164183
}
165184
}
166185

@@ -320,4 +339,4 @@ class PhoneConnection @Inject constructor(@ApplicationContext private val contex
320339
}
321340
}
322341
}
323-
}
342+
}

0 commit comments

Comments
 (0)