Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void showVideos(PriorityQueue<VideoFile> queue) {
- mainLay.removeAllViews();
- if (queue.isEmpty()) {
- TextView textView = new TextView(this);
- textView.setText("No files match your conditions");
- textView.setGravity(Gravity.CENTER);
- mainLay.addView(textView);
- return;
- }
- View inf = inflater.inflate(R.layout.videolay, null);
- videoRow = inf.findViewById(R.id.videoRow); //creating a 'line' for videofiles
- int count = 0;
- Iterator<VideoFile> it = queue.iterator();
- while (it.hasNext()) {
- VideoFile vf = it.next(); //creating a layout for each videofile. It consists of name, preview and is clickable
- if (count == 4) { //i want to have 4 videofiles on my screen in one line (videoRow)
- count = 0;
- mainLay.addView(inf);
- inf = inflater.inflate(R.layout.videolay, null);
- videoRow = inf.findViewById(R.id.videoRow);
- }
- File videofile = new File(vf.videoPath);
- //initializing videofile layout
- final Uri videoURI = FileProvider.getUriForFile(MainActivity.this,
- BuildConfig.APPLICATION_ID + ".provider",
- videofile);
- View videoInf = inflater.inflate(R.layout.video, null);
- RelativeLayout rel = videoInf.findViewById(R.id.videoLay);
- ImageView iv = videoInf.findViewById(R.id.videoThumb);
- TextView text = videoInf.findViewById(R.id.videoName);
- text.setText(vf.title);
- rel.setOnClickListener(v -> {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(videoURI, "video");
- intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(intent);
- });
- rel.setOnLongClickListener(v -> {
- if (!videoTags.isEmpty()) {
- ChooseTags chooseTags = new ChooseTags();
- Bundle args = new Bundle();
- args.putParcelable("vf", vf);
- chooseTags.setArguments(args);
- chooseTags.show(getFragmentManager(), TAG);
- } else
- Toast.makeText(this, "There are currently no tags. Add some via navigation drawer", Toast.LENGTH_SHORT).show();
- return false;
- });
- //if (vf.thumbPath != null) iv.setImageBitmap(BitmapFactory.decodeFile(vf.thumbPath));
- imageViews.put(vf, iv); //putting reference for imageview for latter inflating.
- videoRow.addView(videoInf);
- ++count;
- if (!it.hasNext()) mainLay.addView(inf);
- }
- mainLay.invalidate();
- GetThumbs getThumbs = new GetThumbs();
- getThumbs.execute(imageViews);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement