Giter VIP home page Giter VIP logo

Comments (4)

rubensousa avatar rubensousa commented on August 18, 2024

Hi @fankloano. Can you please post the XML and kotlin code for your ViewHolders?

from dpadrecyclerview.

fankloano avatar fankloano commented on August 18, 2024

Following the xml-code of rv_item_movies:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:id="@+id/cardview_movie"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="5dp"
    app:cardElevation="2dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:foreground="@drawable/selector_vod_card_background">

    <FrameLayout
        android:background="@color/colorBG"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="1dp">

        <ImageView
            android:id="@+id/ivMovies"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:scaleType="fitXY"
            tools:src="@drawable/testposter"/>

        <ImageView
            android:id="@+id/tv_isFullyWatched"
            android:layout_width="35dp"
            android:layout_height="20dp"
            android:background="#D02E3035"
            android:src="@drawable/ic_checked"
            android:layout_gravity="end"
            app:tint="@color/light_blue"
            android:visibility="invisible"/>
        

        <TextView
            android:id="@+id/tvMovies"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/ivMovies"
            android:layout_gravity="bottom"
            android:fontFamily="sans-serif-smallcaps"
            android:gravity="center"
            android:padding="5dp"
            android:background="#C12E3035"
            android:textColor="@color/white"
            android:textSize="10dp"
            android:typeface="monospace" />

        <ImageView
            android:id="@+id/tv_isFavorite"
            android:layout_width="35dp"
            android:layout_height="20dp"
            android:background="#D02E3035"
            android:src="@drawable/ic_favorite_vod"
            android:layout_gravity="start"
            android:visibility="invisible"/>

    </FrameLayout>

</androidx.cardview.widget.CardView>

With kotlin code you mean the adapter code?

inner class ViewHolder(val binding: RvItemMoviesBinding) : RecyclerView.ViewHolder(binding.root) {

      fun bind(movie: Movie) {
          binding.apply {
              tvMovies.text = movie.movieName

              val image = movie.poster_url
              if (!image.isNullOrEmpty()) {
                  Glide.with(itemView.context).load(image)
                      .into(ivMovies)
              }

              binding.tvIsFavorite.visibility = if (movie.isFavorite) View.VISIBLE else View.INVISIBLE


              binding.cardviewMovie.setOnKeyListener { _, keyCode, event ->
                      if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && event.action == KeyEvent.ACTION_DOWN) {
                         
                          if (bindingAdapterPosition % 7 == 0) {
                              fragment.setMovieCategoriesVisibilityAnimated(true)
                              return@setOnKeyListener true
                          }
                      }
                      if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
                          fragment.setMovieCategoriesVisibilityAnimated(true)
                          return@setOnKeyListener true
                      }
                      if (keyCode == KeyEvent.KEYCODE_DPAD_UP && event.action == KeyEvent.ACTION_DOWN) {
                          if (bindingAdapterPosition == 0) {
                              binding.cardviewMovie.requestFocus()
                              return@setOnKeyListener true
                          }
                      }
                      if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && event.action == KeyEvent.ACTION_DOWN) {
                          if (bindingAdapterPosition == itemCount - 1) {
                              binding.cardviewMovie.requestFocus()
                              return@setOnKeyListener true
                          }
                      }
                      return@setOnKeyListener false
                  }
              }
          }
      }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      val binding = RvItemMoviesBinding.inflate(
          LayoutInflater.from(parent.context),
          parent,
          false
      )
      val viewHolder = ViewHolder(binding)
      return viewHolder
  }

  @UnstableApi
  override fun onBindViewHolder(holder: ViewHolder, position: Int) {
      val movie = getItem(position)!!
      holder.bind(movie)
      holder.binding.cardviewMovie.setOnFocusChangeListener { _, hasFocus ->
          if (hasFocus) {
              fragment.setDetailsUi(movie)
          } else {
          }
      }
  }

from dpadrecyclerview.

rubensousa avatar rubensousa commented on August 18, 2024

So your problem seems to be the usage of DpadLinearSpacingDecoration. Please use this instead: https://rubensousa.github.io/DpadRecyclerView/recipes/spacing/#grid-spacings

from dpadrecyclerview.

fankloano avatar fankloano commented on August 18, 2024

@rubensousa
sorry I overlooked the spacing recipes for grid..
using DpadGridSpacingDecoration solved the problem, thanks

from dpadrecyclerview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.