From a60082b96c85ffe72ad9b10d5ab43df61dec82c7 Mon Sep 17 00:00:00 2001 From: Smarshal21 Date: Tue, 19 Sep 2023 01:49:31 +0530 Subject: [PATCH 1/4] Replaced ListView with RecyclerView --- .../talk/adapters/GeocodingAdapter.kt | 48 ++++++++++++------- .../talk/location/GeocodingActivity.kt | 29 ++++++----- .../main/res/layout/activity_geocoding.xml | 5 +- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/GeocodingAdapter.kt b/app/src/main/java/com/nextcloud/talk/adapters/GeocodingAdapter.kt index 698d319b2..8350da0b0 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/GeocodingAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/GeocodingAdapter.kt @@ -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
) : BaseAdapter() { +class GeocodingAdapter(private val context: Context, private val dataSource: List
) : + RecyclerView.Adapter() { - 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 } - override fun getItem(position: Int): Any { + fun getItem(position: Int): Any { return dataSource[position] } - override fun getItemId(position: Int): Long { - return position.toLong() - } - - 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 + inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val nameView: TextView = itemView.findViewById(R.id.name) } } diff --git a/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt b/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt index 854d3825c..5e94022a5 100644 --- a/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt @@ -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 @@ -77,6 +78,7 @@ class GeocodingActivity : lateinit var adapter: GeocodingAdapter private var geocodingResults: List
= ArrayList() + private lateinit var recyclerView: RecyclerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -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() { @@ -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) + } + }) } private fun setupActionBar() { diff --git a/app/src/main/res/layout/activity_geocoding.xml b/app/src/main/res/layout/activity_geocoding.xml index 545467887..d58ca3b71 100644 --- a/app/src/main/res/layout/activity_geocoding.xml +++ b/app/src/main/res/layout/activity_geocoding.xml @@ -44,10 +44,9 @@ tools:title="@string/nc_app_product_name" /> - - + android:layout_height="match_parent"/> From 7f70e3f92705fa2d270e9f3ae916bca4ad4bf6f5 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 26 Sep 2023 10:28:38 +0200 Subject: [PATCH 2/4] Align geo search results with search input Signed-off-by: Andy Scherzinger --- app/src/main/res/layout/geocoding_item.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/geocoding_item.xml b/app/src/main/res/layout/geocoding_item.xml index 268945a7e..1cd084c72 100644 --- a/app/src/main/res/layout/geocoding_item.xml +++ b/app/src/main/res/layout/geocoding_item.xml @@ -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" /> From d16aaf1695a56285e2d37d7321a657b61ab5bff7 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 26 Sep 2023 08:51:04 +0000 Subject: [PATCH 3/4] Analysis: update lint results to reflect reduced error/warning count Signed-off-by: github-actions --- scripts/analysis/lint-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/lint-results.txt b/scripts/analysis/lint-results.txt index 2d857a44d..9a13c695d 100644 --- a/scripts/analysis/lint-results.txt +++ b/scripts/analysis/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 92 warnings + Lint Report: 91 warnings From d2a1cf9e8c29d406f7ef51ea2e0b1ae211171f95 Mon Sep 17 00:00:00 2001 From: Smarshal21 Date: Tue, 26 Sep 2023 19:39:01 +0530 Subject: [PATCH 4/4] Fixed OnClickListener for the GeocodingAdapter --- .../com/nextcloud/talk/location/GeocodingActivity.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt b/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt index 5e94022a5..ff08ef6e8 100644 --- a/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt @@ -141,6 +141,17 @@ class GeocodingActivity : private fun initAdapter(addresses: List
) { 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 }