summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/build.gradle6
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java39
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java102
-rw-r--r--app/src/main/res/layout/downloadlog_item.xml120
4 files changed, 174 insertions, 93 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 7591a414d..d85803538 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -14,9 +14,9 @@ dependencies {
compile 'commons-io:commons-io:2.4'
compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
compile 'org.jsoup:jsoup:1.7.3'
- compile 'com.squareup.picasso:picasso:2.4.0'
- compile 'com.squareup.okhttp:okhttp:2.2.0'
- compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
+ compile 'com.squareup.picasso:picasso:2.5.2'
+ compile 'com.squareup.okhttp:okhttp:2.3.0'
+ compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
compile 'com.squareup.okio:okio:1.2.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.joanzapata.android:android-iconify:1.0.9'
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
index 3b03ed2db..2b1b13ae6 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
@@ -26,7 +26,6 @@ import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
-import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedPreferences;
@@ -91,12 +90,10 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
getSupportActionBar().setTitle(R.string.add_new_feed_label);
} else {
- throw new IllegalArgumentException(
- "Activity must be started with feedurl argument!");
+ throw new IllegalArgumentException("Activity must be started with feedurl argument!");
}
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Activity was started with url " + feedUrl);
+ Log.d(TAG, "Activity was started with url " + feedUrl);
setLoadingLayout();
if (savedInstanceState == null) {
startFeedDownload(feedUrl, null, null);
@@ -147,7 +144,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
@Override
public void run() {
- if (BuildConfig.DEBUG) Log.d(TAG, "Download was completed");
+ Log.d(TAG, "Download was completed");
DownloadStatus status = downloader.getResult();
if (status != null) {
if (!status.isCancelled()) {
@@ -164,15 +161,13 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
OnlineFeedViewActivity.this);
if (errorMsg != null
&& status.getReasonDetailed() != null) {
- errorMsg += " ("
- + status.getReasonDetailed() + ")";
+ errorMsg += " (" + status.getReasonDetailed() + ")";
}
showErrorDialog(errorMsg);
}
}
} else {
- Log.wtf(TAG,
- "DownloadStatus returned by Downloader was null");
+ Log.wtf(TAG, "DownloadStatus returned by Downloader was null");
finish();
}
}
@@ -181,21 +176,18 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
}
private void startFeedDownload(String url, String username, String password) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Starting feed download");
+ Log.d(TAG, "Starting feed download");
url = URLChecker.prepareURL(url);
feed = new Feed(url, new Date(0));
if (username != null && password != null) {
feed.setPreferences(new FeedPreferences(0, false, username, password));
}
String fileUrl = new File(getExternalCacheDir(),
- FileNameGenerator.generateFileName(feed.getDownload_url()))
- .toString();
+ FileNameGenerator.generateFileName(feed.getDownload_url())).toString();
feed.setFile_url(fileUrl);
final DownloadRequest request = new DownloadRequest(feed.getFile_url(),
feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED, username, password, true, null);
- downloader = new HttpDownloader(
- request);
+ downloader = new HttpDownloader(request);
new Thread() {
@Override
public void run() {
@@ -233,8 +225,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
"feed must be non-null and downloaded when parseFeed is called");
}
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Parsing feed");
+ Log.d(TAG, "Parsing feed");
Thread thread = new Thread() {
@@ -258,7 +249,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
e.printStackTrace();
reasonDetailed = e.getMessage();
} catch (UnsupportedFeedtypeException e) {
- if (BuildConfig.DEBUG) Log.d(TAG, "Unsupported feed type detected");
+ Log.d(TAG, "Unsupported feed type detected");
if (StringUtils.equalsIgnoreCase("html", e.getRootElement())) {
if (showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url())) {
return;
@@ -269,8 +260,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
}
} finally {
boolean rc = new File(feed.getFile_url()).delete();
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Deleted feed source file. Result: " + rc);
+ Log.d(TAG, "Deleted feed source file. Result: " + rc);
}
if (successful) {
@@ -386,7 +376,12 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
String selectedUrl = urls.get(which);
dialog.dismiss();
resetIntent(selectedUrl, titles.get(which));
- startFeedDownload(selectedUrl, null, null);
+ FeedPreferences prefs = feed.getPreferences();
+ if(prefs != null) {
+ startFeedDownload(selectedUrl, prefs.getUsername(), prefs.getPassword());
+ } else {
+ startFeedDownload(selectedUrl, null, null);
+ }
}
};
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 f982e86ce..f29cfdf2f 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
@@ -2,20 +2,34 @@ package de.danoeh.antennapod.adapter;
import android.content.Context;
import android.text.format.DateUtils;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
+import android.widget.Button;
import android.widget.TextView;
+import android.widget.Toast;
+
+import com.joanzapata.android.iconify.Iconify;
+
+import java.util.Date;
+
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedImage;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.service.download.DownloadStatus;
+import de.danoeh.antennapod.core.storage.DBReader;
+import de.danoeh.antennapod.core.storage.DBTasks;
+import de.danoeh.antennapod.core.storage.DownloadRequestException;
/** Displays a list of DownloadStatus entries. */
public class DownloadLogAdapter extends BaseAdapter {
+ private final String TAG = "DownloadLogAdapter";
+
private Context context;
private ItemAccess itemAccess;
@@ -35,11 +49,11 @@ public class DownloadLogAdapter extends BaseAdapter {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.downloadlog_item, parent, false);
+ holder.icon = (TextView) convertView.findViewById(R.id.txtvIcon);
+ holder.retry = (Button) convertView.findViewById(R.id.btnRetry);
+ holder.date = (TextView) convertView.findViewById(R.id.txtvDate);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.type = (TextView) convertView.findViewById(R.id.txtvType);
- holder.date = (TextView) convertView.findViewById(R.id.txtvDate);
- holder.successful = (TextView) convertView
- .findViewById(R.id.txtvStatus);
holder.reason = (TextView) convertView
.findViewById(R.id.txtvReason);
convertView.setTag(holder);
@@ -62,33 +76,99 @@ public class DownloadLogAdapter extends BaseAdapter {
status.getCompletionDate().getTime(),
System.currentTimeMillis(), 0, 0));
if (status.isSuccessful()) {
- holder.successful.setTextColor(convertView.getResources().getColor(
+ holder.icon.setTextColor(convertView.getResources().getColor(
R.color.download_success_green));
- holder.successful.setText(R.string.download_successful);
+ holder.icon.setText("{fa-check-circle}");
+ Iconify.addIcons(holder.icon);
+ holder.retry.setVisibility(View.GONE);
holder.reason.setVisibility(View.GONE);
} else {
- holder.successful.setTextColor(convertView.getResources().getColor(
+ holder.icon.setTextColor(convertView.getResources().getColor(
R.color.download_failed_red));
- holder.successful.setText(R.string.download_failed);
+ holder.icon.setText("{fa-times-circle}");
+ Iconify.addIcons(holder.icon);
String reasonText = status.getReason().getErrorString(context);
if (status.getReasonDetailed() != null) {
reasonText += ": " + status.getReasonDetailed();
}
holder.reason.setText(reasonText);
holder.reason.setVisibility(View.VISIBLE);
+ if(status.getFeedfileType() != FeedImage.FEEDFILETYPE_FEEDIMAGE &&
+ !newerWasSuccessful(position, status.getFeedfileType(), status.getFeedfileId())) {
+ holder.retry.setVisibility(View.VISIBLE);
+ holder.retry.setText("{fa-repeat}");
+ Iconify.addIcons(holder.retry);
+ 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(context, holder.id);
+ feed.setLastUpdate(new Date(0)); // force refresh
+ try {
+ DBTasks.refreshFeed(context, feed);
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ }
+ } else if(holder.typeId == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
+ FeedMedia media = DBReader.getFeedMedia(context, holder.id);
+ try {
+ DBTasks.downloadFeedItems(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, "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 {
+ TextView icon;
+ Button retry;
TextView title;
TextView type;
TextView date;
- TextView successful;
TextView reason;
}
+ static class ButtonHolder {
+ int typeId;
+ long id;
+ }
+
@Override
public int getCount() {
return itemAccess.getCount();
@@ -104,9 +184,9 @@ public class DownloadLogAdapter extends BaseAdapter {
return position;
}
- public static interface ItemAccess {
- public int getCount();
- public DownloadStatus getItem(int position);
+ public interface ItemAccess {
+ int getCount();
+ DownloadStatus getItem(int position);
}
}
diff --git a/app/src/main/res/layout/downloadlog_item.xml b/app/src/main/res/layout/downloadlog_item.xml
index df1501222..c6a34a517 100644
--- a/app/src/main/res/layout/downloadlog_item.xml
+++ b/app/src/main/res/layout/downloadlog_item.xml
@@ -1,78 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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:orientation="vertical"
+ android:paddingTop="8dp"
+ android:paddingLeft="16dp"
+ android:paddingRight="16dp"
+ android:paddingBottom="8dp"
tools:background="@android:color/darker_gray">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
- android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding"
- android:layout_marginTop="@dimen/listitem_threeline_verticalpadding">
-
- <TextView
- android:id="@+id/txtvType"
- style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_marginLeft="@dimen/listitem_threeline_textleftpadding"
- tools:text="Media file"
- tools:background="@android:color/holo_green_dark" />
-
- <TextView
- android:id="@+id/txtvTitle"
- style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_toLeftOf="@id/txtvType"
- tools:text="Download item title"
- tools:background="@android:color/holo_blue_light" />
- </RelativeLayout>
+ <TextView
+ android:id="@+id/txtvIcon"
+ android:layout_width="48dp"
+ android:layout_height="48dp"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentLeft="true"
+ android:textSize="48sp"
+ tools:text="[Icon]"
+ android:gravity="center" />
- <RelativeLayout
- android:layout_width="match_parent"
+ <Button
+ android:id="@+id/btnRetry"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
- android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
- android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding">
+ android:layout_below="@id/txtvIcon"
+ android:layout_alignLeft="@id/txtvIcon"
+ android:layout_alignRight="@id/txtvIcon"
+ android:layout_marginTop="8dp"
+ tools:text="↻" />
- <TextView
- android:id="@+id/txtvDate"
- style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_marginRight="8dp"
- tools:text="January 23"
- tools:background="@android:color/holo_green_dark" />
+ <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_marginLeft="8dp"
+ android:layout_marginBottom="8dp"
+ tools:text="Media file"
+ tools:background="@android:color/holo_green_dark" />
- <TextView
- android:id="@+id/txtvStatus"
- style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- tools:text="successful"
- tools:background="@android:color/holo_green_dark" />
+ <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_toLeftOf="@id/txtvType"
+ android:layout_marginLeft="8dp"
+ android:layout_marginBottom="8dp"
+ android:minLines="1"
+ android:maxLines="2"
+ tools:text="Download item title"
+ tools:background="@android:color/holo_blue_light" />
- </RelativeLayout>
+ <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_below="@id/txtvTitle"
+ android:layout_marginLeft="8dp"
+ android:layout_marginBottom="8dp"
+ tools:text="January 23"
+ tools:background="@android:color/holo_green_dark" />
<TextView
android:id="@+id/txtvReason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
- android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
- android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding"
+ android:layout_below="@id/txtvDate"
+ android:layout_toRightOf="@id/txtvIcon"
+ android:layout_marginLeft="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" />
-</LinearLayout> \ No newline at end of file
+</RelativeLayout> \ No newline at end of file