Skip to content

Commit

Permalink
fix names
Browse files Browse the repository at this point in the history
# Change Log
1. UnClickBridgeLinkButton -> UnClickBridgeLinkButtonException
2. lightIdx -> lightId
  • Loading branch information
reno-kim-km committed Jan 20, 2021
1 parent afe08f2 commit 21674a4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,7 +64,7 @@ class BridgeControlActivity : AppCompatActivity() {
CoroutineScope(Dispatchers.Main).launch {
lightController.changeColor(
token!!,
lightIdx,
lightId,
selectColor
)
}
Expand Down Expand Up @@ -116,8 +116,8 @@ class BridgeControlActivity : AppCompatActivity() {

class ControlAdapter : RecyclerView.Adapter<ControlViewHolder>() {
private var lightList = ArrayList<Light>()
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<Light>) {
this.lightList.addAll(lightList)
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ interface BridgeControlApi {
@GET("/api/{token}/lights")
suspend fun getLightList(@Path("token") token: String): Map<String, Light>

@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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ interface IBridgeController {
suspend fun getToken(userName: String): String
suspend fun getToken(): String
suspend fun getLights(token: String): List<Light>
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)
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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 =
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 21674a4

Please sign in to comment.