Skip to content

Commit

Permalink
Грузить иконки видео более высокого качества, чтобы выглядело норм на…
Browse files Browse the repository at this point in the history
… планшетах
  • Loading branch information
sadr0b0t committed Nov 22, 2020
1 parent 9d6bf97 commit 128f1fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import su.sadrobot.yashlang.R;
import su.sadrobot.yashlang.model.VideoItem;
import su.sadrobot.yashlang.util.PlaylistUrlUtil;

public class VideoThumbManager {
private static VideoThumbManager _instance;
Expand All @@ -47,8 +48,6 @@ public static VideoThumbManager getInstance() {
private VideoThumbManager() {
}

private Map<String, Bitmap> thumbCache = new HashMap<String, Bitmap>();

//private static final String THUMB_URL_TEMPLATE = "https://img.youtube.com/vi/%id%/sddefault.jpg";
private static final String THUMB_URL_TEMPLATE = "https://img.youtube.com/vi/%id%/default.jpg";

Expand All @@ -59,8 +58,6 @@ private VideoThumbManager() {
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg


private Bitmap defaultThumb = null;//BitmapFactory.decodeResource(R.drawable.bug1);

public Bitmap loadBitmap(final String url) throws IOException {

final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
Expand Down Expand Up @@ -128,14 +125,16 @@ public Bitmap loadVideoThumb(final String ytId) throws IOException {
* чтобы было понятно, что произошло.
*
* Загрузить картинку с превью видео или вернуть картинку по умолчанию.
* @param context
* @param vid
* @return
*/
public Bitmap loadVideoThumb(final Context context, final VideoItem vid) {
Bitmap thumb = null;
try {
//thumb = loadVideoThumb(vid.getYtId());
thumb = loadBitmap(vid.getThumbUrl());
// Будем грузить для роликов YouTube иконку большего размера (так будет лучше на планшетах),
// для PeerTube ссылка останется без изменений
thumb = loadBitmap(PlaylistUrlUtil.fixYtVideoThumbSize(vid.getThumbUrl()));
} catch (IOException e) {
//thumb = defaultThumb; // default thumb
//e.printStackTrace();
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/su/sadrobot/yashlang/util/PlaylistUrlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,14 @@ public static String fixYtChannelAvatarSize(final String iconUrl) {
// У нас иконки примерно 100x100 везде, но будем брать с запасом 240x240, чтобы хайрез
return iconUrl.replace("=s48-", "=s240-");
}

public static String fixYtVideoThumbSize(final String thumbUrl) {
// NewPipeExtractor возвращает иконку для видео такую:
// https://i.ytimg.com/vi/pevcwilRM8o/hqdefault.jpg?sqp=-oaymwEYCKgBEF5IVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLB8Bx4_LmDq7dowwMZPclW_qixhbQ
// на сайте ютюб эту же иконку даёт в таком варианте:
// https://i.ytimg.com/vi/pevcwilRM8o/mqdefault.jpg?sqp=-oaymwEYCKgBEF5IVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLB8Bx4_LmDq7dowwMZPclW_qixhbQ
// отличие только "hquedefault" и "mquedefault"
// второй вариант лучше 1-го, на телефоне маленький вариант еще ок, но на планшете уже не ок
return thumbUrl.replace("hquedefault", "mquedefault");
}
}
6 changes: 3 additions & 3 deletions app/src/main/res/layout-xlarge/video_list_item_hor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<ImageView
android:id="@+id/video_thumb_img"
android:layout_width="392dp"
android:layout_height="220dp"
android:layout_width="320dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_yashlang_thumb" />
Expand All @@ -32,7 +32,7 @@

<TextView
android:id="@+id/video_name_txt"
android:layout_width="392dp"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:maxLines="2"
Expand Down

0 comments on commit 128f1fb

Please # to comment.