1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2025-12-15 00:31:11 +01:00

Improve sharing *a lot* +GIF - add support for multiple filetypes

* now supporting GIFs too ;)
* Create connection over netcipher
This commit is contained in:
Gregor Santner 2018-04-08 19:11:12 +02:00
parent 68be2f3a4a
commit 38cf36b46c
8 changed files with 112 additions and 209 deletions

View file

@ -9,7 +9,7 @@
*
#########################################################*/
/*
/*
* Parses most common markdown tags. Only inline tags are supported, multiline/block syntax
* is not supported (citation, multiline code, ..). This is intended to stay as easy as possible.
*

View file

@ -48,8 +48,8 @@ package net.gsantner.opoc.preference.nonsupport;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.preference.ListPreference;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;

View file

@ -0,0 +1,57 @@
/*
This file is part of the dandelion*.
dandelion* is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dandelion* is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the dandelion*.
If not, see <http://www.gnu.org/licenses/>.
*/
package net.gsantner.opoc.util;
import android.os.AsyncTask;
import android.support.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import javax.net.ssl.HttpsURLConnection;
import info.guardianproject.netcipher.NetCipher;
public class DownloadTask extends AsyncTask<String, Void, Boolean> {
private File _targetFile;
private Callback.a2<Boolean, File> _callback;
public DownloadTask(File targetFile, @Nullable Callback.a2<Boolean, File> callback) {
_targetFile = targetFile;
_callback = callback;
}
protected Boolean doInBackground(String... urls) {
if (urls != null && urls.length > 0 && urls[0] != null) {
try {
HttpsURLConnection connection = NetCipher.getHttpsURLConnection(urls[0]);
return NetworkUtils.downloadFile(null, _targetFile, connection, null);
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
protected void onPostExecute(Boolean result) {
if (_callback != null) {
_callback.callback(result, _targetFile);
}
}
}

View file

@ -53,11 +53,16 @@ public class NetworkUtils {
}
public static boolean downloadFile(final URL url, final File outFile, final Callback.a1<Float> progressCallback) {
return downloadFile(url, outFile, null, progressCallback);
}
public static boolean downloadFile(final URL url, final File outFile, HttpURLConnection connection, final Callback.a1<Float> progressCallback) {
InputStream input = null;
OutputStream output = null;
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
if (connection == null) {
connection = (HttpURLConnection) url.openConnection();
}
connection.connect();
input = connection.getInputStream();