Skip to content
This repository was archived by the owner on Apr 19, 2022. It is now read-only.

Commit 0bdc518

Browse files
committed
Add numberLines variable
1 parent 9cb9663 commit 0bdc518

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CodeView/src/main/java/me/jackdevey/libraries/codeview/CodeView.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package me.jackdevey.libraries.codeview
22

33
import android.content.Context
44
import android.graphics.Canvas
5+
import android.graphics.Color
56
import android.util.AttributeSet
67
import androidx.recyclerview.widget.LinearLayoutManager
78
import androidx.recyclerview.widget.RecyclerView
@@ -14,13 +15,14 @@ class CodeView : RecyclerView {
1415

1516
var fontSize: Float = 14f
1617
var code: String = "No code provided"
18+
var numberLines: Boolean = true
1719

1820
fun show() {
1921
val data : MutableList<Line> = mutableListOf()
2022
for ((i, line) in code.lines().withIndex()) {
2123
data.add(Line(i, line))
2224
}
23-
this.adapter = LineAdapter(data, fontSize)
25+
this.adapter = LineAdapter(data, fontSize, numberLines)
2426
this.layoutManager = LinearLayoutManager(context)
2527
}
2628

CodeView/src/main/java/me/jackdevey/libraries/codeview/LineAdapter.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import org.bandev.libraries.databinding.LineBinding
1010
class LineAdapter(
1111

1212
private val lines: MutableList<Line>,
13-
private val fontSize: Float
13+
private val fontSize: Float,
14+
private val numberLines: Boolean
1415

1516
) : RecyclerView.Adapter<LineAdapter.ViewHolder>() {
1617

@@ -28,10 +29,12 @@ class LineAdapter(
2829
text = currentItem.lineText
2930
textSize = fontSize
3031
}
31-
with(holder.lineNumber) {
32-
text = currentItem.lineNumber.toString().padStart(3, '0')
33-
textSize = fontSize
34-
}
32+
if(numberLines) {
33+
with(holder.lineNumber) {
34+
text = currentItem.lineNumber.toString().padStart(3, '0')
35+
textSize = fontSize
36+
}
37+
}else holder.lineNumber.visibility = View.INVISIBLE
3538
}
3639

3740
override fun getItemCount(): Int = lines.size

0 commit comments

Comments
 (0)