move the widget note picker in settings

This commit is contained in:
tibbi 2016-11-26 20:49:54 +01:00
parent 6e1a530da1
commit 133161cd66
12 changed files with 57 additions and 75 deletions

View File

@ -16,7 +16,6 @@ import com.simplemobiletools.notes.databases.DBHelper
import com.simplemobiletools.notes.dialogs.NewNoteDialog
import com.simplemobiletools.notes.dialogs.OpenNoteDialog
import com.simplemobiletools.notes.dialogs.RenameNoteDialog
import com.simplemobiletools.notes.dialogs.WidgetNoteDialog
import com.simplemobiletools.notes.extensions.dpToPx
import com.simplemobiletools.notes.models.Note
import kotlinx.android.synthetic.main.activity_main.*
@ -43,7 +42,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
fun initViewPager() {
mNotes = mDb.getNotes().sortedBy(Note::title)
mNotes = mDb.getNotes()
mCurrentNote = mNotes[0]
var itemIndex = 0
for (i in 0..mNotes.count() - 1) {
@ -103,10 +102,6 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
shareText()
true
}
R.id.change_widget_note -> {
showWidgetNotePicker()
true
}
R.id.delete_note -> {
displayDeleteNotePrompt()
true
@ -123,10 +118,6 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
}
private fun showWidgetNotePicker() {
WidgetNoteDialog(this)
}
private fun displayRenameDialog() {
RenameNoteDialog(this, mDb, mCurrentNote) {
mCurrentNote = it

View File

@ -5,6 +5,8 @@ import android.support.v4.app.TaskStackBuilder
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.databases.DBHelper
import com.simplemobiletools.notes.extensions.updateWidget
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
@ -14,6 +16,7 @@ class SettingsActivity : SimpleActivity() {
setupDarkTheme()
setupFontSize()
setupWidgetNote()
}
private fun setupDarkTheme() {
@ -37,6 +40,26 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupWidgetNote() {
val notes = DBHelper.newInstance(this).getNotes()
if (notes.size <= 1) {
settings_widget_note_holder.visibility = View.GONE
return
}
settings_widget_note.setSelection(config.fontSize)
settings_widget_note.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val note = notes[settings_widget_note.selectedItemPosition]
config.widgetNoteId = note.id
updateWidget()
}
override fun onNothingSelected(parent: AdapterView<*>?) {
}
}
}
private fun restartActivity() {
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
}

View File

@ -1,47 +0,0 @@
package com.simplemobiletools.notes.dialogs
import android.app.Activity
import android.app.AlertDialog
import android.view.ViewGroup
import android.widget.RadioButton
import android.widget.RadioGroup
import com.simplemobiletools.notes.Config
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.databases.DBHelper
import kotlinx.android.synthetic.main.dialog_radio_group.view.*
class WidgetNoteDialog(val activity: Activity) : RadioGroup.OnCheckedChangeListener {
val dialog: AlertDialog?
var mConfig: Config
init {
mConfig = Config.newInstance(activity)
val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null)
val radioGroup = view.dialog_radio_group
radioGroup.setOnCheckedChangeListener(this)
val db = DBHelper.newInstance(activity)
val notes = db.getNotes()
notes.forEach {
val radioButton = activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton
radioButton.apply {
text = it.title
isChecked = it.id == mConfig.widgetNoteId
id = it.id
}
radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
}
dialog = AlertDialog.Builder(activity)
.setTitle(activity.resources.getString(R.string.pick_a_note_for_widget))
.setView(view)
.create()
dialog?.show()
}
override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
mConfig.widgetNoteId = checkedId
dialog?.dismiss()
}
}

View File

@ -63,5 +63,31 @@
android:entries="@array/font_sizes"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_widget_note_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/normal_padding"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/normal_padding"
android:paddingTop="@dimen/activity_margin">
<TextView
android:id="@+id/settings_widget_note_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/normal_padding"
android:text="@string/widget_note"/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/settings_widget_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

View File

@ -21,10 +21,6 @@
android:icon="@mipmap/delete"
android:title="@string/delete_note"
app:showAsAction="never"/>
<item
android:id="@+id/change_widget_note"
android:title="@string/change_widget_note"
app:showAsAction="never"/>
<item
android:id="@+id/settings"
android:title="@string/settings"

View File

@ -17,8 +17,6 @@
<string name="delete_note_prompt_title">Notiz löschen</string>
<string name="delete_note_prompt_message">Bist du sicher, dass du Notiz \"%1$s\" löschen willst?</string>
<string name="pick_a_note">Notiz auswählen</string>
<string name="change_widget_note">Wechsel Notiz des Widgets</string>
<string name="pick_a_note_for_widget">Wähle Notiz für das Widget</string>
<string name="rename">Umbennen</string>
<string name="rename_note">Notiz umbennen</string>
<string name="general_note">Hauptnotiz</string>
@ -27,6 +25,7 @@
<string name="settings">Einstellungen</string>
<string name="dark_theme">Dunkles Thema</string>
<string name="note_font_size">Schriftgröße</string>
<string name="widget_note">Note used in widget</string>
<string name="small">Klein</string>
<string name="normal">Normal</string>
<string name="large">Groß</string>

View File

@ -17,8 +17,6 @@
<string name="delete_note_prompt_title">Eliminar nota</string>
<string name="delete_note_prompt_message">¿Está seguro de querer eliminar la nota \"%1$s\"?</string>
<string name="pick_a_note">Seleccione una nota</string>
<string name="change_widget_note">Cambiar nota del widget</string>
<string name="pick_a_note_for_widget">Seleccione una nota para el widget</string>
<string name="rename">Renombrar</string>
<string name="rename_note">Renombrar nota</string>
<string name="general_note">Nota principal</string>
@ -27,6 +25,7 @@
<string name="settings">Opciones</string>
<string name="dark_theme">Tema oscuro</string>
<string name="note_font_size">Tamaño de fuente</string>
<string name="widget_note">Note used in widget</string>
<string name="small">Pequeña</string>
<string name="normal">Normal</string>
<string name="large">Grande</string>

View File

@ -17,8 +17,6 @@
<string name="delete_note_prompt_title">Delete note</string>
<string name="delete_note_prompt_message">Are you sure you want to delete note \"%1$s\"?</string>
<string name="pick_a_note">Pick a note</string>
<string name="change_widget_note">Change widget\'s note</string>
<string name="pick_a_note_for_widget">Pick a note for the widget</string>
<string name="rename">Rename</string>
<string name="rename_note">Rename note</string>
<string name="general_note">General note</string>
@ -27,6 +25,7 @@
<string name="settings">Impostazioni</string>
<string name="dark_theme">Tema scuro</string>
<string name="note_font_size">Note font size</string>
<string name="widget_note">Note used in widget</string>
<string name="small">Small</string>
<string name="normal">Normal</string>
<string name="large">Large</string>

View File

@ -17,8 +17,6 @@
<string name="delete_note_prompt_title">メモを削除</string>
<string name="delete_note_prompt_message">メモ \"%1$s\" を削除してもよろしいですか?</string>
<string name="pick_a_note">メモを選択</string>
<string name="change_widget_note">ウィジェットのメモを変更</string>
<string name="pick_a_note_for_widget">ウィジェットのメモを選択</string>
<string name="rename">Rename</string>
<string name="rename_note">Rename note</string>
<string name="general_note">General note</string>
@ -27,6 +25,7 @@
<string name="settings">設定</string>
<string name="dark_theme">ダークテーマ</string>
<string name="note_font_size">メモのフォントサイズ</string>
<string name="widget_note">Note used in widget</string>
<string name="small"></string>
<string name="normal">通常</string>
<string name="large"></string>

View File

@ -17,8 +17,6 @@
<string name="delete_note_prompt_title">Apagar nota</string>
<string name="delete_note_prompt_message">Deseja mesmo apagar a nota \"%1$s\"?</string>
<string name="pick_a_note">Selecione uma nota</string>
<string name="change_widget_note">Alterar nota do widget</string>
<string name="pick_a_note_for_widget">Escolha uma nota para o widget</string>
<string name="rename">Renomear</string>
<string name="rename_note">Renomear nota</string>
<string name="general_note">Nota genérica</string>
@ -27,6 +25,7 @@
<string name="settings">Definições</string>
<string name="dark_theme">Tema escuro</string>
<string name="note_font_size">Tamanho do texto da nota</string>
<string name="widget_note">Note used in widget</string>
<string name="small">Pequeno</string>
<string name="normal">Normal</string>
<string name="large">Grande</string>

View File

@ -17,8 +17,6 @@
<string name="delete_note_prompt_title">Delete note</string>
<string name="delete_note_prompt_message">Are you sure you want to delete note \"%1$s\"?</string>
<string name="pick_a_note">Pick a note</string>
<string name="change_widget_note">Change widget\'s note</string>
<string name="pick_a_note_for_widget">Pick a note for the widget</string>
<string name="rename">Rename</string>
<string name="rename_note">Rename note</string>
<string name="general_note">General note</string>
@ -27,6 +25,7 @@
<string name="settings">Inställningar</string>
<string name="dark_theme">Mörkt tema</string>
<string name="note_font_size">Note font size</string>
<string name="widget_note">Note used in widget</string>
<string name="small">Small</string>
<string name="normal">Normal</string>
<string name="large">Large</string>

View File

@ -17,8 +17,6 @@
<string name="delete_note_prompt_title">Delete note</string>
<string name="delete_note_prompt_message">Are you sure you want to delete note \"%1$s\"?</string>
<string name="pick_a_note">Pick a note</string>
<string name="change_widget_note">Change widget\'s note</string>
<string name="pick_a_note_for_widget">Pick a note for the widget</string>
<string name="rename">Rename</string>
<string name="rename_note">Rename note</string>
<string name="general_note">General note</string>
@ -27,6 +25,7 @@
<string name="settings">Settings</string>
<string name="dark_theme">Dark theme</string>
<string name="note_font_size">Note font size</string>
<string name="widget_note">Note used in widget</string>
<string name="small">Small</string>
<string name="normal">Normal</string>
<string name="large">Large</string>