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

Replaced ListView with RecyclerView #3322

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions app/src/main/java/com/nextcloud/talk/adapters/GeocodingAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,47 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.talk.R
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

override fun getCount(): Int {
return dataSource.size
interface OnItemClickListener {
fun onItemClick(position: Int)
}

override fun getItem(position: Int): Any {
return dataSource[position]
private var listener: OnItemClickListener? = null
fun setOnItemClickListener(listener: OnItemClickListener) {
this.listener = listener
}

override fun getItemId(position: Int): Long {
return position.toLong()
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 getView(position: Int, convertView: View?, parent: ViewGroup): View {
val rowView = inflater.inflate(R.layout.geocoding_item, parent, false)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val address = dataSource[position]
holder.nameView.text = address.displayName

val nameView = rowView.findViewById(R.id.name) as TextView
holder.itemView.setOnClickListener {
listener?.onItemClick(position)
}
}

val address = getItem(position) as Address
nameView.text = address.displayName
override fun getItemCount(): Int {
return dataSource.size
}

fun getItem(position: Int): Any {
return dataSource[position]
}

return rowView
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val nameView: TextView = itemView.findViewById(R.id.name)
}
}
40 changes: 29 additions & 11 deletions app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.inputmethod.EditorInfo
import android.widget.AdapterView
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import autodagger.AutoInjector
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.talk.R
Expand Down Expand Up @@ -77,6 +78,7 @@ class GeocodingActivity :

lateinit var adapter: GeocodingAdapter
private var geocodingResults: List<Address> = ArrayList()
private lateinit var recyclerView: RecyclerView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -91,6 +93,10 @@ class GeocodingActivity :

roomToken = intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!!
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() {
Expand All @@ -108,16 +114,17 @@ class GeocodingActivity :
Log.e(TAG, "search string that was passed to GeocodingController was null or empty")
}

binding.geocodingResults.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
val address: Address = adapter.getItem(position) as Address
val geocodingResult = GeocodingResult(address.latitude, address.longitude, address.displayName)

val intent = Intent(this, LocationPickerActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.putExtra(BundleKeys.KEY_ROOM_TOKEN, roomToken)
intent.putExtra(BundleKeys.KEY_GEOCODING_RESULT, geocodingResult)
startActivity(intent)
}
adapter.setOnItemClickListener(object : GeocodingAdapter.OnItemClickListener {
override fun onItemClick(position: Int) {
val address: Address = adapter.getItem(position) as Address
val geocodingResult = GeocodingResult(address.latitude, address.longitude, address.displayName)
val intent = Intent(this@GeocodingActivity, LocationPickerActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.putExtra(BundleKeys.KEY_ROOM_TOKEN, roomToken)
intent.putExtra(BundleKeys.KEY_GEOCODING_RESULT, geocodingResult)
startActivity(intent)
}
})
Smarshal21 marked this conversation as resolved.
Show resolved Hide resolved
}

private fun setupActionBar() {
Expand All @@ -134,6 +141,17 @@ class GeocodingActivity :

private fun initAdapter(addresses: List<Address>) {
adapter = GeocodingAdapter(binding.geocodingResults.context!!, addresses)
adapter.setOnItemClickListener(object : GeocodingAdapter.OnItemClickListener {
override fun onItemClick(position: Int) {
val address: Address = adapter.getItem(position) as Address
val geocodingResult = GeocodingResult(address.latitude, address.longitude, address.displayName)
val intent = Intent(this@GeocodingActivity, LocationPickerActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.putExtra(BundleKeys.KEY_ROOM_TOKEN, roomToken)
intent.putExtra(BundleKeys.KEY_GEOCODING_RESULT, geocodingResult)
startActivity(intent)
}
})
binding.geocodingResults.adapter = adapter
}

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_geocoding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@
tools:title="@string/nc_app_product_name" />
</com.google.android.material.appbar.AppBarLayout>

<ListView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/geocoding_results"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
android:layout_height="match_parent"/>

</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/geocoding_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:layout_gravity="top"
android:layout_marginStart="@dimen/standard_half_margin"
android:layout_marginTop="@dimen/standard_margin"
android:layout_marginEnd="@dimen/standard_double_padding"
android:layout_marginEnd="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_margin"
android:contentDescription="@null"
android:src="@drawable/ic_circular_location" />
Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 92 warnings</span>
<span class="mdl-layout-title">Lint Report: 91 warnings</span>
Loading