Skip to content

Commit 9eddd2e

Browse files
committed
Create ActionableTextView interface
1 parent 9b07393 commit 9eddd2e

6 files changed

Lines changed: 32 additions & 27 deletions

File tree

app/src/main/java/com/orgzly/android/ui/views/TextViewWithMarkup.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ import com.orgzly.android.ui.views.style.DrawerSpan
1717
import com.orgzly.android.util.LogUtils
1818
import com.orgzly.android.util.OrgFormatter
1919

20-
2120
/**
2221
* [TextView] with markup support.
2322
*
2423
* Used for title, content and preface text.
2524
*/
26-
class TextViewWithMarkup : TextViewFixed {
25+
class TextViewWithMarkup : TextViewFixed, ActionableTextView {
2726
constructor(context: Context) : super(context) {
2827
// addTextChangedListener(EditTextWatcher())
2928
}
@@ -67,15 +66,15 @@ class TextViewWithMarkup : TextViewFixed {
6766
}
6867

6968
// TODO: Consider getting MainActivity's *ViewModel* here instead
70-
fun followLinkToNoteWithProperty(name: String, value: String) {
69+
override fun followLinkToNoteWithProperty(name: String, value: String) {
7170
MainActivity.followLinkToNoteWithProperty(name, value)
7271
}
7372

74-
fun followLinkToFile(path: String) {
73+
override fun followLinkToFile(path: String) {
7574
MainActivity.followLinkToFile(path)
7675
}
7776

78-
fun toggleDrawer(drawerSpan: DrawerSpan) {
77+
override fun toggleDrawer(drawerSpan: DrawerSpan) {
7978
val textSpanned = text as Spanned
8079

8180
val drawerStart = textSpanned.getSpanStart(drawerSpan)
@@ -109,7 +108,7 @@ class TextViewWithMarkup : TextViewFixed {
109108
text = builder
110109
}
111110

112-
fun toggleCheckbox(checkboxSpan: CheckboxSpan) {
111+
override fun toggleCheckbox(checkboxSpan: CheckboxSpan) {
113112
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, checkboxSpan)
114113

115114
val content = if (checkboxSpan.isChecked()) "[ ]" else "[X]"
@@ -171,3 +170,10 @@ class TextViewWithMarkup : TextViewFixed {
171170
val TAG: String = TextViewWithMarkup::class.java.name
172171
}
173172
}
173+
174+
interface ActionableTextView {
175+
fun toggleCheckbox(checkboxSpan: CheckboxSpan)
176+
fun followLinkToNoteWithProperty(name: String, value: String)
177+
fun toggleDrawer(drawerSpan: DrawerSpan)
178+
fun followLinkToFile(path: String)
179+
}

app/src/main/java/com/orgzly/android/ui/views/style/CheckboxSpan.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package com.orgzly.android.ui.views.style
33
import android.text.TextPaint
44
import android.text.style.ClickableSpan
55
import android.view.View
6-
import com.orgzly.android.ui.views.TextViewWithMarkup
6+
import com.orgzly.android.ui.views.ActionableTextView
77

88
/**
99
* @param content is `[ ]` or `[X]`
1010
* @param rawStart is a position of dash
1111
*/
1212
class CheckboxSpan(val content: CharSequence, val rawStart: Int, val rawEnd: Int) : ClickableSpan() {
1313

14-
override fun onClick(widget: View) {
15-
if (widget is TextViewWithMarkup) {
16-
widget.toggleCheckbox(this)
14+
override fun onClick(view: View) {
15+
if (view is ActionableTextView) {
16+
view.toggleCheckbox(this)
1717
}
1818
}
1919

app/src/main/java/com/orgzly/android/ui/views/style/CustomIdLinkSpan.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.orgzly.android.ui.views.style
22

33
import android.view.View
4-
import com.orgzly.android.ui.views.TextViewWithMarkup
4+
import com.orgzly.android.ui.views.ActionableTextView
55

66
class CustomIdLinkSpan(override val type: Int, val value: String, override val name: String?) : LinkSpan(type, value, name) {
7-
override fun onClick(widget: View) {
8-
if (widget is TextViewWithMarkup) {
9-
widget.followLinkToNoteWithProperty(PROPERTY, value)
7+
override fun onClick(view: View) {
8+
if (view is ActionableTextView) {
9+
view.followLinkToNoteWithProperty(PROPERTY, value)
1010
}
1111
}
1212

app/src/main/java/com/orgzly/android/ui/views/style/DrawerSpan.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package com.orgzly.android.ui.views.style
33
import android.text.TextPaint
44
import android.text.style.ClickableSpan
55
import android.view.View
6+
import com.orgzly.android.ui.views.ActionableTextView
67
import com.orgzly.android.ui.views.TextViewWithMarkup
78

89
class DrawerSpan(val name: String, val content: CharSequence, var isFolded: Boolean) : ClickableSpan() {
9-
override fun onClick(widget: View) {
10-
if (widget is TextViewWithMarkup) {
11-
widget.toggleDrawer(this)
10+
override fun onClick(view: View) {
11+
if (view is ActionableTextView) {
12+
view.toggleDrawer(this)
1213
}
1314
}
1415

app/src/main/java/com/orgzly/android/ui/views/style/FileLinkSpan.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.orgzly.android.ui.views.style
22

33
import android.os.Handler
4-
import android.text.style.ClickableSpan
54
import android.view.View
6-
import com.orgzly.android.ui.views.TextViewWithMarkup
5+
import com.orgzly.android.ui.views.ActionableTextView
76

87
class FileLinkSpan(override val type: Int, val path: String, override val name: String?) : LinkSpan(type, path, name) {
9-
override fun onClick(widget: View) {
10-
if (widget is TextViewWithMarkup) {
8+
override fun onClick(view: View) {
9+
if (view is ActionableTextView) {
1110
Handler().post { // Run after onClick to prevent Snackbar from closing immediately
12-
widget.followLinkToFile(path)
11+
view.followLinkToFile(path)
1312
}
1413
}
1514
}

app/src/main/java/com/orgzly/android/ui/views/style/IdLinkSpan.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.orgzly.android.ui.views.style
22

3-
import android.text.style.ClickableSpan
43
import android.view.View
5-
import com.orgzly.android.ui.views.TextViewWithMarkup
4+
import com.orgzly.android.ui.views.ActionableTextView
65

76
class IdLinkSpan(override val type: Int, val value: String, override val name: String?) : LinkSpan(type, value, name) {
8-
override fun onClick(widget: View) {
9-
if (widget is TextViewWithMarkup) {
10-
widget.followLinkToNoteWithProperty(PROPERTY, value)
7+
override fun onClick(view: View) {
8+
if (view is ActionableTextView) {
9+
view.followLinkToNoteWithProperty(PROPERTY, value)
1110
}
1211
}
1312

0 commit comments

Comments
 (0)