Skip to content

Commit 5445d7e

Browse files
committed
Upload file
1 parent f6ae1a7 commit 5445d7e

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

krscript/src/main/java/com/omarea/krscript/model/ShellHandlerBase.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public abstract class ShellHandlerBase extends Handler {
3939
*/
4040
public static final int EVENT_EXIT = -2;
4141

42+
protected abstract void onToast(String text);
43+
4244
protected abstract void onProgress(int current, int total);
4345

4446
protected abstract void onStart(Object msg);
@@ -79,17 +81,35 @@ public void handleMessage(Message msg) {
7981
}
8082

8183
protected void onReaderMsg(Object msg) {
82-
if (msg != null) {
83-
String log = msg.toString().trim();
84-
if (Pattern.matches("^progress:\\[[\\-0-9\\\\]{1,}/[0-9\\\\]{1,}]$", log)) {
85-
String[] values = log.substring("progress:[".length(), log.indexOf("]")).split("/");
86-
int start = Integer.parseInt(values[0]);
87-
int total = Integer.parseInt(values[1]);
88-
onProgress(start, total);
89-
} else {
90-
onReader(msg);
84+
if (msg == null) return;
85+
86+
// KHÔNG trim để giữ newline
87+
String log = msg.toString();
88+
89+
// progress:[x/y]
90+
if (Pattern.matches("^progress:\\[[\\-0-9]+/[0-9]+]$", log.trim())) {
91+
String[] values = log
92+
.substring("progress:[".length(), log.indexOf("]"))
93+
.split("/");
94+
95+
int start = Integer.parseInt(values[0]);
96+
int total = Integer.parseInt(values[1]);
97+
onProgress(start, total);
98+
return;
99+
}
100+
101+
// toast:[text...]
102+
if (log.startsWith("toast:[")) {
103+
int end = log.lastIndexOf("]");
104+
if (end > 6) {
105+
String text = log.substring(6, end);
106+
onToast(text);
91107
}
108+
return;
92109
}
110+
111+
// log thường
112+
onReader(msg);
93113
}
94114

95115
protected void onReader(Object msg) {

krscript/src/main/java/com/omarea/krscript/ui/DialogLogFragment.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ class DialogLogFragment : androidx.fragment.app.DialogFragment() {
231231
}
232232
}
233233
}
234+
235+
override fun onToast(text: String) {
236+
logView?.post {
237+
context?.let {
238+
Toast.makeText(it, text, Toast.LENGTH_LONG).show()
239+
}
240+
}
241+
}
234242

235243
override fun onStart(msg: Any?) {
236244
logView?.text = ""

0 commit comments

Comments
 (0)