Advertisement
Guest User

Untitled

a guest
Jan 10th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.90 KB | None | 0 0
  1. private void showVideos(PriorityQueue<VideoFile> queue) {
  2.         mainLay.removeAllViews();
  3.         if (queue.isEmpty()) {
  4. TextView textView = new TextView(this);
  5.             textView.setText("No files match your conditions");
  6.             textView.setGravity(Gravity.CENTER);
  7.             mainLay.addView(textView);
  8.             return;
  9.         }
  10.         View inf = inflater.inflate(R.layout.videolay, null);
  11.         videoRow = inf.findViewById(R.id.videoRow); //creating a 'line' for videofiles
  12.         int count = 0;
  13.         Iterator<VideoFile> it = queue.iterator();
  14.         while (it.hasNext()) {
  15.             VideoFile vf = it.next(); //creating a layout for each videofile. It consists of name, preview and is clickable
  16.             if (count == 4) {  //i want to have 4 videofiles on my screen in one line (videoRow)
  17.                 count = 0;
  18.                 mainLay.addView(inf);
  19.                 inf = inflater.inflate(R.layout.videolay, null);
  20.                 videoRow = inf.findViewById(R.id.videoRow);
  21.             }
  22.  
  23.             File videofile = new File(vf.videoPath);
  24.             //initializing videofile layout
  25.             final Uri videoURI = FileProvider.getUriForFile(MainActivity.this,
  26.                     BuildConfig.APPLICATION_ID + ".provider",
  27.                     videofile);
  28.             View videoInf = inflater.inflate(R.layout.video, null);
  29.             RelativeLayout rel = videoInf.findViewById(R.id.videoLay);
  30.             ImageView iv = videoInf.findViewById(R.id.videoThumb);
  31.             TextView text = videoInf.findViewById(R.id.videoName);
  32.  
  33.             text.setText(vf.title);
  34.  
  35.             rel.setOnClickListener(v -> {
  36.                 Intent intent = new Intent(Intent.ACTION_VIEW);
  37.                 intent.setDataAndType(videoURI, "video");
  38.                 intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  39.                 startActivity(intent);
  40.             });
  41.  
  42.             rel.setOnLongClickListener(v -> {
  43.                 if (!videoTags.isEmpty()) {
  44.                     ChooseTags chooseTags = new ChooseTags();
  45.                     Bundle args = new Bundle();
  46.                     args.putParcelable("vf", vf);
  47.                     chooseTags.setArguments(args);
  48.                     chooseTags.show(getFragmentManager(), TAG);
  49.                 } else
  50.                     Toast.makeText(this, "There are currently no tags. Add some via navigation drawer", Toast.LENGTH_SHORT).show();
  51.                 return false;
  52.             });
  53.  
  54.             //if (vf.thumbPath != null) iv.setImageBitmap(BitmapFactory.decodeFile(vf.thumbPath));
  55.             imageViews.put(vf, iv); //putting reference for imageview for latter inflating.
  56.  
  57.             videoRow.addView(videoInf);
  58.             ++count;
  59.             if (!it.hasNext()) mainLay.addView(inf);
  60.         }
  61.         mainLay.invalidate();
  62.         GetThumbs getThumbs = new GetThumbs();
  63.         getThumbs.execute(imageViews);
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement