diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-22 23:35:05 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-12-23 12:24:50 +0300 |
commit | 033f8bfe8e21c76013b45a6607eac380c4c5b233 (patch) | |
tree | 22ec30761747fcd7a6291f2744ddebd9dde2d885 /app/src/main/java/it/niedermann/nextcloud/deck | |
parent | db2d8ce8e0f225e729bd6a0d3a2a40d0e946dc16 (diff) |
Single Card Widget enhancements
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck')
3 files changed, 110 insertions, 1 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidget.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidget.java index b44b80d1b..f9596a565 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidget.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidget.java @@ -36,11 +36,13 @@ public class SingleCardWidget extends AppWidgetProvider { final Intent intent = EditActivity.createEditCardIntent(context, fullModel.getAccount(), fullModel.getModel().getBoardId(), fullModel.getFullCard().getLocalId()); final PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT); final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_single_card); + Intent serviceIntent = new Intent(context, SingleCardWidgetService.class); + serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); views.setOnClickPendingIntent(R.id.widget_card, pendingIntent); views.setTextViewText(R.id.title, fullModel.getFullCard().getCard().getTitle()); - views.setTextViewText(R.id.description, fullModel.getFullCard().getCard().getDescription()); + views.setRemoteAdapter(R.id.description_lv, serviceIntent); if (fullModel.getFullCard().getCard().getDueDate() != null) { views.setTextViewText(R.id.card_due_date, DateUtil.getRelativeDateTimeString(context, fullModel.getFullCard().getCard().getDueDate().toEpochMilli())); @@ -92,6 +94,7 @@ public class SingleCardWidget extends AppWidgetProvider { } awm.updateAppWidget(appWidgetId, views); + awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.description_lv); } catch (NoSuchElementException e) { // onUpdate has been triggered before the user finished configuring the widget } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidgetFactory.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidgetFactory.java new file mode 100644 index 000000000..e233c0502 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidgetFactory.java @@ -0,0 +1,95 @@ +package it.niedermann.nextcloud.deck.ui.widget.singlecard; + +import android.appwidget.AppWidgetManager; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.text.TextUtils; +import android.widget.RemoteViews; +import android.widget.RemoteViewsService; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import it.niedermann.android.markdown.MarkdownUtil; +import it.niedermann.nextcloud.deck.R; +import it.niedermann.nextcloud.deck.model.full.FullSingleCardWidgetModel; +import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; +import it.niedermann.nextcloud.deck.ui.card.EditActivity; + +public class SingleCardWidgetFactory implements RemoteViewsService.RemoteViewsFactory { + private final Context context; + private final int appWidgetId; + private final SyncManager syncManager; + private FullSingleCardWidgetModel model; + + public SingleCardWidgetFactory(@NonNull Context context, @NonNull Intent intent) { + this.context = context; + this.appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); + this.syncManager = new SyncManager(context); + } + + @Override + public void onCreate() { + + } + + @Override + public void onDataSetChanged() { + this.model = syncManager.getSingleCardWidgetModelDirectly(appWidgetId); + } + + @Override + public void onDestroy() { + + } + + @Override + public int getCount() { + return getDescriptionOrNull(model) == null ? 0 : 1; + } + + @Override + public RemoteViews getViewAt(int position) { + final CharSequence description = getDescriptionOrNull(model); + if (description == null) { + return null; + } + + final Intent intent = EditActivity.createEditCardIntent(context, model.getAccount(), model.getModel().getBoardId(), model.getFullCard().getLocalId()); + intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); + final RemoteViews widget_entry = new RemoteViews(context.getPackageName(), R.layout.widget_single_card_content); + widget_entry.setTextViewText(R.id.description, MarkdownUtil.renderForWidget(context, description)); + widget_entry.setOnClickFillInIntent(R.id.description, intent); + + return widget_entry; + } + + @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 true; + } + + @Nullable + private static CharSequence getDescriptionOrNull(@Nullable FullSingleCardWidgetModel model) { + if (model == null || model.getFullCard() == null && model.getFullCard().getCard() == null && TextUtils.isEmpty(model.getFullCard().getCard().getDescription())) { + return null; + } + return model.getFullCard().getCard().getDescription(); + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidgetService.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidgetService.java new file mode 100644 index 000000000..d938e383a --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidgetService.java @@ -0,0 +1,11 @@ +package it.niedermann.nextcloud.deck.ui.widget.singlecard; + +import android.content.Intent; +import android.widget.RemoteViewsService; + +public class SingleCardWidgetService extends RemoteViewsService { + @Override + public RemoteViewsFactory onGetViewFactory(Intent intent) { + return new SingleCardWidgetFactory(this.getApplicationContext(), intent); + } +} |