Merge pull request #141 from chrjsorg/feature/chrjsorg/40-word-count

Add optional Word Count to Note
This commit is contained in:
Tibor Kaputa 2017-11-21 12:13:14 +01:00 committed by GitHub
commit 7ecde39e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 108 additions and 2 deletions

View File

@ -35,6 +35,7 @@ class SettingsActivity : SimpleActivity() {
setupClickableLinks() setupClickableLinks()
setupMonospacedFont() setupMonospacedFont()
setupShowKeyboard() setupShowKeyboard()
setupShowWordCount()
setupFontSize() setupFontSize()
setupGravity() setupGravity()
setupWidgetNote() 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() { private fun setupFontSize() {
settings_font_size.text = getFontSizeText() settings_font_size.text = getFontSizeText()
settings_font_size_holder.setOnClickListener { settings_font_size_holder.setOnClickListener {

View File

@ -3,6 +3,8 @@ package com.simplemobiletools.notes.fragments
import android.graphics.Typeface import android.graphics.Typeface
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.text.Editable
import android.text.TextWatcher
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.text.util.Linkify import android.text.util.Linkify
import android.util.TypedValue 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.GRAVITY_RIGHT
import com.simplemobiletools.notes.helpers.NOTE_ID import com.simplemobiletools.notes.helpers.NOTE_ID
import com.simplemobiletools.notes.models.Note import com.simplemobiletools.notes.models.Note
import kotlinx.android.synthetic.main.fragment_note.*
import kotlinx.android.synthetic.main.fragment_note.view.* import kotlinx.android.synthetic.main.fragment_note.view.*
import java.io.File import java.io.File
@ -95,6 +98,7 @@ class NoteFragment : Fragment() {
super.onResume() super.onResume()
val config = context!!.config val config = context!!.config
view.notes_view.apply { view.notes_view.apply {
typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT
@ -113,10 +117,42 @@ class NoteFragment : Fragment() {
setSelection(if (config.placeCursorToEnd) text.length else 0) 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() { override fun onPause() {
super.onPause() super.onPause()
saveText() 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)
}
} }
} }

View File

@ -24,6 +24,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(SHOW_KEYBOARD, true) get() = prefs.getBoolean(SHOW_KEYBOARD, true)
set(showKeyboard) = prefs.edit().putBoolean(SHOW_KEYBOARD, showKeyboard).apply() 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 var fontSize: Int
get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM) get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
set(size) = prefs.edit().putInt(FONT_SIZE, size).apply() set(size) = prefs.edit().putInt(FONT_SIZE, size).apply()

View File

@ -10,6 +10,7 @@ val CLICKABLE_LINKS = "clickable_links"
val WIDGET_NOTE_ID = "widget_note_id" val WIDGET_NOTE_ID = "widget_note_id"
val MONOSPACED_FONT = "monospaced_font" val MONOSPACED_FONT = "monospaced_font"
val SHOW_KEYBOARD = "show_keyboard" val SHOW_KEYBOARD = "show_keyboard"
val SHOW_WORD_COUNT = "show_word_count"
val FONT_SIZE = "font_size" val FONT_SIZE = "font_size"
val GRAVITY = "gravity" val GRAVITY = "gravity"
val CURSOR_PLACEMENT = "cursor_placement" val CURSOR_PLACEMENT = "cursor_placement"

View File

@ -159,6 +159,29 @@
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_word_count_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/bigger_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_show_word_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/show_word_count"/>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/settings_font_size_holder" android:id="@+id/settings_font_size_holder"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" 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"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -11,6 +11,11 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:fillViewport="true"> android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/notes_relative_layout"
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"
@ -22,5 +27,18 @@
android:padding="@dimen/activity_margin" android:padding="@dimen/activity_margin"
android:textCursorDrawable="@null"/> android:textCursorDrawable="@null"/>
<TextView
android:id="@+id/notes_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
tools:text="123"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
</ScrollView> </ScrollView>
</RelativeLayout> </RelativeLayout>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Platziere Cursor am Ende der Notiz</string> <string name="place_cursor_end">Platziere Cursor am Ende der Notiz</string>
<string name="monospaced_font">Benutze Monospace Schrift</string> <string name="monospaced_font">Benutze Monospace Schrift</string>
<string name="show_keyboard">Zeige Tastatur beim Start</string> <string name="show_keyboard">Zeige Tastatur beim Start</string>
<string name="show_word_count">Zeige Wortanzahl</string>
<string name="alignment">Ausrichtung</string> <string name="alignment">Ausrichtung</string>
<string name="left">Linksbündig</string> <string name="left">Linksbündig</string>
<string name="center">Zentriert</string> <string name="center">Zentriert</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Place cursor to the end of note</string> <string name="place_cursor_end">Place cursor to the end of note</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Alineación del texto</string> <string name="alignment">Alineación del texto</string>
<string name="left">Izquierda</string> <string name="left">Izquierda</string>
<string name="center">Centrado</string> <string name="center">Centrado</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Placer le curseur à la fin de la note</string> <string name="place_cursor_end">Placer le curseur à la fin de la note</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Alignment</string> <string name="alignment">Alignment</string>
<string name="left">Gauche</string> <string name="left">Gauche</string>
<string name="center">Centre</string> <string name="center">Centre</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Place cursor to the end of note</string> <string name="place_cursor_end">Place cursor to the end of note</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Igazítottság</string> <string name="alignment">Igazítottság</string>
<string name="left">Bal</string> <string name="left">Bal</string>
<string name="center">Közép</string> <string name="center">Közép</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Place cursor to the end of note</string> <string name="place_cursor_end">Place cursor to the end of note</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Alignment</string> <string name="alignment">Alignment</string>
<string name="left">Left</string> <string name="left">Left</string>
<string name="center">Center</string> <string name="center">Center</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Place cursor to the end of note</string> <string name="place_cursor_end">Place cursor to the end of note</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">重力</string> <string name="alignment">重力</string>
<string name="left"></string> <string name="left"></string>
<string name="center">中央</string> <string name="center">中央</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Perkelti þymeklá á áraðo pabaigà</string> <string name="place_cursor_end">Perkelti þymeklá á áraðo pabaigà</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Átrauka</string> <string name="alignment">Átrauka</string>
<string name="left">Kairëje</string> <string name="left">Kairëje</string>
<string name="center">Centre</string> <string name="center">Centre</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Cursor onderaan notitie plaatsen</string> <string name="place_cursor_end">Cursor onderaan notitie plaatsen</string>
<string name="monospaced_font">Lettertype met vaste breedte gebruiken</string> <string name="monospaced_font">Lettertype met vaste breedte gebruiken</string>
<string name="show_keyboard">Toetsenbord bij start tonen</string> <string name="show_keyboard">Toetsenbord bij start tonen</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Uitlijning</string> <string name="alignment">Uitlijning</string>
<string name="left">Links</string> <string name="left">Links</string>
<string name="center">Midden</string> <string name="center">Midden</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Umieszczaj kursor na końcu notatki</string> <string name="place_cursor_end">Umieszczaj kursor na końcu notatki</string>
<string name="monospaced_font">Używaj czcionki monospace</string> <string name="monospaced_font">Używaj czcionki monospace</string>
<string name="show_keyboard">Pokazuj klawiaturę na starcie</string> <string name="show_keyboard">Pokazuj klawiaturę na starcie</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Wyrównanie tekstu w notatkach</string> <string name="alignment">Wyrównanie tekstu w notatkach</string>
<string name="left">Do lewej strony</string> <string name="left">Do lewej strony</string>
<string name="center">Do środka</string> <string name="center">Do środka</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Place cursor to the end of note</string> <string name="place_cursor_end">Place cursor to the end of note</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Gravidade</string> <string name="alignment">Gravidade</string>
<string name="left">Esquerda</string> <string name="left">Esquerda</string>
<string name="center">Centro</string> <string name="center">Centro</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Colocar cursor no fim da nota</string> <string name="place_cursor_end">Colocar cursor no fim da nota</string>
<string name="monospaced_font">Usar letra mono-espaçada</string> <string name="monospaced_font">Usar letra mono-espaçada</string>
<string name="show_keyboard">Mostrar teclado ao inciar</string> <string name="show_keyboard">Mostrar teclado ao inciar</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Gravidade</string> <string name="alignment">Gravidade</string>
<string name="left">Esquerda</string> <string name="left">Esquerda</string>
<string name="center">Centro</string> <string name="center">Centro</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Помещать курсор в конец заметки</string> <string name="place_cursor_end">Помещать курсор в конец заметки</string>
<string name="monospaced_font">Использовать моноширинный шрифт</string> <string name="monospaced_font">Использовать моноширинный шрифт</string>
<string name="show_keyboard">Показывать клавиатуру при запуске</string> <string name="show_keyboard">Показывать клавиатуру при запуске</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Выравнивание</string> <string name="alignment">Выравнивание</string>
<string name="left">По левому краю</string> <string name="left">По левому краю</string>
<string name="center">По центру</string> <string name="center">По центру</string>

View File

@ -32,6 +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="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>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Placera markören vid slutet av anteckningen</string> <string name="place_cursor_end">Placera markören vid slutet av anteckningen</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Justering</string> <string name="alignment">Justering</string>
<string name="left">Vänster</string> <string name="left">Vänster</string>
<string name="center">Centrerad</string> <string name="center">Centrerad</string>

View File

@ -32,6 +32,7 @@
<string name="place_cursor_end">Place cursor to the end of note</string> <string name="place_cursor_end">Place cursor to the end of note</string>
<string name="monospaced_font">Use monospaced font</string> <string name="monospaced_font">Use monospaced font</string>
<string name="show_keyboard">Show keyboard on startup</string> <string name="show_keyboard">Show keyboard on startup</string>
<string name="show_word_count">Show word count</string>
<string name="alignment">Alignment</string> <string name="alignment">Alignment</string>
<string name="left">Left</string> <string name="left">Left</string>
<string name="center">Center</string> <string name="center">Center</string>