app/src/main/java/cl/ucn/disc/dsm/thenews/activities/adapters/NoticiaAdapter.java
@NotNull
  @Override
  public NoticiaViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

    // The inflater
    final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());

    // The row of noticia
    final RowNoticiaBinding rowNoticiaBinding = RowNoticiaBinding.inflate(
        layoutInflater,
        parent,
        false
    );

    // The NoticiaViewHolder
    final NoticiaViewHolder noticiaViewHolder = new NoticiaViewHolder(rowNoticiaBinding);

    // Click over the image
    rowNoticiaBinding.sdvFoto.setOnClickListener(view -> {

      // The position
      final int position = noticiaViewHolder.getAdapterPosition();

      // The id
      final long id = noticiaViewHolder.getItemId();
      log.debug("Click! position: {}, id: {}.", position, Long.toHexString(id));

      // Noticia to show
      final Noticia noticia = this.theNoticias.get(position);

      // Nothing to do
      if (noticia.getUrlFoto() == null) {
        return;
      }

      // Popup the image
      this.showImagePopup(noticia, layoutInflater, parent.getContext());

    });

    // Click in the row
    rowNoticiaBinding.getRoot().setOnClickListener(view -> {

      // The position
      final int position = noticiaViewHolder.getAdapterPosition();

      // The id
      final long id = noticiaViewHolder.getItemId();
      log.debug("Click! position: {}, id: {}.", position, Long.toHexString(id));

      // Noticia to show
      final Noticia noticia = this.theNoticias.get(position);

      log.debug("Link: {}.", noticia.getUrl());
      if (noticia.getUrl() != null) {

        // Open the browser
        parent.getContext().startActivity(
            new Intent(
                Intent.ACTION_VIEW,
                Uri.parse(noticia.getUrl())
            )
        );
      }

    });

    return noticiaViewHolder;

  }
/**
   * Called when RecyclerView needs a newViewHolder of the given type to represent an item.
   */
Called when RecyclerView needs a newViewHolder of the given type to represent an item.
Called when RecyclerView needs a newViewHolder of the given type to represent an item .
@NotNull
  @Override
  public NoticiaViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
    final RowNoticiaBinding rowNoticiaBinding = RowNoticiaBinding.inflate(
        layoutInflater,
        parent,
        false
    );
    final NoticiaViewHolder noticiaViewHolder = new NoticiaViewHolder(rowNoticiaBinding);
    rowNoticiaBinding.sdvFoto.setOnClickListener(view -> {
      final int position = noticiaViewHolder.getAdapterPosition();
      final long id = noticiaViewHolder.getItemId();
      log.debug("Click! position: {}, id: {}.", position, Long.toHexString(id));
      final Noticia noticia = this.theNoticias.get(position);
      if (noticia.getUrlFoto() == null) {
        return;
      }
      this.showImagePopup(noticia, layoutInflater, parent.getContext());
    });
    rowNoticiaBinding.getRoot().setOnClickListener(view -> {
      final int position = noticiaViewHolder.getAdapterPosition();
      final long id = noticiaViewHolder.getItemId();
      log.debug("Click! position: {}, id: {}.", position, Long.toHexString(id));
      final Noticia noticia = this.theNoticias.get(position);
      log.debug("Link: {}.", noticia.getUrl());
      if (noticia.getUrl() != null) {
        parent.getContext().startActivity(
            new Intent(
                Intent.ACTION_VIEW,
                Uri.parse(noticia.getUrl())
            )
        );
      }
    });
    return noticiaViewHolder;
  }
@ NotNull @ Override public NoticiaViewHolder onCreateViewHolder ( @ NonNull ViewGroup parent , int viewType ) { final LayoutInflater layoutInflater = LayoutInflater . from ( parent . getContext ( ) ) ; final RowNoticiaBinding rowNoticiaBinding = RowNoticiaBinding . inflate ( layoutInflater , parent , false ) ; final NoticiaViewHolder noticiaViewHolder = new NoticiaViewHolder ( rowNoticiaBinding ) ; rowNoticiaBinding . sdvFoto . setOnClickListener ( view -> { final int position = noticiaViewHolder . getAdapterPosition ( ) ; final long id = noticiaViewHolder . getItemId ( ) ; log . debug ( "Click! position: {}, id: {}." , position , Long . toHexString ( id ) ) ; final Noticia noticia = this . theNoticias . get ( position ) ; if ( noticia . getUrlFoto ( ) == null ) { return ; } this . showImagePopup ( noticia , layoutInflater , parent . getContext ( ) ) ; } ) ; rowNoticiaBinding . getRoot ( ) . setOnClickListener ( view -> { final int position = noticiaViewHolder . getAdapterPosition ( ) ; final long id = noticiaViewHolder . getItemId ( ) ; log . debug ( "Click! position: {}, id: {}." , position , Long . toHexString ( id ) ) ; final Noticia noticia = this . theNoticias . get ( position ) ; log . debug ( "Link: {}." , noticia . getUrl ( ) ) ; if ( noticia . getUrl ( ) != null ) { parent . getContext ( ) . startActivity ( new Intent ( Intent . ACTION_VIEW , Uri . parse ( noticia . getUrl ( ) ) ) ) ; } } ) ; return noticiaViewHolder ; }
Called when RecyclerView needs a newViewHolder of the given type to represent an item.
Called when RecyclerView needs a newViewHolder of the given type to represent an item .
// The inflater // The row of noticia // The NoticiaViewHolder // Click over the image // The position // The id // Noticia to show // Nothing to do // Popup the image // Click in the row // The position // The id // Noticia to show // Open the browser