diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java index 1a09b023c..491df2779 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java @@ -22,7 +22,6 @@ import android.media.MediaPlayer; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -43,7 +42,6 @@ import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleAsyncTask; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; -import fr.gouv.etalab.mastodon.client.Entities.Peertube; import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.client.TLSSocketFactory; import fr.gouv.etalab.mastodon.helper.FullScreenMediaController; @@ -58,9 +56,8 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface; public class PeertubeActivity extends BaseActivity implements OnRetrievePeertubeInterface { - private String url, stream_url, peertubeInstance, videoId; + private String peertubeInstance, videoId; private String peertubeLinkToFetch; - private boolean peertubeLink; private FullScreenMediaController.fullscreen fullscreen; private VideoView videoView; private RelativeLayout loader; @@ -92,29 +89,17 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube if(b != null) { peertubeInstance = b.getString("peertube_instance", null); videoId = b.getString("video_id", null); - stream_url = b.getString("stream_url", null); peertubeLinkToFetch = b.getString("peertubeLinkToFetch", null); - peertubeLink = b.getBoolean("peertubeLink", true); - url = b.getString("url", null); } - if( url == null) + if( peertubeLinkToFetch == null) finish(); if( getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); videoView = findViewById(R.id.media_video); new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - /*if(fullscreen == FullScreenMediaController.fullscreen.ON){ - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - getSupportActionBar().hide(); - }else{ - getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, - WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); - getSupportActionBar().show(); - }*/ } public void change(){ @@ -132,10 +117,8 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_webview, menu); - if( peertubeLink ){ - menu.findItem(R.id.action_go).setVisible(false); - menu.findItem(R.id.action_comment).setVisible(true); - } + menu.findItem(R.id.action_go).setVisible(false); + menu.findItem(R.id.action_comment).setVisible(true); return true; } @Override @@ -144,14 +127,6 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube case android.R.id.home: finish(); return true; - case R.id.action_go: - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - try { - startActivity(browserIntent); - }catch (Exception e){ - Toast.makeText(PeertubeActivity.this, R.string.toast_error, Toast.LENGTH_LONG).show(); - } - return true; case R.id.action_comment: Toast.makeText(PeertubeActivity.this, R.string.retrieve_remote_status, Toast.LENGTH_LONG).show(); new AsyncTask() { @@ -162,7 +137,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube @Override protected Void doInBackground(Void... voids) { - if(url != null) { + if(peertubeLinkToFetch != null) { Results search = new API(contextReference.get()).search(peertubeLinkToFetch); if (search != null) { remoteStatuses = search.getStatuses(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index 448216669..cb7893386 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -58,6 +58,7 @@ import java.util.regex.Pattern; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.HashTagActivity; import fr.gouv.etalab.mastodon.activities.MainActivity; +import fr.gouv.etalab.mastodon.activities.PeertubeActivity; import fr.gouv.etalab.mastodon.activities.ShowAccountActivity; import fr.gouv.etalab.mastodon.activities.WebviewActivity; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; @@ -841,12 +842,12 @@ public class Status implements Parcelable{ link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/watch\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$"); matcherLink = link.matcher(url); if( matcherLink.find()){ //Peertubee video - String peertubeUrl = matcherLink.group(1) + "/videos/embed/" + matcherLink.group(2); - Intent intent = new Intent(context, WebviewActivity.class); + Intent intent = new Intent(context, PeertubeActivity.class); Bundle b = new Bundle(); - b.putString("url", peertubeUrl); + String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2); b.putString("peertubeLinkToFetch", url); - b.putBoolean("peertubeLink", true); + b.putString("peertube_instance", matcherLink.group(1).replace("https://","").replace("http://","")); + b.putString("video_id", matcherLink.group(2)); intent.putExtras(b); context.startActivity(intent); }else { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java index a7889191f..93eb6d16c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/PeertubeAdapter.java @@ -111,15 +111,11 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio Intent intent = new Intent(context, PeertubeActivity.class); Bundle b = new Bundle(); String finalUrl = "https://" + instance + peertube.getEmbedPath(); - b.putString("url", finalUrl); - b.putBoolean("peertubeLink", true); Pattern link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/embed\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$"); Matcher matcherLink = link.matcher(finalUrl); if( matcherLink.find()) { String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2); - String stream_url = peertube.getStreamURL(); b.putString("peertubeLinkToFetch", url); - b.putString("stream_url", stream_url); b.putString("peertube_instance", matcherLink.group(1).replace("https://","").replace("http://","")); b.putString("video_id", matcherLink.group(2)); }