diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e92e542793..d8ee6a8d6a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -110,6 +110,22 @@
android:name="other.writeily.widget.WrFilesWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />
+
+
+
+
+
+
+
+
+
+
getProjects() {
}
public String getCreationDate() {
- return getCreationaDate("");
+ return getCreationDate("");
}
- public String getCreationaDate(final String defaultValue) {
+ public String getCreationDate(final String defaultValue) {
if (creationDate == null) {
creationDate = parseOneValueOrDefault(line, PATTERN_CREATION_DATE, defaultValue);
}
diff --git a/app/src/main/java/net/gsantner/markor/widget/TodoWidgetProvider.java b/app/src/main/java/net/gsantner/markor/widget/TodoWidgetProvider.java
new file mode 100644
index 0000000000..3cee11e85b
--- /dev/null
+++ b/app/src/main/java/net/gsantner/markor/widget/TodoWidgetProvider.java
@@ -0,0 +1,70 @@
+package net.gsantner.markor.widget;
+
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProvider;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.widget.RemoteViews;
+
+import net.gsantner.markor.ApplicationObject;
+import net.gsantner.markor.R;
+import net.gsantner.markor.activity.openeditor.OpenFromShortcutOrWidgetActivity;
+import net.gsantner.markor.model.AppSettings;
+import net.gsantner.markor.model.Document;
+
+public class TodoWidgetProvider extends AppWidgetProvider {
+
+ @Override
+ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
+
+ int requestCode = 1;
+ final AppSettings appSettings = ApplicationObject.settings();
+
+ final int staticFlags = PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0);
+ final int mutableFlags = PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : 0);
+
+ for (int appWidgetId : appWidgetIds) {
+
+ RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.todo_widget_layout);
+
+ final Intent intent = new Intent(context, TodoWidgetService.class);
+ views.setRemoteAdapter(R.id.todo_widget_list_view, intent);
+ views.setEmptyView(R.id.todo_widget_list_view, R.id.todo_widget_empty_view);
+ views.setInt(R.id.todo_widget_list_view, "setBackgroundColor", appSettings.getEditorBackgroundColor());
+
+ final Intent openTodo = new Intent(context, OpenFromShortcutOrWidgetActivity.class)
+ .setAction(Intent.ACTION_EDIT)
+ .putExtra(Document.EXTRA_FILE, appSettings.getTodoFile());
+ views.setPendingIntentTemplate(R.id.todo_widget_list_view, PendingIntent.getActivity(context, requestCode++, openTodo, mutableFlags));
+ views.setOnClickPendingIntent(R.id.todo_widget_container, PendingIntent.getActivity(context, requestCode++, openTodo, staticFlags));
+
+ // Tell the AppWidgetManager to perform an update on the current app widget
+ appWidgetManager.updateAppWidget(appWidgetId, views);
+ }
+
+ super.onUpdate(context, appWidgetManager, appWidgetIds);
+ }
+
+ // Update all widget lists and shortcuts for all widgets
+ public static void updateTodoWidgets() {
+ final Context context = ApplicationObject.get().getApplicationContext();
+ final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
+ if (appWidgetManager == null) {
+ // The device does not support widgets.
+ return;
+ }
+ final ComponentName comp = new ComponentName(context, TodoWidgetProvider.class);
+ final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(comp);
+
+ // Update List
+ appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.todo_widget_list_view);
+
+ // Trigger remote views update
+ context.sendBroadcast(new Intent(context, TodoWidgetProvider.class)
+ .setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
+ .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds));
+ }
+}
diff --git a/app/src/main/java/net/gsantner/markor/widget/TodoWidgetRemoteViewsFactory.java b/app/src/main/java/net/gsantner/markor/widget/TodoWidgetRemoteViewsFactory.java
new file mode 100644
index 0000000000..058c073c56
--- /dev/null
+++ b/app/src/main/java/net/gsantner/markor/widget/TodoWidgetRemoteViewsFactory.java
@@ -0,0 +1,89 @@
+package net.gsantner.markor.widget;
+
+import android.content.Context;
+import android.content.Intent;
+import android.widget.RemoteViews;
+import android.widget.RemoteViewsService;
+
+import net.gsantner.markor.ApplicationObject;
+import net.gsantner.markor.R;
+import net.gsantner.markor.format.todotxt.TodoTxtTask;
+import net.gsantner.markor.model.AppSettings;
+import net.gsantner.markor.model.Document;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TodoWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
+
+ private final Context _context;
+ private final AppSettings _appSettings;
+ private final Document _document;
+ private final List _tasks;
+
+ public TodoWidgetRemoteViewsFactory(Context context, Intent intent) {
+ _context = context;
+ _appSettings = ApplicationObject.settings();
+ _document = new Document(_appSettings.getTodoFile());
+ _tasks = new ArrayList<>();
+ }
+
+ @Override
+ public void onCreate() {
+ onDataSetChanged();
+ }
+
+ @Override
+ public void onDataSetChanged() {
+ _tasks.clear();
+ final String content = _document.loadContent(_context);
+ if (content == null) {
+ return;
+ }
+ List tasks = TodoTxtTask.getAllTasks(content);
+ _tasks.addAll(tasks);
+ }
+
+ @Override
+ public void onDestroy() {
+ _tasks.clear();
+ }
+
+ @Override
+ public int getCount() {
+ return _tasks.size();
+ }
+
+ @Override
+ public RemoteViews getViewAt(int position) {
+ RemoteViews views = new RemoteViews(_context.getPackageName(), R.layout.todo_widget_list_item);
+ views.setTextViewText(R.id.todo_widget_item_text, _tasks.get(position).getDescription());
+ views.setInt(R.id.todo_widget_item_text, "setTextColor", _appSettings.getEditorForegroundColor());
+
+ final Intent fillInIntent = new Intent()
+ .putExtra(Document.EXTRA_FILE_LINE_NUMBER, position);
+ views.setOnClickFillInIntent(R.id.todo_widget_item_text, fillInIntent);
+
+ return views;
+ }
+
+ @Override
+ public RemoteViews getLoadingView() {
+ return null;
+ }
+
+ @Override
+ public int getViewTypeCount() {
+ return 1;
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+}
diff --git a/app/src/main/java/net/gsantner/markor/widget/TodoWidgetService.java b/app/src/main/java/net/gsantner/markor/widget/TodoWidgetService.java
new file mode 100644
index 0000000000..f65b8d0ef1
--- /dev/null
+++ b/app/src/main/java/net/gsantner/markor/widget/TodoWidgetService.java
@@ -0,0 +1,12 @@
+
+package net.gsantner.markor.widget;
+
+import android.content.Intent;
+import android.widget.RemoteViewsService;
+
+public class TodoWidgetService extends RemoteViewsService {
+ @Override
+ public RemoteViewsFactory onGetViewFactory(Intent intent) {
+ return (new TodoWidgetRemoteViewsFactory(getApplicationContext(), intent));
+ }
+}
diff --git a/app/src/main/res/drawable-nodpi/todo_widget_preview.png b/app/src/main/res/drawable-nodpi/todo_widget_preview.png
new file mode 100644
index 0000000000..5c97c862b0
Binary files /dev/null and b/app/src/main/res/drawable-nodpi/todo_widget_preview.png differ
diff --git a/app/src/main/res/layout/todo_widget_layout.xml b/app/src/main/res/layout/todo_widget_layout.xml
new file mode 100644
index 0000000000..8b44245d6a
--- /dev/null
+++ b/app/src/main/res/layout/todo_widget_layout.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/todo_widget_list_item.xml b/app/src/main/res/layout/todo_widget_list_item.xml
new file mode 100644
index 0000000000..f846da9354
--- /dev/null
+++ b/app/src/main/res/layout/todo_widget_list_item.xml
@@ -0,0 +1,8 @@
+
+
diff --git a/app/src/main/res/xml/todo_widget.xml b/app/src/main/res/xml/todo_widget.xml
new file mode 100644
index 0000000000..467a60334a
--- /dev/null
+++ b/app/src/main/res/xml/todo_widget.xml
@@ -0,0 +1,12 @@
+
+