mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 14:27:24 +00:00
Replaced ListView with RecyclerView
This commit is contained in:
parent
3efd9fde68
commit
a60082b96c
@ -24,35 +24,47 @@ import android.content.Context
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.BaseAdapter
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
import fr.dudie.nominatim.model.Address
|
import fr.dudie.nominatim.model.Address
|
||||||
|
|
||||||
class GeocodingAdapter(context: Context, val dataSource: List<Address>) : BaseAdapter() {
|
class GeocodingAdapter(private val context: Context, private val dataSource: List<Address>) :
|
||||||
|
RecyclerView.Adapter<GeocodingAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val inflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
interface OnItemClickListener {
|
||||||
|
fun onItemClick(position: Int)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getCount(): Int {
|
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
|
return dataSource.size
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItem(position: Int): Any {
|
fun getItem(position: Int): Any {
|
||||||
return dataSource[position]
|
return dataSource[position]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
return position.toLong()
|
val nameView: TextView = itemView.findViewById(R.id.name)
|
||||||
}
|
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
|
||||||
val rowView = inflater.inflate(R.layout.geocoding_item, parent, false)
|
|
||||||
|
|
||||||
val nameView = rowView.findViewById(R.id.name) as TextView
|
|
||||||
|
|
||||||
val address = getItem(position) as Address
|
|
||||||
nameView.text = address.displayName
|
|
||||||
|
|
||||||
return rowView
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,11 @@ import android.util.Log
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.AdapterView
|
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.view.MenuItemCompat
|
import androidx.core.view.MenuItemCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import autodagger.AutoInjector
|
import autodagger.AutoInjector
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
@ -77,6 +78,7 @@ class GeocodingActivity :
|
|||||||
|
|
||||||
lateinit var adapter: GeocodingAdapter
|
lateinit var adapter: GeocodingAdapter
|
||||||
private var geocodingResults: List<Address> = ArrayList()
|
private var geocodingResults: List<Address> = ArrayList()
|
||||||
|
private lateinit var recyclerView: RecyclerView
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -91,6 +93,10 @@ class GeocodingActivity :
|
|||||||
|
|
||||||
roomToken = intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!!
|
roomToken = intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!!
|
||||||
query = intent.getStringExtra(BundleKeys.KEY_GEOCODING_QUERY)
|
query = intent.getStringExtra(BundleKeys.KEY_GEOCODING_QUERY)
|
||||||
|
recyclerView = findViewById(R.id.geocoding_results)
|
||||||
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
|
adapter = GeocodingAdapter(this, geocodingResults)
|
||||||
|
recyclerView.adapter = adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@ -108,16 +114,17 @@ class GeocodingActivity :
|
|||||||
Log.e(TAG, "search string that was passed to GeocodingController was null or empty")
|
Log.e(TAG, "search string that was passed to GeocodingController was null or empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.geocodingResults.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
|
adapter.setOnItemClickListener(object : GeocodingAdapter.OnItemClickListener {
|
||||||
|
override fun onItemClick(position: Int) {
|
||||||
val address: Address = adapter.getItem(position) as Address
|
val address: Address = adapter.getItem(position) as Address
|
||||||
val geocodingResult = GeocodingResult(address.latitude, address.longitude, address.displayName)
|
val geocodingResult = GeocodingResult(address.latitude, address.longitude, address.displayName)
|
||||||
|
val intent = Intent(this@GeocodingActivity, LocationPickerActivity::class.java)
|
||||||
val intent = Intent(this, LocationPickerActivity::class.java)
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
intent.putExtra(BundleKeys.KEY_ROOM_TOKEN, roomToken)
|
intent.putExtra(BundleKeys.KEY_ROOM_TOKEN, roomToken)
|
||||||
intent.putExtra(BundleKeys.KEY_GEOCODING_RESULT, geocodingResult)
|
intent.putExtra(BundleKeys.KEY_GEOCODING_RESULT, geocodingResult)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupActionBar() {
|
private fun setupActionBar() {
|
||||||
|
@ -44,10 +44,9 @@
|
|||||||
tools:title="@string/nc_app_product_name" />
|
tools:title="@string/nc_app_product_name" />
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<ListView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/geocoding_results"
|
android:id="@+id/geocoding_results"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"/>
|
||||||
</ListView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user