@@ -194,7 +194,7 @@ abstract class AbstractCodeAdapter<T> : RecyclerView.Adapter<AbstractCodeAdapter
194
194
}
195
195
196
196
private fun showAllBottomNote () = mContext.getString(R .string.show_all)
197
-
197
+
198
198
private fun monoTypeface () = MonoFontCache .getInstance(mContext).typeface
199
199
200
200
// - View holder
@@ -230,6 +230,12 @@ abstract class AbstractCodeAdapter<T> : RecyclerView.Adapter<AbstractCodeAdapter
230
230
231
231
override fun getItemCount () = mLines.size
232
232
233
+ private fun Int.isFirst () = this == 0
234
+ private fun Int.isLast () = this == itemCount - 1
235
+ private fun Int.isJustFirst () = isFirst() && ! isLast()
236
+ private fun Int.isJustLast () = isLast() && ! isFirst()
237
+ private fun Int.isBorder () = isFirst() || isLast()
238
+
233
239
// - Helpers (for view holder)
234
240
235
241
private fun setupLine (position : Int , line : String , holder : ViewHolder ) {
@@ -266,13 +272,10 @@ abstract class AbstractCodeAdapter<T> : RecyclerView.Adapter<AbstractCodeAdapter
266
272
}
267
273
268
274
private fun addExtraPadding (position : Int , holder : ViewHolder ) {
269
- val dp8 = dpToPx(mContext, 8 )
270
- val isFirst = position == 0
271
- val isLast = position == itemCount - 1
272
-
273
- if (isFirst || isLast) {
274
- val topPadding = if (isFirst) dp8 else 0
275
- val bottomPadding = if (isLast) dp8 else 0
275
+ if (position.isBorder()) {
276
+ val dp8 = dpToPx(mContext, 8 )
277
+ val topPadding = if (position.isJustFirst()) dp8 else 0
278
+ val bottomPadding = if (position.isJustLast()) dp8 else 0
276
279
holder.tvLineNum.setPadding(0 , topPadding, 0 , bottomPadding)
277
280
holder.tvLineContent.setPadding(0 , topPadding, 0 , bottomPadding)
278
281
} else {
0 commit comments