Commit eea467fc authored by fengruiyu's avatar fengruiyu

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

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