Skip to content

Commit 5f232a4

Browse files
author
e16din
committed
fix onCodeLineClicked line number;
changed vPlaceholder.visibility to vPlaceholder.alpha to fix animation blinking when android:animateLayoutChanges is true and we has several CodeView in the Layout;
1 parent b4a6820 commit 5f232a4

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import android.view.LayoutInflater
66
import android.view.View
77
import android.view.ViewGroup
88
import android.widget.TextView
9-
import io.github.kbiakov.codeview.classifier.CodeProcessor
10-
import io.github.kbiakov.codeview.highlight.*
119
import io.github.kbiakov.codeview.Thread.async
1210
import io.github.kbiakov.codeview.Thread.ui
1311
import io.github.kbiakov.codeview.classifier.CodeClassifier
12+
import io.github.kbiakov.codeview.classifier.CodeProcessor
13+
import io.github.kbiakov.codeview.highlight.*
1414
import java.util.*
1515

1616
/**
@@ -178,7 +178,7 @@ class CodeContentAdapter : RecyclerView.Adapter<CodeContentAdapter.ViewHolder> {
178178
holder.mItem = codeLine
179179

180180
holder.itemView.setOnClickListener {
181-
codeListener?.onCodeLineClicked(position)
181+
codeListener?.onCodeLineClicked(position + 1)
182182
}
183183

184184
holder.tvLineContent.text = html(codeLine)

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import android.view.ViewPropertyAnimator
1313
import android.widget.RelativeLayout
1414
import io.github.kbiakov.codeview.highlight.ColorTheme
1515
import io.github.kbiakov.codeview.highlight.ColorThemeData
16-
import io.github.kbiakov.codeview.highlight.color
1716
import java.util.*
1817

1918
/**
@@ -186,7 +185,7 @@ class CodeView : RelativeLayout {
186185
* @param isVisible Shadows visibility
187186
*/
188187
fun setShadowsVisible(isVisible: Boolean = true) = addTask {
189-
val visibility = if (isVisible) View.VISIBLE else GONE
188+
val visibility = if (isVisible) VISIBLE else GONE
190189
vShadowRight.visibility = visibility
191190
vShadowBottomLine.visibility = visibility
192191
vShadowBottomContent.visibility = visibility
@@ -271,17 +270,16 @@ class CodeView : RelativeLayout {
271270

272271
vPlaceholder.layoutParams = RelativeLayout.LayoutParams(
273272
RelativeLayout.LayoutParams.MATCH_PARENT, height)
274-
vPlaceholder.visibility = View.VISIBLE
273+
274+
vPlaceholder.alpha = 1f
275275
}
276276

277277
// - Animations
278278

279279
private fun hidePlaceholder() = vPlaceholder.animate()
280280
.setDuration(350)
281281
.alpha(0f)
282-
.didAnimated {
283-
vPlaceholder.visibility = View.GONE
284-
}
282+
.didAnimated { vPlaceholder.alpha = 0f }
285283

286284
private fun refreshAnimated() = animate()
287285
.setDuration(150)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import android.os.Bundle;
44
import android.support.annotation.Nullable;
5-
import android.support.v4.content.ContextCompat;
65
import android.support.v7.app.AppCompatActivity;
76
import android.util.Log;
87

98
import io.github.kbiakov.codeview.CodeView;
9+
import io.github.kbiakov.codeview.OnCodeLineClickListener;
1010
import io.github.kbiakov.codeview.highlight.ColorTheme;
1111

1212
public class ListingsActivity extends AppCompatActivity {
@@ -18,7 +18,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
1818

1919
//int myColor = ContextCompat.getColor(this, R.color.code_content_background);
2020

21-
CodeView codeView = (CodeView) findViewById(R.id.code_view);
21+
final CodeView codeView = (CodeView) findViewById(R.id.code_view);
2222

2323
// use chaining to build view
2424
codeView.highlightCode("js")
@@ -30,5 +30,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3030
codeView.setCodeContent(getString(R.string.listing_java));
3131
codeView.setColorTheme(ColorTheme.DEFAULT);
3232
codeView.highlightCode("java");
33+
34+
codeView.setCodeListener(new OnCodeLineClickListener() {
35+
@Override
36+
public void onCodeLineClicked(int n) {
37+
Log.i("example", "Line: " + n);
38+
}
39+
});
3340
}
3441
}

example/src/main/res/layout/activity_listings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:animateLayoutChanges="true"
78
tools:context=".ListingsActivity">
89

910
<io.github.kbiakov.codeview.CodeView

0 commit comments

Comments
 (0)