Skip to content

Commit

Permalink
fix count word logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wise4rmgod committed Sep 5, 2020
1 parent e581cb2 commit f2d859c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

9 changes: 9 additions & 0 deletions app/src/main/java/com/dev/readtime/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ class MainActivity : AppCompatActivity() {
"To use this endpoint, simply append live to your API request URL, followed by your API access key and any of your preferred options." +
"To use this endpoint, simply append live to your API request URL, followed by your API access key and any of your preferred options." +
"To use this endpoint, simply append live to your API request URL, followed by your API access key and any of your preferred options."

val you = "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."
// Read Time Logic
// text.text = ReadTime.readtime(ty)
wordct.text = ReadTime.countWords(ty).toString()

minread.text = ReadTime.readtime(ty)

Expand Down
28 changes: 18 additions & 10 deletions app/src/main/java/com/dev/readtime/ReadTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@ package com.dev.readtime
object ReadTime {
fun readtime(string: String): String {

val word_count = string.length
val word_count = countWords(string)
val total = word_count / 200
if (total == 0)
if (total < 1)
return "0.5 min read"
else
return "$total min read"
}

fun custome_readtime(string: String, message: String): String {

val word_count = string.length
val word_count = countWords(string)
val total = word_count / 200
if (total == 0)
if (total < 1)
return "0.5 $message"
else
return "$total $message"

}

fun wordcount(string: String): String {

val word_count = string.length
val total = word_count / 200
return word_count.toString()

fun countWords(inputString: String): Int {
//Split String by Space
val strArray = inputString.split(" ".toRegex()).toTypedArray() // Spilt String by Space
val sb = StringBuilder()
var count = 0

//iterate String array
for (s in strArray) {
if (s != "") {
//Increase Word Counter
count++
}
}
return count
}

}
13 changes: 10 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@

<TextView
android:id="@+id/minread"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/wordct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/minread" />

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="@string/lngmessage"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="30dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/minread" />
app:layout_constraintTop_toBottomOf="@id/wordct" />

</androidx.constraintlayout.widget.ConstraintLayout>
32 changes: 20 additions & 12 deletions minread/src/main/java/com/dev/minread/Minread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@ package com.dev.minread

object Minread {

fun readtime(string: String): String {
fun minread(string: String): String {

val word_count = string.length
val word_count = countWords(string)
val total = word_count / 200
if (total == 0)
if (total < 1)
return "0.5 min read"
else
return "$total min read"
}

fun custome_readtime(string: String, message: String): String {
fun custome_minread(string: String, message: String): String {

val word_count = string.length
val word_count = countWords(string)
val total = word_count / 200
if (total == 0)
if (total < 1)
return "0.5 $message"
else
return "$total $message"

}

fun wordcount(string: String): String {

val word_count = string.length
val total = word_count / 200
return word_count.toString()

fun countWords(inputString: String): Int {
//Split String by Space
val strArray = inputString.split(" ".toRegex()).toTypedArray() // Spilt String by Space
val sb = StringBuilder()
var count = 0

//iterate String array
for (s in strArray) {
if (s != "") {
//Increase Word Counter
count++
}
}
return count
}
}

0 comments on commit f2d859c

Please sign in to comment.