Skip to content

Commit

Permalink
fix bug when get current fragments with new navigation component.
Browse files Browse the repository at this point in the history
  • Loading branch information
WahdanZ committed Jun 30, 2019
1 parent c16b417 commit 7e2a3c1
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/spockAdb.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
## **Features**

- Navigate to current active activity in your IDE
- Current BackStack Activities
- Navigate to current active fragments
- Clear application data
- Enable and Disable Permissions of your application
- Kill or
Reopen Application
- Kill or Restart Application

## Download

Expand Down
13 changes: 3 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.wahdan'
version '1.0.1'
version '1.0.2'

repositories {
jcenter()
Expand Down Expand Up @@ -45,11 +45,6 @@ patchPluginXml {
<ul>
<li><a href="#spockadb">SpockAdb</a>
<ul>
<li><a href="#features">Features</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#demo">Demo</a></li>
</ul>
</li>
</ul>
Expand All @@ -62,11 +57,11 @@ patchPluginXml {
<h2 id="features"><strong>Features</strong></h2>
<ul>
<li>Navigate to current active activity in your IDE</li>
<li>show current back satck </li>
<li>Navigate to current active fragments</li>
<li>Clear application data</li>
<li>Enable and Disable Permissions of your application -Kill Application</li>
<li>Kill or<br>
Reopen Application</li>
<li>Kill or Reopen Application</li>
</ul>
<h2 id="download">Download</h2>
<p><a href="https://plugins.jetbrains.com/plugin/11591-spock-adb">https://plugins.jetbrains.com/plugin/11591-spock-adb</a></p>
Expand All @@ -90,7 +85,5 @@ limitations under the License.
</div>
</div>
</body></html> """
}
11 changes: 7 additions & 4 deletions src/main/kotlin/spock/adb/AdbControllerImp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AdbControllerImp(
GetBackStackCommand().execute(Any(), project, device)
val list = JBList(activitiesClass.mapIndexed
{ index, className -> "$index-$className" })
showClassPopup("Activities", list, activitiesClass.map { it.psiClassByNameFromProjct(project) })
showClassPopup("Activities", list, activitiesClass.map { it?.psiClassByNameFromProjct(project) })

}

Expand All @@ -75,10 +75,13 @@ class AdbControllerImp(
error: (message: String) -> Unit
) {
execute({
val applicationID = getApplicationID(device)

val fragmentsClass =
GetFragmentsCommand().execute(Any(), project, device) ?: throw NotFoundException("Class Not Found")
GetFragmentsCommand().execute(applicationID, project, device)
?: throw NotFoundException("Class Not Found")
if (fragmentsClass.size > 1) {
val list = JBList(fragmentsClass.map { it1 -> it1.toString().split(":").lastOrNull() })
val list = JBList(fragmentsClass.map { it1 -> it1.toString().split(":").lastOrNull() ?: "" })
showClassPopup("Fragments", list, fragmentsClass.map { it?.psiClassByNameFromCache(project) })
} else {
fragmentsClass.firstOrNull()?.let {
Expand Down Expand Up @@ -166,7 +169,7 @@ class AdbControllerImp(

private fun showClassPopup(
title: String,
list: JBList<String?>,
list: JBList<String>,
classes: List<PsiClass?>
) {
PopupChooserBuilder<String>(list).apply {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/spock/adb/SpockAdbViewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SpockAdbViewer(private val adbController: AdbController
}
}

permissionButton.addActionListener { it ->
permissionButton.addActionListener {
selectedIDevice?.let {device->
adbController.getApplicationPermissions(device,{
val dialog = PermissionDialog(device,adbController,it)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/spock/adb/command/GetBackStackCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import spock.adb.ShellOutputReceiver
import java.util.concurrent.TimeUnit

class GetBackStackCommand : Command<Any, List<String?>> {
override fun execute(p: Any, project: Project, device: IDevice): List<String> {
override fun execute(p: Any, project: Project, device: IDevice): List<String?> {
val shellOutputReceiver = ShellOutputReceiver()
device.executeShellCommand(
"dumpsys activity activities | sed -En -e '/Running activities/,/Run #0/p'",
Expand Down
24 changes: 12 additions & 12 deletions src/main/kotlin/spock/adb/command/GetFragmentsCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import com.intellij.openapi.project.Project
import spock.adb.ShellOutputReceiver
import java.util.concurrent.TimeUnit

class GetFragmentsCommand : Command<Any, List<String?>?> {
override fun execute(p: Any, project: Project, device: IDevice): List<String?>? {
class GetFragmentsCommand : Command<String, List<String?>?> {
override fun execute(p: String, project: Project, device: IDevice): List<String?>? {
val shellOutputReceiver = ShellOutputReceiver()
device.executeShellCommand("dumpsys activity top", shellOutputReceiver, 15L, TimeUnit.SECONDS)
return getCurrentFragmentsFromLog(shellOutputReceiver)
return getCurrentFragmentsFromLog(shellOutputReceiver)


}

private fun getCurrentFragmentsFromLog(shellOutputReceiver: ShellOutputReceiver):List<String>? {
return shellOutputReceiver.toString().split("Added Fragments:").lastOrNull()?.split("\n")
?.filter {
it.contains("#")
}?.map {
it.split("{").first()
.split(" ")
.last()
}?.filter { !it.contains(".") }?.distinct()
private fun getCurrentFragmentsFromLog(shellOutputReceiver: ShellOutputReceiver): List<String>? {
val task = shellOutputReceiver.toString().split("TASK").lastOrNull()
val addedFragments = if (task?.contains("NavHostFragment") == true)
task.split("Added Fragments:")[2]
else task?.split("Added Fragments:")?.lastOrNull()
return addedFragments?.lines()?.map { it.trim() }
?.filter { (it.startsWith("#") && !it.contains("BackStackEntry")) }
?.map { it.split("{").first().split(" ").last() }?.distinct()

}

}
3 changes: 3 additions & 0 deletions src/test/kotlin/spock/adb/command/GetFragmentsCommandTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package spock.adb.command

class GetFragmentsCommandTest

0 comments on commit 7e2a3c1

Please sign in to comment.