Fixes issue #91 - Can't save video
This commit is contained in:
parent
5cd0068411
commit
33f55accd9
|
@ -379,10 +379,21 @@ public class MediaActivity extends AppCompatActivity implements OnDownloadInterf
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDownloaded(String path, Error error) {
|
||||
public void onDownloaded(String path, String originUrl, Error error) {
|
||||
|
||||
File response = new File(path);
|
||||
File dir = getCacheDir();
|
||||
File from = new File(dir, response.getName());
|
||||
File to = new File(dir, Helper.md5(originUrl) + ".mp4");
|
||||
if (from.exists())
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
from.renameTo(to);
|
||||
fileVideo = to;
|
||||
downloadedImage = null;
|
||||
progress.setVisibility(View.GONE);
|
||||
Uri uri = Uri.parse(to.getAbsolutePath());
|
||||
videoView.setVisibility(View.VISIBLE);
|
||||
videoView.setVideoURI(Uri.parse(path));
|
||||
videoView.setVideoURI(uri);
|
||||
videoView.start();
|
||||
MediaController mc = new MediaController(MediaActivity.this);
|
||||
videoView.setMediaController(mc);
|
||||
|
|
|
@ -1260,7 +1260,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDownloaded(String pathToFile, Error error) {
|
||||
public void onDownloaded(String pathToFile, String url, Error error) {
|
||||
picture_scrollview.setVisibility(View.VISIBLE);
|
||||
Bitmap pictureMention = BitmapFactory.decodeFile(pathToFile);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
|
|
@ -228,12 +228,12 @@ public class HttpsConnection {
|
|||
if(context instanceof TootActivity)
|
||||
((TootActivity)context).runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
listener.onDownloaded(saveFilePath, null);
|
||||
listener.onDownloaded(saveFilePath, downloadUrl, null);
|
||||
}});
|
||||
if(context instanceof MediaActivity)
|
||||
((MediaActivity)context).runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
listener.onDownloaded(saveFilePath, null);
|
||||
listener.onDownloaded(saveFilePath, downloadUrl,null);
|
||||
}});
|
||||
} else {
|
||||
final Error error = new Error();
|
||||
|
@ -241,12 +241,12 @@ public class HttpsConnection {
|
|||
if(context instanceof TootActivity)
|
||||
((TootActivity)context).runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
listener.onDownloaded(null, error);
|
||||
listener.onDownloaded(null, downloadUrl, error);
|
||||
}});
|
||||
if(context instanceof MediaActivity)
|
||||
((MediaActivity)context).runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
listener.onDownloaded(null, error);
|
||||
listener.onDownloaded(null,downloadUrl, error);
|
||||
}});
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
|
@ -61,12 +62,10 @@ import android.support.v4.app.NotificationCompat;
|
|||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Patterns;
|
||||
import android.view.Menu;
|
||||
|
@ -789,10 +788,24 @@ public class Helper {
|
|||
Uri uri = Uri.parse("file://" + file.getAbsolutePath());
|
||||
intent.setDataAndType(uri, getMimeType(url));
|
||||
|
||||
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(preview_url)
|
||||
.listener(new RequestListener<Bitmap>(){
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
|
||||
notify_user(context, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(),
|
||||
R.mipmap.ic_launcher), context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
|
||||
Toast.makeText(context, R.string.toast_saved,Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
|
|
|
@ -21,6 +21,6 @@ import fr.gouv.etalab.mastodon.client.Entities.Error;
|
|||
* Interface when a media has been downloaded
|
||||
*/
|
||||
public interface OnDownloadInterface {
|
||||
void onDownloaded(String saveFilePath, Error error);
|
||||
void onDownloaded(String saveFilePath, String downloadUrl, Error error);
|
||||
void onUpdateProgress(int progress);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue