/* * Nextcloud Talk application * * @author Marcel Hibbe * Copyright (C) 2021 Marcel Hibbe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.nextcloud.talk.adapters import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.nextcloud.talk.R import fr.dudie.nominatim.model.Address class GeocodingAdapter(private val context: Context, private var dataSource: List
) : RecyclerView.Adapter() { interface OnItemClickListener { fun onItemClick(position: Int) } fun updateData(data: List
) { this.dataSource = data notifyDataSetChanged() } private var listener: OnItemClickListener? = null fun setOnItemClickListener(listener: OnItemClickListener) { this.listener = listener } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val inflater = LayoutInflater.from(context) val view = inflater.inflate(R.layout.geocoding_item, parent, false) return ViewHolder(view) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { val address = dataSource[position] holder.nameView.text = address.displayName holder.itemView.setOnClickListener { listener?.onItemClick(position) } } override fun getItemCount(): Int { return dataSource.size } fun getItem(position: Int): Any { return dataSource[position] } inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val nameView: TextView = itemView.findViewById(R.id.name) } }