DeviceTypes.kt 1.82 KB
Newer Older
Christophe Deschamps's avatar
Christophe Deschamps committed
1 2
package org.lindoor.customisation

3
import android.graphics.Bitmap
Christophe Deschamps's avatar
Christophe Deschamps committed
4
import org.lindoor.customisation.Customisation.deviceTypesConfig
5
import org.lindoor.entities.Device
Christophe Deschamps's avatar
Christophe Deschamps committed
6 7
import org.lindoor.ui.widgets.SpinnerItem
import java.util.*
8 9
import org.lindoor.linphonecore.extensions.getString

Christophe Deschamps's avatar
Christophe Deschamps committed
10 11

object DeviceTypes {
12
    var deviceTypes: ArrayList<SpinnerItem> = ArrayList()
Christophe Deschamps's avatar
Christophe Deschamps committed
13
    lateinit var defaultType: String
14
    var defaultTypeIconAsBitmap: Bitmap? = null
15

Christophe Deschamps's avatar
Christophe Deschamps committed
16 17 18
    init {
        deviceTypesConfig.let { config ->
            config.sectionsNamesList.forEach {
Christophe Deschamps's avatar
Christophe Deschamps committed
19
                if (config.getBool(it, "default", false))
20 21
                    defaultType = it
                deviceTypes.add(
Christophe Deschamps's avatar
Christophe Deschamps committed
22
                    SpinnerItem(
23
                        config.getString(it, "textkey", nonNullDefault = "missing"),
Christophe Deschamps's avatar
Christophe Deschamps committed
24 25 26
                        config.getString(it, "icon", null),
                        it
                    )
Christophe Deschamps's avatar
Christophe Deschamps committed
27
                )
28
                defaultTypeIconAsBitmap = Device.typeIconAsBitmap(defaultType)
Christophe Deschamps's avatar
Christophe Deschamps committed
29 30
            }
        }
Christophe Deschamps's avatar
Christophe Deschamps committed
31 32
    }

Christophe Deschamps's avatar
Christophe Deschamps committed
33
    fun iconNameForDeviceType(typeKey: String, circle: Boolean = false): String? {
Christophe Deschamps's avatar
Christophe Deschamps committed
34
        return deviceTypesConfig.let { config ->
Christophe Deschamps's avatar
Christophe Deschamps committed
35
            config.getString(typeKey, "icon" + (if (circle) "_circle" else ""), null)
Christophe Deschamps's avatar
Christophe Deschamps committed
36 37 38
        }
    }

Christophe Deschamps's avatar
Christophe Deschamps committed
39
    fun typeNameForDeviceType(typeKey: String): String? {
Christophe Deschamps's avatar
Christophe Deschamps committed
40
        return deviceTypesConfig.let { config ->
41 42 43
            config.getString(typeKey, "textkey", deviceTypes.get(0).backingKey)?.let {
                Texts.get(it)
            }
Christophe Deschamps's avatar
Christophe Deschamps committed
44 45 46
        }
    }

Christophe Deschamps's avatar
Christophe Deschamps committed
47
    fun supportsAudio(typeKey: String): Boolean {
Christophe Deschamps's avatar
Christophe Deschamps committed
48
        return deviceTypesConfig.let { config ->
Christophe Deschamps's avatar
Christophe Deschamps committed
49
            config.getBool(typeKey, "hasaudio", true)
Christophe Deschamps's avatar
Christophe Deschamps committed
50 51 52
        }
    }

Christophe Deschamps's avatar
Christophe Deschamps committed
53
    fun supportsVideo(typeKey: String): Boolean {
Christophe Deschamps's avatar
Christophe Deschamps committed
54
        return deviceTypesConfig.let { config ->
Christophe Deschamps's avatar
Christophe Deschamps committed
55
            config.getBool(typeKey, "hasvideo", false)
Christophe Deschamps's avatar
Christophe Deschamps committed
56 57 58
        }
    }

Christophe Deschamps's avatar
Christophe Deschamps committed
59
}