地区选择

This commit is contained in:
itgaojian163 2020-07-21 13:17:29 +08:00
parent 8190653f70
commit 6ab7a40a63
12 changed files with 696 additions and 5 deletions

View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/gray_f1" />
<solid android:color="@color/white" />
<stroke
android:width="1dp"
android:color="@color/gray_f1" />
<corners android:radius="80dp" />
</shape>

View File

@ -57,6 +57,8 @@ dependencies {
implementation "com.scwang.smartrefresh:SmartRefreshLayout:${rootProject.ext.gSmartRefreshLayoutVersion}"
//
implementation 'q.rorbin:badgeview:1.1.3'
//
implementation 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'
//Rxjava
implementation "io.reactivex.rxjava2:rxjava:${rootProject.ext.gRxJavaVersion}"
implementation "io.reactivex.rxjava2:rxandroid:${rootProject.ext.gRxAndroid}"

View File

@ -1,27 +1,305 @@
package com.tengshisoft.mudulemain.cultural.activitys.base;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.beloo.widget.chipslayoutmanager.ChipsLayoutManager;
import com.sucstepsoft.cm_utils.constant.PathConfig;
import com.sucstepsoft.cm_utils.core.retrofit_net.RetrofitManager;
import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity;
import com.sucstepsoft.cm_utils.core.widget.base.BaseRecyclerAdapter;
import com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView;
import com.sucstepsoft.cm_utils.utils.ToastUtils;
import com.sucstepsoft.cm_utils.utils.UIUtil;
import com.sucstepsoft.cm_utils.utils.UserLgUtils;
import com.tengshisoft.mudulemain.R;
import com.tengshisoft.mudulemain.R2;
import com.tengshisoft.mudulemain.cultural.adapter.AreaListAdapter;
import com.tengshisoft.mudulemain.cultural.beans.AreaListBean;
import com.tengshisoft.mudulemain.cultural.net.HomeApi;
import java.util.ArrayList;
import java.util.List;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
@Route(path = PathConfig.PATH_MODULE_MAIN_CHOOSE_CITY)
public class ChooseCityActivity extends BaseActivity {
@BindView(R2.id.tv_search)
TypeFaceTextView mTvSearch;
@BindView(R2.id.tv_current_area)
TextView mTvCurrentArea;
@BindView(R2.id.rlv_area_1_content)
RecyclerView mRlvArea1Content;
@BindView(R2.id.tv_area_1_hint)
TextView mTvArea1Hint;
@BindView(R2.id.rlv_area_2_content)
RecyclerView mRlvArea2Content;
@BindView(R2.id.tv_area_2_hint)
TextView mTvArea2Hint;
@BindView(R2.id.rlv_area_3_content)
RecyclerView mRlvArea3Content;
@BindView(R2.id.tv_area_3_hint)
TextView mTvArea3Hint;
@BindView(R2.id.rlv_area_4_content)
RecyclerView mRlvArea4Content;
@BindView(R2.id.tv_area_4_hint)
TextView mTvArea4Hint;
@BindView(R2.id.nsv_content)
NestedScrollView mNsvContent;
private Unbinder mBind;
private String mCurrentCityName = "";
private String mCurrentCityCode = "";
private AreaListAdapter mArea1Adapter;
private AreaListAdapter mArea2Adapter;
private AreaListAdapter mArea3Adapter;
private AreaListAdapter mArea4Adapter;
private List<AreaListBean> mArea1List;
private List<AreaListBean> mArea2List;
private List<AreaListBean> mArea3List;
private List<AreaListBean> mArea4List;
@Override
public void initData() {
mBind = ButterKnife.bind(this);
mTvBaseTitle.setText("地区选择");
mTvPublish.setVisibility(View.VISIBLE);
mTvPublish.setText("确定");
mTvCurrentArea.setText(mCurrentCityName);
mTvPublish.setOnClickListener(v -> doChooseArea());
mCurrentCityName = UserLgUtils.getCurrentCity();
mTvCurrentArea.setText(mCurrentCityName);
mCurrentCityCode = UserLgUtils.getCurrentCityCode();
refreshView(STATE_LOAD_SUCCESS);
ChipsLayoutManager area1Manager = ChipsLayoutManager.newBuilder(mActivity)
.setOrientation(ChipsLayoutManager.HORIZONTAL)
.build();
ChipsLayoutManager area2Manager = ChipsLayoutManager.newBuilder(mActivity)
.setOrientation(ChipsLayoutManager.HORIZONTAL)
.build();
ChipsLayoutManager area3Manager = ChipsLayoutManager.newBuilder(mActivity)
.setOrientation(ChipsLayoutManager.HORIZONTAL)
.build();
ChipsLayoutManager area4Manager = ChipsLayoutManager.newBuilder(mActivity)
.setOrientation(ChipsLayoutManager.HORIZONTAL)
.build();
mArea1List = new ArrayList<>();
mArea2List = new ArrayList<>();
mArea3List = new ArrayList<>();
mArea4List = new ArrayList<>();
mRlvArea1Content.setLayoutManager(area1Manager);
mRlvArea2Content.setLayoutManager(area2Manager);
mRlvArea3Content.setLayoutManager(area3Manager);
mRlvArea4Content.setLayoutManager(area4Manager);
mArea1Adapter = new AreaListAdapter(mActivity, mArea1List);
mArea2Adapter = new AreaListAdapter(mActivity, mArea2List);
mArea3Adapter = new AreaListAdapter(mActivity, mArea3List);
mArea4Adapter = new AreaListAdapter(mActivity, mArea4List);
mRlvArea1Content.setAdapter(mArea1Adapter);
mRlvArea2Content.setAdapter(mArea2Adapter);
mRlvArea3Content.setAdapter(mArea3Adapter);
mRlvArea4Content.setAdapter(mArea4Adapter);
mArea1Adapter.addOnItemClickListener(areaListBean -> {
getArea2List("");
});
mArea2Adapter.addOnItemClickListener(areaListBean -> {
getArea3List("");
});
mArea3Adapter.addOnItemClickListener(areaListBean -> {
getArea4List("");
});
mArea4Adapter.addOnItemClickListener(areaListBean -> {
//TODO 进行选择
});
}
private void getArea1List() {
ProgressDialog dialog = UIUtil.initDialog(mActivity, "加载中...");
dialog.show();
RetrofitManager.getInstance()
.create(HomeApi.class)
.getAreaListByPid("")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<AreaListBean>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(AreaListBean areaListBean) {
dialog.dismiss();
mArea2List.clear();
mArea2Adapter.setData(mArea2List);
mTvArea2Hint.setVisibility(View.VISIBLE);
mTvArea2Hint.setText("请选择");
mArea3List.clear();
mArea3Adapter.setData(mArea2List);
mTvArea3Hint.setVisibility(View.VISIBLE);
mTvArea3Hint.setText("请选择");
mArea4List.clear();
mArea4Adapter.setData(mArea2List);
mTvArea4Hint.setVisibility(View.VISIBLE);
mTvArea4Hint.setText("请选择");
}
@Override
public void onError(Throwable e) {
dialog.dismiss();
}
@Override
public void onComplete() {
}
});
}
private void getArea2List(String id) {
ProgressDialog dialog = UIUtil.initDialog(mActivity, "加载中...");
dialog.show();
RetrofitManager.getInstance()
.create(HomeApi.class)
.getAreaListByPid(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<AreaListBean>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(AreaListBean areaListBean) {
dialog.dismiss();
mArea3List.clear();
mArea3Adapter.setData(mArea2List);
mTvArea3Hint.setVisibility(View.VISIBLE);
mTvArea3Hint.setText("请选择");
mArea4List.clear();
mArea4Adapter.setData(mArea2List);
mTvArea4Hint.setVisibility(View.VISIBLE);
mTvArea4Hint.setText("请选择");
}
@Override
public void onError(Throwable e) {
dialog.dismiss();
}
@Override
public void onComplete() {
}
});
}
private void getArea3List(String id) {
ProgressDialog dialog = UIUtil.initDialog(mActivity, "加载中...");
dialog.show();
RetrofitManager.getInstance()
.create(HomeApi.class)
.getAreaListByPid(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<AreaListBean>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(AreaListBean areaListBean) {
dialog.dismiss();
mArea4List.clear();
mArea4Adapter.setData(mArea2List);
mTvArea4Hint.setVisibility(View.VISIBLE);
mTvArea4Hint.setText("请选择");
}
@Override
public void onError(Throwable e) {
dialog.dismiss();
}
@Override
public void onComplete() {
}
});
}
private void getArea4List(String id) {
ProgressDialog dialog = UIUtil.initDialog(mActivity, "加载中...");
dialog.show();
RetrofitManager.getInstance()
.create(HomeApi.class)
.getAreaListByPid(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<AreaListBean>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(AreaListBean areaListBean) {
dialog.dismiss();
mArea4List = new ArrayList<>();
mArea4Adapter.setData(mArea4List);
}
@Override
public void onError(Throwable e) {
dialog.dismiss();
}
@Override
public void onComplete() {
}
});
}
/**
* 确定选择
*/
private void doChooseArea() {
if (TextUtils.isEmpty(mCurrentCityCode)) {
ToastUtils.showShort("请选择地区");
} else {
Intent intent = new Intent();
intent.putExtra("chooseCity", mCurrentCityName);
intent.putExtra("chooseCityCode", mCurrentCityCode);
setResult(333, intent);
finish();
}
}
@Override
@ -36,4 +314,6 @@ public class ChooseCityActivity extends BaseActivity {
protected int setLayoutId() {
return R.layout.activity_choose_city;
}
}

View File

@ -0,0 +1,37 @@
package com.tengshisoft.mudulemain.cultural.adapter;
import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.sucstepsoft.cm_utils.core.widget.base.BaseRecyclerAdapter;
import com.tengshisoft.mudulemain.R;
import com.tengshisoft.mudulemain.cultural.beans.AreaListBean;
import com.tengshisoft.mudulemain.cultural.holder.AreaHolder;
import java.util.List;
/**
* 作者: adam
* 日期: 2020/7/21 - 10:56 AM
* 邮箱: itgaojian@163.com
* 描述:
*/
public class AreaListAdapter extends BaseRecyclerAdapter<AreaListBean, AreaHolder> {
public AreaListAdapter(Context ctx, List<AreaListBean> list) {
super(ctx, list);
}
@Override
public AreaHolder createHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_area_layout, parent, false);
return new AreaHolder(itemView);
}
@Override
public void bindHolder(AreaHolder areaHolder, int i) {
}
}

View File

@ -0,0 +1,19 @@
package com.tengshisoft.mudulemain.cultural.beans;
/**
* 作者: adam
* 日期: 2020/7/21 - 10:49 AM
* 邮箱: itgaojian@163.com
* 描述:
*/
public class AreaListBean {
private boolean checkEd;
public boolean isCheckEd() {
return checkEd;
}
public void setCheckEd(boolean checkEd) {
this.checkEd = checkEd;
}
}

View File

@ -0,0 +1,24 @@
package com.tengshisoft.mudulemain.cultural.holder;
import android.view.View;
import android.widget.TextView;
import com.tengshisoft.mudulemain.R;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
/**
* 作者: adam
* 日期: 2020/7/21 - 10:56 AM
* 邮箱: itgaojian@163.com
* 描述:
*/
public class AreaHolder extends RecyclerView.ViewHolder {
public TextView mTvName;
public AreaHolder(@NonNull View itemView) {
super(itemView);
mTvName = itemView.findViewById(R.id.tv_name);
}
}

View File

@ -5,6 +5,7 @@ import com.tengshisoft.moduleactivity.beans.ActivityListBeans;
import com.tengshisoft.modulecultural.bean.CulturalLiveBean;
import com.tengshisoft.modulecultural.bean.LegacyListBean;
import com.tengshisoft.moduleplace.beans.PlaceListBean;
import com.tengshisoft.mudulemain.cultural.beans.AreaListBean;
import com.tengshisoft.mudulemain.cultural.beans.BaseUserBean;
import com.tengshisoft.mudulemain.cultural.beans.CommentListBean;
import com.tengshisoft.mudulemain.cultural.beans.NewsItemBean;
@ -236,4 +237,8 @@ public interface HomeApi {
@Headers({"base_url_name:live", "Content-Type:application/json", "Accept:application/json"})
@GET("app/liveplan/listpageliveplanrelease")
Observable<CulturalLiveBean> getLiveRecord(@Query("page") String page, @Query("rows") String rows);
@Headers({"Content-Type:application/json", "Accept:application/json"})
@GET("app/liveplan/listpageliveplanrelease")
Observable<AreaListBean> getAreaListByPid(@Query("parentId") String pId);
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_red_line_ra_2" android:state_selected="true" />
<item android:drawable="@drawable/shape_gray_line_ra_2" />
</selector>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/gray_BA" />
<corners android:radius="3dp" />
</shape>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/app_title" />
<corners android:radius="3dp" />
</shape>

View File

@ -4,6 +4,284 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
tools:context=".cultural.activitys.base.ChooseCityActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingRight="10dp"
android:paddingBottom="5dp">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@drawable/shape_search_input_box"
android:hint="请输入地区名称"
android:padding="5dp"
android:textSize="15sp" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:id="@+id/tv_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/sel_btn_activity_sign_up_no_ra"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:text="搜索"
android:textColor="@color/col_verify_text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nsv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
<View
android:layout_width="3dp"
android:layout_height="14dp"
android:background="@color/app_title" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:text="当前选择"
android:textColor="#242424"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_current_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/shape_search_input_box"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:textColor="@color/black"
android:textSize="16sp"
tools:text="呼和浩特" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
<View
android:layout_width="3dp"
android:layout_height="14dp"
android:background="@color/app_title" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:text="省、自治区、直辖市、特别行政区"
android:textColor="#242424"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rlv_area_1_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/tv_area_1_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="请选择"
android:textSize="16sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
<View
android:layout_width="3dp"
android:layout_height="14dp"
android:background="@color/app_title" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:text="地级市、地区、自治州、盟"
android:textColor="#242424"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rlv_area_2_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/tv_area_2_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="请选择"
android:textSize="16sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
<View
android:layout_width="3dp"
android:layout_height="14dp"
android:background="@color/app_title" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:text="市辖区、县级市、县、自治县、旗、自治旗、特区、林区"
android:textColor="#242424"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rlv_area_3_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/tv_area_3_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="请选择"
android:textSize="16sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
<View
android:layout_width="3dp"
android:layout_height="14dp"
android:background="@color/app_title" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:text="街道、镇、乡、民族乡、苏木、民族苏木、县辖区"
android:textColor="#242424"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rlv_area_4_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/tv_area_4_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="请选择"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/sel_line_ra_3"
android:clickable="true"
android:focusable="true"
android:paddingLeft="5dp"
android:paddingTop="3dp"
android:paddingRight="5dp"
android:paddingBottom="3dp"
tools:text="梅里斯达斡尔族区" />
</LinearLayout>