Skip to content

Commit

Permalink
Replaced some list operations with sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
Szaki committed Nov 2, 2019
1 parent 0e9206d commit 07bb723
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/main/kotlin/AppManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ object AppManager : Command() {
fun readPotentialApps() {
potentialApps.clear()
potentialApps["android.autoinstalls.config.Xiaomi.${Device.codename}"] = "PAI"
this::class.java.classLoader.getResource("apps.yml")!!.readText().trim().lines().forEach { line ->
this::class.java.classLoader.getResource("apps.yml")!!.readText().trim().lineSequence().forEach { line ->
val app = line.split(':')
potentialApps[app[0].trim()] = app[1].trim()
}
if (appsFile.exists()) {
appsFile.readText().trim().lines().forEach { line ->
appsFile.readText().trim().lineSequence().forEach { line ->
val app = line.split(':')
if (app.size == 1) {
potentialApps[app[0].trim()] = app[0].trim()
Expand All @@ -55,16 +55,16 @@ object AppManager : Command() {
val disableApps = mutableMapOf<String, MutableList<String>>()
val enableApps = mutableMapOf<String, MutableList<String>>()
val deviceApps = mutableMapOf<String, String>()
exec("adb shell pm list packages -u --user $user").trim().lines().forEach {
exec("adb shell pm list packages -u --user $user").trim().lineSequence().forEach {
deviceApps[it.substringAfter(':')] = "uninstalled"
}
exec("adb shell pm list packages -d --user $user").trim().lines().forEach {
exec("adb shell pm list packages -d --user $user").trim().lineSequence().forEach {
deviceApps[it.substringAfter(':')] = "disabled"
}
exec("adb shell pm list packages -e --user $user").trim().lines().forEach {
exec("adb shell pm list packages -e --user $user").trim().lineSequence().forEach {
deviceApps[it.substringAfter(':')] = "enabled"
}
potentialApps.forEach { (pkg, name) ->
potentialApps.asSequence().forEach { (pkg, name) ->
when (deviceApps[pkg]) {
"disabled" -> {
uninstallApps.add(name, pkg)
Expand Down Expand Up @@ -93,7 +93,7 @@ object AppManager : Command() {
progress.progress = 0.0
progressInd.isVisible = true
thread(true, true) {
selected.forEach {
selected.asSequence().forEach {
it.packagenameProperty().get().trim().lines().forEach { pkg ->
proc =
pb.command("${prefix}adb", "shell", "pm", "uninstall", "--user", "$user", pkg)
Expand Down Expand Up @@ -129,7 +129,7 @@ object AppManager : Command() {
progress.progress = 0.0
progressInd.isVisible = true
thread(true, true) {
selected.forEach {
selected.asSequence().forEach {
it.packagenameProperty().get().trim().lines().forEach { pkg ->
proc =
pb.command(
Expand Down Expand Up @@ -178,7 +178,7 @@ object AppManager : Command() {
progress.progress = 0.0
progressInd.isVisible = true
thread(true, true) {
selected.forEach {
selected.asSequence().forEach {
it.packagenameProperty().get().trim().lines().forEach { pkg ->
proc = pb.command(
"${prefix}adb",
Expand Down Expand Up @@ -223,7 +223,7 @@ object AppManager : Command() {
progress.progress = 0.0
progressInd.isVisible = true
thread(true, true) {
selected.forEach {
selected.asSequence().forEach {
it.packagenameProperty().get().trim().lines().forEach { pkg ->
proc =
pb.command("${prefix}adb", "shell", "pm", "enable", "--user", "$user", pkg)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/Device.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Device {
if (mode == Mode.ADB && serial in propstring && dpi != -1 && width != -1 && height != -1)
return true
props.clear()
propstring.trim().lines().forEach {
propstring.trim().lineSequence().forEach {
val parts = it.split("]: [")
if (parts.size == 2)
props[parts[0].trimStart('[')] = parts[1].trimEnd(']')
Expand Down Expand Up @@ -78,7 +78,7 @@ object Device {
mode == Mode.FASTBOOT && serial in status -> return true
}
props.clear()
command.exec("fastboot getvar all").trim().lines().forEach {
command.exec("fastboot getvar all").trim().lineSequence().forEach {
if (it[0] == '(')
props[it.substringAfter(')').substringBeforeLast(':').trim()] = it.substringAfterLast(':').trim()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/FileExplorer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FileExplorer(val statusTextField: TextField, val statusProgressBar: Progre

fun getFiles(): ObservableList<AndroidFile> {
val files = FXCollections.observableArrayList<AndroidFile>()
exec("adb shell ls -l $path", lim = 5).trim().lines().forEach {
exec("adb shell ls -l $path", lim = 5).trim().lineSequence().forEach {
if ("ls:" !in it && ':' in it)
makeFile(it)?.let { file ->
files.add(file)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/MainController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ class MainController : Initializable {
setPanels()
val selected = FXCollections.observableArrayList<App>()
var n = 0
items.forEach {
items.asSequence().forEach {
if (it.selectedProperty().get()) {
selected.add(it)
n += it.packagenameProperty().get().trim().lines().size
Expand Down

0 comments on commit 07bb723

Please sign in to comment.