Skip to content

Commit 2fc9e0e

Browse files
committed
Infinity line note views (not customizable) adding
1 parent b07530b commit 2fc9e0e

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

codeview/src/main/java/io/github/kbiakov/codeview/CodeContentAdapter.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,14 @@ class CodeContentAdapter : RecyclerView.Adapter<CodeContentAdapter.ViewHolder> {
234234
notes?.let {
235235
holder.llLineNotes.visibility = if (it.isNotEmpty()) View.VISIBLE else View.GONE
236236

237+
val noteBg = colorTheme.bgNum.color()
238+
val noteColor = colorTheme.noteColor.color()
239+
var isFirst = true
240+
237241
it.forEach { note ->
238-
val noteView = LineNoteView.create(mContext, note, colorTheme.noteColor.color())
242+
val noteView = LineNoteView.create(mContext, note, isFirst, noteBg, noteColor)
239243
holder.llLineNotes.addView(noteView)
244+
isFirst = false
240245
}
241246
}
242247
}
@@ -247,14 +252,14 @@ class CodeContentAdapter : RecyclerView.Adapter<CodeContentAdapter.ViewHolder> {
247252
val isLast = position == itemCount - 1
248253

249254
if (isFirst || isLast) {
250-
// itemView.layoutParams.height = dp8 * 4
255+
// holder.itemView.layoutParams.height = dp8 * 4
251256

252257
val topPadding = if (isFirst) dp8 else 0
253258
val bottomPadding = if (isLast) dp8 else 0
254259
holder.tvLineNum.setPadding(0, topPadding, 0, bottomPadding)
255260
holder.tvLineContent.setPadding(0, topPadding, 0, bottomPadding)
256261
} else {
257-
// itemView.layoutParams.height = dp8 * 3
262+
// holder.itemView.layoutParams.height = dp8 * 3
258263

259264
holder.tvLineNum.setPadding(0, 0, 0, 0)
260265
holder.tvLineContent.setPadding(0, 0, 0, 0)
@@ -271,16 +276,14 @@ class CodeContentAdapter : RecyclerView.Adapter<CodeContentAdapter.ViewHolder> {
271276
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
272277
var tvLineNum: TextView
273278
var tvLineContent: TextView
274-
var rlLineBlock: RelativeLayout
275279
var llLineNotes: LinearLayout
276280

277281
var mItem: String? = null
278282

279283
init {
280284
tvLineNum = itemView.findViewById(R.id.tv_line_num) as TextView
281285
tvLineContent = itemView.findViewById(R.id.tv_line_content) as TextView
282-
rlLineBlock = itemView.findViewById(R.id.rl_line_block) as RelativeLayout
283-
llLineNotes = itemView.findViewById(R.id.ll_line_notes) as LinearLayout
286+
llLineNotes = itemView.findViewById(R.id.ll_line_footer) as LinearLayout
284287
}
285288

286289
override fun toString() = "${super.toString()} '$mItem'"

codeview/src/main/java/io/github/kbiakov/codeview/LineNoteView.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,35 @@ package io.github.kbiakov.codeview
33
import android.content.Context
44
import android.widget.TextView
55

6+
/**
7+
* Simple note view for code line.
8+
*
9+
* @author Kirill Biakov
10+
*/
611
class LineNoteView(context: Context?) : TextView(context) {
712

813
companion object Factory {
9-
fun create(context: Context, text: String, textColor: Int): LineNoteView {
14+
/**
15+
* Simple factory method to create note view.
16+
*
17+
* @param context Context
18+
* @param text Note text
19+
* @param isFirst If is first note
20+
* @param bgColor Background color
21+
* @param textColor Text Color
22+
* @return Created line note view
23+
*/
24+
fun create(context: Context, text: String, isFirst: Boolean,
25+
bgColor: Int, textColor: Int): LineNoteView {
1026
val noteView = LineNoteView(context)
1127
noteView.textSize = 12f
1228
noteView.text = text
1329
noteView.setTextColor(textColor)
30+
noteView.setBackgroundColor(bgColor)
31+
32+
val dp8 = dpToPx(context, 8)
33+
noteView.setPadding(dpToPx(context, 48), if (isFirst) dp8 else 0, dp8, dp8)
34+
1435
return noteView
1536
}
1637
}

codeview/src/main/res/layout/item_code_line.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
<RelativeLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="match_parent"
5-
android:layout_height="wrap_content"
6-
android:animateLayoutChanges="true">
5+
android:layout_height="wrap_content">
76

87
<TextView
98
android:id="@+id/tv_line_num"
109
android:layout_width="32dp"
11-
android:layout_height="match_parent"
10+
android:layout_height="24dp"
1211
android:gravity="center"
1312
android:fontFamily="monospace"
1413
android:textSize="12sp"
@@ -27,13 +26,12 @@
2726
android:textSize="12sp"
2827
android:text="@string/stub_line_content"/>
2928

30-
<!--
3129
<LinearLayout
32-
android:id="@+id/ll_line_notes"
30+
android:id="@+id/ll_line_footer"
3331
android:layout_width="match_parent"
3432
android:layout_height="match_parent"
3533
android:layout_below="@+id/tv_line_content"
3634
android:orientation="vertical"
37-
android:visibility="gone"/>-->
35+
android:visibility="gone"/>
3836

3937
</RelativeLayout>

example/src/main/java/io/github/kbiakov/codeviewexample/ListingsActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
1717
super.onCreate(savedInstanceState);
1818
setContentView(R.layout.activity_listings);
1919

20-
//int myColor = ContextCompat.getColor(this, R.color.code_content_background);
20+
// int myColor = ContextCompat.getColor(this, R.color.code_content_background);
2121

2222
final CodeView codeView = (CodeView) findViewById(R.id.code_view);
2323

@@ -28,7 +28,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2828

2929
// do not use chaining for built view
3030
// (you can, but follow it should be performed sequentially)
31-
codeView.setCodeContent(getString(R.string.mark));
31+
codeView.setCodeContent(getString(R.string.listing_java));
3232
codeView.setColorTheme(ColorTheme.DEFAULT);
3333
codeView.highlightCode("java");
3434

0 commit comments

Comments
 (0)