How to more accurately estimate read time in your Android Kotlin Project
This article will cover steps on how to get an accurate read time in Android Studio using an awesome library built by me.
Firstly, I will like you to understand what is Read time and why you need it in your next project. most project that has a section where they show a long article, story, or post, should have (read time) in their Android project.
What is Read Time?
An estimate of how long it will take you to read that story/article/post (in minutes).
Benefits of Read Time in your next Android Project
- It lets your users know how long it will take them to finish your content
- It helps your users plan on what content to read because of the read time he/she is seeing.
- It also improves the user experience(UX) of your app
How to implement Read-Time in your Android kotlin project
There is an Android Library called “ Min read “it's an open-source Android library that is used to get the number of words and give you the time it will take you to read an article/story.
Kindly follow the steps below to set up in your project
Step 1:
add a dependency code to your module’s build.gradle file.
dependencies {
implementation 'com.github.wise4rmgod:ReadTime:0.1.0'
}
Step 2:
Add the below codes to your root build.gradle file (not your module build.gradle file).
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 3:
There are 3 methods in this library
countWords("String")= it takes a string parametalcustome_minread("String", "message") = you get to add a cutome messgaemiread("String") = just add the words
use the minread(“string”) to get the read time
Example
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val ty = "f your audience reads slower or faster than 200 words per minute — \n" +
" perhaps your blog is in English, which isn’t your audience’s first language, or perhaps your material is extremely\n" +
" basic and easy to skim — then you’ll want to use calculator instead. First, you’ll have to divide your total word \n" +
" count by the average words read per minute of your audience. Let’s say your 938-word article has an audience that \n" +
" reads 150 words per minute. That gives you 6.253. Enter 6.253 into the Decimal-to-Time Calculator, choose “Minutes” \n" +
" from the drop-down menu and press “Calculate.”\n" +
" Immediately, you’ll get a minute and seconds estimate. In this case, it’s 6 minutes and 15 seconds."
wordct.text = Minread.countWords(ty).toString()
minread.text = Minread.minread(ty)
//custom message in the min read
minread.text = Minread.custome_minread(ty,"min read")
}
}
min read Android library: https://github.com/wise4rmgod/ReadTime
you see how simple it is to achieve this in an android studio using a single line of code.
Thanks for reading.