Skip to content

Commit

Permalink
fix: changing volume with rotating crown freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
matejdro committed Jan 5, 2022
1 parent 2ea50be commit 057a77a
Showing 1 changed file with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import android.net.Uri
import android.os.Handler
import android.os.Looper
import androidx.lifecycle.MutableLiveData
import com.google.android.gms.wearable.*
import com.google.android.gms.wearable.CapabilityClient
import com.google.android.gms.wearable.CapabilityInfo
import com.google.android.gms.wearable.DataClient
import com.google.android.gms.wearable.DataEvent
import com.google.android.gms.wearable.DataEventBuffer
import com.google.android.gms.wearable.DataItem
import com.google.android.gms.wearable.Wearable
import com.matejdro.wearmusiccenter.R
import com.matejdro.wearmusiccenter.common.CommPaths
import com.matejdro.wearmusiccenter.common.buttonconfig.ButtonInfo
Expand All @@ -17,11 +23,22 @@ import com.matejdro.wearmusiccenter.proto.MusicState
import com.matejdro.wearmusiccenter.proto.Notification
import com.matejdro.wearmusiccenter.watch.util.launchWithErrorHandling
import com.matejdro.wearutils.coroutines.await
import com.matejdro.wearutils.lifecycle.*
import com.matejdro.wearutils.messages.*
import com.matejdro.wearutils.lifecycle.ListenableLiveData
import com.matejdro.wearutils.lifecycle.LiveDataLifecycleCombiner
import com.matejdro.wearutils.lifecycle.LiveDataLifecycleListener
import com.matejdro.wearutils.lifecycle.Resource
import com.matejdro.wearutils.lifecycle.SingleLiveEvent
import com.matejdro.wearutils.messages.getByteArrayAsset
import com.matejdro.wearutils.messages.getNearestNodeId
import com.matejdro.wearutils.messages.sendMessageToNearestClient
import com.matejdro.wearutils.miscutils.BitmapUtils
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.cancel
import kotlinx.coroutines.withContext
import java.lang.ref.WeakReference
import java.nio.ByteBuffer
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -149,18 +166,20 @@ class PhoneConnection @Inject constructor(@ApplicationContext private val contex
return@launchWithErrorHandling
}

sendingVolume = true

messageClient.sendMessageToNearestClient(
nodeClient,
CommPaths.MESSAGE_CHANGE_VOLUME,
FloatPacker.packFloat(newVolume)
)
}
try {
sendingVolume = true

sendingVolume = false
if (nextVolume >= 0) {
sendVolume(nextVolume)
messageClient.sendMessageToNearestClient(
nodeClient,
CommPaths.MESSAGE_CHANGE_VOLUME,
FloatPacker.packFloat(newVolume)
)
} finally {
sendingVolume = false
if (nextVolume >= 0) {
sendVolume(nextVolume)
}
}
}
}

Expand Down Expand Up @@ -320,4 +339,4 @@ class PhoneConnection @Inject constructor(@ApplicationContext private val contex
}
}
}
}
}

0 comments on commit 057a77a

Please sign in to comment.