Commit eea467fc authored by fengruiyu's avatar fengruiyu

1.搜索页面的境内境外切换

2.bean的list修改
parent 858398fe
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<application <application
android:name=".AppApplication" android:name=".AppApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/logo" android:icon="@mipmap/ic_launcher_main"
android:label="@string/app_name" android:label="@string/app_name"
android:largeHeap="true" android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
......
...@@ -38,11 +38,11 @@ interface BaiduApi { ...@@ -38,11 +38,11 @@ interface BaiduApi {
// fun suggestionPlaceAbroad(@Query vo: @JvmSuppressWildcards Map<String, Any>): Observable<Response<BaseResponse<Any>>> // fun suggestionPlaceAbroad(@Query vo: @JvmSuppressWildcards Map<String, Any>): Observable<Response<BaseResponse<Any>>>
fun suggestionPlaceAbroad(@Query("query") vo: String,@Query("region") vo2: String, fun suggestionPlaceAbroad(@Query("query") vo: String,@Query("region") vo2: String,
@Query("output") vo3: String,@Query("ak") vo4: String): @Query("output") vo3: String,@Query("ak") vo4: String):
Observable<Response<BaseArrayResponse<PositionBean>>> Observable<Response<BaseResponse<PositionBean>>>
@GET("place/v2/suggestion") @GET("place/v2/suggestion")
fun suggestionPlaceDomestic(@Query("query") vo: String,@Query("region") vo2: String, fun suggestionPlaceDomestic(@Query("query") vo: String,@Query("region") vo2: String,
@Query("output") vo3: String,@Query("ak") vo4: String): @Query("output") vo3: String,@Query("ak") vo4: String):
Observable<Response<BaseArrayResponse<PositionBean>>> Observable<Response<BaseResponse<PositionBean>>>
} }
\ No newline at end of file
...@@ -6,17 +6,9 @@ import java.util.List; ...@@ -6,17 +6,9 @@ import java.util.List;
* Created by goldze on 2017/5/10. * Created by goldze on 2017/5/10.
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义, * 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
*/ */
public class BaseArrayResponse<T> extends BaseResponse<List<T>>{ public class BaseArrayResponse<T> {
@Override
public List<T> getResult() {
return result;
}
@Override
public void setResult(List<T> result) {
this.result = result;
}
} }
...@@ -5,6 +5,7 @@ import androidx.annotation.Nullable; ...@@ -5,6 +5,7 @@ import androidx.annotation.Nullable;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* Created by goldze on 2017/5/10. * Created by goldze on 2017/5/10.
...@@ -17,7 +18,10 @@ public class BaseResponse<T> implements Serializable { ...@@ -17,7 +18,10 @@ public class BaseResponse<T> implements Serializable {
// @JsonAdapter(value = JsonAdapterGsonDeserializer.class) // @JsonAdapter(value = JsonAdapterGsonDeserializer.class)
@SerializedName("data") @SerializedName("data")
protected @Nullable T result; private @Nullable T result;
@SerializedName("result")
private @Nullable List<T> resultList;
public BaseResponse() { public BaseResponse() {
} }
...@@ -50,7 +54,7 @@ public class BaseResponse<T> implements Serializable { ...@@ -50,7 +54,7 @@ public class BaseResponse<T> implements Serializable {
} }
public boolean isOk() { public boolean isOk() {
return status == 200 && status < 700; return status == 200 || status == 0;
} }
public String getMessage() { public String getMessage() {
...@@ -61,6 +65,15 @@ public class BaseResponse<T> implements Serializable { ...@@ -61,6 +65,15 @@ public class BaseResponse<T> implements Serializable {
this.message = message; this.message = message;
} }
public void setResultList(@Nullable List<T> resultList) {
this.resultList = resultList;
}
@Nullable
public List<T> getResultList() {
return resultList;
}
@Override @Override
public String toString() { public String toString() {
return "BaseResponse{" + return "BaseResponse{" +
......
...@@ -22,8 +22,8 @@ import com.mints.street.databinding.ActivitySearchMapBinding ...@@ -22,8 +22,8 @@ import com.mints.street.databinding.ActivitySearchMapBinding
/** /**
* Created by 冯瑞雨 on 2021/7/13. * Created by 冯瑞雨 on 2021/7/13.
*/ */
class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewModel>(){ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewModel>() {
// OnGetSuggestionResultListener { // OnGetSuggestionResultListener {
companion object { companion object {
const val HISTORY_NAME = "history_name" const val HISTORY_NAME = "history_name"
const val REQUEST_CODE = 201 const val REQUEST_CODE = 201
...@@ -75,16 +75,15 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo ...@@ -75,16 +75,15 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo
viewModel.searchAfterOneItems.clear() viewModel.searchAfterOneItems.clear()
return return
} }
if (viewModel.index==0){ if (viewModel.index.value == 0) {
//国外 //国外
viewModel.searchdomestic(s.toString()) viewModel.searchdomestic(s.toString())
}else{ } else {
//传入参数【这里是可以获取到参数的】【国外】 //传入参数【这里是可以获取到参数的】【国外】
viewModel.searchabroad(s.toString()) viewModel.searchabroad(s.toString())
} }
// onGetSuggestionResult(postionConfig) // onGetSuggestionResult(postionConfig)
// // 使用建议搜索服务获取建议列表,结果在onSuggestionResult()中更新【这里也是百度三方的东西】 // // 使用建议搜索服务获取建议列表,结果在onSuggestionResult()中更新【这里也是百度三方的东西】
// mSuggestionSearch?.requestSuggestion( // mSuggestionSearch?.requestSuggestion(
...@@ -120,13 +119,12 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo ...@@ -120,13 +119,12 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo
} }
private fun update() { private fun update() {
historyRecordAdapter?.apply { historyRecordAdapter?.apply {
this.type = viewModel.index this.type = viewModel.index.value ?: 0
} }
popularSceneAdapter?.apply { popularSceneAdapter?.apply {
if (viewModel.index == 0) { if (viewModel.index.value ?: 0 == 0) {
this.data = viewModel.mapBean.value?.innerPlaces?.places this.data = viewModel.mapBean.value?.innerPlaces?.places
} else { } else {
this.data = viewModel.mapBean.value?.outerPlaces?.places this.data = viewModel.mapBean.value?.outerPlaces?.places
...@@ -151,13 +149,24 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo ...@@ -151,13 +149,24 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo
it?.apply { it?.apply {
onGetSuggestionResult(this) onGetSuggestionResult(this)
} }
})
viewModel.index.observe(this, Observer {
if(TextUtils.isEmpty(binding.et.text)){
return@Observer
}
if (it == 0) {
//国外
viewModel.searchdomestic(binding.et.text.toString())
} else {
//传入参数【这里是可以获取到参数的】【国外】
viewModel.searchabroad(binding.et.text.toString())
}
}) })
} }
private fun territory() { private fun territory() {
if (viewModel.index == 0) return if (viewModel.index.value ?: 0 == 0) return
viewModel.index = 0 viewModel.index.value = 0
binding.territory.setTextColor(ResourceUtils.getColor(R.color.color_668BFF)) binding.territory.setTextColor(ResourceUtils.getColor(R.color.color_668BFF))
binding.abroad.setTextColor(ResourceUtils.getColor(R.color.white)) binding.abroad.setTextColor(ResourceUtils.getColor(R.color.white))
binding.territory.solid = ResourceUtils.getColor(R.color.white) binding.territory.solid = ResourceUtils.getColor(R.color.white)
...@@ -166,8 +175,8 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo ...@@ -166,8 +175,8 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo
} }
private fun abroad() { private fun abroad() {
if (viewModel.index == 1) return if (viewModel.index.value ?: 0 == 1) return
viewModel.index = 1 viewModel.index.value = 1
binding.territory.setTextColor(ResourceUtils.getColor(R.color.white)) binding.territory.setTextColor(ResourceUtils.getColor(R.color.white))
binding.abroad.setTextColor(ResourceUtils.getColor(R.color.color_668BFF)) binding.abroad.setTextColor(ResourceUtils.getColor(R.color.color_668BFF))
binding.territory.solid = ResourceUtils.getColor(R.color.color_668BFF) binding.territory.solid = ResourceUtils.getColor(R.color.color_668BFF)
...@@ -194,7 +203,6 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo ...@@ -194,7 +203,6 @@ class SearchMapActivity : BaseActivity<ActivitySearchMapBinding, SearchMapViewMo
} }
/** /**
* 获取在线建议搜索结果,得到requestSuggestion返回的搜索结果 * 获取在线建议搜索结果,得到requestSuggestion返回的搜索结果
* 【这里是第三方百度的东西】 * 【这里是第三方百度的东西】
......
...@@ -26,7 +26,8 @@ import java.io.InputStreamReader ...@@ -26,7 +26,8 @@ import java.io.InputStreamReader
* Created by 冯瑞雨 on 2021/7/13. * Created by 冯瑞雨 on 2021/7/13.
*/ */
class SearchMapViewModel(application: Application) : BaseViewModel(application) { class SearchMapViewModel(application: Application) : BaseViewModel(application) {
var index = 0;//0=境内 1=境外 //0=境内 1=境外
val index = MutableLiveData(0)
val positiondata: MutableLiveData<List<PositionBean>> = MutableLiveData() val positiondata: MutableLiveData<List<PositionBean>> = MutableLiveData()
//这里是走的一个点击回调,能够打开首页进行定位 //这里是走的一个点击回调,能够打开首页进行定位
val searchAfterItemBinding = ItemBinding.of<SearchAfterItem>(BR.viewModel, R.layout.item_search_after) val searchAfterItemBinding = ItemBinding.of<SearchAfterItem>(BR.viewModel, R.layout.item_search_after)
...@@ -76,58 +77,38 @@ class SearchMapViewModel(application: Application) : BaseViewModel(application) ...@@ -76,58 +77,38 @@ class SearchMapViewModel(application: Application) : BaseViewModel(application)
* 获取国外搜索信息【通过搜索内容进行查找】 * 获取国外搜索信息【通过搜索内容进行查找】
*/ */
fun searchabroad(position:String) { fun searchabroad(position:String) {
val vo = hashMapOf<String, Any>() BaiduModel.suggestionPlaceAbroad(lifecycleProvider
vo["query"] = "澳大利亚 海岸" ,position,"全球","json","tnFhCM9cTeTDZqNjRPVHbfzOz6AUPoEq")
vo["region"] = "全球" .safeSubscribe(
vo["output"] = "json" object : HttpSubscribeImpl<BaseResponse<PositionBean>>(
vo["ak"] = "tnFhCM9cTeTDZqNjRPVHbfzOz6AUPoEq"
// BaiduModel.suggestionPlaceAbroad(lifecycleProvider,vo).safeSubscribe(
BaiduModel.suggestionPlaceAbroad(lifecycleProvider,position,"全球","json","tnFhCM9cTeTDZqNjRPVHbfzOz6AUPoEq").safeSubscribe(
object : HttpSubscribeImpl<BaseArrayResponse<PositionBean>>(
this@SearchMapViewModel, true) { this@SearchMapViewModel, true) {
override fun onBusinessSuccess(response: BaseArrayResponse<PositionBean>) { override fun onBusinessSuccess(response: BaseResponse<PositionBean>) {
positiondata.value = response.result positiondata.value = response.resultList
println("mcg __ "+response.result) println("mcg __ "+response.resultList)
}
override fun onError(e: Throwable) {
} }
} }
) )
} }
/** /**
* 获取国内搜索信息 * 获取国内搜索信息
* "query"" = "北京"
* "region"" = "中国"
* "output"" = "json"
* "ak"" = "C56Qdc560TQKtQaavS0NTPUYupsZHspI"
*/ */
fun searchdomestic(position:String) { fun searchdomestic(position:String) {
val vo = hashMapOf<String, Any>() BaiduModel.suggestionPlaceDomestic(lifecycleProvider,position
vo["query"] = "北京" ,"中国","json","C56Qdc560TQKtQaavS0NTPUYupsZHspI")
vo["region"] = "中国" .safeSubscribe(
vo["output"] = "json" object : HttpSubscribeImpl<BaseResponse<PositionBean>>(
vo["ak"] = "C56Qdc560TQKtQaavS0NTPUYupsZHspI"
// BaiduModel.suggestionPlaceAbroad(lifecycleProvider,vo).safeSubscribe(
/*
http://api.map.baidu.com/place/v2/suggestion?
query=%E5%8C%97%E4%BA%AC
&region=%E5%85%A8%E5%9B%BD
&output=json
&page_size=50&
ak=C56Qdc560TQKtQaavS0NTPUYupsZHspI
*/
BaiduModel.suggestionPlaceDomestic(lifecycleProvider,position,"中国","json","C56Qdc560TQKtQaavS0NTPUYupsZHspI").safeSubscribe(
object : HttpSubscribeImpl<BaseArrayResponse<PositionBean>>(
this@SearchMapViewModel, true) { this@SearchMapViewModel, true) {
override fun onBusinessSuccess(response: BaseArrayResponse<PositionBean>) { override fun onBusinessSuccess(response: BaseResponse<PositionBean>) {
positiondata.value = response.result positiondata.value = response.resultList
println("mcg __ "+response.result) println("mcg __ "+response.result)
} }
override fun onError(e: Throwable) {
}
} }
) )
} }
......
...@@ -20,11 +20,11 @@ object BaiduModel { ...@@ -20,11 +20,11 @@ object BaiduModel {
// .execute(lifecycleProvider, BaiduApi.newInstance().suggestionPlaceAbroad(map)) // .execute(lifecycleProvider, BaiduApi.newInstance().suggestionPlaceAbroad(map))
// } // }
fun suggestionPlaceAbroad(lifecycleProvider: LifecycleProvider<Any>?, map: String,map2 :String,map3: String,map4: String): Observable<Response<BaseArrayResponse<PositionBean>>> { fun suggestionPlaceAbroad(lifecycleProvider: LifecycleProvider<Any>?, map: String,map2 :String,map3: String,map4: String): Observable<Response<BaseResponse<PositionBean>>> {
return BaiduHttpManager.getInstance() return BaiduHttpManager.getInstance()
.execute(lifecycleProvider, BaiduApi.newInstance().suggestionPlaceAbroad(map,map2,map3,map4)) .execute(lifecycleProvider, BaiduApi.newInstance().suggestionPlaceAbroad(map,map2,map3,map4))
} }
fun suggestionPlaceDomestic(lifecycleProvider: LifecycleProvider<Any>?, map: String,map2 :String,map3: String,map4: String): Observable<Response<BaseArrayResponse<PositionBean>>> { fun suggestionPlaceDomestic(lifecycleProvider: LifecycleProvider<Any>?, map: String,map2 :String,map3: String,map4: String): Observable<Response<BaseResponse<PositionBean>>> {
return BaiduHttpManager.getInstance() return BaiduHttpManager.getInstance()
.execute(lifecycleProvider, BaiduApi.newInstance().suggestionPlaceDomestic(map,map2,map3,map4)) .execute(lifecycleProvider, BaiduApi.newInstance().suggestionPlaceDomestic(map,map2,map3,map4))
} }
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginBottom="65dp" android:layout_marginBottom="65dp"
android:src="@mipmap/logo" /> android:src="@mipmap/ic_launcher_main" />
<LinearLayout <LinearLayout
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:id="@+id/ly_text" android:id="@+id/ly_text"
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
android:layout_height="70dp" android:layout_height="70dp"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp" android:layout_marginTop="50dp"
android:src="@mipmap/logo" /> android:src="@mipmap/ic_launcher_main" />
<LinearLayout <LinearLayout
......
...@@ -114,7 +114,7 @@ public class NotificationUtils extends ContextWrapper { ...@@ -114,7 +114,7 @@ public class NotificationUtils extends ContextWrapper {
//文本内容 //文本内容
builder.setContentText(content); builder.setContentText(content);
//小图标 //小图标
builder.setSmallIcon(R.mipmap.logo); builder.setSmallIcon(R.mipmap.ic_launcher_main);
//设置点击信息后自动清除通知 //设置点击信息后自动清除通知
builder.setAutoCancel(true); builder.setAutoCancel(true);
return builder; return builder;
...@@ -157,10 +157,10 @@ public class NotificationUtils extends ContextWrapper { ...@@ -157,10 +157,10 @@ public class NotificationUtils extends ContextWrapper {
//文本内容 //文本内容
builder.setContentText(content); builder.setContentText(content);
//小图标 //小图标
builder.setSmallIcon(R.mipmap.logo); builder.setSmallIcon(R.mipmap.ic_launcher_main);
//设置大图标,未设置时使用小图标代替,拉下通知栏显示的那个图标 //设置大图标,未设置时使用小图标代替,拉下通知栏显示的那个图标
//设置大图片 BitmpFactory.decodeResource(Resource res,int id) 根据给定的资源Id解析成位图 //设置大图片 BitmpFactory.decodeResource(Resource res,int id) 根据给定的资源Id解析成位图
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.logo)); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_main));
if (progress < 100) { if (progress < 100) {
//一种是有进度刻度的(false),一种是循环流动的(true) //一种是有进度刻度的(false),一种是循环流动的(true)
//设置为false,表示刻度,设置为true,表示流动 //设置为false,表示刻度,设置为true,表示流动
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
android:id="@+id/iv_image" android:id="@+id/iv_image"
android:layout_width="28dp" android:layout_width="28dp"
android:layout_height="28dp" android:layout_height="28dp"
android:src="@mipmap/logo" android:src="@mipmap/ic_launcher_main"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:visibility="gone" android:visibility="gone"
/> />
......
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