summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java274
-rw-r--r--app/src/main/java/de/danoeh/antennapod/view/viewholder/DownloadItemViewHolder.java41
-rw-r--r--app/src/main/res/layout/downloadlog_item.xml169
-rw-r--r--core/src/main/res/values/colors.xml4
4 files changed, 245 insertions, 243 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
index 4d66fd486..9206cebea 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
@@ -26,171 +26,139 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester;
+import de.danoeh.antennapod.core.util.ThemeUtils;
+import de.danoeh.antennapod.view.viewholder.DownloadItemViewHolder;
+import de.danoeh.antennapod.view.viewholder.FeedViewHolder;
-/** Displays a list of DownloadStatus entries. */
+/**
+ * Displays a list of DownloadStatus entries.
+ */
public class DownloadLogAdapter extends BaseAdapter {
+ private static final String TAG = "DownloadLogAdapter";
- private static final String TAG = "DownloadLogAdapter";
-
- private final Context context;
-
+ private final Context context;
private final ItemAccess itemAccess;
- public DownloadLogAdapter(Context context, ItemAccess itemAccess) {
- super();
+ public DownloadLogAdapter(Context context, ItemAccess itemAccess) {
+ super();
this.itemAccess = itemAccess;
- this.context = context;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- Holder holder;
- DownloadStatus status = getItem(position);
- if (convertView == null) {
- holder = new Holder();
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(R.layout.downloadlog_item, parent, false);
- holder.icon = convertView.findViewById(R.id.txtvIcon);
- holder.retry = convertView.findViewById(R.id.btnRetry);
- holder.date = convertView.findViewById(R.id.txtvDate);
- holder.title = convertView.findViewById(R.id.txtvTitle);
- if(Build.VERSION.SDK_INT >= 23) {
- holder.title.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
- }
- holder.type = convertView.findViewById(R.id.txtvType);
- holder.reason = convertView.findViewById(R.id.txtvReason);
- convertView.setTag(holder);
- } else {
- holder = (Holder) convertView.getTag();
- }
- if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
- holder.type.setText(R.string.download_type_feed);
- } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
- holder.type.setText(R.string.download_type_media);
- }
- if (status.getTitle() != null) {
- holder.title.setText(status.getTitle());
- } else {
- holder.title.setText(R.string.download_log_title_unknown);
- }
- holder.date.setText(DateUtils.getRelativeTimeSpanString(
- status.getCompletionDate().getTime(),
- System.currentTimeMillis(), 0, 0));
- if (status.isSuccessful()) {
- holder.icon.setTextColor(ContextCompat.getColor(convertView.getContext(),
- R.color.download_success_green));
- holder.icon.setText("{fa-check-circle}");
- holder.retry.setVisibility(View.GONE);
- holder.reason.setVisibility(View.GONE);
- } else {
- holder.icon.setTextColor(ContextCompat.getColor(convertView.getContext(),
- R.color.download_failed_red));
- holder.icon.setText("{fa-times-circle}");
- String reasonText = status.getReason().getErrorString(context);
- if (status.getReasonDetailed() != null) {
- reasonText += ": " + status.getReasonDetailed();
- }
- holder.reason.setText(reasonText);
- holder.reason.setVisibility(View.VISIBLE);
- if(!newerWasSuccessful(position, status.getFeedfileType(), status.getFeedfileId())) {
- holder.retry.setVisibility(View.VISIBLE);
- holder.retry.setOnClickListener(clickListener);
- ButtonHolder btnHolder;
- if(holder.retry.getTag() != null) {
- btnHolder = (ButtonHolder) holder.retry.getTag();
- } else {
- btnHolder = new ButtonHolder();
- }
- btnHolder.typeId = status.getFeedfileType();
- btnHolder.id = status.getFeedfileId();
- holder.retry.setTag(btnHolder);
- } else {
- holder.retry.setVisibility(View.GONE);
- holder.retry.setOnClickListener(null);
- holder.retry.setTag(null);
- }
- }
-
- return convertView;
- }
-
- private final View.OnClickListener clickListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ButtonHolder holder = (ButtonHolder) v.getTag();
- if(holder.typeId == Feed.FEEDFILETYPE_FEED) {
- Feed feed = DBReader.getFeed(holder.id);
- if (feed != null) {
- try {
- DBTasks.forceRefreshFeed(context, feed);
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- }
- } else {
- Log.wtf(TAG, "Could not find feed for feed id: " + holder.id);
- }
- } else if(holder.typeId == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
- FeedMedia media = DBReader.getFeedMedia(holder.id);
- if (media != null) {
- try {
- DownloadRequester.getInstance().downloadMedia(context, media.getItem());
- Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
- }
- } else {
- Log.wtf(TAG, "Could not find media for id: " + holder.id);
- }
- } else {
- Log.wtf(TAG, "Unexpected type id: " + holder.typeId);
- }
- v.setVisibility(View.GONE);
- }
- };
-
- private boolean newerWasSuccessful(int position, int feedTypeId, long id) {
- for (int i = 0; i < position; i++) {
- DownloadStatus status = getItem(i);
- if (status.getFeedfileType() == feedTypeId && status.getFeedfileId() == id &&
- status.isSuccessful()) return true;
- }
- return false;
- }
-
- static class Holder {
- IconTextView icon;
- IconButton retry;
- TextView title;
- TextView type;
- TextView date;
- TextView reason;
- }
-
- static class ButtonHolder {
- int typeId;
- long id;
- }
-
- @Override
- public int getCount() {
+ this.context = context;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ DownloadItemViewHolder holder;
+ if (convertView == null) {
+ holder = new DownloadItemViewHolder(context, parent);
+ } else {
+ holder = (DownloadItemViewHolder) convertView.getTag();
+ }
+
+ DownloadStatus status = getItem(position);
+ if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
+ holder.type.setText(R.string.download_type_feed);
+ } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
+ holder.type.setText(R.string.download_type_media);
+ }
+
+ if (status.getTitle() != null) {
+ holder.title.setText(status.getTitle());
+ } else {
+ holder.title.setText(R.string.download_log_title_unknown);
+ }
+ holder.date.setText(DateUtils.getRelativeTimeSpanString(status.getCompletionDate().getTime(),
+ System.currentTimeMillis(), 0, 0));
+
+ if (status.isSuccessful()) {
+ holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_success_green));
+ holder.icon.setText("{fa-check-circle}");
+ holder.secondaryActionButton.setVisibility(View.INVISIBLE);
+ holder.reason.setVisibility(View.GONE);
+ } else {
+ holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_failed_red));
+ holder.icon.setText("{fa-times-circle}");
+ String reasonText = status.getReason().getErrorString(context);
+ if (status.getReasonDetailed() != null) {
+ reasonText += ": " + status.getReasonDetailed();
+ }
+ holder.reason.setText(reasonText);
+ holder.reason.setVisibility(View.VISIBLE);
+
+ if (newerWasSuccessful(position, status.getFeedfileType(), status.getFeedfileId())) {
+ holder.secondaryActionButton.setVisibility(View.INVISIBLE);
+ holder.secondaryActionButton.setOnClickListener(null);
+ holder.secondaryActionButton.setTag(null);
+ } else {
+ holder.secondaryActionIcon.setImageResource(
+ ThemeUtils.getDrawableFromAttr(context, R.attr.navigation_refresh));
+ holder.secondaryActionButton.setVisibility(View.VISIBLE);
+
+ if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
+ holder.secondaryActionButton.setOnClickListener(v -> {
+ holder.secondaryActionButton.setVisibility(View.INVISIBLE);
+ Feed feed = DBReader.getFeed(status.getFeedfileId());
+ if (feed == null) {
+ Log.e(TAG, "Could not find feed for feed id: " + status.getFeedfileId());
+ return;
+ }
+ try {
+ DBTasks.forceRefreshFeed(context, feed);
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ }
+ });
+ } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
+ holder.secondaryActionButton.setOnClickListener(v -> {
+ holder.secondaryActionButton.setVisibility(View.INVISIBLE);
+ FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
+ if (media == null) {
+ Log.e(TAG, "Could not find feed media for feed id: " + status.getFeedfileId());
+ return;
+ }
+ try {
+ DownloadRequester.getInstance().downloadMedia(context, media.getItem());
+ Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
+ }
+ });
+ }
+ }
+ }
+
+ return holder.itemView;
+ }
+
+ private boolean newerWasSuccessful(int position, int feedTypeId, long id) {
+ for (int i = 0; i < position; i++) {
+ DownloadStatus status = getItem(i);
+ if (status.getFeedfileType() == feedTypeId && status.getFeedfileId() == id && status.isSuccessful()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int getCount() {
return itemAccess.getCount();
- }
+ }
- @Override
- public DownloadStatus getItem(int position) {
+ @Override
+ public DownloadStatus getItem(int position) {
return itemAccess.getItem(position);
- }
+ }
- @Override
- public long getItemId(int position) {
- return position;
- }
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
public interface ItemAccess {
- int getCount();
- DownloadStatus getItem(int position);
+ int getCount();
+
+ DownloadStatus getItem(int position);
}
}
diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/DownloadItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/DownloadItemViewHolder.java
new file mode 100644
index 000000000..d48db196f
--- /dev/null
+++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/DownloadItemViewHolder.java
@@ -0,0 +1,41 @@
+package de.danoeh.antennapod.view.viewholder;
+
+import android.content.Context;
+import android.os.Build;
+import android.text.Layout;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+import androidx.recyclerview.widget.RecyclerView;
+import com.joanzapata.iconify.widget.IconTextView;
+import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.view.CircularProgressBar;
+
+public class DownloadItemViewHolder extends RecyclerView.ViewHolder {
+ public final View secondaryActionButton;
+ public final ImageView secondaryActionIcon;
+ public final CircularProgressBar secondaryActionProgress;
+ public final IconTextView icon;
+ public final TextView title;
+ public final TextView type;
+ public final TextView date;
+ public final TextView reason;
+
+ public DownloadItemViewHolder(Context context, ViewGroup parent) {
+ super(LayoutInflater.from(context).inflate(R.layout.downloadlog_item, parent, false));
+ date = itemView.findViewById(R.id.txtvDate);
+ type = itemView.findViewById(R.id.txtvType);
+ icon = itemView.findViewById(R.id.txtvIcon);
+ reason = itemView.findViewById(R.id.txtvReason);
+ secondaryActionProgress = itemView.findViewById(R.id.secondaryActionProgress);
+ secondaryActionButton = itemView.findViewById(R.id.secondaryActionButton);
+ secondaryActionIcon = itemView.findViewById(R.id.secondaryActionIcon);
+ title = itemView.findViewById(R.id.txtvTitle);
+ if (Build.VERSION.SDK_INT >= 23) {
+ title.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
+ }
+ itemView.setTag(this);
+ }
+}
diff --git a/app/src/main/res/layout/downloadlog_item.xml b/app/src/main/res/layout/downloadlog_item.xml
index 505102ea4..c8cbf15f6 100644
--- a/app/src/main/res/layout/downloadlog_item.xml
+++ b/app/src/main/res/layout/downloadlog_item.xml
@@ -1,97 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dp"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:paddingBottom="8dp"
- android:descendantFocusability="blocksDescendants"
- tools:background="@android:color/darker_gray">
+<LinearLayout
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:gravity="center_vertical"
+ android:baselineAligned="false"
+ android:descendantFocusability="blocksDescendants">
<com.joanzapata.iconify.widget.IconTextView
- android:id="@+id/txtvIcon"
- android:layout_width="48sp"
- android:layout_height="48sp"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:textSize="48sp"
- android:gravity="center" />
+ android:id="@+id/txtvIcon"
+ android:layout_width="40dp"
+ android:layout_height="40dp"
+ android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
+ android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
+ android:layout_marginLeft="@dimen/listitem_threeline_textleftpadding"
+ android:layout_marginStart="@dimen/listitem_threeline_textleftpadding"
+ android:textSize="40dp"
+ android:gravity="center"
+ tools:text="X"/>
- <com.joanzapata.iconify.widget.IconButton
- android:id="@+id/btnRetry"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtvIcon"
- android:layout_alignLeft="@id/txtvIcon"
- android:layout_alignStart="@id/txtvIcon"
- android:layout_alignRight="@id/txtvIcon"
- android:layout_alignEnd="@id/txtvIcon"
- android:layout_marginTop="8dp"
- android:text="{fa-repeat}"
- tools:text="↻" />
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
+ android:layout_marginRight="@dimen/listitem_threeline_textrightpadding"
+ android:layout_marginEnd="@dimen/listitem_threeline_textrightpadding"
+ android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
+ android:layout_marginLeft="16dp"
+ android:layout_marginStart="16dp"
+ android:layout_weight="1"
+ android:orientation="vertical">
- <TextView
- android:id="@+id/txtvType"
- style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
- android:layout_marginBottom="8dp"
- tools:text="Media file"
- tools:background="@android:color/holo_green_dark" />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/status"
+ android:orientation="horizontal"
+ android:gravity="center_vertical">
- <TextView
- android:id="@+id/txtvTitle"
- style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_toRightOf="@id/txtvIcon"
- android:layout_toEndOf="@id/txtvIcon"
- android:layout_toLeftOf="@id/txtvType"
- android:layout_toStartOf="@id/txtvType"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
- android:layout_marginBottom="8dp"
- android:minLines="1"
- android:maxLines="2"
- tools:text="Download item title"
- tools:background="@android:color/holo_blue_light" />
+ <TextView
+ android:id="@+id/txtvType"
+ style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ tools:text="Media file"/>
+ <TextView
+ style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="4dp"
+ android:layout_marginEnd="4dp"
+ android:layout_marginLeft="4dp"
+ android:layout_marginStart="4dp"
+ android:text="·"
+ tools:background="@android:color/holo_blue_light"/>
+ <TextView
+ android:id="@+id/txtvDate"
+ style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ tools:text="January 23"/>
- <TextView
- android:id="@+id/txtvDate"
- style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/txtvIcon"
- android:layout_toEndOf="@id/txtvIcon"
- android:layout_below="@id/txtvTitle"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
- android:layout_marginBottom="8dp"
- tools:text="January 23"
- tools:background="@android:color/holo_green_dark" />
+ </LinearLayout>
+ <TextView
+ android:id="@+id/txtvTitle"
+ style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ tools:text="@sample/episodes.json/data/title"
+ android:ellipsize="end"
+ tools:background="@android:color/holo_blue_light"/>
- <TextView
- android:id="@+id/txtvReason"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtvDate"
- android:layout_toRightOf="@id/txtvIcon"
- android:layout_toEndOf="@id/txtvIcon"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
- android:textColor="?android:attr/textColorTertiary"
- android:textSize="@dimen/text_size_micro"
- tools:text="@string/design_time_downloaded_log_failure_reason"
- tools:background="@android:color/holo_green_dark" />
+ <TextView
+ android:id="@+id/txtvReason"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="14sp"
+ android:textColor="?android:attr/textColorSecondary"
+ tools:text="@string/design_time_downloaded_log_failure_reason"/>
+
+ </LinearLayout>
+
+ <include layout="@layout/secondary_action"/>
-</RelativeLayout> \ No newline at end of file
+</LinearLayout> \ No newline at end of file
diff --git a/core/src/main/res/values/colors.xml b/core/src/main/res/values/colors.xml
index fea7da4a4..b162038cf 100644
--- a/core/src/main/res/values/colors.xml
+++ b/core/src/main/res/values/colors.xml
@@ -7,8 +7,8 @@
<color name="black">#000000</color>
<color name="holo_blue_light">#33B5E5</color>
<color name="holo_blue_dark">#0099CC</color>
- <color name="download_success_green">#669900</color>
- <color name="download_failed_red">#CC0000</color>
+ <color name="download_success_green">#248800</color>
+ <color name="download_failed_red">#B00020</color>
<color name="status_progress">#E033B5E5</color>
<color name="overlay_dark">#2C2C2C</color>
<color name="overlay_light">#FFFFFF</color>