diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-05-12 17:46:31 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-05-12 17:46:31 +0300 |
commit | a106fef4e7904075070a2d24cd316c667def1101 (patch) | |
tree | 2798b2e9758c7a5ad87075ca4c403a1506262547 /app/src/main/java/it/niedermann/nextcloud/deck/ui/widget | |
parent | 9cbbd2af04f885d80dc7b4f3dff2e1c41bfb1e8c (diff) |
#217 SingleCardWidget
Hide images on Android < 5
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 | 23 |
1 files changed, 20 insertions, 3 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 dfc8ac275..b0e789865 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 @@ -6,9 +6,11 @@ import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.view.View; import android.widget.RemoteViews; +import androidx.annotation.DrawableRes; import androidx.annotation.IdRes; import androidx.annotation.NonNull; @@ -55,25 +57,34 @@ public class SingleCardWidget extends AppWidgetProvider { final int attachmentsCount = fullModel.getFullCard().getAttachments().size(); if (attachmentsCount == 0) { views.setViewVisibility(R.id.card_count_attachments, View.GONE); + views.setViewVisibility(R.id.card_count_attachments_image, View.GONE); } else { views.setViewVisibility(R.id.card_count_attachments, View.VISIBLE); + views.setViewVisibility(R.id.card_count_attachments_image, View.VISIBLE); setupCounter(views, R.id.card_count_attachments, attachmentsCount, counterMaxValue); + setImageDrawable(views, R.id.card_count_attachments_image, R.drawable.ic_check_grey600_24dp); } final int commentsCount = fullModel.getFullCard().getCommentCount(); if (commentsCount == 0) { views.setViewVisibility(R.id.card_count_comments, View.GONE); + views.setViewVisibility(R.id.card_count_comments_image, View.GONE); } else { - setupCounter(views, R.id.card_count_comments, commentsCount, counterMaxValue); views.setViewVisibility(R.id.card_count_comments, View.VISIBLE); + views.setViewVisibility(R.id.card_count_comments_image, View.VISIBLE); + setupCounter(views, R.id.card_count_comments, commentsCount, counterMaxValue); + setImageDrawable(views, R.id.card_count_comments_image, R.drawable.ic_comment_white_24dp); } 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); + views.setViewVisibility(R.id.card_count_tasks_image, View.VISIBLE); + views.setTextViewText(R.id.card_count_tasks, context.getResources().getString(R.string.task_count, String.valueOf(taskStatus.doneCount), String.valueOf(taskStatus.taskCount))); + setImageDrawable(views, R.id.card_count_tasks_image, R.drawable.ic_attach_file_grey600_24dp); } else { views.setViewVisibility(R.id.card_count_tasks, View.GONE); + views.setViewVisibility(R.id.card_count_tasks_image, View.GONE); } awm.updateAppWidget(appWidgetId, views); @@ -87,13 +98,19 @@ public class SingleCardWidget extends AppWidgetProvider { private static void setupCounter(@NonNull RemoteViews views, @IdRes int textViewId, int count, String counterMaxValue) { if (count > 99) { views.setTextViewText(textViewId, counterMaxValue); - } else if (count > 1) { + } else if (count > 1 || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { views.setTextViewText(textViewId, String.valueOf(count)); } else if (count == 1) { views.setTextViewText(textViewId, ""); } } + private static void setImageDrawable(@NonNull RemoteViews views, @IdRes int imageView, @DrawableRes int image) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + views.setImageViewResource(imageView, image); + } + } + @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); |