Skip to content

Commit 10815cd

Browse files
committed
DeviceHelper로 로직 분리
1 parent 47eb3d4 commit 10815cd

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

src/main/kotlin/kr/co/finda/androidtemplate/feature/showLayoutBound/action/ShowLayoutBoundsAction.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import com.intellij.openapi.actionSystem.AnAction
55
import com.intellij.openapi.actionSystem.AnActionEvent
66
import com.intellij.openapi.project.Project
77
import kr.co.finda.androidtemplate.ext.showMessageDialog
8+
import kr.co.finda.androidtemplate.util.DeviceHelper
9+
import kr.co.finda.androidtemplate.util.DeviceHelperImpl
810
import org.jetbrains.android.sdk.AndroidSdkUtils
911

1012
class ShowLayoutBoundsAction : AnAction(), ShowLayoutBoundsActionContract.View {
1113

1214
private val presenter: ShowLayoutBoundsActionContract.Presenter by lazy {
13-
ShowLayoutBoundsActionPresenter(this)
15+
ShowLayoutBoundsActionPresenter(this, DeviceHelperImpl())
1416
}
1517

1618
override fun actionPerformed(e: AnActionEvent) {

src/main/kotlin/kr/co/finda/androidtemplate/feature/showLayoutBound/action/ShowLayoutBoundsActionPresenter.kt

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,24 @@ package kr.co.finda.androidtemplate.feature.showLayoutBound.action
33
import com.android.ddmlib.MultiLineReceiver
44
import com.android.ddmlib.NullOutputReceiver
55
import com.intellij.openapi.project.Project
6+
import kr.co.finda.androidtemplate.util.DeviceHelper
67
import org.jetbrains.android.sdk.AndroidSdkUtils
78

89
class ShowLayoutBoundsActionPresenter(
9-
private val view: ShowLayoutBoundsActionContract.View
10+
private val view: ShowLayoutBoundsActionContract.View,
11+
private val deviceHelper: DeviceHelper
1012
) : ShowLayoutBoundsActionContract.Presenter {
1113

1214
override fun onShowLayoutBoundsActionPerformed(project: Project) {
13-
val devices = AndroidSdkUtils.getDebugBridge(project)?.devices
15+
val devices = deviceHelper.getDebugDevices(project)
1416

15-
if (devices == null) {
17+
if (devices.isNullOrEmpty()) {
1618
view.showDialog(project, "연결된 디바이스가 없습니다", "디바이스 연결 상태를 확인해주세요")
1719
return
1820
}
1921

20-
devices.forEach { device ->
21-
device.executeShellCommand(
22-
"getprop debug.layout",
23-
object : MultiLineReceiver() {
24-
var cancelled = false
25-
26-
override fun isCancelled(): Boolean {
27-
return cancelled
28-
}
29-
30-
override fun processNewLines(lines: Array<out String>?) {
31-
lines?.firstOrNull()?.let { first ->
32-
device.executeShellCommand(
33-
"setprop debug.layout ${!first.toBoolean()} ; service call activity 1599295570",
34-
NullOutputReceiver()
35-
)
36-
}
37-
cancelled = true
38-
}
39-
40-
}
41-
)
22+
deviceHelper.getDebugLayoutBoundsEnabled(devices[0]) { isEnabled ->
23+
deviceHelper.setDebugLayoutBoundsEnabled(devices, !isEnabled)
4224
}
4325
}
4426
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package kr.co.finda.androidtemplate.util
2+
3+
import com.android.ddmlib.IDevice
4+
import com.android.ddmlib.MultiLineReceiver
5+
import com.android.ddmlib.NullOutputReceiver
6+
import com.intellij.openapi.project.Project
7+
import org.jetbrains.android.sdk.AndroidSdkUtils
8+
9+
interface DeviceHelper {
10+
11+
fun getDebugLayoutBoundsEnabled(device: IDevice, on: (isEnabled: Boolean) -> Unit)
12+
13+
fun setDebugLayoutBoundsEnabled(devices: List<IDevice>, isEnabled: Boolean)
14+
15+
fun getDebugDevices(project: Project): List<IDevice>?
16+
}
17+
18+
class DeviceHelperImpl : DeviceHelper {
19+
override fun getDebugLayoutBoundsEnabled(device: IDevice, on: (isEnabled: Boolean) -> Unit) {
20+
device.executeShellCommand(
21+
"getprop debug.layout",
22+
object : MultiLineReceiver() {
23+
var cancelled = false
24+
25+
override fun isCancelled(): Boolean {
26+
return cancelled
27+
}
28+
29+
override fun processNewLines(lines: Array<out String>?) {
30+
val firstLine = lines?.firstOrNull()
31+
on(firstLine?.toBoolean() ?: false)
32+
cancelled = true
33+
}
34+
}
35+
)
36+
}
37+
38+
override fun setDebugLayoutBoundsEnabled(devices: List<IDevice>, isEnabled: Boolean) {
39+
devices.forEach { device ->
40+
device.executeShellCommand(
41+
"setprop debug.layout $isEnabled ; service call activity 1599295570",
42+
NullOutputReceiver()
43+
)
44+
}
45+
}
46+
47+
override fun getDebugDevices(project: Project): List<IDevice>? {
48+
return AndroidSdkUtils.getDebugBridge(project)?.devices?.toList()
49+
}
50+
}

0 commit comments

Comments
 (0)