Skip to content

Commit 4750eda

Browse files
committed
Update
1 parent d17821a commit 4750eda

12 files changed

Lines changed: 511 additions & 1 deletion

File tree

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@
9393
<action android:name="android.intent.action.VIEW" />
9494
</intent-filter>
9595
</activity>
96+
<activity
97+
android:name=".TextEditorActivity"
98+
android:exported="false"
99+
android:label="@string/app_name"
100+
android:windowSoftInputMode="adjustResize"
101+
android:configChanges="keyboardHidden|orientation|layoutDirection|screenLayout|colorMode|fontScale|smallestScreenSize|density|keyboard|screenSize|touchscreen" />
96102
<activity
97103
android:theme="@style/AppThemeDark"
98104
android:name=".CrashLogActivity"

app/src/main/assets/home/etc/boot

-672 Bytes
Binary file not shown.

app/src/main/java/com/omarea/krscript/config/PageConfigReader.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class PageConfigReader {
111111
var group: GroupNode? = null
112112
var page: PageNode? = null
113113
var text: TextNode? = null
114+
var editor: EditorNode? = null
114115
var isRootNode = true
115116
while (type != XmlPullParser.END_DOCUMENT) { // 如果事件不等于文档结束事件就继续循环
116117
when (type) {
@@ -141,6 +142,11 @@ class PageConfigReader {
141142
}
142143
} else if ("text" == parser.name) {
143144
text = mainNode(TextNode(pageConfigAbsPath), parser) as TextNode?
145+
} else if ("editor" == parser.name) {
146+
editor = clickbleNode(EditorNode(pageConfigAbsPath), parser) as EditorNode?
147+
if (editor != null) {
148+
editor = editorNode(editor, parser)
149+
}
144150
} else if (page != null) {
145151
tagStartInPage(page, parser)
146152
} else if (action != null) {
@@ -200,6 +206,12 @@ class PageConfigReader {
200206
}
201207
text = null
202208
}
209+
"editor" -> {
210+
if (editor != null) {
211+
group.children.add(editor)
212+
}
213+
editor = null
214+
}
203215
}
204216
} else {
205217
when (parser.name) {
@@ -238,6 +250,12 @@ class PageConfigReader {
238250
}
239251
text = null
240252
}
253+
"editor" -> {
254+
if (editor != null) {
255+
mainList.add(editor)
256+
}
257+
editor = null
258+
}
241259
}
242260
}
243261
}
@@ -597,6 +615,19 @@ class PageConfigReader {
597615
}
598616
}
599617

618+
// Đọc thuộc tính riêng của thẻ <editor file="" title="" desc="" wrap="" />
619+
private fun editorNode(editor: EditorNode, parser: XmlPullParser): EditorNode {
620+
for (attrIndex in 0 until parser.attributeCount) {
621+
val attrName = parser.getAttributeName(attrIndex)
622+
val attrValue = parser.getAttributeValue(attrIndex)
623+
when (attrName) {
624+
"file", "path" -> editor.file = attrValue.trim()
625+
"wrap" -> editor.wrap = !(attrValue == "0" || attrValue == "false" || attrValue == "off" || attrValue == "no-wrap")
626+
}
627+
}
628+
return editor
629+
}
630+
600631
private fun descNode(nodeInfoBase: NodeInfoBase, parser: XmlPullParser) {
601632
for (i in 0 until parser.attributeCount) {
602633
val attrName = parser.getAttributeName(i)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.omarea.krscript.model
2+
3+
/**
4+
* Node cho thẻ <editor file="" title="" desc="" ... />
5+
* Khi người dùng bấm vào mục này, ứng dụng sẽ mở trang soạn thảo văn bản (TextEditorActivity)
6+
* để xem/sửa nội dung file được chỉ định bởi thuộc tính "file".
7+
* Nếu file chưa tồn tại thì trang soạn thảo sẽ tạo mới khi lưu.
8+
*/
9+
class EditorNode(currentConfigXml: String) : ClickableNode(currentConfigXml) {
10+
// Đường dẫn file cần mở để soạn thảo (bắt buộc)
11+
var file: String = ""
12+
13+
// Trạng thái ngắt dòng mặc định khi mở trang soạn thảo (mặc định: bật ngắt dòng)
14+
var wrap: Boolean = true
15+
}

app/src/main/java/com/omarea/krscript/ui/ActionListFragment.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ class ActionListFragment : androidx.fragment.app.Fragment(), PageLayoutRender.On
207207
}
208208
}
209209

210+
override fun onEditorClick(item: EditorNode, onCompleted: Runnable) {
211+
if (!checkAndLockClick()) return
212+
if (nodeUnlocked(item)) {
213+
val context = context ?: return
214+
if (item.file.isEmpty()) {
215+
Toast.makeText(context, getString(R.string.editor_file_missing), Toast.LENGTH_SHORT).show()
216+
return
217+
}
218+
com.tool.tree.TextEditorActivity.start(context, item.file, item.title, item.desc, item.wrap, item.pageConfigDir)
219+
onCompleted.run()
220+
}
221+
}
222+
210223
override fun onPickerClick(item: PickerNode, onCompleted: Runnable) {
211224
if (!checkAndLockClick()) return
212225
if (nodeUnlocked(item)) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.omarea.krscript.ui
2+
3+
import android.content.Context
4+
import android.view.View
5+
import android.widget.ImageView
6+
import com.tool.tree.R
7+
import com.omarea.krscript.model.EditorNode
8+
9+
class ListItemEditor(context: Context, config: EditorNode) : ListItemClickable(context, R.layout.kr_action_list_item, config) {
10+
private val widgetView = layout.findViewById<ImageView?>(R.id.kr_widget)
11+
12+
init {
13+
widgetView?.visibility = View.VISIBLE
14+
widgetView?.setImageDrawable(context.getDrawable(R.drawable.kr_script))
15+
}
16+
}

app/src/main/java/com/omarea/krscript/ui/PageLayoutRender.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class PageLayoutRender(private val mContext: Context,
1818
fun onActionClick(item: ActionNode, onCompleted: Runnable)
1919
fun onSwitchClick(item: SwitchNode, onCompleted: Runnable)
2020
fun onPickerClick(item: PickerNode, onCompleted: Runnable)
21+
fun onEditorClick(item: EditorNode, onCompleted: Runnable)
2122
fun onItemLongClick(clickableNode: ClickableNode)
2223
}
2324

@@ -55,6 +56,7 @@ class PageLayoutRender(private val mContext: Context,
5556
is ActionNode -> clickListener.onActionClick(item, getCommonOnExitRunnable(item, listItemView))
5657
is PickerNode -> clickListener.onPickerClick(item, getCommonOnExitRunnable(item, listItemView))
5758
is SwitchNode -> clickListener.onSwitchClick(item, getCommonOnExitRunnable(item, listItemView))
59+
is EditorNode -> clickListener.onEditorClick(item, getCommonOnExitRunnable(item, listItemView))
5860
}
5961
}
6062

@@ -98,6 +100,8 @@ class PageLayoutRender(private val mContext: Context,
98100
uiRender = createListItem(it)
99101
} else if (it is TextNode) {
100102
uiRender = if (parent.isRootGroup) createTextItem(it) else createTextItemWhite(it)
103+
} else if (it is EditorNode) {
104+
uiRender = createEditorItem(it)
101105
} else if (it is GroupNode) {
102106
val subGroup = createItemGroup(it)
103107
if (it.children.isNotEmpty()) {
@@ -143,6 +147,10 @@ class PageLayoutRender(private val mContext: Context,
143147
return ListItemAction(mContext, node)
144148
}
145149

150+
private fun createEditorItem(node: EditorNode): ListItemView {
151+
return ListItemEditor(mContext, node)
152+
}
153+
146154
private fun createItemGroup(node: GroupNode): ListItemGroup {
147155
return ListItemGroup(mContext, false, node)
148156
}

0 commit comments

Comments
 (0)