diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java
index 1e51b6a34..98839c5a5 100644
--- a/app/src/main/java/org/schabi/newpipe/App.java
+++ b/app/src/main/java/org/schabi/newpipe/App.java
@@ -57,7 +57,7 @@ public class App extends Application {
/**
* Set the proxy settings based on whether Tor should be enabled or not.
*/
- static void configureTor(boolean enabled) {
+ public static void configureTor(boolean enabled) {
useTor = enabled;
if (useTor) {
NetCipher.useTor();
@@ -66,13 +66,13 @@ public class App extends Application {
}
}
- static void checkStartTor(Context context) {
+ public static void checkStartTor(Context context) {
if (useTor) {
OrbotHelper.requestStartTor(context);
}
}
- static boolean isUsingTor() {
+ public static boolean isUsingTor() {
return useTor;
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/NewPipeSettings.java b/app/src/main/java/org/schabi/newpipe/NewPipeSettings.java
index 1dea05f36..39a2f5a7f 100644
--- a/app/src/main/java/org/schabi/newpipe/NewPipeSettings.java
+++ b/app/src/main/java/org/schabi/newpipe/NewPipeSettings.java
@@ -25,7 +25,6 @@ import android.content.SharedPreferences;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
-import android.util.Log;
import java.io.File;
@@ -43,10 +42,6 @@ public class NewPipeSettings {
getAudioDownloadFolder(context);
}
- public static File getDownloadFolder() {
- return getFolder(Environment.DIRECTORY_DOWNLOADS);
- }
-
public static File getVideoDownloadFolder(Context context) {
return getFolder(context, R.string.download_path_key, Environment.DIRECTORY_MOVIES);
}
diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java
index 81b51da75..65d04bc8c 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java
@@ -48,6 +48,7 @@ import java.util.ArrayList;
import java.util.Vector;
+import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.extractor.AudioStream;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.ParsingException;
diff --git a/app/src/main/java/org/schabi/newpipe/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
similarity index 91%
rename from app/src/main/java/org/schabi/newpipe/DownloadDialog.java
rename to app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
index b528dfef3..8791f5a3d 100644
--- a/app/src/main/java/org/schabi/newpipe/DownloadDialog.java
+++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
@@ -1,4 +1,4 @@
-package org.schabi.newpipe;
+package org.schabi.newpipe.download;
import android.Manifest;
import android.app.Dialog;
@@ -16,6 +16,10 @@ import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
+import org.schabi.newpipe.App;
+import org.schabi.newpipe.NewPipeSettings;
+import org.schabi.newpipe.R;
+
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -71,7 +75,8 @@ public class DownloadDialog extends DialogFragment {
case 0: // Video
download(arguments.getString(VIDEO_URL),
title,
- arguments.getString(FILE_SUFFIX_VIDEO), context);
+ arguments.getString(FILE_SUFFIX_VIDEO),
+ NewPipeSettings.getVideoDownloadFolder(context),context);
break;
default:
Log.d(TAG, "lolz");
@@ -89,7 +94,8 @@ public class DownloadDialog extends DialogFragment {
case 0: // Audio
download(arguments.getString(AUDIO_URL),
title,
- arguments.getString(FILE_SUFFIX_AUDIO), context);
+ arguments.getString(FILE_SUFFIX_AUDIO),
+ NewPipeSettings.getAudioDownloadFolder(context),context);
break;
default:
Log.d(TAG, "lolz");
@@ -107,12 +113,14 @@ public class DownloadDialog extends DialogFragment {
case 0: // Video
download(arguments.getString(VIDEO_URL),
title,
- arguments.getString(FILE_SUFFIX_VIDEO), context);
+ arguments.getString(FILE_SUFFIX_VIDEO),
+ NewPipeSettings.getVideoDownloadFolder(context), context);
break;
case 1:
download(arguments.getString(AUDIO_URL),
title,
- arguments.getString(FILE_SUFFIX_AUDIO), context);
+ arguments.getString(FILE_SUFFIX_AUDIO),
+ NewPipeSettings.getAudioDownloadFolder(context), context);
break;
default:
Log.d(TAG, "lolz");
@@ -141,8 +149,8 @@ public class DownloadDialog extends DialogFragment {
return nameToTest;
}
- private void download(String url, String title, String fileSuffix, Context context) {
- File downloadDir = NewPipeSettings.getDownloadFolder();
+ private void download(String url, String title,
+ String fileSuffix, File downloadDir, Context context) {
if(!downloadDir.exists()) {
//attempt to create directory
@@ -162,6 +170,8 @@ public class DownloadDialog extends DialogFragment {
File saveFilePath = new File(downloadDir,createFileName(title) + fileSuffix);
long id = 0;
+
+
if (App.isUsingTor()) {
// if using Tor, do not use DownloadManager because the proxy cannot be set
FileDownloader.downloadFile(getContext(), url, saveFilePath, title);
diff --git a/app/src/main/java/org/schabi/newpipe/FileDownloader.java b/app/src/main/java/org/schabi/newpipe/download/FileDownloader.java
similarity index 95%
rename from app/src/main/java/org/schabi/newpipe/FileDownloader.java
rename to app/src/main/java/org/schabi/newpipe/download/FileDownloader.java
index 31ce9ecc8..1da8d0182 100644
--- a/app/src/main/java/org/schabi/newpipe/FileDownloader.java
+++ b/app/src/main/java/org/schabi/newpipe/download/FileDownloader.java
@@ -1,26 +1,21 @@
-package org.schabi.newpipe;
-
+package org.schabi.newpipe.download;
import android.app.NotificationManager;
import android.content.Context;
-import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
-import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
+import org.schabi.newpipe.R;
+
import java.io.BufferedInputStream;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.UnknownHostException;
import javax.net.ssl.HttpsURLConnection;
@@ -46,6 +41,8 @@ import info.guardianproject.netcipher.NetCipher;
* along with NewPipe. If not, see .
*/
+
+// TODO: FOR HEVEN SAKE !!! DO NOT SIMPLY USE ASYNCTASK. MAKE THIS A PROPER SERVICE !!!
public class FileDownloader extends AsyncTask {
public static final String TAG = "FileDownloader";
@@ -165,5 +162,4 @@ public class FileDownloader extends AsyncTask {
super.onPostExecute(aVoid);
nm.cancel(notifyId);
}
-
}