mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-17 08:47:22 +02:00
minor tweaks to the word count code style
This commit is contained in:
parent
7ecde39e0b
commit
4cd1dfc4f9
@ -12,6 +12,8 @@ import android.view.Gravity
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import com.simplemobiletools.commons.extensions.beGone
|
||||||
|
import com.simplemobiletools.commons.extensions.beVisible
|
||||||
import com.simplemobiletools.notes.R
|
import com.simplemobiletools.notes.R
|
||||||
import com.simplemobiletools.notes.activities.MainActivity
|
import com.simplemobiletools.notes.activities.MainActivity
|
||||||
import com.simplemobiletools.notes.extensions.*
|
import com.simplemobiletools.notes.extensions.*
|
||||||
@ -120,28 +122,23 @@ class NoteFragment : Fragment() {
|
|||||||
|
|
||||||
if (config.showWordCount) {
|
if (config.showWordCount) {
|
||||||
view.notes_view.addTextChangedListener(textWatcher)
|
view.notes_view.addTextChangedListener(textWatcher)
|
||||||
view.notes_counter.visibility = View.VISIBLE
|
view.notes_counter.beVisible()
|
||||||
|
view.notes_counter.setTextColor(config.textColor)
|
||||||
setWordCounter(view.notes_view.text)
|
setWordCounter(view.notes_view.text)
|
||||||
}
|
} else {
|
||||||
else {
|
view.notes_counter.beGone()
|
||||||
view.notes_counter.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
saveText()
|
saveText()
|
||||||
|
|
||||||
removeTextWatcher()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun removeTextWatcher() {
|
|
||||||
view.notes_view.removeTextChangedListener(textWatcher)
|
view.notes_view.removeTextChangedListener(textWatcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setWordCounter(text: Editable) {
|
private fun setWordCounter(text: Editable) {
|
||||||
val wordArray = text.toString().replace("\n", " ").split(" ")
|
val words = text.toString().replace("\n", " ").split(" ")
|
||||||
notes_counter.text = wordArray.count { it.isNotEmpty() }.toString()
|
notes_counter.text = words.count { it.isNotEmpty() }.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var textWatcher: TextWatcher = object : TextWatcher {
|
private var textWatcher: TextWatcher = object : TextWatcher {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/note_Fragment_holder"
|
android:id="@+id/note_Fragment_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -12,33 +13,32 @@
|
|||||||
android:fillViewport="true">
|
android:fillViewport="true">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:id="@+id/notes_relative_layout"
|
android:id="@+id/notes_relative_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyEditText
|
<com.simplemobiletools.commons.views.MyEditText
|
||||||
android:id="@+id/notes_view"
|
android:id="@+id/notes_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
android:freezesText="true"
|
android:freezesText="true"
|
||||||
android:gravity="top"
|
android:gravity="top"
|
||||||
android:inputType="textCapSentences|textMultiLine"
|
android:inputType="textCapSentences|textMultiLine"
|
||||||
android:padding="@dimen/activity_margin"
|
android:padding="@dimen/activity_margin"
|
||||||
android:textCursorDrawable="@null"/>
|
android:textCursorDrawable="@null"/>
|
||||||
|
|
||||||
<TextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/notes_counter"
|
android:id="@+id/notes_counter"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textStyle="italic"
|
|
||||||
tools:text="123"
|
|
||||||
android:padding="5dp"
|
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true" />
|
android:layout_alignParentRight="true"
|
||||||
|
android:padding="@dimen/small_margin"
|
||||||
|
android:textStyle="italic"
|
||||||
|
tools:text="123"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<string name="place_cursor_end">Umiestniť kurzor na koniec poznámky</string>
|
<string name="place_cursor_end">Umiestniť kurzor na koniec poznámky</string>
|
||||||
<string name="monospaced_font">Použiť písmo Monospace</string>
|
<string name="monospaced_font">Použiť písmo Monospace</string>
|
||||||
<string name="show_keyboard">Zobraziť klávesnicu po spustení</string>
|
<string name="show_keyboard">Zobraziť klávesnicu po spustení</string>
|
||||||
<string name="show_word_count">Show word count</string>
|
<string name="show_word_count">Zobraziť počítadlo slov</string>
|
||||||
<string name="alignment">Zarovnanie</string>
|
<string name="alignment">Zarovnanie</string>
|
||||||
<string name="left">Vľavo</string>
|
<string name="left">Vľavo</string>
|
||||||
<string name="center">Uprostred</string>
|
<string name="center">Uprostred</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user