Browse Source

Copy YouTube videos links onLongClick

pull/70/head
Ezerous 4 years ago
parent
commit
eba2c6f067
  1. 20
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java
  2. 19
      app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java

20
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

@ -128,6 +128,8 @@ public class ParseHelpers {
}
}
public static final String VIDEO_ID_PARAMETER = "videoId";
/**
* This method fixes html so that embedded videos will render properly and be lightweight.
*
@ -146,24 +148,28 @@ public class ParseHelpers {
}
String fixed = html.outerHtml();
int tmp_counter = 0;
int counter = 0;
while (fixed.contains("<embed")) {
if (tmp_counter > embededVideosUrls.size())
if (counter > embededVideosUrls.size())
break;
final String videoId = embededVideosUrls.get(counter);
fixed = fixed.replace(
fixed.substring(fixed.indexOf("<embed"), fixed.indexOf("/noembed>") + 9)
, "<div class=\"yt\">"
+ "<a href=\"https://www.youtube.com/watch?v="
+ embededVideosUrls.get(tmp_counter)
+ videoId
+ "\" target=\"_blank\">"
+ "<img class=\"embedded-video-play\" "
+ "src=\"YouTube_light_color_icon.png\" "
+ "style=\"background-image: url('"
+ "src=\"YouTube_light_color_icon.png?"
+ VIDEO_ID_PARAMETER
+ "="
+ videoId // To grab it in ReactiveWebView
+ "\" style=\"background-image: url('"
+ "https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter)
+ videoId
+ "/default.jpg');\"></a></div>"
);
++tmp_counter;
++counter;
}
return fixed;
}

19
app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java

@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.views;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebView;
@ -13,6 +14,7 @@ import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.utils.ui.ImageDownloadDialogBuilder;
import static android.content.Context.CLIPBOARD_SERVICE;
import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.VIDEO_ID_PARAMETER;
import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage;
public class ReactiveWebView extends WebView {
@ -77,8 +79,16 @@ public class ReactiveWebView extends WebView {
copyUrlToClipboard(result.getExtra());
else if(result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
String imageURL = result.getExtra();
ImageDownloadDialogBuilder builder = new ImageDownloadDialogBuilder(context,imageURL);
builder.show();
showImageDownloadDialog(imageURL);
}
else if(result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
final String imageURL = result.getExtra();
Uri uri = Uri.parse(imageURL);
String videoId = uri.getQueryParameter(VIDEO_ID_PARAMETER);
if (videoId!=null)
copyUrlToClipboard("https://www.youtube.com/watch?v=" + videoId);
else
showImageDownloadDialog(imageURL);
}
return false;
});
@ -90,4 +100,9 @@ public class ReactiveWebView extends WebView {
clipboard.setPrimaryClip(clip);
Toast.makeText(BaseApplication.getInstance().getApplicationContext(),context.getString(R.string.link_copied_msg),Toast.LENGTH_SHORT).show();
}
private void showImageDownloadDialog(String imageURL){
ImageDownloadDialogBuilder builder = new ImageDownloadDialogBuilder(context, imageURL);
builder.show();
}
}

Loading…
Cancel
Save