mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-01-29 06:10:52 +00:00
fix: when both airpods are not worn, the settings screen would say not connected
This commit is contained in:
@@ -40,12 +40,14 @@ import android.os.IBinder
|
||||
import android.os.ParcelUuid
|
||||
import android.util.Log
|
||||
import android.widget.RemoteViews
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.core.app.NotificationCompat
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import me.kavishdevar.aln.BatteryWidget
|
||||
import me.kavishdevar.aln.MainActivity
|
||||
import me.kavishdevar.aln.R
|
||||
import me.kavishdevar.aln.utils.AirPodsNotifications
|
||||
import me.kavishdevar.aln.utils.Battery
|
||||
@@ -67,10 +69,18 @@ object ServiceManager {
|
||||
fun setService(service: AirPodsService?) {
|
||||
this.service = service
|
||||
}
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Synchronized
|
||||
fun restartService(context: Context) {
|
||||
service?.stopSelf()
|
||||
context.startService(Intent(context, AirPodsService::class.java))
|
||||
Log.d("ServiceManager", "Restarting service, service is null: ${service == null}")
|
||||
val intent = Intent(context, AirPodsService::class.java)
|
||||
context.stopService(intent)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
delay(1000)
|
||||
context.startService(intent)
|
||||
context.startActivity(Intent(context, MainActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,13 +129,6 @@ class AirPodsService: Service() {
|
||||
context?.sendBroadcast(intent)
|
||||
}
|
||||
}
|
||||
if (BluetoothDevice.ACTION_ACL_DISCONNECTED == action
|
||||
|| BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED == action
|
||||
) {
|
||||
context?.sendBroadcast(
|
||||
Intent(AirPodsNotifications.Companion.AIRPODS_DISCONNECTED)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,8 +259,6 @@ class AirPodsService: Service() {
|
||||
// .setOngoing(true)
|
||||
// .build()
|
||||
|
||||
// Instead have something like L: 50% | R: 50% | C: 12% with the emojis, without using remote views, in thte title itself.
|
||||
|
||||
updatedNotification = NotificationCompat.Builder(this, "background_service_status")
|
||||
.setSmallIcon(R.drawable.airpods)
|
||||
.setContentTitle("""L: ${batteryList?.find { it.component == BatteryComponent.LEFT }?.let {
|
||||
@@ -474,7 +475,6 @@ class AirPodsService: Service() {
|
||||
Log.d("AirPods Data", "Data received: $formattedHex")
|
||||
} else if (bytesRead == -1) {
|
||||
Log.d("AirPods Service", "Socket closed (bytesRead = -1)")
|
||||
// socket.close()
|
||||
sendBroadcast(Intent(AirPodsNotifications.Companion.AIRPODS_DISCONNECTED))
|
||||
return@launch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user