There is a method that compares the links of one object with another:
public boolean contains(ImageUpload newVideoUpload) { for (ImageUpload imageUpload : imageUploads) { if (imageUpload.getUrl().equals(newVideoUpload.getUrl())) return true; } return false; } And the method in which I work with youtube id’s (pull out id, after which I insert a preview video where I display it on the screen):
void getIdUrl(String url, int position) { String video_id = ""; String expression = ""; if (url != null && url.trim().length() > 0 && url.matches(".*\\byoutube\\b.*")) { expression = "^.*((youtu.be" + "\\/)" + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; CharSequence input = url; Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(input); if (matcher.matches()) { String groupIndex1 = matcher.group(7); if (groupIndex1 != null && groupIndex1.length() == 11) video_id = groupIndex1; ImageUpload imageUpload = new ImageUpload(); imageUpload.setLoadImage(true); OutputMetadata outputMetadata = new OutputMetadata(); outputMetadata.setVideoUrl("http://img.youtube.com/vi/" + video_id + "/0.jpg"); outputMetadata.setFilename("http://img.youtube.com/vi/" + video_id + "/0.jpg"); imageUpload.setOutputMetadata(outputMetadata); controlList.get(position).getImageUploads().add(imageUpload); adapterForm.notifyDataSetChanged(); } else { Toast.makeText(getActivity().getApplicationContext(), "This video already exists!", Toast.LENGTH_SHORT).show(); } The question is how to use the contains method in the getIdUrl method.
ImageUpload, and in thecontainsmethod -VideoUpload. Bring them to the same denominator. - post_zeewgetIdUrl(...)method, it should return something. - post_zeewgetpresent in the method name, then, logically, this method is used to get something, that is, it must return something. If it does not return anything to you, then you should think about the correct name of the method in accordance with its functionality. - post_zeew