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

Commit 2b7baf1

Browse files
authored
Merge pull request #1 from jackdevey/more-customisation
Add more customisation
2 parents 3ff882e + 1cd27c6 commit 2b7baf1

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

β€ŽCodeView/src/main/java/me/jackdevey/libraries/codeview/CodeView.ktβ€Ž

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,45 @@ import android.util.AttributeSet
66
import androidx.recyclerview.widget.LinearLayoutManager
77
import androidx.recyclerview.widget.RecyclerView
88

9+
/**
10+
* The main CodeView element
11+
*/
912
class CodeView : RecyclerView {
1013

1114
constructor(context: Context) : super(context)
1215
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
1316
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)
1417

18+
/**
19+
* The font size of the text
20+
*/
1521
var fontSize: Float = 14f
22+
23+
/**
24+
* The code to display on the view
25+
*/
1626
var code: String = "No code provided"
1727

28+
/**
29+
* Number each line
30+
*/
31+
var numberLines: Boolean = true
32+
33+
/**
34+
* Show all the changes made
35+
*/
1836
fun show() {
1937
val data : MutableList<Line> = mutableListOf()
2038
for ((i, line) in code.lines().withIndex()) {
2139
data.add(Line(i, line))
2240
}
23-
this.adapter = LineAdapter(data, fontSize)
41+
this.adapter = LineAdapter(data, fontSize, numberLines)
2442
this.layoutManager = LinearLayoutManager(context)
2543
}
2644

45+
/**
46+
* Draw the element
47+
*/
2748
override fun onDraw(canvas: Canvas) {
2849
super.onDraw(canvas)
2950
}

β€Ž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

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ You can customise the CodeView to make sure that it fits with the theme of your
4444
|----------|-----------|-------------|---------|--------|
4545
| code | String | The code to display on the view | "No code provided" | βœ” |
4646
| fontSize | Float | The font size of the text | 14f | βœ” |
47-
| numberLines | Boolean | Number each line | true | ❌ |
47+
| numberLines | Boolean | Number each line | true | βœ” |
4848
| backgroundColour | Color | The colour of the background | GREY | ❌ |
4949

5050

0 commit comments

Comments
Β (0)