Commit d7726323 authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :海外魔盒
[实现方案] :修改地址选择器
parent f01baad9
......@@ -51,7 +51,7 @@
<string name="box_detail_open_box_tips">FAIRNESS GUARANTEED</string>
<string name="box_detail_open_box_rule">Rule</string>
<string name="box_detail_open_box_test_play">TRY FOR FREE</string>
<string name="box_detail_open_box_re_pumping">重抽卡</string>
<string name="box_detail_open_box_re_pumping">reopen card</string>
<string name="box_detail_open_box_shop_pool">Items in this box</string>
<string name="box_detail_open_box_one_lottery_btn">Open</string>
<string name="box_detail_open_box_five_lottery_btn">Open 5x</string>
......
......@@ -10,10 +10,11 @@ import android.provider.ContactsContract
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.google.gson.Gson
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.box.AddressEntity
......@@ -22,7 +23,6 @@ import com.zxhl.cms.utils.Utils
import com.zxhl.main.R
import com.zxhl.main.page.contract.EditAddressContract
import com.zxhl.main.page.entity.AddressBean
import com.zxhl.main.page.entity.JsonBean
import com.zxhl.main.page.presenter.EditAddressPresenter
import kotlinx.android.synthetic.main.activity_layout_edit_address.*
import org.json.JSONArray
......@@ -36,7 +36,10 @@ class EditAddressActivity : BaseActivity(), EditAddressContract.View {
private var mPresenter: EditAddressPresenter? = null
private var defaultAddress: String = "0"
private var addressList: ArrayList<AddressBean> = ArrayList() //地址
private var addressList: ArrayList<AddressBean> = ArrayList() //城市
private var addressCountryList: ArrayList<String> = ArrayList() //国家
private var isInitSelect = true
override fun onClick(v: View?) {
......@@ -53,6 +56,7 @@ class EditAddressActivity : BaseActivity(), EditAddressContract.View {
override fun init() {
initCityData()
initSelect()
var username = intent?.data?.getQueryParameter("username") ?: ""
var mobile = intent?.data?.getQueryParameter("mobile") ?: ""
......@@ -75,14 +79,25 @@ class EditAddressActivity : BaseActivity(), EditAddressContract.View {
id_img_moren.setImageResource(R.drawable.icon_guan)
}
}
//国家选择
id_select_country.setOnClickListener {
isInitSelect = false
id_country_select_spinner.performClick()
}
//城市选择
id_select_city?.setOnClickListener {
hideKeyBoard()
// hideKeyBoard()
isInitSelect = false
id_city_select_spinner.performClick()
}
// id_select_country?.text = addressList[0].country
// id_select_city?.text = addressList[0].cityLis?.get(0)
id_edit_name?.setText(username)
id_edit_phone?.setText(mobile)
id_select_country?.text = addressList[0].country
id_select_city?.text = addressList[0].cityLis?.get(0)
id_edit_address1?.setText(address)
id_img_back?.setOnClickListener {
finish()
......@@ -97,11 +112,11 @@ class EditAddressActivity : BaseActivity(), EditAddressContract.View {
id_select_city.text.toString()
) || TextUtils.isEmpty(id_select_country.text.toString())
) {
Utils.showToast(AppContext.get(), "请完整填写信息")
// Utils.showToast(AppContext.get(), "请完整填写信息")
return@setOnClickListener
} else {
if (id_edit_phone.text.toString()?.length != 11) {
Utils.showToast(AppContext.get(), "请检查手机号码")
// Utils.showToast(AppContext.get(), "请检查手机号码")
return@setOnClickListener
}
enity = AddressEntity()
......@@ -234,27 +249,8 @@ class EditAddressActivity : BaseActivity(), EditAddressContract.View {
finish()
}
fun parseData(result: String?): ArrayList<JsonBean>? { //Gson 解析
val detail: ArrayList<JsonBean> = ArrayList()
try {
val data = JSONArray(result)
val gson = Gson()
for (i in 0 until data.length()) {
val entity = gson.fromJson(
data.optJSONObject(i).toString(),
JsonBean::class.java
)
detail.add(entity)
}
} catch (e: Exception) {
e.printStackTrace()
}
return detail
}
private fun initCityData() {
Log.d("wxw", "start")
//获取assets目录下的地址json文件数据
val addressJson = GetJsonDataUtil().getJson(this, "address.json")
......@@ -266,18 +262,73 @@ class EditAddressActivity : BaseActivity(), EditAddressContract.View {
val key = keys.next()
val value: JSONArray? = addressObj.optJSONArray(key)
var addressBean = AddressBean()
addressBean.country = key
var cityList = ArrayList<String>(value?.length() ?: 0)
if (value != null && value.length() > 0) {
for (index in 0 until value.length()) {
cityList.add(value.getString(index))
}
}
addressBean.country = key
addressBean.cityLis = cityList
addressCountryList.add(key)
addressList.add(addressBean)
}
Log.d("wxw", "end" + addressList.size)
}
private fun initSelect() {
val strAdapter: ArrayAdapter<String> =
ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, addressCountryList)
strAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
id_country_select_spinner.adapter = strAdapter
id_country_select_spinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
Log.d("wxw", " 1select")
if (!isInitSelect) {
id_select_country?.text = addressCountryList[position]
}
if (addressList[position].cityLis != null) {
initCitySelect(addressList[position].cityLis!!)
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {
Log.d("wxw", " 2select")
}
}
// if (defPos != -1) {
// id_country_select_spinner.setSelection(defPos)
// }
}
private fun initCitySelect(cityList: ArrayList<String>) {
val strAdapter: ArrayAdapter<String> =
ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cityList)
strAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
id_city_select_spinner.adapter = strAdapter
id_city_select_spinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
if (!isInitSelect){
id_select_city?.text = cityList[position]
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {
}
}
}
}
\ No newline at end of file
package com.zxhl.main.page.entity
import com.zxhl.main.page.entity.JsonBean.CityBean
/**
* @author (wangXuewei)
* @datetime 2022-03-08 16:30 GMT+8
......
package com.zxhl.main.page.entity;
/**
* @author (wangXuewei)
* @datetime 2022-03-08 16:15 GMT+8
* @detail :
*/
public class AllAddressBean {
}
......@@ -67,7 +67,7 @@
android:textColor="@color/color_333333"
android:textColorHint="#B0B0B0"
android:textCursorDrawable="@null"
android:textSize="15sp" />
android:textSize="13sp" />
</LinearLayout>
<!--电话-->
......@@ -193,10 +193,16 @@
android:layout_height="match_parent"
android:gravity="center_vertical"
android:hint="@string/Please_select"
android:textColorHint="#B0B0B0"
android:textColor="@color/color_333333"
android:textColorHint="#B0B0B0"
android:textSize="13sp" />
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/id_country_select_spinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:spinnerMode="dialog" />
</LinearLayout>
<!--城市-->
<LinearLayout
......@@ -221,10 +227,15 @@
android:layout_height="match_parent"
android:gravity="center_vertical"
android:hint="@string/Please_select"
android:textColorHint="#B0B0B0"
android:textColor="@color/color_333333"
android:textColorHint="#B0B0B0"
android:textSize="13sp" />
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/id_city_select_spinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:spinnerMode="dialog" />
</LinearLayout>
<!--填写省市-->
<LinearLayout
......
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