Manage peertube videos comments
This commit is contained in:
parent
06a3238927
commit
3324fd7c32
|
@ -16,10 +16,12 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
|
@ -34,6 +36,11 @@ import android.webkit.WebView;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.webview.MastalabWebChromeClient;
|
||||
import fr.gouv.etalab.mastodon.webview.MastalabWebViewClient;
|
||||
|
@ -51,9 +58,10 @@ import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads;
|
|||
public class WebviewActivity extends BaseActivity {
|
||||
|
||||
private String url;
|
||||
private String peertubeLinkToFetch;
|
||||
private boolean peertubeLink;
|
||||
private WebView webView;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -75,8 +83,11 @@ public class WebviewActivity extends BaseActivity {
|
|||
|
||||
setContentView(R.layout.activity_webview);
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null)
|
||||
if(b != null) {
|
||||
url = b.getString("url", null);
|
||||
peertubeLinkToFetch = b.getString("peertubeLinkToFetch", null);
|
||||
peertubeLink = b.getBoolean("peertubeLink", false);
|
||||
}
|
||||
if( url == null)
|
||||
finish();
|
||||
if( getSupportActionBar() != null)
|
||||
|
@ -135,6 +146,10 @@ public class WebviewActivity extends BaseActivity {
|
|||
@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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
|
@ -151,6 +166,43 @@ public class WebviewActivity extends BaseActivity {
|
|||
Toast.makeText(WebviewActivity.this, R.string.toast_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
case R.id.action_comment:
|
||||
Toast.makeText(WebviewActivity.this, R.string.retrieve_remote_status, Toast.LENGTH_LONG).show();
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Status> remoteStatuses;
|
||||
private WeakReference<Context> contextReference = new WeakReference<>(WebviewActivity.this);
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
|
||||
if(url != null) {
|
||||
Results search = new API(contextReference.get()).search(peertubeLinkToFetch);
|
||||
if (search != null) {
|
||||
remoteStatuses = search.getStatuses();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
Intent intent = new Intent(contextReference.get(), TootActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
if( remoteStatuses == null || remoteStatuses.size() == 0){
|
||||
Toast.makeText(contextReference.get(), R.string.toast_error, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if( remoteStatuses.get(0).getReblog() != null ) {
|
||||
b.putParcelable("tootReply", remoteStatuses.get(0).getReblog());
|
||||
}else {
|
||||
b.putParcelable("tootReply", remoteStatuses.get(0));
|
||||
}
|
||||
intent.putExtras(b); //Put your id to your next Intent
|
||||
contextReference.get().startActivity(intent);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR );
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ 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.ShowAccountActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
|
@ -831,7 +832,7 @@ public class Status implements Parcelable{
|
|||
for (URLSpan span : spans) {
|
||||
spannableStringT.removeSpan(span);
|
||||
}
|
||||
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
|
||||
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition) {
|
||||
spannableStringT.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View textView) {
|
||||
|
@ -844,9 +845,23 @@ public class Status implements Parcelable{
|
|||
intent.putExtra(SEARCH_URL, url);
|
||||
context.startActivity(intent);
|
||||
}else {
|
||||
if( !url.startsWith("http://") && ! url.startsWith("https://"))
|
||||
finalUrl = "http://" + url;
|
||||
Helper.openBrowser(context, finalUrl);
|
||||
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);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("url", peertubeUrl);
|
||||
b.putString("peertubeLinkToFetch", url);
|
||||
b.putBoolean("peertubeLink", true);
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}else {
|
||||
if( !url.startsWith("http://") && ! url.startsWith("https://"))
|
||||
finalUrl = "http://" + url;
|
||||
Helper.openBrowser(context, finalUrl);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
@ -857,6 +872,7 @@ public class Status implements Parcelable{
|
|||
},
|
||||
startPosition, endPosition,
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
if(endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
|
||||
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, (theme==Helper.THEME_DARK||theme==Helper.THEME_BLACK)?R.color.mastodonC2:R.color.mastodonC4)), startPosition, endPosition,
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
|
|
@ -33,6 +33,8 @@ import android.widget.TextView;
|
|||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.ListActivity;
|
||||
|
@ -125,6 +127,13 @@ public class HowToVideosAdapter extends BaseAdapter implements OnListActionInter
|
|||
Bundle b = new Bundle();
|
||||
String finalUrl = "https://peertube.fr" + howToVideo.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);
|
||||
b.putString("peertubeLinkToFetch", url);
|
||||
}
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 213 B |
Binary file not shown.
After Width: | Height: | Size: 275 B |
Binary file not shown.
After Width: | Height: | Size: 165 B |
Binary file not shown.
After Width: | Height: | Size: 189 B |
Binary file not shown.
After Width: | Height: | Size: 270 B |
Binary file not shown.
After Width: | Height: | Size: 296 B |
|
@ -6,4 +6,10 @@
|
|||
android:title="@string/open_with"
|
||||
android:icon="@drawable/ic_open_with"
|
||||
app:showAsAction="always" />
|
||||
<item
|
||||
android:id="@+id/action_comment"
|
||||
android:title="@string/comment"
|
||||
android:icon="@drawable/ic_comment_peertube"
|
||||
android:visible="false"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
||||
|
|
|
@ -632,6 +632,7 @@
|
|||
<string name="toast_block_domain">The domain is blocked</string>
|
||||
<string name="toast_unblock_domain">The domain is no longer blocked!</string>
|
||||
<string name="retrieve_remote_status">Fetching remote status</string>
|
||||
<string name="comment">Comment</string>
|
||||
|
||||
<string-array name="filter_expire">
|
||||
<item>Never</item>
|
||||
|
|
Loading…
Reference in New Issue