mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-01 01:27:53 +01:00
properly update the widgets note
This commit is contained in:
parent
27c279e843
commit
6744135ef6
@ -47,7 +47,7 @@ public class Config {
|
||||
}
|
||||
|
||||
public int getWidgetNoteIndex() {
|
||||
return mPrefs.getInt(Constants.WIDGET_NOTE_ID, 0);
|
||||
return mPrefs.getInt(Constants.WIDGET_NOTE_ID, 1);
|
||||
}
|
||||
|
||||
public void setWidgetNoteIndex(int id) {
|
||||
|
@ -13,7 +13,7 @@ import com.simplemobiletools.notes.activities.MainActivity;
|
||||
import com.simplemobiletools.notes.databases.DBHelper;
|
||||
import com.simplemobiletools.notes.models.Note;
|
||||
|
||||
import java.util.List;
|
||||
import static com.simplemobiletools.notes.R.layout.widget;
|
||||
|
||||
public class MyWidgetProvider extends AppWidgetProvider {
|
||||
private DBHelper mDb;
|
||||
@ -39,7 +39,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
||||
private void initVariables(Context context) {
|
||||
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE);
|
||||
mDb = DBHelper.newInstance(context);
|
||||
mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
|
||||
mRemoteViews = new RemoteViews(context.getPackageName(), widget);
|
||||
setupAppOpenIntent(R.id.notes_holder, context);
|
||||
}
|
||||
|
||||
@ -50,10 +50,9 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
||||
}
|
||||
|
||||
private void updateWidget(AppWidgetManager widgetManager, int widgetId, RemoteViews remoteViews) {
|
||||
final List<Note> notes = mDb.getNotes();
|
||||
final int currNoteIndex = mPrefs.getInt(Constants.CURRENT_NOTE_INDEX, 0);
|
||||
final String text = notes.get(currNoteIndex).getValue();
|
||||
remoteViews.setTextViewText(R.id.notes_view, text);
|
||||
final int widgetNoteId = mPrefs.getInt(Constants.WIDGET_NOTE_ID, 1);
|
||||
final Note note = mDb.getNote(widgetNoteId);
|
||||
remoteViews.setTextViewText(R.id.notes_view, note != null ? note.getValue() : "");
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews);
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +115,23 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public Note getNote(int id) {
|
||||
final String cols[] = {COL_TITLE, COL_VALUE};
|
||||
final String selection = COL_ID + " = ?";
|
||||
final String selectionArgs[] = {String.valueOf(id)};
|
||||
final Cursor cursor = mDb.query(TABLE_NAME, cols, selection, selectionArgs, null, null, null);
|
||||
Note note = null;
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String value = cursor.getString(cursor.getColumnIndex(COL_VALUE));
|
||||
note = new Note(id, title, value);
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
return note;
|
||||
}
|
||||
|
||||
public void updateNote(Note note) {
|
||||
final ContentValues values = fillContentValues(note);
|
||||
final String selection = COL_ID + " = ?";
|
||||
|
Loading…
x
Reference in New Issue
Block a user