diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-05-12 16:01:09 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-05-12 16:01:09 +0300 |
commit | 3f3684d087d3bbd2d9fcbd88f20354c1e9839634 (patch) | |
tree | a1881a5ee3358d837c97e30eabfed97aa59cce42 /app/src/main/java/it/niedermann/nextcloud/deck/ui/widget | |
parent | 1b2b7860f9a2c4f0a180f0b519c904ffe25d819d (diff) |
#217 SingleCardWidget
Add database table
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/widget')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/singlecard/SingleCardWidget.java | 104 |
1 files changed, 53 insertions, 51 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 4ba5f8a01..dfc8ac275 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 @@ -27,58 +27,60 @@ public class SingleCardWidget extends AppWidgetProvider { final SyncManager syncManager = new SyncManager(context); for (int appWidgetId : appWidgetIds) { - try { - final FullSingleCardWidgetModel fullModel = syncManager.getSingleCardWidgetModelDirectly(appWidgetId); - - 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); - - views.setOnClickPendingIntent(R.id.title, pendingIntent); - - views.setTextViewText(R.id.title, fullModel.getFullCard().getCard().getTitle()); - - if (fullModel.getFullCard().getCard().getDueDate() != null) { - views.setTextViewText(R.id.card_due_date, DateUtil.getRelativeDateTimeString(context, fullModel.getFullCard().getCard().getDueDate().getTime())); - // TODO Use multiple views for background colors and only set the necessary to View.VISIBLE - // https://stackoverflow.com/a/3376537 - // Because otherwise using Reflection is the only way - views.setViewVisibility(R.id.card_due_date, View.VISIBLE); - } else { - views.setViewVisibility(R.id.card_due_date, View.GONE); + new Thread(() -> { + try { + final FullSingleCardWidgetModel fullModel = syncManager.getSingleCardWidgetModelDirectly(appWidgetId); + + 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); + + views.setOnClickPendingIntent(R.id.widget_card, pendingIntent); + + views.setTextViewText(R.id.title, fullModel.getFullCard().getCard().getTitle()); + + if (fullModel.getFullCard().getCard().getDueDate() != null) { + views.setTextViewText(R.id.card_due_date, DateUtil.getRelativeDateTimeString(context, fullModel.getFullCard().getCard().getDueDate().getTime())); + // TODO Use multiple views for background colors and only set the necessary to View.VISIBLE + // https://stackoverflow.com/a/3376537 + // Because otherwise using Reflection is the only way + views.setViewVisibility(R.id.card_due_date, View.VISIBLE); + } else { + views.setViewVisibility(R.id.card_due_date, View.GONE); + } + + + final String counterMaxValue = context.getString(R.string.counter_max_value); + + final int attachmentsCount = fullModel.getFullCard().getAttachments().size(); + if (attachmentsCount == 0) { + views.setViewVisibility(R.id.card_count_attachments, View.GONE); + } else { + views.setViewVisibility(R.id.card_count_attachments, View.VISIBLE); + setupCounter(views, R.id.card_count_attachments, attachmentsCount, counterMaxValue); + } + + final int commentsCount = fullModel.getFullCard().getCommentCount(); + if (commentsCount == 0) { + views.setViewVisibility(R.id.card_count_comments, View.GONE); + } else { + setupCounter(views, R.id.card_count_comments, commentsCount, counterMaxValue); + views.setViewVisibility(R.id.card_count_comments, View.VISIBLE); + } + + final Card.TaskStatus taskStatus = fullModel.getFullCard().getCard().getTaskStatus(); + if (taskStatus.taskCount > 0) { + views.setTextViewText(R.id.card_count_tasks, context.getResources().getString(R.string.task_count, String.valueOf(taskStatus.doneCount), String.valueOf(taskStatus.taskCount))); + views.setViewVisibility(R.id.card_count_tasks, View.VISIBLE); + } else { + views.setViewVisibility(R.id.card_count_tasks, View.GONE); + } + + awm.updateAppWidget(appWidgetId, views); + } catch (NoSuchElementException e) { + // onUpdate has been triggered before the user finished configuring the widget } - - - final String counterMaxValue = context.getString(R.string.counter_max_value); - - final int attachmentsCount = fullModel.getFullCard().getAttachments().size(); - if (attachmentsCount == 0) { - views.setViewVisibility(R.id.card_count_attachments, View.GONE); - } else { - views.setViewVisibility(R.id.card_count_attachments, View.VISIBLE); - setupCounter(views, R.id.card_count_attachments, attachmentsCount, counterMaxValue); - } - - final int commentsCount = fullModel.getFullCard().getCommentCount(); - if (commentsCount == 0) { - views.setViewVisibility(R.id.card_count_comments, View.GONE); - } else { - setupCounter(views, R.id.card_count_comments, commentsCount, counterMaxValue); - views.setViewVisibility(R.id.card_count_comments, View.VISIBLE); - } - - final Card.TaskStatus taskStatus = fullModel.getFullCard().getCard().getTaskStatus(); - if (taskStatus.taskCount > 0) { - views.setTextViewText(R.id.card_count_tasks, context.getResources().getString(R.string.task_count, String.valueOf(taskStatus.doneCount), String.valueOf(taskStatus.taskCount))); - views.setViewVisibility(R.id.card_count_tasks, View.VISIBLE); - } else { - views.setViewVisibility(R.id.card_count_tasks, View.GONE); - } - - awm.updateAppWidget(appWidgetId, views); - } catch (NoSuchElementException e) { - // onUpdate has been triggered before the user finished configuring the widget - } + }).start(); } } |