replace the Font size spinner in Settings with a dialog

This commit is contained in:
tibbi 2017-03-09 23:45:47 +01:00
parent 05099e4753
commit 4262446d3a
9 changed files with 39 additions and 36 deletions

View File

@ -32,7 +32,7 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.9.5'
compile 'com.simplemobiletools:commons:2.9.6'
compile 'com.facebook.stetho:stetho:1.4.1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

View File

@ -185,7 +185,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun saveAsFile() {
SaveAsDialog(this, mCurrentNote.title) {
SaveAsDialog(this, mCurrentNote) {
saveNoteValueToFile(it, getCurrentNoteText())
}
}

View File

@ -4,11 +4,16 @@ import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.extensions.config
import com.simplemobiletools.notes.extensions.updateWidget
import com.simplemobiletools.notes.helpers.DBHelper
import com.simplemobiletools.notes.helpers.FONT_SIZE_LARGE
import com.simplemobiletools.notes.helpers.FONT_SIZE_NORMAL
import com.simplemobiletools.notes.helpers.FONT_SIZE_SMALL
import com.simplemobiletools.notes.models.Note
import kotlinx.android.synthetic.main.activity_settings.*
@ -53,17 +58,28 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupFontSize() {
settings_font_size.setSelection(config.fontSize)
settings_font_size.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
config.fontSize = settings_font_size.selectedItemPosition
}
settings_font_size.text = getFontSizeText()
settings_font_size_holder.setOnClickListener {
val items = arrayOf(
RadioItem(0, R.string.small),
RadioItem(1, R.string.normal),
RadioItem(2, R.string.large),
RadioItem(3, R.string.extra_large))
override fun onNothingSelected(parent: AdapterView<*>?) {
RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
config.fontSize = it
settings_font_size.text = getFontSizeText()
}
}
}
private fun getFontSizeText() = getString(when (config.fontSize) {
FONT_SIZE_SMALL -> R.string.small
FONT_SIZE_NORMAL -> R.string.normal
FONT_SIZE_LARGE -> R.string.large
else -> R.string.extra_large
})
private fun setupWidgetNote() {
val notes = DBHelper.newInstance(this).getNotes()
if (notes.size <= 1) {

View File

@ -7,17 +7,18 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.activities.SimpleActivity
import com.simplemobiletools.notes.models.Note
import kotlinx.android.synthetic.main.dialog_save_as.view.*
import java.io.File
class SaveAsDialog(val activity: SimpleActivity, val noteTitle: String, val callback: (savePath: String) -> Unit) {
class SaveAsDialog(val activity: SimpleActivity, val note: Note, val callback: (savePath: String) -> Unit) {
init {
var realPath = activity.internalStoragePath
var realPath = File(note.path).parent
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null).apply {
file_path.text = activity.humanizePath(realPath)
file_name.setText(noteTitle)
file_name.setText(note.title)
file_path.setOnClickListener {
FilePickerDialog(activity, realPath, false, false, true) {
file_path.text = activity.humanizePath(it)

View File

@ -17,7 +17,7 @@ class Config(context: Context) : BaseConfig(context) {
set(clickableLinks) = prefs.edit().putBoolean(CLICKABLE_LINKS, clickableLinks).apply()
var fontSize: Int
get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
get() = prefs.getInt(FONT_SIZE, FONT_SIZE_NORMAL)
set(size) = prefs.edit().putInt(FONT_SIZE, size).apply()
var gravity: Int

View File

@ -17,7 +17,7 @@ val GRAVITY_RIGHT = 2
// font sizes
val FONT_SIZE_SMALL = 0
val FONT_SIZE_MEDIUM = 1
val FONT_SIZE_NORMAL = 1
val FONT_SIZE_LARGE = 2
val FONT_SIZE_EXTRA_LARGE = 3

View File

@ -76,7 +76,10 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
android:paddingBottom="@dimen/bigger_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_font_size_label"
@ -89,13 +92,16 @@
android:paddingRight="@dimen/medium_margin"
android:text="@string/note_font_size"/>
<com.simplemobiletools.commons.views.MyAppCompatSpinner
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_font_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:entries="@array/font_sizes"/>
android:layout_marginEnd="@dimen/medium_margin"
android:layout_marginRight="@dimen/medium_margin"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_radio_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:id="@+id/dialog_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin"/>
</ScrollView>

View File

@ -1,12 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="font_sizes" translatable="false">
<item>@string/small</item>
<item>@string/normal</item>
<item>@string/large</item>
<item>@string/extra_large</item>
</string-array>
<string-array name="gravities" translatable="false">
<item>@string/left</item>
<item>@string/center</item>