@@ -15,15 +15,12 @@ import io.github.kbiakov.codeview.highlight.FontCache
1515 *
1616 * @author Kirill Biakov
1717 */
18- class LineDiffView : RelativeLayout {
18+ class LineDiffView ( context : Context ) : RelativeLayout(context) {
1919
2020 private val tvLineDiff: TextView
2121 private val tvLineContent: TextView
2222
23- /* *
24- * Default constructor.
25- */
26- constructor (context: Context ) : super (context) {
23+ init {
2724 val inflater = context.getSystemService(Context .LAYOUT_INFLATER_SERVICE ) as LayoutInflater
2825 inflater.inflate(R .layout.item_code_diff, this , true )
2926
@@ -39,19 +36,16 @@ class LineDiffView : RelativeLayout {
3936 * @param model Diff model
4037 * @return Created line diff view
4138 */
42- fun create (context : Context , model : DiffModel ): LineDiffView {
43- val diffView = LineDiffView (context)
44- diffView.tvLineDiff.text = if (model.isAddition) " +" else " -"
45- diffView.tvLineContent.text = model.content
46- diffView.tvLineContent.typeface = FontCache .get(context).getTypeface(context)
39+ fun create (context : Context , model : DiffModel ) = LineDiffView (context).apply {
40+ tvLineDiff.text = if (model.isAddition) " +" else " -"
41+ tvLineContent.text = model.content
42+ tvLineContent.typeface = FontCache .get(context).getTypeface(context)
4743
48- diffView. setBackgroundColor(ContextCompat .getColor(context,
44+ setBackgroundColor(ContextCompat .getColor(context,
4945 if (model.isAddition)
5046 R .color.diff_add_background
5147 else
5248 R .color.diff_del_background))
53-
54- return diffView
5549 }
5650 }
5751}
0 commit comments