diff --git a/app/build.gradle b/app/build.gradle index 7f6a0836c..26c8ae5d6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,7 +56,7 @@ ext.photoViewLibraryVersion = '2.0.0' ext.swipebackLibraryVersion = '1.0.2' ext.ratethisappLibraryVersion = '1.2.0' ext.uploadServiceVersion = "3.4.2" - +ext.torrentstreamVersion = "2.6.1" dependencies { implementation "com.android.support:appcompat-v7:$supportLibraryVersion" @@ -84,5 +84,7 @@ dependencies { implementation 'com.github.GrenderG:Toasty:1.3.1' implementation 'com.elconfidencial.bubbleshowcase:bubbleshowcase:1.3.1' implementation 'com.android.support:multidex:1.0.3' + implementation 'com.google.android.exoplayer:exoplayer:2.9.3' + implementation "com.github.TorrentStream:TorrentStream-Android:$torrentstreamVersion" playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 144a65db5..deac3ea75 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -234,6 +234,11 @@ android:theme="@style/Base.V7.Theme.AppCompat.Dialog" android:excludeFromRecents="true" /> + + = 23 ){ if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE); } else { manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null)); } @@ -506,8 +570,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube stopPosition = videoView.getCurrentPosition(); //stopPosition is an int videoView.pause(); } + nPanel = new NotificationPanel(PeertubeActivity.this); } + @Override public void onResume(){ super.onResume(); @@ -516,6 +582,8 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube videoView.resume(); videoView.start(); } + if( nPanel != null) + nPanel.notificationCancel(); } public void displayResolution(){ @@ -545,12 +613,41 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube public void onClick(DialogInterface dialog, int which) { String res = arrayAdapter.getItem(which).substring(0, arrayAdapter.getItem(which).length() - 1); if( mediaPlayer != null) { + loader.setVisibility(View.VISIBLE); int position = videoView.getCurrentPosition(); - mediaPlayer.stop(); - videoView.setVideoURI(Uri.parse(peertube.getFileUrl(res))); - fullScreenMediaController.setResolutionVal(res); - videoView.seekTo(position); - videoView.start(); + torrentStream.stopStream(); + torrentStream.removeListener(torrentListener); + torrentStream.startStream(peertube.getTorrentUrl(res)); + torrentListener = new TorrentListener() { + @Override + public void onStreamPrepared(Torrent torrent) { + loader.setVisibility(View.VISIBLE); + } + @Override + public void onStreamStarted(Torrent torrent) { + } + @Override + public void onStreamError(Torrent torrent, Exception e) { + } + @Override + public void onStreamReady(Torrent torrent) { + videoView.setVisibility(View.GONE); + videoView.setVisibility(View.VISIBLE); + loader.setVisibility(View.GONE); + videoView.setVideoURI( Uri.fromFile(torrent.getVideoFile())); + fullScreenMediaController.setResolutionVal(res); + videoView.seekTo(position); + videoView.start(); + } + @Override + public void onStreamProgress(Torrent torrent, StreamStatus status) { + } + @Override + public void onStreamStopped() { + loader.setVisibility(View.GONE); + } + }; + torrentStream.addListener(torrentListener); } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java index 81fb9fe48..643c0e06d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java @@ -176,6 +176,15 @@ public class Peertube { } + public String getTorrentUrl(String resolution) { + if( resolution == null) + resolution = this.getResolution().get(0); + if(resolution == null) + return null; + return "https://" + this.host + "/static/torrents/" + getUuid()+ "-" + resolution + ".torrent"; + + } + public String getTorrentDownloadUrl(String resolution) { if( resolution == null) resolution = this.getResolution().get(0); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/NotificationPanel.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/NotificationPanel.java new file mode 100644 index 000000000..771138083 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/NotificationPanel.java @@ -0,0 +1,55 @@ +package fr.gouv.etalab.mastodon.helper; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.NotificationCompat; +import android.widget.RemoteViews; + +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.activities.NotificationReturnSlot; + +public class NotificationPanel { + + private Context parent; + private NotificationManager nManager; + private NotificationCompat.Builder nBuilder; + private RemoteViews remoteView; + + public NotificationPanel(Context parent) { + // TODO Auto-generated constructor stub + this.parent = parent; + nBuilder = new NotificationCompat.Builder(parent) + .setContentTitle("Parking Meter") + .setSmallIcon(R.drawable.ic_launcher_background) + .setOngoing(true); + + remoteView = new RemoteViews(parent.getPackageName(), R.layout.notificationview); + + //set the button listeners + setListeners(remoteView); + nBuilder.setContent(remoteView); + + nManager = (NotificationManager) parent.getSystemService(Context.NOTIFICATION_SERVICE); + nManager.notify(2, nBuilder.build()); + } + + public void setListeners(RemoteViews view){ + //listener 1 + Intent volume = new Intent(parent,NotificationReturnSlot.class); + volume.putExtra("DO", "volume"); + PendingIntent btn1 = PendingIntent.getActivity(parent, 0, volume, 0); + view.setOnClickPendingIntent(R.id.btn1, btn1); + + //listener 2 + Intent stop = new Intent(parent, NotificationReturnSlot.class); + stop.putExtra("DO", "stop"); + PendingIntent btn2 = PendingIntent.getActivity(parent, 1, stop, 0); + view.setOnClickPendingIntent(R.id.btn2, btn2); + } + + public void notificationCancel() { + nManager.cancel(2); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/notificationview.xml b/app/src/main/res/layout/notificationview.xml new file mode 100644 index 000000000..597003193 --- /dev/null +++ b/app/src/main/res/layout/notificationview.xml @@ -0,0 +1,26 @@ + + + +