diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 2996d53..6153c14 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -3,11 +3,15 @@ diff --git a/README.md b/README.md index b031c47..f2e4ab8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Release](https://jitpack.io/v/mahimrocky/ShowMoreText.svg)](https://github.com/mahimrocky/ShowMoreText/releases/tag/1.0.1) +[![Release](https://jitpack.io/v/mahimrocky/ShowMoreText.svg)](https://github.com/mahimrocky/ShowMoreText/releases/tag/1.0.2) # ShowMoreText @@ -25,7 +25,7 @@ Sample ```sh dependencies { - implementation 'com.github.mahimrocky:ShowMoreText:1.0.1' + implementation 'com.github.mahimrocky:ShowMoreText:1.0.2' } ``` You have to use just this xml. You can modify or set color your own textView. **But don`t need to use maxLength or maxLine in text view. It may be confilict with library**. diff --git a/showmoretextview/src/main/java/com/skyhope/showmoretextview/SaveState.java b/showmoretextview/src/main/java/com/skyhope/showmoretextview/SaveState.java new file mode 100644 index 0000000..d844a9f --- /dev/null +++ b/showmoretextview/src/main/java/com/skyhope/showmoretextview/SaveState.java @@ -0,0 +1,18 @@ +package com.skyhope.showmoretextview; + +/* + * **************************************************************************** + * * Created by : Md Tariqul Islam on 5/2/2019 at 4:28 PM. + * * Email : tariqul@w3engineers.com + * * + * * Purpose: + * * + * * Last edited by : Md Tariqul Islam on 5/2/2019. + * * + * * Last Reviewed by : on + * **************************************************************************** + */ + +public class SaveState { + public static boolean isCollapse = true; +} diff --git a/showmoretextview/src/main/java/com/skyhope/showmoretextview/ShowMoreTextView.java b/showmoretextview/src/main/java/com/skyhope/showmoretextview/ShowMoreTextView.java index 2752104..218e87a 100644 --- a/showmoretextview/src/main/java/com/skyhope/showmoretextview/ShowMoreTextView.java +++ b/showmoretextview/src/main/java/com/skyhope/showmoretextview/ShowMoreTextView.java @@ -2,6 +2,7 @@ import android.content.Context; import android.graphics.Color; +import android.os.Parcelable; import android.support.annotation.Nullable; import android.text.Spannable; import android.text.SpannableString; @@ -49,6 +50,7 @@ public class ShowMoreTextView extends TextView { private boolean isAlreadySet; + public ShowMoreTextView(Context context) { super(context); } @@ -65,6 +67,15 @@ protected void onFinishInflate() { mainText = getText().toString(); } + @Override + public Parcelable onSaveInstanceState() { + return super.onSaveInstanceState(); + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + super.onRestoreInstanceState(state); + } private void addShowMore() { ViewTreeObserver vto = getViewTreeObserver(); @@ -87,6 +98,9 @@ public void onGlobalLayout() { } String newText = text.substring(0, showingChar); newText += dotdot + showMore; + + SaveState.isCollapse = true; + setText(newText); Log.d(TAG, "Text: " + newText); } else { @@ -114,6 +128,8 @@ public void onGlobalLayout() { Log.d(TAG, "Text: " + showingText); newText += dotdot + showMore; + SaveState.isCollapse = true; + setText(newText); } @@ -140,6 +156,7 @@ public void updateDrawState(TextPaint ds) { public void onClick(@Nullable View view) { setMaxLines(Integer.MAX_VALUE); setText(mainText); + SaveState.isCollapse = false; showLessButton(); Log.d(TAG, "Item clicked: " + mainText); @@ -215,8 +232,13 @@ public void setShowingLine(int lineNumber) { setMaxLines(showingLine); + if (SaveState.isCollapse) { + addShowMore(); + } else { + setMaxLines(Integer.MAX_VALUE); + showLessButton(); + } - addShowMore(); } /** @@ -237,8 +259,12 @@ public void setShowingChar(int character) { isCharEnable = true; this.showingChar = character; - - addShowMore(); + if (SaveState.isCollapse) { + addShowMore(); + } else { + setMaxLines(Integer.MAX_VALUE); + showLessButton(); + } } /**