@@ -194,7 +194,7 @@ abstract class AbstractCodeAdapter<T> : RecyclerView.Adapter<AbstractCodeAdapter
194194 }
195195
196196 private fun showAllBottomNote () = mContext.getString(R .string.show_all)
197-
197+
198198 private fun monoTypeface () = MonoFontCache .getInstance(mContext).typeface
199199
200200 // - View holder
@@ -230,6 +230,12 @@ abstract class AbstractCodeAdapter<T> : RecyclerView.Adapter<AbstractCodeAdapter
230230
231231 override fun getItemCount () = mLines.size
232232
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+
233239 // - Helpers (for view holder)
234240
235241 private fun setupLine (position : Int , line : String , holder : ViewHolder ) {
@@ -266,13 +272,10 @@ abstract class AbstractCodeAdapter<T> : RecyclerView.Adapter<AbstractCodeAdapter
266272 }
267273
268274 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
276279 holder.tvLineNum.setPadding(0 , topPadding, 0 , bottomPadding)
277280 holder.tvLineContent.setPadding(0 , topPadding, 0 , bottomPadding)
278281 } else {
0 commit comments