mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 23:12:02 +02:00
Add optional Word Count to Note
- Setting included (default: deactived) - Translation for en/de refs #40
This commit is contained in:
parent
11b57f1bda
commit
e763f05ec8
@ -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 {
|
||||
|
@ -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
|
||||
@ -95,6 +97,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 +116,45 @@ 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() {
|
||||
//Avoid memory leak
|
||||
view.notes_view.removeTextChangedListener(textWatcher)
|
||||
}
|
||||
|
||||
private fun setWordCounter(text: Editable) {
|
||||
//Replace new lines with space
|
||||
val wordArray = text.toString().replace("\n", " ").split(" ")
|
||||
//Count only items which are not empty
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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_WORDCOUNT, false)
|
||||
set(showWordCount) = prefs.edit().putBoolean(SHOW_WORDCOUNT, showWordCount).apply()
|
||||
|
||||
var fontSize: Int
|
||||
get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
|
||||
set(size) = prefs.edit().putInt(FONT_SIZE, size).apply()
|
||||
|
@ -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_WORDCOUNT = "show_word_count"
|
||||
val FONT_SIZE = "font_size"
|
||||
val GRAVITY = "gravity"
|
||||
val CURSOR_PLACEMENT = "cursor_placement"
|
||||
|
@ -159,6 +159,29 @@
|
||||
|
||||
</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_wordcount"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_font_size_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -11,6 +11,10 @@
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/notes_view"
|
||||
android:layout_width="match_parent"
|
||||
@ -22,5 +26,18 @@
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:textCursorDrawable="@null"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notes_counter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textStyle="italic"
|
||||
android:text="123"
|
||||
android:padding="5dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Platziere Cursor am Ende der Notiz</string>
|
||||
<string name="monospaced_font">Benutze Monospace Schrift</string>
|
||||
<string name="show_keyboard">Zeige Tastatur beim Start</string>
|
||||
<string name="show_wordcount">Zeige Wort Zähler</string>
|
||||
<string name="alignment">Ausrichtung</string>
|
||||
<string name="left">Linksbündig</string>
|
||||
<string name="center">Zentriert</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Place cursor to the end of note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_wordcount">Show word counter</string>
|
||||
<string name="alignment">Alignment</string>
|
||||
<string name="left">Left</string>
|
||||
<string name="center">Center</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user