From 21674a4b1c801fbe9916e9c2ea08b180b2412a1f Mon Sep 17 00:00:00 2001 From: Reno Date: Wed, 20 Jan 2021 23:52:22 +0900 Subject: [PATCH] fix names # Change Log 1. UnClickBridgeLinkButton -> UnClickBridgeLinkButtonException 2. lightIdx -> lightId --- .../BridgeControlActivity.kt | 16 ++++----- .../bridgecontrol/BridgeControlApi.kt | 12 +++---- .../bridgecontrol/BridgeController.kt | 36 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt b/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt index 1fb66f0..01fc4e7 100644 --- a/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt +++ b/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt @@ -41,14 +41,14 @@ class BridgeControlActivity : AppCompatActivity() { rvLight.layoutManager = LinearLayoutManager(this) rvLight.adapter = ControlAdapter().apply { - onClickPower = { lightIdx, turnOn -> + onClickPower = { lightId, turnOn -> token ?: showToast("no token") CoroutineScope(Dispatchers.Main).launch { - lightController.turnOn(token!!, lightIdx, turnOn) + lightController.turnOn(token!!, lightId, turnOn) } } - onClickColor = { lightIdx -> + onClickColor = { lightId -> token ?: showToast("no token") var selectColor = Color.WHITE @@ -64,7 +64,7 @@ class BridgeControlActivity : AppCompatActivity() { CoroutineScope(Dispatchers.Main).launch { lightController.changeColor( token!!, - lightIdx, + lightId, selectColor ) } @@ -116,8 +116,8 @@ class BridgeControlActivity : AppCompatActivity() { class ControlAdapter : RecyclerView.Adapter() { private var lightList = ArrayList() - var onClickPower: ((lightIdx: Int, turnOn: Boolean) -> Unit)? = null - var onClickColor: ((lightIdx: Int) -> Unit)? = null + var onClickPower: ((lightId: Int, turnOn: Boolean) -> Unit)? = null + var onClickColor: ((lightId: Int) -> Unit)? = null fun addAll(lightList: List) { this.lightList.addAll(lightList) @@ -147,8 +147,8 @@ class BridgeControlActivity : AppCompatActivity() { fun onBind( light: Light, - onClickPower: ((lightIdx: Int, turnOn: Boolean) -> Unit)?, - onClickColor: ((lightIdx: Int) -> Unit)? + onClickPower: ((lightId: Int, turnOn: Boolean) -> Unit)?, + onClickColor: ((lightId: Int) -> Unit)? ) { tvLightName.text = light.name butLightPower.text = if (light.state.on) "Turn On" else "Turn Off" diff --git a/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeControlApi.kt b/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeControlApi.kt index aa1f31c..90f4c5b 100644 --- a/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeControlApi.kt +++ b/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeControlApi.kt @@ -36,20 +36,20 @@ interface BridgeControlApi { @GET("/api/{token}/lights") suspend fun getLightList(@Path("token") token: String): Map - @GET("/api/{token}/lights/{lightIdx}") - suspend fun getLight(@Path("token") token: String, @Path("lightIdx") lightIdx: Int): Light + @GET("/api/{token}/lights/{lightId}") + suspend fun getLight(@Path("token") token: String, @Path("lightId") lightId: Int): Light - @PUT("/api/{token}/lights/{lightIdx}/state") + @PUT("/api/{token}/lights/{lightId}/state") suspend fun turnOn( @Path("token") token: String, - @Path("lightIdx") lightIdx: Int, + @Path("lightId") lightId: Int, @Body bridgeLightRequestBody: BridgeLightRequestBody ) - @PUT("/api/{token}/lights/{lightIdx}/state") + @PUT("/api/{token}/lights/{lightId}/state") suspend fun changeColor( @Path("token") token: String, - @Path("lightIdx") lightIdx: Int, + @Path("lightId") lightId: Int, @Body bridgeLightRequestBody: BridgeLightRequestBody ) } diff --git a/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeController.kt b/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeController.kt index 067129e..53cf76f 100644 --- a/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeController.kt +++ b/philipshue/src/main/java/com/reno/philipshue/bridgecontrol/BridgeController.kt @@ -17,18 +17,18 @@ interface IBridgeController { suspend fun getToken(userName: String): String suspend fun getToken(): String suspend fun getLights(token: String): List - suspend fun getLight(token: String, lightIdx: Int): Light - suspend fun turnOn(token: String, lightIdx: Int, isOn: Boolean) + suspend fun getLight(token: String, lightId: Int): Light + suspend fun turnOn(token: String, lightId: Int, isOn: Boolean) suspend fun changeColor( token: String, - lightIdx: Int, + lightId: Int, @ColorInt colorInt: Int ) suspend fun changeRGBColor( token: String, - lightIdx: Int, + lightId: Int, @IntRange(from = 0, to = 254) red: Int, @IntRange(from = 0, to = 254) @@ -39,7 +39,7 @@ interface IBridgeController { suspend fun changeHSVColor( token: String, - lightIdx: Int, + lightId: Int, @IntRange(from = 0, to = 254) brightness: Int, @IntRange(from = 0, to = 254) @@ -57,7 +57,7 @@ class BridgeController(bridgeIp: String) : IBridgeController { ) } - @Throws(UnClickBridgeLinkButton::class, UnknownBridgeException::class) + @Throws(UnClickBridgeLinkButtonException::class, UnknownBridgeException::class) override suspend fun getToken(userName: String): String { return withContext(Dispatchers.Default) { val response = bridgeControlApi.getToken(BridgeTokenRequestBody(userName)) @@ -66,7 +66,7 @@ class BridgeController(bridgeIp: String) : IBridgeController { } } - @Throws(UnClickBridgeLinkButton::class, UnknownBridgeException::class) + @Throws(UnClickBridgeLinkButtonException::class, UnknownBridgeException::class) override suspend fun getToken(): String { return withContext(Dispatchers.Default) { val response = @@ -84,7 +84,7 @@ class BridgeController(bridgeIp: String) : IBridgeController { jsonObject.asJsonObject.has("error") -> { val type = jsonObject.asJsonObject["error"].asJsonObject["type"].asInt if (type == 101) { - throw UnClickBridgeLinkButton() + throw UnClickBridgeLinkButtonException() } else { val description = jsonObject.asJsonObject["error"].asJsonObject["description"].asString @@ -104,19 +104,19 @@ class BridgeController(bridgeIp: String) : IBridgeController { } } - override suspend fun getLight(token: String, lightIdx: Int): Light { - return bridgeControlApi.getLight(token, lightIdx) + override suspend fun getLight(token: String, lightId: Int): Light { + return bridgeControlApi.getLight(token, lightId) } - override suspend fun turnOn(token: String, lightIdx: Int, isOn: Boolean) { - return bridgeControlApi.turnOn(token, lightIdx, BridgeLightRequestBody(on = isOn)) + override suspend fun turnOn(token: String, lightId: Int, isOn: Boolean) { + return bridgeControlApi.turnOn(token, lightId, BridgeLightRequestBody(on = isOn)) } @SuppressLint("Range") - override suspend fun changeColor(token: String, lightIdx: Int, @ColorInt colorInt: Int) { + override suspend fun changeColor(token: String, lightId: Int, @ColorInt colorInt: Int) { return changeRGBColor( token, - lightIdx, + lightId, Color.red(colorInt), Color.green(colorInt), Color.blue(colorInt) @@ -125,7 +125,7 @@ class BridgeController(bridgeIp: String) : IBridgeController { override suspend fun changeRGBColor( token: String, - lightIdx: Int, + lightId: Int, @IntRange(from = 0, to = 255) red: Int, @IntRange(from = 0, to = 255) @@ -141,7 +141,7 @@ class BridgeController(bridgeIp: String) : IBridgeController { Log.d("color", "brightness: $brightness, saturation: $saturation, hue: $hue") return changeHSVColor( token, - lightIdx, + lightId, brightness, saturation, hue @@ -151,7 +151,7 @@ class BridgeController(bridgeIp: String) : IBridgeController { @SuppressLint("Range") override suspend fun changeHSVColor( token: String, - lightIdx: Int, + lightId: Int, @IntRange(from = 0, to = 255) brightness: Int, @IntRange(from = 0, to = 255) @@ -160,7 +160,7 @@ class BridgeController(bridgeIp: String) : IBridgeController { hue: Int ) { return bridgeControlApi.changeColor( - token, lightIdx, BridgeLightRequestBody( + token, lightId, BridgeLightRequestBody( on = true, brightness = brightness, saturation = saturation,