2018-12-29 14:19:17 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
|
|
|
|
*
|
|
|
|
* License: GPL-3.0+
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-12-15 14:24:11 +01:00
|
|
|
package net.schueller.peertube.intents;
|
|
|
|
|
2019-01-05 23:05:01 +01:00
|
|
|
import android.Manifest;
|
|
|
|
import android.app.DownloadManager;
|
2018-12-15 14:24:11 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2019-01-05 23:05:01 +01:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Environment;
|
2020-06-01 20:15:50 +02:00
|
|
|
import android.webkit.MimeTypeMap;
|
2019-01-05 23:05:01 +01:00
|
|
|
import android.webkit.URLUtil;
|
|
|
|
|
2020-06-01 20:15:50 +02:00
|
|
|
|
2019-01-05 23:05:01 +01:00
|
|
|
import com.github.se_bastiaan.torrentstream.TorrentOptions;
|
|
|
|
|
2020-06-01 20:15:50 +02:00
|
|
|
import net.schueller.peertube.R;
|
2018-12-15 14:24:11 +01:00
|
|
|
import net.schueller.peertube.helper.APIUrlHelper;
|
|
|
|
import net.schueller.peertube.model.Video;
|
|
|
|
|
2019-01-05 23:05:01 +01:00
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
2018-12-15 14:24:11 +01:00
|
|
|
|
|
|
|
public class Intents {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://troll.tv/videos/watch/6edbd9d1-e3c5-4a6c-8491-646e2020469c
|
|
|
|
*
|
|
|
|
* @param context context
|
|
|
|
* @param video video
|
|
|
|
*/
|
2019-01-05 23:05:01 +01:00
|
|
|
// TODO, offer which version to download
|
2018-12-15 14:24:11 +01:00
|
|
|
public static void Share(Context context, Video video) {
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_SEND);
|
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, video.getName());
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, APIUrlHelper.getShareUrl(context, video.getUuid()) );
|
|
|
|
intent.setType("text/plain");
|
|
|
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
|
|
|
}
|
2019-01-05 23:05:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param context context
|
|
|
|
* @param video video
|
|
|
|
*/
|
|
|
|
// TODO, offer which version to download
|
|
|
|
public static void Download(Context context, Video video) {
|
|
|
|
|
|
|
|
String url = video.getFiles().get(0).getFileDownloadUrl();
|
2020-06-27 21:59:06 +02:00
|
|
|
// make sure it is a valid filename
|
|
|
|
String destFilename = video.getName().replaceAll("[^a-zA-Z0-9]", "_") + "." + MimeTypeMap.getFileExtensionFromUrl(URLUtil.guessFileName(url,null,null));
|
|
|
|
|
2020-06-01 20:15:50 +02:00
|
|
|
//Toast.makeText(context, destFilename, Toast.LENGTH_LONG).show();
|
2019-01-05 23:05:01 +01:00
|
|
|
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
|
|
|
request.setDescription(video.getDescription());
|
|
|
|
request.setTitle(video.getName());
|
|
|
|
request.allowScanningByMediaScanner();
|
|
|
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
2020-06-01 20:15:50 +02:00
|
|
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, destFilename);
|
2019-01-05 23:05:01 +01:00
|
|
|
|
|
|
|
// get download service and enqueue file
|
|
|
|
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
|
manager.enqueue(request);
|
|
|
|
}
|
2018-12-15 14:24:11 +01:00
|
|
|
}
|