mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 15:02:05 +02:00
display the currently selected notes content at the widget
This commit is contained in:
parent
d672ea3878
commit
4a1f1ae0f9
@ -11,6 +11,9 @@ import android.widget.RemoteViews;
|
||||
|
||||
import com.simplemobiletools.notes.activities.MainActivity;
|
||||
import com.simplemobiletools.notes.databases.DBHelper;
|
||||
import com.simplemobiletools.notes.models.Note;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MyWidgetProvider extends AppWidgetProvider {
|
||||
private DBHelper mDb;
|
||||
@ -47,7 +50,9 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
||||
}
|
||||
|
||||
private void updateWidget(AppWidgetManager widgetManager, int widgetId, RemoteViews remoteViews) {
|
||||
final String text = mDb.getGeneralNote().getValue();
|
||||
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);
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews);
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ public class MainActivity extends SimpleActivity {
|
||||
|
||||
mCurrNoteLabel.setVisibility(mNotes.size() <= 1 ? View.GONE : View.VISIBLE);
|
||||
mCurrNoteTitle.setVisibility(mNotes.size() <= 1 ? View.GONE : View.VISIBLE);
|
||||
Utils.updateWidget(getApplicationContext());
|
||||
}
|
||||
|
||||
@OnClick(R.id.notes_fab)
|
||||
|
@ -121,24 +121,4 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
final String selectionArgs[] = new String[]{String.valueOf(note.getId())};
|
||||
mDb.update(TABLE_NAME, values, selection, selectionArgs);
|
||||
}
|
||||
|
||||
public Note getGeneralNote() {
|
||||
final String cols[] = {COL_ID, COL_TITLE, COL_VALUE};
|
||||
final String selection = COL_TITLE + " = ?";
|
||||
final String selectionArgs[] = {NOTE};
|
||||
Cursor cursor = mDb.query(TABLE_NAME, cols, selection, selectionArgs, null, null, null);
|
||||
if (cursor == null)
|
||||
return null;
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
final int id = cursor.getInt(cursor.getColumnIndex(COL_ID));
|
||||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String value = cursor.getString(cursor.getColumnIndex(COL_VALUE));
|
||||
cursor.close();
|
||||
return new Note(id, title, value);
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user