Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'getItem' is final and cannot be overriden #2164

Open
Cosmopal opened this issue Jun 25, 2024 · 0 comments
Open

'getItem' is final and cannot be overriden #2164

Cosmopal opened this issue Jun 25, 2024 · 0 comments

Comments

@Cosmopal
Copy link

Welcome to FirebaseUI and thanks for submitting an issue!

Please take a look at open issues, as well as resolved issues, to see if your issue is either already being addressed, or has been solved by someone else.

If not, please feel free to fill in the following info so we can help faster!

Step 1: Are you in the right place?

  • For issues or feature requests related to the code in this repository file a GitHub issue.
  • For general technical questions, post a question on StackOverflow tagged appropriately.
  • For general Firebase discussion, use the firebase-talk google group
  • For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel

Step 2: Describe your environment

  • Android device: Android 13+
  • Android OS version: target sdk 34
  • Google Play Services version: _____
  • Firebase/Play Services SDK version: 33.1.0
  • FirebaseUI version: 8.0.2

Step 3: Describe the problem:

I am unable to override getItem function when extending the FirestorePagingAdapter. The build fails saying 'getItem' is final and cannot be overriden. I need to override getItem because I am trying to insert a header item in the list.

Steps to reproduce:




Observed Results:

  • What happened? This could be a description, logcat output, etc.

Build fails:
image

Expected Results:

  • What did you expect to happen?

Expected to be able to override this function as it is marked protected in PagingDataAdapter class

Relevant Code:

class VideoFirebaseAdapter(var context: Context,
                                  private var showCategory: Boolean = true,
                                  options: FirestorePagingOptions<VideoMetadata>,
                                  private val hasHeader:Boolean = false)
  :FirestorePagingAdapter<VideoMetadata, RecyclerView.ViewHolder>(options) {

  private val TYPE_HEADER = 0
  private val TYPE_ITEM = 1

  val TAG = "VideoAdapter"

  var config = ImageLoaderConfiguration.Builder(this.context)
          .build()!!

  private val loader: ImageLoader = ImageLoader.getInstance()

  init {
      loader.init(config)
  }


  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
      return if (hasHeader && viewType == TYPE_HEADER) {
          getHeaderVH(parent, viewType)!!
      } else {
          val itemView = LayoutInflater.from(context).inflate(R.layout.video_item, parent, false)
          VideoListItemVH(itemView, showCategory, context, loader)
      }
  }

  abstract fun getHeaderVH(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder?

  override fun getItemViewType(position: Int): Int {
      return TYPE_ITEM
      return if (hasHeader && position == 0)
          TYPE_HEADER
      else
          TYPE_ITEM
  }

  override fun getItemCount(): Int {
      return if (hasHeader)
          super.getItemCount() + 1
      else
          super.getItemCount()
  }

//  fails to override saying getItem is final
override fun getItem(position: Int): DocumentSnapshot? {
      if(hasHeader) {
          if(position==0) return super.getItem(0) // This will be ignored!
          return super.getItem(position-1)
      }
      return super.getItem(position)
  }

  override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, video: VideoMetadata) {
      if (hasHeader && holder !is VideoListItemVH) {
          return
      } else {
          (holder as VideoListItemVH).bind(video)
      }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant