优化搜索结果逻辑
This commit is contained in:
@@ -2,6 +2,7 @@ package com.mogo.module.navi.ui.search
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
@@ -9,6 +10,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.map.marker.IMogoMarker
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener
|
||||
import com.mogo.map.marker.MogoMarkerOptions
|
||||
@@ -22,6 +24,7 @@ import com.mogo.module.navi.ui.adapter.SearchCategoryAdapter
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
import com.mogo.module.navi.uitls.BitmapUtils
|
||||
import com.mogo.module.navi.uitls.StringUtils
|
||||
import com.mogo.utils.UiThreadHandler
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.cv_search_result
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.et_navi_search
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.iv_navi_back
|
||||
@@ -33,8 +36,7 @@ import kotlinx.android.synthetic.main.fragment_search_category.tv_navi_navi
|
||||
* @author zyz
|
||||
* 2020-01-09.
|
||||
*/
|
||||
class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBack
|
||||
{
|
||||
class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBack {
|
||||
// override fun onMarkerClicked(marker: IMogoMarker?): Boolean {
|
||||
//
|
||||
// return true
|
||||
@@ -64,6 +66,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
private val TAG: String = "CategorySearchFragment"
|
||||
private var addMarkers: List<IMogoMarker>? = null
|
||||
var arrayList = ArrayList<MogoMarkerOptions>()
|
||||
var locationList = ArrayList<MogoLatLng>()
|
||||
|
||||
private lateinit var cmds: ArrayList<String>
|
||||
override fun renderSearchPoiResult(datums: List<MogoPoiItem>?) {
|
||||
@@ -74,6 +77,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
.speakTTSVoice(String.format("搜索到%d个位置,请选择", datums?.size))
|
||||
|
||||
arrayList.clear()
|
||||
locationList.clear()
|
||||
|
||||
for (index in 0 until datums!!.size) {
|
||||
var decodeResource =
|
||||
@@ -94,8 +98,9 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
// .anchor(0.5f, 1f)
|
||||
.longitude(datums[index].point?.lng ?: 0.0)
|
||||
arrayList.add(options)
|
||||
locationList.add(datums[index].point)
|
||||
|
||||
var int2String = StringUtils.int2String(index+1)
|
||||
var int2String = StringUtils.int2String(index + 1)
|
||||
AIAssist.getInstance(context)
|
||||
.registerUnWakeupCommand(
|
||||
"position" + index, arrayOf("第" + int2String + "个", "第" + int2String + "条"), this
|
||||
@@ -103,16 +108,26 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
cmds.add("position" + index)
|
||||
|
||||
}
|
||||
addMarkers()
|
||||
}
|
||||
|
||||
private fun addMarkers() {
|
||||
addMarkers = SearchServiceHolder.getMarkerManger()
|
||||
.addMarkers(TAG, arrayList, true)
|
||||
moveMapToRight()
|
||||
|
||||
UiThreadHandler.postDelayed(Runnable {
|
||||
SearchServiceHolder.getMapUIController()
|
||||
.showBounds(TAG, null, locationList, Rect(cv_search_result.width,0,0,0), false)
|
||||
|
||||
},1000)
|
||||
// moveMapToRight()
|
||||
addClick()
|
||||
}
|
||||
|
||||
private fun registerVoice() {
|
||||
|
||||
for (index in 0 until cmds.size) {
|
||||
var int2String = StringUtils.int2String(index+1)
|
||||
var int2String = StringUtils.int2String(index + 1)
|
||||
AIAssist.getInstance(context)
|
||||
.registerUnWakeupCommand(
|
||||
"position" + index, arrayOf("第" + int2String + "个", "第" + int2String + "条"), this
|
||||
@@ -124,23 +139,20 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
override fun onHiddenChanged(hidden: Boolean) {
|
||||
super.onHiddenChanged(hidden)
|
||||
if (!hidden) {
|
||||
addMarkers = SearchServiceHolder.getMarkerManger()
|
||||
.addMarkers(TAG, arrayList, true)
|
||||
registerVoice()
|
||||
addClick()
|
||||
|
||||
addMarkers()
|
||||
} else {
|
||||
unRegisterVoice()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addClick(){
|
||||
private fun addClick() {
|
||||
if (addMarkers != null) {
|
||||
for (item in addMarkers!!){
|
||||
for (item in addMarkers!!) {
|
||||
item.setOnMarkerClickListener {
|
||||
|
||||
var index = it.mogoMarkerOptions.`object` as Int
|
||||
mAdapter.current=index
|
||||
mAdapter.current = index
|
||||
rv_search_result.smoothScrollToPosition(index)
|
||||
updateMarker()
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user