package com.birdsounds.identify.presentation

import com.google.android.gms.wearable.MessageEvent
import com.google.android.gms.wearable.WearableListenerService
import java.nio.ByteBuffer


class MessageListenerService : WearableListenerService() {
    private val tag = "MessageListenerService"

    override fun onMessageReceived(p0: MessageEvent) {
        super.onMessageReceived(p0)
        val t_scored = ByteBuffer.wrap(p0.data).getLong()
        var byte_strings: ByteArray = p0.data.copyOfRange(8, p0.data.size)
        var score_species_string = byte_strings.decodeToString()
        var list_strings: List<String> = score_species_string.split(';')
        list_strings.map({
            var split_str = it.split(',')
            if (split_str.size == 2) {
                var out = AScore(split_str[0], split_str[1].toFloat(), t_scored)
                if (out.score > 0.05) {
                    SpeciesList.add_observation(out)
                }
            }
        })
        MessageSender.messageLog.add(t_scored)
    }
}