fetch data from the database at updating the widget too

This commit is contained in:
tibbi 2016-10-01 11:10:29 +02:00
parent 00f361ffc5
commit 87442a9515

View File

@ -10,8 +10,10 @@ import android.graphics.Color;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import com.simplemobiletools.notes.activities.MainActivity; import com.simplemobiletools.notes.activities.MainActivity;
import com.simplemobiletools.notes.databases.DBHelper;
public class MyWidgetProvider extends AppWidgetProvider { public class MyWidgetProvider extends AppWidgetProvider {
private DBHelper mDb;
private static SharedPreferences mPrefs; private static SharedPreferences mPrefs;
private static RemoteViews mRemoteViews; private static RemoteViews mRemoteViews;
@ -33,6 +35,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
private void initVariables(Context context) { private void initVariables(Context context) {
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); 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(), R.layout.widget);
setupAppOpenIntent(R.id.notes_holder, context); setupAppOpenIntent(R.id.notes_holder, context);
} }
@ -44,7 +47,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
} }
private void updateWidget(AppWidgetManager widgetManager, int widgetId, RemoteViews remoteViews) { private void updateWidget(AppWidgetManager widgetManager, int widgetId, RemoteViews remoteViews) {
final String text = mPrefs.getString(Constants.TEXT, ""); final String text = mDb.getGeneralNote().getValue();
remoteViews.setTextViewText(R.id.notes_view, text); remoteViews.setTextViewText(R.id.notes_view, text);
widgetManager.updateAppWidget(widgetId, remoteViews); widgetManager.updateAppWidget(widgetId, remoteViews);
} }