diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt index 30d75c75..8cbd8e16 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt @@ -35,6 +35,7 @@ class SettingsActivity : SimpleActivity() { setupClickableLinks() setupMonospacedFont() setupShowKeyboard() + setupShowWordCount() setupFontSize() setupGravity() setupWidgetNote() @@ -90,6 +91,14 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupShowWordCount() { + settings_show_word_count.isChecked = config.showWordCount + settings_show_word_count_holder.setOnClickListener { + settings_show_word_count.toggle() + config.showWordCount = settings_show_word_count.isChecked + } + } + private fun setupFontSize() { settings_font_size.text = getFontSizeText() settings_font_size_holder.setOnClickListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt index 104e5588..19e370aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt @@ -3,6 +3,8 @@ package com.simplemobiletools.notes.fragments import android.graphics.Typeface import android.os.Bundle import android.support.v4.app.Fragment +import android.text.Editable +import android.text.TextWatcher import android.text.method.LinkMovementMethod import android.text.util.Linkify import android.util.TypedValue @@ -18,6 +20,7 @@ import com.simplemobiletools.notes.helpers.GRAVITY_CENTER import com.simplemobiletools.notes.helpers.GRAVITY_RIGHT import com.simplemobiletools.notes.helpers.NOTE_ID import com.simplemobiletools.notes.models.Note +import kotlinx.android.synthetic.main.fragment_note.* import kotlinx.android.synthetic.main.fragment_note.view.* import java.io.File @@ -95,6 +98,7 @@ class NoteFragment : Fragment() { super.onResume() val config = context!!.config + view.notes_view.apply { typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT @@ -113,10 +117,42 @@ class NoteFragment : Fragment() { setSelection(if (config.placeCursorToEnd) text.length else 0) } } + + if (config.showWordCount) { + view.notes_view.addTextChangedListener(textWatcher) + view.notes_counter.visibility = View.VISIBLE + setWordCounter(view.notes_view.text) + } + else { + view.notes_counter.visibility = View.GONE + } } override fun onPause() { super.onPause() saveText() + + removeTextWatcher() + } + + private fun removeTextWatcher() { + view.notes_view.removeTextChangedListener(textWatcher) + } + + private fun setWordCounter(text: Editable) { + val wordArray = text.toString().replace("\n", " ").split(" ") + notes_counter.text = wordArray.count { it.isNotEmpty() }.toString() + } + + private var textWatcher: TextWatcher = object : TextWatcher { + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + } + + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + } + + override fun afterTextChanged(editable: Editable) { + setWordCounter(editable) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt index 97c0dda4..54b43093 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt @@ -24,6 +24,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(SHOW_KEYBOARD, true) set(showKeyboard) = prefs.edit().putBoolean(SHOW_KEYBOARD, showKeyboard).apply() + var showWordCount: Boolean + get() = prefs.getBoolean(SHOW_WORD_COUNT, false) + set(showWordCount) = prefs.edit().putBoolean(SHOW_WORD_COUNT, showWordCount).apply() + var fontSize: Int get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM) set(size) = prefs.edit().putInt(FONT_SIZE, size).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt index 9c5d64f9..814f0c8c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt @@ -10,6 +10,7 @@ val CLICKABLE_LINKS = "clickable_links" val WIDGET_NOTE_ID = "widget_note_id" val MONOSPACED_FONT = "monospaced_font" val SHOW_KEYBOARD = "show_keyboard" +val SHOW_WORD_COUNT = "show_word_count" val FONT_SIZE = "font_size" val GRAVITY = "gravity" val CURSOR_PLACEMENT = "cursor_placement" diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index c5a6dc67..ddf8e41d 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -159,6 +159,29 @@ + + + + + + - @@ -11,6 +11,11 @@ android:layout_height="match_parent" android:fillViewport="true"> + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 9aafc561..c77647a7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -32,6 +32,7 @@ Platziere Cursor am Ende der Notiz Benutze Monospace Schrift Zeige Tastatur beim Start + Zeige Wortanzahl Ausrichtung Linksbündig Zentriert diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 6281ffab..b4f7fc2d 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -32,6 +32,7 @@ Place cursor to the end of note Use monospaced font Show keyboard on startup + Show word count Alineación del texto Izquierda Centrado diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 3795b717..4ec9bc76 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -32,6 +32,7 @@ Placer le curseur à la fin de la note Use monospaced font Show keyboard on startup + Show word count Alignment Gauche Centre diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index c7445d7e..e0624eb8 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -32,6 +32,7 @@ Place cursor to the end of note Use monospaced font Show keyboard on startup + Show word count Igazítottság Bal Közép diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 07144df0..2bfa7d47 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -32,6 +32,7 @@ Place cursor to the end of note Use monospaced font Show keyboard on startup + Show word count Alignment Left Center diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index cd499385..67e011bb 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -32,6 +32,7 @@ Place cursor to the end of note Use monospaced font Show keyboard on startup + Show word count 重力 中央 diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index 591a0371..21bc2f83 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -32,6 +32,7 @@ Perkelti þymeklá á áraðo pabaigà Use monospaced font Show keyboard on startup + Show word count Átrauka Kairëje Centre diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 5e33d456..86523ed2 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -32,6 +32,7 @@ Cursor onderaan notitie plaatsen Lettertype met vaste breedte gebruiken Toetsenbord bij start tonen + Show word count Uitlijning Links Midden diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 3062fef4..ca847cea 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -32,6 +32,7 @@ Umieszczaj kursor na końcu notatki Używaj czcionki monospace Pokazuj klawiaturę na starcie + Show word count Wyrównanie tekstu w notatkach Do lewej strony Do środka diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 35ee3d4e..b97a529d 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -32,6 +32,7 @@ Place cursor to the end of note Use monospaced font Show keyboard on startup + Show word count Gravidade Esquerda Centro diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 3d62362c..81703167 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -32,6 +32,7 @@ Colocar cursor no fim da nota Usar letra mono-espaçada Mostrar teclado ao inciar + Show word count Gravidade Esquerda Centro diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index fa76daaf..3ef5d19a 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -32,6 +32,7 @@ Помещать курсор в конец заметки Использовать моноширинный шрифт Показывать клавиатуру при запуске + Show word count Выравнивание По левому краю По центру diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 06bf5b75..e76c8e8b 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -32,6 +32,7 @@ Umiestniť kurzor na koniec poznámky Použiť písmo Monospace Zobraziť klávesnicu po spustení + Show word count Zarovnanie Vľavo Uprostred diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index e3b3be3a..7c1309da 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -32,6 +32,7 @@ Placera markören vid slutet av anteckningen Use monospaced font Show keyboard on startup + Show word count Justering Vänster Centrerad diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 508be5da..8e9c5cac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,6 +32,7 @@ Place cursor to the end of note Use monospaced font Show keyboard on startup + Show word count Alignment Left Center