diff --git a/app/src/main/java/com/simplemobiletools/notes/Config.java b/app/src/main/java/com/simplemobiletools/notes/Config.java index 1a70fbee..fc633f58 100644 --- a/app/src/main/java/com/simplemobiletools/notes/Config.java +++ b/app/src/main/java/com/simplemobiletools/notes/Config.java @@ -45,4 +45,12 @@ public class Config { public void setCurrentNoteIndex(int index) { mPrefs.edit().putInt(Constants.CURRENT_NOTE_INDEX, index).apply(); } + + public int getWidgetNoteIndex() { + return mPrefs.getInt(Constants.WIDGET_NOTE_ID, 0); + } + + public void setWidgetNoteIndex(int id) { + mPrefs.edit().putInt(Constants.WIDGET_NOTE_ID, id).apply(); + } } diff --git a/app/src/main/java/com/simplemobiletools/notes/Constants.java b/app/src/main/java/com/simplemobiletools/notes/Constants.java index 153ece9f..c531b9e2 100644 --- a/app/src/main/java/com/simplemobiletools/notes/Constants.java +++ b/app/src/main/java/com/simplemobiletools/notes/Constants.java @@ -8,6 +8,7 @@ public class Constants { public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_DARK_THEME = "is_dark_theme"; public static final String CURRENT_NOTE_INDEX = "current_note_index"; + public static final String WIDGET_NOTE_ID = "widget_note_id"; public static final String FONT_SIZE = "font_size"; public static final String WIDGET_BG_COLOR = "widget_bg_color"; public static final String WIDGET_TEXT_COLOR = "widget_text_color"; diff --git a/app/src/main/java/com/simplemobiletools/notes/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/notes/activities/MainActivity.java index 26a6e6d7..e000b670 100644 --- a/app/src/main/java/com/simplemobiletools/notes/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/notes/activities/MainActivity.java @@ -19,6 +19,7 @@ import com.simplemobiletools.notes.R; import com.simplemobiletools.notes.Utils; import com.simplemobiletools.notes.databases.DBHelper; import com.simplemobiletools.notes.models.Note; +import com.simplemobiletools.notes.views.dialogs.WidgetNoteDialog; import java.util.List; @@ -107,7 +108,7 @@ public class MainActivity extends SimpleActivity { } private void showWidgetNotePicker() { - + new WidgetNoteDialog(this); } private void updateSelectedNote(int index) { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/views/dialogs/WidgetNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/views/dialogs/WidgetNoteDialog.kt new file mode 100644 index 00000000..10d9041c --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/views/dialogs/WidgetNoteDialog.kt @@ -0,0 +1,45 @@ +package com.simplemobiletools.notes.views.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 + +class WidgetNoteDialog(val activity: Activity) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener { + val dialog: AlertDialog? + var mConfig: Config + + init { + mConfig = Config.newInstance(context) + val view = activity.layoutInflater.inflate(R.layout.dialog_change_widget_note, null) as RadioGroup + view.setOnCheckedChangeListener(this) + + val db = DBHelper.newInstance(context) + val notes = db.notes + notes.forEach { + val radioButton = activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton + radioButton.apply { + text = it.title + isChecked = it.id == mConfig.widgetNoteIndex + id = it.id + } + view.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.widgetNoteIndex = checkedId + dialog?.dismiss() + } +} diff --git a/app/src/main/res/layout/dialog_change_widget_note.xml b/app/src/main/res/layout/dialog_change_widget_note.xml new file mode 100644 index 00000000..f6e23b42 --- /dev/null +++ b/app/src/main/res/layout/dialog_change_widget_note.xml @@ -0,0 +1,7 @@ + + diff --git a/app/src/main/res/layout/radio_button.xml b/app/src/main/res/layout/radio_button.xml new file mode 100644 index 00000000..c467212a --- /dev/null +++ b/app/src/main/res/layout/radio_button.xml @@ -0,0 +1,8 @@ + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 4c0e4b95..64e9d66a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -20,6 +20,7 @@ Notiz auswählen Aktuelle Notiz: Change widget\'s note + Pick a note for the widget Einstellungen diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index a337be03..4cf6d7ed 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -20,6 +20,7 @@ Pick a note Current note: Change widget\'s note + Pick a note for the widget Impostazioni diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index b8dfcade..97f33108 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -20,6 +20,7 @@ Pick a note Current note: Change widget\'s note + Pick a note for the widget 設定 diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 57660ddf..1161a69a 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -20,6 +20,7 @@ Selecione uma nota Nota atual: Change widget\'s note + Pick a note for the widget Definições diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 8ce0f57a..071e55a5 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -20,6 +20,7 @@ Pick a note Current note: Change widget\'s note + Pick a note for the widget Inställningar diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 906a8ba8..ad464640 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,6 +20,7 @@ Pick a note Current note: Change widget\'s note + Pick a note for the widget Settings