Skip to content

Commit

Permalink
Органичить количество фоновых потоков при загрузке иконок для роликов
Browse files Browse the repository at this point in the history
  • Loading branch information
sadr0b0t committed Oct 3, 2020
1 parent f026fa3 commit 6d67146
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import su.sadrobot.yashlang.R;
import su.sadrobot.yashlang.controller.VideoThumbManager;
Expand All @@ -52,6 +54,9 @@ public class VideoItemArrayAdapter extends RecyclerView.Adapter<VideoItemArrayAd
private OnListItemSwitchListener<VideoItem> onItemSwitchListener;
private int orientation = ORIENTATION_VERTICAL;


private ExecutorService thumbLoaderExecutor = Executors.newFixedThreadPool(10);

public static class VideoItemViewHolder extends RecyclerView.ViewHolder {
TextView nameTxt;
TextView durationTxt;
Expand Down Expand Up @@ -142,7 +147,7 @@ public void onBindViewHolder(@NonNull final VideoItemViewHolder holder, final in
if (item.getThumbBitmap() != null) {
holder.thumbImg.setImageBitmap(item.getThumbBitmap());
} else {
new Thread(new Runnable() {
thumbLoaderExecutor.execute(new Runnable() {
@Override
public void run() {
final Bitmap thumb =
Expand All @@ -155,7 +160,7 @@ public void run() {
}
});
}
}).start();
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import su.sadrobot.yashlang.R;
import su.sadrobot.yashlang.WatchVideoActivity;
import su.sadrobot.yashlang.controller.VideoThumbManager;
Expand All @@ -59,6 +62,8 @@ public class VideoItemPagedListAdapter extends PagedListAdapter<VideoItem, Video
private OnListItemSwitchListener<VideoItem> onItemSwitchListener;
private int orientation = ORIENTATION_VERTICAL;

private ExecutorService thumbLoaderExecutor = Executors.newFixedThreadPool(10);


public static class VideoItemViewHolder extends RecyclerView.ViewHolder {
TextView nameTxt;
Expand Down Expand Up @@ -188,7 +193,7 @@ public void run() {
if (item.getThumbBitmap() != null) {
holder.thumbImg.setImageBitmap(item.getThumbBitmap());
} else {
new Thread(new Runnable() {
thumbLoaderExecutor.execute(new Runnable() {
@Override
public void run() {
final Bitmap thumb =
Expand All @@ -201,7 +206,7 @@ public void run() {
}
});
}
}).start();
});
}
}

Expand Down

0 comments on commit 6d67146

Please sign in to comment.