Skip to content

Commit

Permalink
Issue #3 is solved
Browse files Browse the repository at this point in the history
View save state added
  • Loading branch information
W3-Tariqul committed May 2, 2019
1 parent 5ef5b1e commit 8057e62
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 37 deletions.
29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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**.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.skyhope.showmoretextview;

/*
* ****************************************************************************
* * Created by : Md Tariqul Islam on 5/2/2019 at 4:28 PM.
* * Email : [email protected]
* *
* * Purpose:
* *
* * Last edited by : Md Tariqul Islam on 5/2/2019.
* *
* * Last Reviewed by : <Reviewer Name> on <mm/dd/yy>
* ****************************************************************************
*/

public class SaveState {
public static boolean isCollapse = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class ShowMoreTextView extends TextView {

private boolean isAlreadySet;


public ShowMoreTextView(Context context) {
super(context);
}
Expand All @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -114,6 +128,8 @@ public void onGlobalLayout() {
Log.d(TAG, "Text: " + showingText);
newText += dotdot + showMore;

SaveState.isCollapse = true;

setText(newText);
}

Expand All @@ -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);

Expand Down Expand Up @@ -215,8 +232,13 @@ public void setShowingLine(int lineNumber) {

setMaxLines(showingLine);

if (SaveState.isCollapse) {
addShowMore();
} else {
setMaxLines(Integer.MAX_VALUE);
showLessButton();
}

addShowMore();
}

/**
Expand All @@ -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();
}
}

/**
Expand Down

0 comments on commit 8057e62

Please sign in to comment.