This repository was archived by the owner on Apr 19, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
CodeView/src/main/java/me/jackdevey/libraries/codeview Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package me.jackdevey.libraries.codeview
22
33import android.content.Context
44import android.graphics.Canvas
5+ import android.graphics.Color
56import android.util.AttributeSet
67import androidx.recyclerview.widget.LinearLayoutManager
78import 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
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ import org.bandev.libraries.databinding.LineBinding
1010class 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
You can’t perform that action at this time.
0 commit comments