mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-02 18:00:12 +02:00
allow changing the note displayed in the widget in a dialog
This commit is contained in:
parent
5c11dec6dc
commit
27c279e843
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -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) {
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
7
app/src/main/res/layout/dialog_change_widget_note.xml
Normal file
7
app/src/main/res/layout/dialog_change_widget_note.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RadioGroup
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_radio_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin"/>
|
8
app/src/main/res/layout/radio_button.xml
Normal file
8
app/src/main/res/layout/radio_button.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RadioButton
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_radio_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"/>
|
@ -20,6 +20,7 @@
|
||||
<string name="pick_a_note">Notiz auswählen</string>
|
||||
<string name="current_note">Aktuelle Notiz:</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>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Einstellungen</string>
|
||||
|
@ -20,6 +20,7 @@
|
||||
<string name="pick_a_note">Pick a note</string>
|
||||
<string name="current_note">Current 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>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Impostazioni</string>
|
||||
|
@ -20,6 +20,7 @@
|
||||
<string name="pick_a_note">Pick a note</string>
|
||||
<string name="current_note">Current 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>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">設定</string>
|
||||
|
@ -20,6 +20,7 @@
|
||||
<string name="pick_a_note">Selecione uma nota</string>
|
||||
<string name="current_note">Nota atual:</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>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Definições</string>
|
||||
|
@ -20,6 +20,7 @@
|
||||
<string name="pick_a_note">Pick a note</string>
|
||||
<string name="current_note">Current 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>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Inställningar</string>
|
||||
|
@ -20,6 +20,7 @@
|
||||
<string name="pick_a_note">Pick a note</string>
|
||||
<string name="current_note">Current 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>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user