Skip to content

Commit 68a26be

Browse files
committed
Фикс бага с консолью
1 parent a571d42 commit 68a26be

5 files changed

Lines changed: 9 additions & 5 deletions

File tree

app/src/main/java/com/apochromat/codeblockmobile/ProjectActivity.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,7 @@ class ProjectActivity : AppCompatActivity() {
560560
listBlocks[i].status = ok()
561561
blocksAdapter.notifyItemChanged(i)
562562
}
563-
if (listBlocks[i].type == "ConsoleInput"){
564-
listBlocks[i].activity = this
565-
}
563+
listBlocks[i].activity = this
566564

567565
}
568566
if (!connectionBlocks()) {
@@ -584,7 +582,7 @@ class ProjectActivity : AppCompatActivity() {
584582

585583
}
586584
}
587-
private fun disconnectAllBlocks(){
585+
fun disconnectAllBlocks(){
588586
for (i in 0 until listBlocks.size){
589587
listBlocks[i].prevBlock = null
590588
listBlocks[i].nextBlock = null

app/src/main/java/com/apochromat/codeblockmobile/logic/Block.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open class Block {
3737
lateinit var adapterConsole : ConsoleAdapter
3838
lateinit var adapterBlocks : BlocksAdapter
3939
lateinit var holder : BlocksAdapter.ViewHolder
40-
lateinit var activity: ProjectActivity
40+
var activity: ProjectActivity? = null
4141

4242
var crutch = true
4343

@@ -68,6 +68,7 @@ open class Block {
6868
when {
6969
nextBlock == null -> {
7070
isProgramRunning = false
71+
activity?.disconnectAllBlocks()
7172
adapterConsole.addMessage(programFinish(status))
7273
adapterBlocks.notifyItemChanged(indexListBlocks)
7374
}
@@ -76,6 +77,7 @@ open class Block {
7677
}
7778
else -> {
7879
isProgramRunning = false
80+
activity?.disconnectAllBlocks()
7981
adapterConsole.addMessage(programFinish(status))
8082
adapterBlocks.notifyItemChanged(indexListBlocks)
8183
}

app/src/main/java/com/apochromat/codeblockmobile/logic/ConsoleInput.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class ConsoleInput : Block() {
104104
when {
105105
nextB == null -> {
106106
isProgramRunning = false
107+
activity?.disconnectAllBlocks()
107108
adapterConsole.addMessage(programFinish(status))
108109
adapterBlocks.notifyItemChanged(indexListBlocks)
109110
}
@@ -112,6 +113,7 @@ class ConsoleInput : Block() {
112113
}
113114
else -> {
114115
isProgramRunning = false
116+
activity?.disconnectAllBlocks()
115117
adapterConsole.addMessage(programFinish(status))
116118
adapterBlocks.notifyItemChanged(indexListBlocks)
117119
}

app/src/main/java/com/apochromat/codeblockmobile/logic/EntryPoint.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class EntryPoint : Block() {
99
}
1010

1111
override fun executeBlock() {
12+
adapterConsole.addMessage(programStart())
1213
accessHeap().clearVariables()
1314
accessHeap().clearArrays()
1415
}

app/src/main/java/com/apochromat/codeblockmobile/logic/Strings.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var tagVariable = fun(): String { return "Variable" }
2929
var tagArray = fun(): String { return "Array" }
3030

3131
var programFinish = fun(status: String): String { return "Program finished with status: $status" }
32+
var programStart = fun(): String { return "Program started" }
3233

3334
var allComparators = listOf(">", ">=", "<", "<=", "==", "!=")
3435

0 commit comments

Comments
 (0)