GithubHelp home page GithubHelp logo

eriffanani / textviewreadmore Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 0.0 360 KB

Android library for creating expand button on your long textview

License: Apache License 2.0

Java 100.00%
android android-library java kotlin readmore textviews expandabletextview textview-android endlesstext expandabletext

textviewreadmore's Introduction

TextView Read More

Make your long textview setup easily and quickly

Installation

settings.gradle

dependencyResolutionManagement {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

build.gradle(app)

dependencies {
    implementation 'com.github.eriffanani:TextViewReadMore:4.1.0'
}

How To Use

  • Basic
<com.erif.readmoretextview.TextViewReadMore
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:readMoreMaxLines="3" (Default 1)
    android:text="YOUR TEXT HERE"/>

basic

Styling

  • Expand
<com.erif.readmoretextview.TextViewReadMore
    app:readMoreMaxLines="3" (Default 1)
    app:expandText="Open Text" (Default "Read More")
    app:expandTextColor="@color/teal_200" (Default Color.BLUE)
    app:expandTextStyle="bold|italic" (Default normal)
    app:expandTextUnderline="true" (Default false)
    android:text="YOUR TEXT HERE"/>

styling

  • Collapse
<com.erif.readmoretextview.TextViewReadMore
    app:collapseText="Close Text" (Default "Close")
    app:collapseTextColor="@color/teal_200" (Default Color.BLUE)
    app:collapseTextStyle="bold|italic" (Default normal)
    app:collapseTextUnderline="true" (Default false)
    app:collapsed="false" (Default true)/>

Animation

<com.erif.readmoretextview.TextViewReadMore
        app:duration="200"
        app:interpolator=""
        app:interpolatorExpand="bounce"
        app:durationExpand="800"
        app:interpolatorCollapse="anticipate_overshoot"
        app:durationCollapse="900"/>

<!--Animation Interpolator-->
<flag name="decelerate"/>
<flag name="accelerate"/>
<flag name="anticipate_overshoot"/>
<flag name="anticipate"/>
<flag name="bounce"/>
<flag name="fast_out_linear_in"/>
<flag name="fast_out_slow_in"/>
<flag name="linear_out_slow_in"/>

Ellipsis Type

<com.erif.readmoretextview.TextViewReadMore
    app:ellipsisType="none" (Default dots)/>

Action

<com.erif.readmoretextview.TextViewReadMore
    app:actionClickColor="@color/colorRed" (Default @color/text_view_read_more_button_hover_color)/>
TextViewReadMore txtReadMore = findViewById(R.id.txtReadMore);
txtReadMore.onClickExpand(v -> txtReadMore.toggle());
txtReadMore.onClickCollapse(v -> txtReadMore.toggle());

Listener

  • Java
txtReadMore.toggleListener(collapsed -> { // TODO ACTION });
  • Kotlin
txtReadMore.toggleListener { collapsed -> // TODO ACTION }

Result

With recyclerview

  • Use collapse function to onBindViewHolder
/** 
    item.isCollapsed() is variable from your item to store and save state of 
    textview (collapsed/expanded) when item displayed again from RecyclerView scroll 
*/
holder.text.collapsed(item.isCollapsed());
  • Use Toggle
holder.text.onClickExpand(v -> holder.text.toggle());
holder.text.onClickCollapse(v -> holder.text.toggle());
holder.text.toggleListener(collapsed -> {
    item.setCollapsed(collapsed);
    notifyItemChanged(position);
});
  • Use Collapse Properties
// onClickExpand or onClickCollapse 
holder.text.onClickExpand(v -> {
    boolean status = !item.isCollapsed();
    holder.text.collapsed(status);
    item.setCollapsed(status);
    notifyItemChanged(position);
});

Result

Information

This library is still being developed further, please provide feedback if you find a bug. Thank you

Licence

Copyright 2022 Mukhammad Erif Fanani

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

textviewreadmore's People

Contributors

eriffanani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

textviewreadmore's Issues

Not working in RecyclerView

The library seems excellent but it is just broken when used in RecyclerView as shown in the video. The list becomes very unstable and does not show the correct text and glitches around.

video_2022-07-30_02-23-59.mp4

Moreover, the app crashes after scrolling up and down for a few seconds.

2022-07-30 02:20:19.547 19214-19214/com.application.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.application.app, PID: 19214
    java.lang.StringIndexOutOfBoundsException: String index out of range: -2
        at java.lang.String.substring(String.java:2064)
        at java.lang.String.subSequence(String.java:2107)
        at com.erif.readmoretextview.TextViewReadMore.onDraw(TextViewReadMore.java:135)
        at android.view.View.draw(View.java:22704)
        at android.view.View.updateDisplayListIfDirty(View.java:21579)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.