GithubHelp home page GithubHelp logo

tchigher / showmoreless Goto Github PK

View Code? Open in Web Editor NEW

This project forked from noowenz/showmoreless

0.0 0.0 0.0 391 KB

A simple Android library for displaying a more and less functionality in TextView and very easy to Convert your TextView in ExpandableTextView

License: Apache License 2.0

Kotlin 100.00%

showmoreless's Introduction

LicenseAndroid Arsenal

ShowMoreLess

ShowMoreLess is a A simple Android library for displaying a more and less functionality in TextView

Screenshots

Installation

Add Jitpack to your project build.gralde file

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

Then add this dependency to your app build.gradle file.

dependencies {
   implementation 'https://github.com/noowenz/ShowMoreLess:latest-release'
   Or
   implementation 'com.github.noowenz:ShowMoreLess:v1.0'
}

Usage

ShowMoreLess.Builder(this)
   /*.textLengthAndLengthType(
     	length = 100,
        textLengthType = ShowMoreLess.TYPE_CHARACTER
   )*/
   .textLengthAndLengthType(
   	length = 5,
        textLengthType = ShowMoreLess.TYPE_LINE
   )
   .showMoreLabel("show more")
   .showLessLabel("show less")
   .showMoreLabelColor(R.color.colorPrimaryDark)
   .showLessLabelColor(R.color.colorPrimaryDark)
   .labelUnderLine(labelUnderLine = false)
   .labelBold(labelBold = false)
   .expandAnimation(expandAnimation = true)
   .textClickable(
   	textClickableInExpand = true,
        textClickableInCollapse = true
   )
   .build().apply {
   	addShowMoreLess(textView = tv_first, text = tv_first.text, isContentExpanded = true)
        setListener(object : ShowMoreLess.OnShowMoreLessClickedListener {

             override fun onShowMoreClicked() {
             	//We can handle or save show more state
             }

             override fun onShowLessClicked() {
             	//We can handle or save show less state
             }
   	}
   )
}

Customization

You can customize things like bellow

1. Can change textLengthAndLengthType as
.textLengthAndLengthType(
     length = 100,//Length where to add show more text
     textLengthType = ShowMoreLess.TYPE_CHARACTER //textLengthType is TYPE_CHARACTER
)
    and
.textLengthAndLengthType(
     length = 5,//Line of text view where to add show more text
     textLengthType = ShowMoreLess.TYPE_LINE //textLengthType is TYPE_LINE
)
2. Can change show more and show less text label as
.showMoreLabel("read more")
.showLessLabel("read less")
3. Can change text color of Show more or Show less
.showMoreLabelColor(Color.parseColor("#ffffff"))
.showLessLabelColor(Color.parseColor("#ffffff"))
4. Can enable labelUnderLine easily as
.labelUnderLine(labelUnderLine = false)//true for underline and false for not underline
5. Can enable labelBold easily as
.labelBold(labelBold = false)//true for bold and false for normal
6. Can easily handle expand and collapse animation by
.expandAnimation(expandAnimation = true)//expandAnimation will affect both expand and collapse logic
7. Can handle textClickable except clicking more or less txt for expand and collapse
.textClickable(
     textClickableInExpand = true,//It will enable text clickable in expand mode
     textClickableInCollapse = true//It will enable text clickable in collapse mode
)
8. addShowMoreLess() function will handle text expand or collapse state
addShowMoreLess(
     textView = tv_first, //It is a text view where we have to add read more or less
     text = tv_first.text, //String in textview
     isContentExpanded = true//Content expand or collapse history
)
9. At last setListener() function for callbacks
setListener(object : ShowMoreLess.OnShowMoreLessClickedListener {

     override fun onShowMoreClicked() {
     	//We can handle or save show more state
     	//This sate will send in no 7.addShowMoreLess() function of isContentExpanded = false / true
     }

     override fun onShowLessClicked() {
     	//We can handle or save show less state
     	//This sate will send in no 7.addShowMoreLess() function of isContentExpanded = false / true
     }
}

License

Copyright (c) 2020 Nabin Shrestha

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.

showmoreless's People

Contributors

nabin-stha avatar noowenz avatar pfieffer avatar

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.