Commit f539ea4a authored by 宋永孟's avatar 宋永孟

add 完成搜索页开发

parent 6008448e
package com.yidian.common
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.amap.api.services.core.PoiItem
/**
* Author: sym
* Date: 2021/6/27 3:35 PM
* Describe:
*/
class PoiSearchAdapter : BaseAdapter() {
private lateinit var data: List<PoiItem>
override fun getCount(): Int {
return if (::data.isInitialized) {
data.size
} else {
0
}
}
override fun getItem(position: Int): Any {
return position
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view: View?
var holder: ViewHolder
if (convertView == null) {
holder = ViewHolder()
view = LayoutInflater.from(parent!!.context).inflate(R.layout.list_view_item, null)
holder.titleTextView = view.findViewById(R.id.list_view_title_text)
holder.areaTextView = view.findViewById(R.id.list_view_area_text)
view.tag = holder
} else {
view = convertView
holder = view.tag as ViewHolder
}
//填充数据
holder.titleTextView!!.text = data[position].title
holder.areaTextView!!.text = data[position].provinceName + data[position].cityName + data[position].adName
return view!!
}
internal class ViewHolder {
var titleTextView: TextView? = null
var areaTextView: TextView? = null
}
fun setData(data: List<PoiItem>) {
this.data = data
notifyDataSetChanged()
}
}
......@@ -8,12 +8,14 @@
<TextView
android:id="@+id/list_view_title_text"
android:layout_width="match_parent"
android:layout_marginLeft="15dp"
android:layout_height="25dp"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/list_view_area_text"
android:layout_width="match_parent"
android:layout_marginLeft="15dp"
android:layout_height="25dp"
tools:ignore="MissingConstraints" />
......
......@@ -23,7 +23,7 @@ class EditStoreActivity : BaseActivity<ActivityStoreEditBinding>(), CommonTopBar
override fun init(savedInstanceState: Bundle?) {
viewBind.addressLayout.setOnClickListener {
startActivity(Intent(this@EditStoreActivity, SelectAddressActivity::class.java))
startActivityForResult(Intent(this@EditStoreActivity, SelectAddressActivity::class.java), 200)
}
viewBind.bvTopBar.setOnCommonTopBarCallback(null, this)
......@@ -32,4 +32,23 @@ class EditStoreActivity : BaseActivity<ActivityStoreEditBinding>(), CommonTopBar
override fun onDoAction() {
Toast.makeText(this@EditStoreActivity, "save", Toast.LENGTH_SHORT).show()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == 200) {
viewBind.storeAddressEdit.text = data!!.getStringExtra("title")
}
// override fun onActivityReenter(resultCode: Int, data: Intent?) {
// super.onActivityReenter(resultCode, data)
// if (resultCode == 200) {
// viewBind.storeAddressEdit.text = intent.getStringExtra("title")
//
//// resultIntent.putExtra("title", data[position].title)
//// resultIntent.putExtra("cityName", data[position].cityName)
//// resultIntent.putExtra("adName", data[position].adName)
//// resultIntent.putExtra("latLonPoint", data[position].latLonPoint)
// }
}
}
package com.yidian.shenghuoquan.newscontent.ui
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.widget.AdapterView
import com.amap.api.services.core.AMapException
import com.amap.api.services.core.PoiItem
import com.amap.api.services.poisearch.PoiResult
import com.amap.api.services.poisearch.PoiSearch
import com.amap.api.services.poisearch.PoiSearch.OnPoiSearchListener
import com.yidian.common.PoiSearchAdapter
import com.yidian.common.base.BaseActivity
import com.yidian.shenghuoquan.newscontent.databinding.LayoutActivityServiceProductAddrSearchBinding
......@@ -9,7 +18,11 @@ import com.yidian.shenghuoquan.newscontent.databinding.LayoutActivityServiceProd
* Date: 2021/6/28 2:55 PM
* Describe:
*/
class SearchAddActivity : BaseActivity<LayoutActivityServiceProductAddrSearchBinding>() {
class SearchAddActivity : BaseActivity<LayoutActivityServiceProductAddrSearchBinding>(), OnPoiSearchListener {
private var adapter = PoiSearchAdapter()
private var resultIntent = Intent()
private var key = ""
private lateinit var data: List<PoiItem>
override fun createViewBinding(): LayoutActivityServiceProductAddrSearchBinding {
return LayoutActivityServiceProductAddrSearchBinding.inflate(layoutInflater)
}
......@@ -20,8 +33,58 @@ class SearchAddActivity : BaseActivity<LayoutActivityServiceProductAddrSearchBin
override fun init(savedInstanceState: Bundle?) {
super.init(savedInstanceState)
viewBind.poiSearchList.adapter = adapter
viewBind.poiSearchList.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
resultIntent.putExtra("title", data[position].title)
resultIntent.putExtra("cityName", data[position].cityName)
resultIntent.putExtra("adName", data[position].adName)
resultIntent.putExtra("latLonPoint", data[position].latLonPoint)
setResult(100, resultIntent)
finish()
}
viewBind.btnHeaderRight.setOnClickListener {
finish()
}
viewBind.etLaspasSearchKey.setOnKeyListener { p0, keyCode, event ->
if (event!!.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
queryPoi()
}
false
}
}
override fun onPoiSearched(poiResult: PoiResult?, rCode: Int) {
if (rCode == AMapException.CODE_AMAP_SUCCESS) {
if (poiResult?.query != null) {
val poiItems: List<PoiItem> = poiResult.pois // 取得第一页的poiitem数据,页数从数字0开始
if (poiItems != null && poiItems.isNotEmpty()) {
adapter.setData(poiItems)
data = poiItems
}
}
}
}
override fun onPoiItemSearched(p0: PoiItem?, p1: Int) {
TODO("Not yet implemented")
}
//poi搜索
private fun queryPoi() {
val typeRange = "汽车服务|汽车销售|" +
"汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务|医疗保健服务|" +
"住宿服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|" +
"金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施"
key = viewBind.etLaspasSearchKey.text.toString()
val query = PoiSearch.Query(key, typeRange, "北京")
query.pageSize = 1000 // 设置每页最多返回多少条poiitem
query.pageNum = 1 //设置查第一页
val poiSearch = PoiSearch(this, query)
poiSearch.setOnPoiSearchListener(this) //设置数据返回的监听器
poiSearch.searchPOIAsyn()
}
}
......@@ -6,7 +6,6 @@ import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.Toast
import com.amap.api.maps.AMap
import com.amap.api.maps.AMap.OnMyLocationChangeListener
import com.amap.api.maps.MapView
......@@ -32,13 +31,15 @@ import kotlinx.android.synthetic.main.activity_select_address.*
class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMyLocationChangeListener, AMap.OnMapClickListener, OnPoiSearchListener{
private lateinit var mapView: MapView
private var adapter = PoiListAdapter()
private var resultIntent = Intent()
private lateinit var data: List<PoiItem>
private var myLocationStyle: MyLocationStyle? = null
var bitmapDescriptor: BitmapDescriptor? = null
private var markerView: View? = null
private var currentMarker: Marker? = null
private var boundsBuilder: LatLngBounds.Builder? = null
var aMap: AMap? = null
override fun createViewBinding(): ActivitySelectAddressBinding {
return ActivitySelectAddressBinding.inflate(layoutInflater)
}
......@@ -51,8 +52,13 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
super.init(savedInstanceState)
mapView = viewBind.map
viewBind.poiList.adapter = adapter
viewBind.poiList.onItemClickListener = AdapterView.OnItemClickListener { _, _, p2, _ ->
Toast.makeText(this@SelectAddressActivity, p2.toString(), Toast.LENGTH_SHORT).show()
viewBind.poiList.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
resultIntent.putExtra("title", data[position].title)
resultIntent.putExtra("cityName", data[position].cityName)
resultIntent.putExtra("adName", data[position].adName)
resultIntent.putExtra("latLonPoint", data[position].latLonPoint)
setResult(200, resultIntent)
finish()
}
mapView.onCreate(savedInstanceState)
......@@ -73,7 +79,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
finish()
}
viewBind.selectAddSearchText.setOnClickListener {
startActivity(Intent(this@SelectAddressActivity, SearchAddActivity::class.java))
startActivityForResult(Intent(this@SelectAddressActivity, SearchAddActivity::class.java), 100)
}
}
......@@ -112,7 +118,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
override fun onMyLocationChange(location: Location?) {
// 定位回调监听
if (location != null) {
Log.e("amap", "onMyLocationChange 定位成功, lat: " + location.getLatitude() + " lon: " + location.getLongitude())
Log.e("amap", "onMyLocationChange 定位成功, lat: " + location.latitude + " lon: " + location.longitude)
val bundle: Bundle = location.extras
if (bundle != null) {
val errorCode = bundle.getInt(MyLocationStyle.ERROR_CODE)
......@@ -181,6 +187,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
if (poiResult?.query != null) {
val poiItems: List<PoiItem> = poiResult.pois // 取得第一页的poiitem数据,页数从数字0开始
if (poiItems != null && poiItems.isNotEmpty()) {
data = poiItems
adapter.setData(poiItems)
}
}
......@@ -190,4 +197,12 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
override fun onPoiItemSearched(p0: PoiItem?, p1: Int) {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == 100) {
setResult(200, data)
finish()
}
}
}
......@@ -70,6 +70,7 @@
android:textSize="16sp" />
<TextView
android:id="@+id/store_address_edit"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
......
......@@ -52,4 +52,9 @@
android:layout_height="1dp"
android:background="#f2f2f2" />
<ListView
android:id="@+id/poi_search_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment