summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/build.gradle37
-rw-r--r--app/src/main/AndroidManifest.xml2
-rw-r--r--app/src/main/assets/.gitignore2
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java40
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java82
-rw-r--r--app/src/main/templates/about.html (renamed from app/src/main/assets/about.html)6
6 files changed, 148 insertions, 21 deletions
diff --git a/app/build.gradle b/app/build.gradle
index d85803538..bb1fa26b7 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,3 +1,5 @@
+import org.apache.tools.ant.filters.ReplaceTokens
+
apply plugin: 'com.android.application'
repositories {
@@ -24,6 +26,20 @@ dependencies {
compile project(':library:drag-sort-listview')
}
+def getMyVersionName() {
+ def parsedManifestXml = (new XmlSlurper())
+ .parse('app/src/main/AndroidManifest.xml')
+ .declareNamespace(android:"http://schemas.android.com/apk/res/android")
+ return parsedManifestXml.'@android:versionName'
+}
+
+def getMyVersionCode() {
+ def parsedManifestXml = (new XmlSlurper())
+ .parse('app/src/main/AndroidManifest.xml')
+ .declareNamespace(android:"http://schemas.android.com/apk/res/android")
+ return parsedManifestXml.'@android:versionCode'.toInteger()
+}
+
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
@@ -31,6 +47,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 21
+ versionCode getMyVersionCode()
+ versionName "${getMyVersionName()}"
testApplicationId "de.test.antennapod"
testInstrumentationRunner "de.test.antennapod.AntennaPodTestRunner"
}
@@ -89,4 +107,21 @@ android {
lintOptions {
abortOnError false
}
-} \ No newline at end of file
+}
+
+// about.html is templatized so that we can automatically insert
+// our version string in to it at build time.
+task filterAbout {
+ inputs.files files(['src/main/templates/about.html',
+ 'src/main/AndroidManifest.xml'])
+ outputs.file 'src/main/assets/about.html'
+} << {
+ copy {
+ from 'src/main/templates/about.html'
+ into 'src/main/assets'
+ filter(ReplaceTokens, tokens: [versionname: android.defaultConfig.versionName,
+ versioncode: android.defaultConfig.versionCode.toString()])
+ }
+}
+
+preBuild.dependsOn filterAbout \ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7a4c8366e..97f8bbdad 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.danoeh.antennapod"
android:versionCode="51"
- android:versionName="1.1.1">
+ android:versionName="1.2">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
diff --git a/app/src/main/assets/.gitignore b/app/src/main/assets/.gitignore
new file mode 100644
index 000000000..328840cfc
--- /dev/null
+++ b/app/src/main/assets/.gitignore
@@ -0,0 +1,2 @@
+# this file is generated automatically
+about.html
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java
index 8d3e73429..8e347a819 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java
@@ -10,7 +10,9 @@ import org.apache.commons.lang3.Validate;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
+import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DownloadRequester;
+import de.danoeh.antennapod.core.util.LongList;
/**
* Utility methods for the action button that is displayed on the right hand side
@@ -26,9 +28,21 @@ public class ActionButtonUtils {
Validate.notNull(context);
this.context = context;
- drawables = context.obtainStyledAttributes(new int[]{
- R.attr.av_play, R.attr.navigation_cancel, R.attr.av_download, R.attr.av_pause, R.attr.navigation_accept});
- labels = new int[]{R.string.play_label, R.string.cancel_download_label, R.string.download_label, R.string.mark_read_label};
+ drawables = context.obtainStyledAttributes(new int[] {
+ R.attr.av_play,
+ R.attr.navigation_cancel,
+ R.attr.av_download,
+ R.attr.av_pause,
+ R.attr.navigation_accept,
+ R.attr.content_new
+ });
+ labels = new int[] {
+ R.string.play_label,
+ R.string.cancel_download_label,
+ R.string.download_label,
+ R.string.mark_read_label,
+ R.string.add_to_queue_label
+ };
}
/**
@@ -50,18 +64,26 @@ public class ActionButtonUtils {
butSecondary.setContentDescription(context.getString(labels[1]));
} else {
// item is not downloaded and not being downloaded
- butSecondary.setVisibility(View.VISIBLE);
- butSecondary.setImageDrawable(drawables.getDrawable(2));
- butSecondary.setContentDescription(context.getString(labels[2]));
+ LongList queueIds = DBReader.getQueueIDList(context);
+ if(DefaultActionButtonCallback.userAllowedMobileDownloads() ||
+ !DefaultActionButtonCallback.userChoseAddToQueue() || queueIds.contains(item.getId())) {
+ butSecondary.setVisibility(View.VISIBLE);
+ butSecondary.setImageDrawable(drawables.getDrawable(2));
+ butSecondary.setContentDescription(context.getString(labels[2]));
+ } else {
+ // mobile download not allowed yet, item is not in queue and user chose add to queue
+ butSecondary.setVisibility(View.VISIBLE);
+ butSecondary.setImageDrawable(drawables.getDrawable(5));
+ butSecondary.setContentDescription(context.getString(labels[4]));
+ }
}
} else {
- // item is not being downloaded
+ // item is downloaded
butSecondary.setVisibility(View.VISIBLE);
if (media.isCurrentlyPlaying()) {
butSecondary.setImageDrawable(drawables.getDrawable(3));
} else {
- butSecondary
- .setImageDrawable(drawables.getDrawable(0));
+ butSecondary.setImageDrawable(drawables.getDrawable(0));
}
butSecondary.setContentDescription(context.getString(labels[0]));
}
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java
index d3843934a..6df18e759 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java
@@ -1,6 +1,8 @@
package de.danoeh.antennapod.adapter;
+import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.widget.Toast;
@@ -10,41 +12,66 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
-import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction;
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
+import de.danoeh.antennapod.core.service.playback.PlaybackService;
+import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester;
+import de.danoeh.antennapod.core.util.LongList;
+import de.danoeh.antennapod.core.util.NetworkUtils;
/**
* Default implementation of an ActionButtonCallback
*/
public class DefaultActionButtonCallback implements ActionButtonCallback {
+
private static final String TAG = "DefaultActionButtonCallback";
private final Context context;
+ private static final int TEN_MINUTES_IN_MILLIS = 60 * 1000 * 10;
+
+ // remember timestamp when user allowed downloading via mobile connection
+ private static long allowMobileDownloadsTimestamp;
+ private static long onlyAddToQueueTimeStamp;
+
public DefaultActionButtonCallback(Context context) {
Validate.notNull(context);
this.context = context;
}
+ public static boolean userAllowedMobileDownloads() {
+ return System.currentTimeMillis() - allowMobileDownloadsTimestamp < TEN_MINUTES_IN_MILLIS;
+ }
+
+ public static boolean userChoseAddToQueue() {
+ return System.currentTimeMillis() - onlyAddToQueueTimeStamp < TEN_MINUTES_IN_MILLIS;
+ }
+
@Override
public void onActionButtonPressed(final FeedItem item) {
-
if (item.hasMedia()) {
final FeedMedia media = item.getMedia();
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
if (!isDownloading && !media.isDownloaded()) {
- try {
- DBTasks.downloadFeedItems(context, item);
- Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
+ LongList queueIds = DBReader.getQueueIDList(context);
+ if (NetworkUtils.isDownloadAllowed(context) || userAllowedMobileDownloads()) {
+ try {
+ DBTasks.downloadFeedItems(context, item);
+ Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
+ }
+ } else if(userChoseAddToQueue() && !queueIds.contains(item.getId())) {
+ DBWriter.addQueueItem(context, item.getId());
+ Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
+ } else {
+ confirmMobileDownload(context, item);
}
} else if (isDownloading) {
DownloadRequester.getInstance().cancelDownload(context, media);
@@ -79,4 +106,43 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
}
}
}
+
+ private void confirmMobileDownload(final Context context, final FeedItem item) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder
+ .setTitle(R.string.confirm_mobile_download_dialog_title)
+ .setMessage(context.getText(R.string.confirm_mobile_download_dialog_message))
+ .setPositiveButton(R.string.confirm_mobile_download_dialog_enable_temporarily,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ allowMobileDownloadsTimestamp = System.currentTimeMillis();
+ try {
+ DBTasks.downloadFeedItems(context, item);
+ Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
+ }
+ }
+ });
+ LongList queueIds = DBReader.getQueueIDList(context);
+ if(!queueIds.contains(item.getId())) {
+ builder.setNeutralButton(R.string.confirm_mobile_download_dialog_only_add_to_queue,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ onlyAddToQueueTimeStamp = System.currentTimeMillis();
+ DBWriter.addQueueItem(context, item.getId());
+ Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
+ }
+ })
+ .setMessage(context.getText(R.string.confirm_mobile_download_dialog_message_not_in_queue));
+ } else {
+ builder.setMessage(context.getText(R.string.confirm_mobile_download_dialog_message));
+ }
+ builder.setNegativeButton(R.string.cancel_label, null)
+ .create()
+ .show();
+ }
}
diff --git a/app/src/main/assets/about.html b/app/src/main/templates/about.html
index af7297564..3a48eeec1 100644
--- a/app/src/main/assets/about.html
+++ b/app/src/main/templates/about.html
@@ -41,9 +41,11 @@
<div id="header" align="center">
<img src="logo.png" alt="Logo" width="100px" height="100px"/>
- <p>AntennaPod, Version 1.1</p>
+ <p>AntennaPod, Version @versionname@, Build @versioncode@</p>
- <p>Copyright © 2014 Daniel Oeh</p>
+ <p>Created by Daniel Oeh</p>
+
+ <p>Copyright © 2015 AntennaPod Contributors <a href="https://github.com/AntennaPod/AntennaPod/blob/master/CONTRIBUTORS">(View)</a></p>
<p>Licensed under the MIT License <a href="LICENSE.html">(View)</a></p>
</div>