同步peko:完成地区选择器优化(调整地区数据、支持字母索引、有效展示当前地区)
This commit is contained in:
1
app/src/main/assets/hot_region.json
Normal file
1
app/src/main/assets/hot_region.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"name":"Taiwan","abbr":"TW","mcc":"466","code":"886"},{"name":"Hong Kong","abbr":"HK","mcc":"454","code":"852"},{"name":"Singapore","abbr":"SG","mcc":"525","code":"65"},{"name":"Malaysia","abbr":"MY","mcc":"502","code":"60"},{"name":"China","abbr":"CN","mcc":"460","code":"86"}]
|
1
app/src/main/assets/region.json
Normal file
1
app/src/main/assets/region.json
Normal file
File diff suppressed because one or more lines are too long
@@ -3,17 +3,19 @@ package com.chwl.app.ui.login
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter
|
||||
import com.chad.library.adapter.base.BaseViewHolder
|
||||
import com.netease.nim.uikit.StatusBarUtil
|
||||
import com.trello.rxlifecycle3.android.ActivityEvent
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.base.BaseViewBindingActivity
|
||||
import com.chwl.app.databinding.ActivityAreaCodeBinding
|
||||
import com.chwl.core.auth.AuthModel
|
||||
import com.chwl.core.auth.bean.AreaInfoBean
|
||||
import com.chwl.core.utils.CoreLogger
|
||||
import com.chwl.core.utils.net.BeanObserver
|
||||
import com.chwl.app.ui.widget.SideBarView
|
||||
import com.example.lib_utils.UiUtils
|
||||
import com.example.lib_utils.ktx.getColorById
|
||||
import com.yizhuan.xchat_android_core.region.RegionHelper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* 区号
|
||||
@@ -22,7 +24,9 @@ import com.chwl.core.utils.net.BeanObserver
|
||||
*/
|
||||
class AreaCodeActivity : BaseViewBindingActivity<ActivityAreaCodeBinding>() {
|
||||
|
||||
private val mCountries = ArrayList<AreaInfoBean>()
|
||||
private val regionRepository = RegionHelper()
|
||||
|
||||
private val adapter = RegionListAdapter()
|
||||
|
||||
companion object {
|
||||
const val COUNTRY_NUMBER = "country_number"
|
||||
@@ -39,55 +43,51 @@ class AreaCodeActivity : BaseViewBindingActivity<ActivityAreaCodeBinding>() {
|
||||
|
||||
override fun init() {
|
||||
initTitleBar(getString(R.string.select_area_code))
|
||||
initCountryData()
|
||||
initListView()
|
||||
initSideBar()
|
||||
loadData()
|
||||
}
|
||||
|
||||
private fun initCountryData() {
|
||||
val countryList = resources.getStringArray(R.array.country_code_list_ch)
|
||||
for (s in countryList) {
|
||||
val country = s.split("*").toTypedArray()
|
||||
val countryName = country[0]
|
||||
val countryNumber = country[1]
|
||||
val c = AreaInfoBean(
|
||||
name = countryName,
|
||||
phoneAreaCode = countryNumber
|
||||
)
|
||||
mCountries.add(c)
|
||||
private fun initSideBar() {
|
||||
binding.sideBarView.setTextColor(context.getColorById(R.color.color_5caaff))
|
||||
binding.sideBarView.setTextSize(UiUtils.dip2px(12f).toFloat())
|
||||
binding.sideBarView.setListener(object : SideBarView.Listener {
|
||||
override fun onSideBarScroll(word: String) {
|
||||
val index = adapter.data.indexOfFirst {
|
||||
it.itemType == RegionListAdapter.ITEM_TYPE_GROUP && it.groupName?.toString() == word
|
||||
}
|
||||
if (index >= 0) {
|
||||
binding.mRecyclerView.scrollToPosition(index)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSideBarScrollEnd() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadData() {
|
||||
lifecycleScope.launch {
|
||||
val list = regionRepository.getRegionSelectorList(RegionListAdapter.ITEM_TYPE_GROUP)
|
||||
withContext(Dispatchers.Main) {
|
||||
adapter.setNewData(list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initListView() {
|
||||
val mAdapter = object :
|
||||
BaseQuickAdapter<AreaInfoBean, BaseViewHolder>(R.layout.item_country) {
|
||||
override fun convert(helper: BaseViewHolder, item: AreaInfoBean) {
|
||||
helper.setText(R.id.tv_name, item.name)
|
||||
helper.setText(R.id.tv_country_code, "+${item.phoneAreaCode}")
|
||||
}
|
||||
}
|
||||
binding.mRecyclerView.adapter = mAdapter
|
||||
mAdapter.setNewData(mCountries)
|
||||
binding.mRecyclerView.adapter = adapter
|
||||
//返回国家
|
||||
mAdapter.setOnItemClickListener { adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int ->
|
||||
val country = mAdapter.data[position]
|
||||
adapter.setOnItemClickListener { adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int ->
|
||||
val region = this.adapter.getItem(position)
|
||||
if (region?.code.isNullOrEmpty()) {
|
||||
return@setOnItemClickListener
|
||||
}
|
||||
val intent = Intent()
|
||||
intent.putExtra(COUNTRY_NUMBER, "+${country.phoneAreaCode}")
|
||||
intent.putExtra(COUNTRY_NUMBER, region?.fullCode)
|
||||
setResult(RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
AuthModel.get()
|
||||
.areaCodeList
|
||||
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
||||
.subscribe(object : BeanObserver<List<AreaInfoBean>>() {
|
||||
override fun onErrorMsg(error: String) {
|
||||
CoreLogger.error("areaCode", error)
|
||||
}
|
||||
|
||||
override fun onSuccess(list: List<AreaInfoBean>) {
|
||||
mAdapter.setNewData(list)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun needSteepStateBar() = true
|
||||
@@ -97,5 +97,4 @@ class AreaCodeActivity : BaseViewBindingActivity<ActivityAreaCodeBinding>() {
|
||||
StatusBarUtil.transparencyBar(this)
|
||||
StatusBarUtil.StatusBarLightMode(this)
|
||||
}
|
||||
|
||||
}
|
@@ -23,6 +23,7 @@ import com.chwl.core.user.UserModel
|
||||
import com.chwl.core.user.bean.UserInfo
|
||||
import com.chwl.library.utils.NetworkUtils
|
||||
import com.chwl.library.utils.ResUtil
|
||||
import com.yizhuan.xchat_android_core.region.RegionHelper
|
||||
import io.reactivex.SingleObserver
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
@@ -50,6 +51,7 @@ class BindPhoneActivity : BaseViewBindingActivity<ActivityBindPhoneBinding>(),
|
||||
override fun init() {
|
||||
initTitleBar(getString(R.string.text_bind_phone))
|
||||
initListener()
|
||||
RegionHelper().loadRecommendRegion(lifecycle, binding.tvAreaCode)
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
|
@@ -34,6 +34,7 @@ import com.chwl.core.code.CodeType;
|
||||
import com.chwl.library.common.SpConstants;
|
||||
import com.chwl.library.common.util.SPUtils;
|
||||
import com.chwl.library.utils.TextWatcherWrapper;
|
||||
import com.yizhuan.xchat_android_core.region.RegionHelper;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@@ -90,6 +91,7 @@ public class LoginPasswordActivity extends BaseActivity {
|
||||
setContentView(R.layout.activity_login_password);
|
||||
EventBus.getDefault().register(this);
|
||||
initView();
|
||||
new RegionHelper().loadRecommendRegion(getLifecycle(), tvAreaCode);
|
||||
}
|
||||
|
||||
private void checkInput() {
|
||||
|
@@ -16,6 +16,7 @@ import com.chwl.app.databinding.ActivityLoginPhoneBinding
|
||||
import com.chwl.core.auth.AuthModel
|
||||
import com.chwl.core.auth.event.LoginEvent
|
||||
import com.chwl.core.code.CodeType
|
||||
import com.yizhuan.xchat_android_core.region.RegionHelper
|
||||
import io.reactivex.SingleObserver
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
@@ -43,6 +44,7 @@ class LoginPhoneActivity : BaseViewBindingActivity<ActivityLoginPhoneBinding>(),
|
||||
override fun init() {
|
||||
EventBus.getDefault().register(this)
|
||||
initListener()
|
||||
RegionHelper().loadRecommendRegion(lifecycle, binding.tvAreaCode)
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
|
32
app/src/main/java/com/chwl/app/ui/login/RegionListAdapter.kt
Normal file
32
app/src/main/java/com/chwl/app/ui/login/RegionListAdapter.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.chwl.app.ui.login
|
||||
|
||||
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
|
||||
import com.chad.library.adapter.base.BaseViewHolder
|
||||
import com.chwl.app.R
|
||||
import com.yizhuan.xchat_android_core.region.bean.RegionBean
|
||||
|
||||
/**
|
||||
* Created by Max on 2023/12/7 19:34
|
||||
* Desc:
|
||||
**/
|
||||
class RegionListAdapter:
|
||||
BaseMultiItemQuickAdapter<RegionBean, BaseViewHolder>(ArrayList<RegionBean>()) {
|
||||
|
||||
companion object {
|
||||
const val ITEM_TYPE_GROUP = 1
|
||||
}
|
||||
|
||||
init {
|
||||
addItemType(0, R.layout.region_item_def)
|
||||
addItemType(ITEM_TYPE_GROUP, R.layout.region_item_group)
|
||||
}
|
||||
|
||||
override fun convert(helper: BaseViewHolder, item: RegionBean?) {
|
||||
if (helper.itemViewType == ITEM_TYPE_GROUP) {
|
||||
helper.setText(R.id.tv_group, item?.groupName?.toString() ?: "")
|
||||
}
|
||||
helper.setText(R.id.tv_name, item?.name ?: "")
|
||||
helper.setText(R.id.tv_country_code, "+${item?.code}")
|
||||
}
|
||||
|
||||
}
|
@@ -23,6 +23,7 @@ import com.chwl.core.code.CodeType
|
||||
import com.chwl.core.user.UserModel
|
||||
import com.chwl.library.utils.ResUtil
|
||||
import com.chwl.library.utils.TextWatcherWrapper
|
||||
import com.yizhuan.xchat_android_core.region.RegionHelper
|
||||
import io.reactivex.SingleObserver
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
@@ -59,6 +60,7 @@ class ResetPasswordActivity : BaseViewBindingActivity<ActivityResetLoginPwdBindi
|
||||
// binding.etAccount.isEnabled = false
|
||||
// }
|
||||
initListener()
|
||||
RegionHelper().loadRecommendRegion(lifecycle, binding.tvAreaCode)
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
|
@@ -21,6 +21,7 @@ import com.chwl.core.code.CodeType
|
||||
import com.chwl.core.pay.PayModel
|
||||
import com.chwl.core.utils.net.BeanObserver
|
||||
import com.chwl.library.utils.ResUtil
|
||||
import com.yizhuan.xchat_android_core.region.RegionHelper
|
||||
|
||||
class VerifyPhoneActivity : BaseViewBindingActivity<ActivityVerifyPhoneBinding>(),
|
||||
View.OnClickListener, TextWatcher {
|
||||
@@ -53,6 +54,7 @@ class VerifyPhoneActivity : BaseViewBindingActivity<ActivityVerifyPhoneBinding>(
|
||||
resetPwd = intent.getBooleanExtra("resetPwd", false)
|
||||
|
||||
initListener()
|
||||
RegionHelper().loadRecommendRegion(lifecycle, binding.tvAreaCode)
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
|
146
app/src/main/java/com/chwl/app/ui/widget/SideBarView.kt
Normal file
146
app/src/main/java/com/chwl/app/ui/widget/SideBarView.kt
Normal file
@@ -0,0 +1,146 @@
|
||||
package com.chwl.app.ui.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Typeface
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewParent
|
||||
|
||||
|
||||
/**
|
||||
* Created by Max on 2023/12/8 10:43
|
||||
* Desc:字母索引
|
||||
**/
|
||||
class SideBarView : View {
|
||||
private var selectIndex = 0
|
||||
private var textSize = 0f
|
||||
private var textColor = 0
|
||||
private var textSizeFocus = 0f
|
||||
private var textColorFocus = 0
|
||||
|
||||
//标记 避免重复调用
|
||||
private var isDown = false
|
||||
|
||||
//这里也可以传入数组方式
|
||||
private var list = listOf(
|
||||
"A", "B", "C", "D", "E", "F", "G", "H", "I",
|
||||
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
|
||||
"W", "X", "Y", "Z", "#"
|
||||
)
|
||||
private var paint = Paint()
|
||||
|
||||
private var listener: Listener? = null
|
||||
|
||||
constructor(context: Context?) : super(context)
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
constructor(
|
||||
context: Context?,
|
||||
attrs: AttributeSet?,
|
||||
defStyleAttr: Int,
|
||||
defStyleRes: Int
|
||||
) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||
|
||||
fun setTextColor(textColor: Int, focusTextColor: Int = textColor) {
|
||||
this.textColor = textColor
|
||||
this.textColorFocus = focusTextColor
|
||||
}
|
||||
|
||||
fun setTextSize(textSize: Float, focusTextSize: Float = textSize) {
|
||||
this.textSize = textSize
|
||||
this.textSizeFocus = focusTextSize
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas?) {
|
||||
super.onDraw(canvas)
|
||||
paintText(canvas)
|
||||
}
|
||||
|
||||
private fun paintText(canvas: Canvas?) {
|
||||
//计算每一个字母的高度,总告诉除以字母集合的高度就可以
|
||||
val height: Int = height / list.size
|
||||
for (i in list.indices) {
|
||||
if (i == selectIndex) {
|
||||
paint.color = textColorFocus
|
||||
paint.textSize = textSizeFocus
|
||||
} else {
|
||||
paint.color = textColor
|
||||
paint.textSize = textSize
|
||||
}
|
||||
paint.isAntiAlias = true //设置抗锯齿
|
||||
paint.typeface = Typeface.DEFAULT_BOLD
|
||||
//计算每一个字母x轴
|
||||
val paintX = width / 2f - paint.measureText(list[i]) / 2
|
||||
//计算每一个字母Y轴
|
||||
val paintY = height * i + height
|
||||
//绘画出来这个TextView
|
||||
canvas?.drawText(list[i], paintX, paintY.toFloat(), paint)
|
||||
//画完一个以后重置画笔
|
||||
paint.reset()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
val parent: ViewParent?
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> {
|
||||
val index = (event.y / height * list.size).toInt()
|
||||
if (index >= 0 && index < list.size && selectIndex != index) {
|
||||
listener?.onSideBarScroll(list[index])
|
||||
selectIndex = index
|
||||
invalidate()
|
||||
//改变标记状态
|
||||
isDown = true
|
||||
}
|
||||
parent = getParent()
|
||||
parent?.requestDisallowInterceptTouchEvent(true)
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
listener?.onSideBarScrollEnd()
|
||||
//改变标记状态
|
||||
isDown = false
|
||||
parent = getParent()
|
||||
parent?.requestDisallowInterceptTouchEvent(false)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
//滚动位置
|
||||
fun onSideBarScroll(word: String)
|
||||
|
||||
//隐藏提示文本
|
||||
fun onSideBarScrollEnd()
|
||||
}
|
||||
|
||||
fun setListener(listener: Listener?) {
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* Item滚动 更新侧边栏字母
|
||||
*
|
||||
* @param word 字母
|
||||
*/
|
||||
fun onUpdateSideBarText(word: String?) {
|
||||
//手指没触摸才调用
|
||||
if (!isDown) {
|
||||
for (i in list.indices) {
|
||||
if (list[i] == word && selectIndex != i) {
|
||||
selectIndex = i
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -19,6 +19,7 @@
|
||||
android:id="@+id/mRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="@dimen/dp_10"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
@@ -27,4 +28,13 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/title_bar" />
|
||||
|
||||
<com.chwl.app.ui.widget.SideBarView
|
||||
android:id="@+id/sideBarView"
|
||||
android:layout_width="@dimen/dp_20"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginVertical="@dimen/dp_150"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title_bar" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
46
app/src/main/res/layout/region_item_group.xml
Normal file
46
app/src/main/res/layout/region_item_group.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="@color/color_666666"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="A" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:textColor="@color/text_title_color"
|
||||
android:textSize="14sp"
|
||||
tools:text="AAAAAA" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_country_code"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="@dimen/dp_15"
|
||||
android:text=""
|
||||
android:textColor="@color/text_title_color"
|
||||
android:textSize="14sp"
|
||||
tools:text="+1" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
@@ -67,175 +67,4 @@
|
||||
<item>夢幻花園CP位</item>
|
||||
<item>永恆愛情城堡CP位\n永恆CP頭飾\n永恆CP銘牌</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="country_code_list_ch" translatable="false">
|
||||
<item>Taiwan*886</item>
|
||||
<item>Hongkong*852</item>
|
||||
<item>Macao*853</item>
|
||||
<item>Malaysia*60</item>
|
||||
<item>Singapore*65</item>
|
||||
<item>India*91</item>
|
||||
<item>Indonesia*62</item>
|
||||
<item>ישראל *972</item>
|
||||
<item>الأردن *962</item>
|
||||
<item>البحرين *973</item>
|
||||
<item>الجزائر *213</item>
|
||||
<item>العراق *964</item>
|
||||
<item>الكويت *965</item>
|
||||
<item>المغرب *212</item>
|
||||
<item>المملكة,العربية,السعودية *966</item>
|
||||
<item>پاکستان *92</item>
|
||||
<item>عُمان *968</item>
|
||||
<item>قطر *974</item>
|
||||
<item>مصر *20</item>
|
||||
<item>Brasil*55</item>
|
||||
<item>Colombia*57</item>
|
||||
<item>Philippines*63</item>
|
||||
<item>افغانستان *93</item>
|
||||
<item>Shqipëri*355</item>
|
||||
<item>American samoa*1684</item>
|
||||
<item>Andorra*376</item>
|
||||
<item>Angola*244</item>
|
||||
<item>Anguilla*1264</item>
|
||||
<item>Antigua and Barbuda*1268</item>
|
||||
<item>Argentina*54</item>
|
||||
<item>Հայաստան*374</item>
|
||||
<item>Aruba*297</item>
|
||||
<item>Ascension,Island*247</item>
|
||||
<item>Australia*61</item>
|
||||
<item>Österreich*43</item>
|
||||
<item>Azərbaycan*994</item>
|
||||
<item>Bahamas*1242</item>
|
||||
<item>বাংলাদেশ*880</item>
|
||||
<item>Barbados*1246</item>
|
||||
<item>Беларусь*375</item>
|
||||
<item>België*32</item>
|
||||
<item>Belize*501</item>
|
||||
<item>Bénin*229</item>
|
||||
<item>Bermuda Is.*1441</item>
|
||||
<item>Bolivia*591</item>
|
||||
<item>Botswana*267</item>
|
||||
<item>Brunei*673</item>
|
||||
<item>България*359</item>
|
||||
<item>Burkina,Faso*226</item>
|
||||
<item>Myanmar*95</item>
|
||||
<item>Burundi*257</item>
|
||||
<item>China*86</item>
|
||||
<item>Cameroon*237</item>
|
||||
<item>Canada*1</item>
|
||||
<item>Kabu Verdi*238</item>
|
||||
<item>Cayman Islands*1345</item>
|
||||
<item>Central African Republic*236</item>
|
||||
<item>Chad*235</item>
|
||||
<item>Chile*56</item>
|
||||
<item>Congo*242</item>
|
||||
<item>Jamhuri ya Kidemokrasia ya Kongo*249</item>
|
||||
<item>Cook Is.*682</item>
|
||||
<item>Costa Rica*506</item>
|
||||
<item>Hrvatska*385</item>
|
||||
<item>Cuba*53</item>
|
||||
<item>Curacao*599</item>
|
||||
<item>Cyprus*357</item>
|
||||
<item>Czech Republic*420</item>
|
||||
<item>Denmark*45</item>
|
||||
<item>Djibouti*253</item>
|
||||
<item>Dominica*1767</item>
|
||||
<item>Dominica Rep.*1809</item>
|
||||
<item>Ecuador*593</item>
|
||||
<item>EI Salvador*503</item>
|
||||
<item>Guinea Ecuatorial*240</item>
|
||||
<item>Estonia*372</item>
|
||||
<item>Ethiopia*251</item>
|
||||
<item>Fiji*679</item>
|
||||
<item>Finland*358</item>
|
||||
<item>France*33</item>
|
||||
<item>French Guiana*594</item>
|
||||
<item>French Polynesia*689</item>
|
||||
<item>Gabon*241</item>
|
||||
<item>Gambia*220</item>
|
||||
<item>Georgia*995</item>
|
||||
<item>Germany*49</item>
|
||||
<item>Ghana*233</item>
|
||||
<item>Gibraltar*350</item>
|
||||
<item>Greece*30</item>
|
||||
<item>Kalaallit Nunaat*299</item>
|
||||
<item>Grenada*1473</item>
|
||||
<item>Guam*1671</item>
|
||||
<item>Guatemala*502</item>
|
||||
<item>Guinea*224</item>
|
||||
<item>Guyana*592</item>
|
||||
<item>Haiti*509</item>
|
||||
<item>Honduras*504</item>
|
||||
<item>Hungary*36</item>
|
||||
<item>Iceland*354</item>
|
||||
<item>ایران *98</item>
|
||||
<item>Ireland*353</item>
|
||||
<item>Italy*39</item>
|
||||
<item>Jamaica*1876</item>
|
||||
<item>Japan*81</item>
|
||||
<item>កម្ពុជា*855</item>
|
||||
<item>Kazakstan*327</item>
|
||||
<item>Kenya*254</item>
|
||||
<item>Kiribati*686</item>
|
||||
<item>Korea*82</item>
|
||||
<item>Kazakstan*996</item>
|
||||
<item>Laos*856</item>
|
||||
<item>Latvia*371</item>
|
||||
<item>لبنان *961</item>
|
||||
<item>Lesotho*266</item>
|
||||
<item>Liberia*231</item>
|
||||
<item>ليبيا *218</item>
|
||||
<item>Liechtenstein*423</item>
|
||||
<item>Lithuania*370</item>
|
||||
<item>Luxembourg*352</item>
|
||||
<item>Madagascar*261</item>
|
||||
<item>Malawi*265</item>
|
||||
<item>Maldives*960</item>
|
||||
<item>Mali*223</item>
|
||||
<item>Malta*356</item>
|
||||
<item>Mauritius*230</item>
|
||||
<item>Mexico*52</item>
|
||||
<item>Moldova, Republic of*373</item>
|
||||
<item>Monaco*377</item>
|
||||
<item>Mongolia*976</item>
|
||||
<item>Mozambique*258</item>
|
||||
<item>Namibia*264</item>
|
||||
<item>Nepal*977</item>
|
||||
<item>Netherlands*31</item>
|
||||
<item>New Zealand*64</item>
|
||||
<item>Nicaragua*505</item>
|
||||
<item>Nijar*227</item>
|
||||
<item>Nigeria*234</item>
|
||||
<item>Norway*47</item>
|
||||
<item>Panama*507</item>
|
||||
<item>Papua New Cuinea*675</item>
|
||||
<item>Paraguay*595</item>
|
||||
<item>Peru*51</item>
|
||||
<item>Poland*48</item>
|
||||
<item>Portugal*351</item>
|
||||
<item>Puerto Rico*1787</item>
|
||||
<item>Romania*40</item>
|
||||
<item>St.Lucia*1758</item>
|
||||
<item>San Marino*378</item>
|
||||
<item>Sao Tome and Principe*239</item>
|
||||
<item>Senegal*221</item>
|
||||
<item>Seychelles*248</item>
|
||||
<item>Sierra Leone*232</item>
|
||||
<item>Slovakia*421</item>
|
||||
<item>Slovenia*386</item>
|
||||
<item>Solomon Is*677</item>
|
||||
<item>Somali*252</item>
|
||||
<item>South Africa*27</item>
|
||||
<item>Spain*34</item>
|
||||
<item>Sri Lanka*94</item>
|
||||
<item>Sudan*249</item>
|
||||
<item>Suriname*597</item>
|
||||
<item>Swaziland*268</item>
|
||||
<item>Sweden*46</item>
|
||||
<item>Switzerland*41</item>
|
||||
<item>Syria*963</item>
|
||||
<item>Vanuatu*678</item>
|
||||
<item>British Virgin Islands*1284</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
@@ -27,7 +27,6 @@ import com.netease.nimlib.sdk.msg.MsgService;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.chwl.core.DemoCache;
|
||||
import com.chwl.core.R;
|
||||
import com.chwl.core.auth.bean.AreaInfoBean;
|
||||
import com.chwl.core.auth.entity.AccountInfo;
|
||||
import com.chwl.core.auth.entity.ThirdUserInfo;
|
||||
import com.chwl.core.auth.entity.TicketInfo;
|
||||
@@ -63,10 +62,6 @@ import com.chwl.library.utils.constant.PackageNameConstants;
|
||||
import com.chwl.library.utils.json.JsonUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import cn.sharesdk.framework.Platform;
|
||||
import io.reactivex.Single;
|
||||
@@ -1068,17 +1063,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
/**
|
||||
* 区号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Single<List<AreaInfoBean>> getAreaCodeList() {
|
||||
return api.getAreaCodeList()
|
||||
.compose(RxHelper.handleBeanData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
@@ -1340,14 +1324,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
@POST("phone/auth/bound")
|
||||
Single<ServiceResult<String>> boundAuthCode(@Field("authCode") String authCode);
|
||||
|
||||
/**
|
||||
* 获取地区码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET("areaInfo/list")
|
||||
Single<ServiceResult<List<AreaInfoBean>>> getAreaCodeList();
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
|
@@ -1,15 +0,0 @@
|
||||
package com.chwl.core.auth.bean
|
||||
|
||||
import lombok.Data
|
||||
|
||||
@Data
|
||||
class AreaInfoBean(
|
||||
val id: Long = 0L,
|
||||
val name: String? = null,
|
||||
val abbr: String? = null,
|
||||
val phoneAreaCode: String? = null,
|
||||
val seq: Int = 0,
|
||||
val status: Int = 0,
|
||||
val createTime: Long = 0L,
|
||||
val updateTime: Long = 0L
|
||||
)
|
@@ -0,0 +1,118 @@
|
||||
package com.yizhuan.xchat_android_core.region
|
||||
|
||||
import android.widget.TextView
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import com.example.lib_utils.AppUtils
|
||||
import com.example.lib_utils.TelephonyUtils
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.yizhuan.xchat_android_core.region.bean.RegionBean
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Created by Max on 2023/12/7 18:23
|
||||
* Desc:地区
|
||||
**/
|
||||
class RegionHelper {
|
||||
|
||||
fun loadRecommendRegion(lifecycle: Lifecycle, textView: TextView){
|
||||
lifecycle.coroutineScope.launch {
|
||||
RegionHelper().getCurrentOrDefRegion().let {
|
||||
textView.text = it.fullCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDefaultRegion(): RegionBean {
|
||||
return RegionBean(name = "Taiwan", abbr = "TW", mcc = "466", code = "886")
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前地区或默认
|
||||
*/
|
||||
private suspend fun getCurrentOrDefRegion(): RegionBean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
var operator = TelephonyUtils.getNetWorkOperator()
|
||||
if (operator.isNullOrEmpty()) {
|
||||
operator = TelephonyUtils.getSimOperator()
|
||||
}
|
||||
val mcc = operator?.take(3)
|
||||
val region = getAllRegionList().firstOrNull {
|
||||
it.mcc == mcc
|
||||
}
|
||||
region ?: getDefaultRegion()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地区选择器列表
|
||||
*/
|
||||
suspend fun getRegionSelectorList(groupItemType: Int): List<RegionBean> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val list = ArrayList<RegionBean>()
|
||||
list.addAll(getHotRegionList())
|
||||
var lastGroup: Char? = null
|
||||
list.addAll(getAllRegionList()
|
||||
.map {
|
||||
val firstName = it.name?.firstOrNull()?.uppercaseChar() ?: '#'
|
||||
if (firstName in 'A'..'Z') {
|
||||
it.groupName = firstName
|
||||
it.sortedBy = "$firstName${it.name?.uppercase()}"
|
||||
} else {
|
||||
it.groupName = '#'
|
||||
it.sortedBy = "${'Z' + 1}${it.name?.uppercase()}"
|
||||
}
|
||||
it
|
||||
}
|
||||
.sortedBy {
|
||||
it.sortedBy
|
||||
}.map {
|
||||
val groupName = it.groupName ?: '#'
|
||||
if (groupName != lastGroup) {
|
||||
it.itemType = groupItemType
|
||||
}
|
||||
lastGroup = groupName
|
||||
it
|
||||
}
|
||||
)
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门地区
|
||||
*/
|
||||
suspend fun getHotRegionList(): List<RegionBean> {
|
||||
return getRegionListFromAssets("hot_region.json")
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部地区
|
||||
*/
|
||||
suspend fun getAllRegionList(): List<RegionBean> {
|
||||
return getRegionListFromAssets("region.json")
|
||||
}
|
||||
|
||||
/**
|
||||
* 从资源文件中获取地区列表
|
||||
*/
|
||||
private fun getRegionListFromAssets(fileName: String): MutableList<RegionBean> {
|
||||
//获取IO流
|
||||
try {
|
||||
val inputStream: InputStream =
|
||||
AppUtils.getApp().applicationContext.assets.open(fileName)
|
||||
val json: String
|
||||
inputStream.use {
|
||||
json = it.bufferedReader().readText()
|
||||
}
|
||||
return Gson().fromJson(json, object : TypeToken<MutableList<RegionBean>>() {}.type)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return mutableListOf()
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package com.yizhuan.xchat_android_core.region.bean
|
||||
|
||||
import com.chad.library.adapter.base.entity.MultiItemEntity
|
||||
import com.netease.nim.uikit.business.ait.selector.model.ItemType
|
||||
|
||||
/**
|
||||
* Created by Max on 2023/12/7 18:48
|
||||
* Desc:地区
|
||||
**/
|
||||
data class RegionBean(
|
||||
// 名称(英文)
|
||||
val name: String?,
|
||||
// 简称
|
||||
val abbr: String?,
|
||||
// 区号
|
||||
val code: String?,
|
||||
// MCC
|
||||
val mcc: String?
|
||||
) : MultiItemEntity {
|
||||
|
||||
val fullCode: String?
|
||||
get() {
|
||||
if (code == null) {
|
||||
return null
|
||||
}
|
||||
return if (code.startsWith("+")) {
|
||||
code
|
||||
} else {
|
||||
"+$code"
|
||||
}
|
||||
}
|
||||
|
||||
// 本地分组用到
|
||||
var groupName: Char? = null
|
||||
|
||||
// 本地排序用到
|
||||
var sortedBy: String? = null
|
||||
|
||||
private var itemType: Int = 0
|
||||
|
||||
fun setItemType(itemType: Int) {
|
||||
this.itemType = itemType
|
||||
}
|
||||
|
||||
override fun getItemType(): Int {
|
||||
return itemType
|
||||
}
|
||||
}
|
@@ -14,6 +14,7 @@ object TelephonyUtils : ILog {
|
||||
* 是否为中国运营商(任意卡属于中国就为true)
|
||||
*/
|
||||
fun isChinaOperator(): Boolean {
|
||||
try {
|
||||
val tm =
|
||||
AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
|
||||
?: return false
|
||||
@@ -32,6 +33,9 @@ object TelephonyUtils : ILog {
|
||||
if (isChainOperator(tm.networkOperatorName)) {
|
||||
return true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -51,6 +55,7 @@ object TelephonyUtils : ILog {
|
||||
* 获取SIM运营商名称
|
||||
*/
|
||||
fun getSimOperator(): String? {
|
||||
try {
|
||||
val tm =
|
||||
AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
|
||||
?: return null
|
||||
@@ -63,13 +68,19 @@ object TelephonyUtils : ILog {
|
||||
logD("getOperatorName()方法获取的运营商名称为:${tm.simOperatorName} ")
|
||||
logD("通过getSimOperator()人为判断的运营商名称是: ${getOperatorName(simOperator)}")
|
||||
return simOperator
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网络运营商
|
||||
*/
|
||||
fun getNetWorkOperator(): String? {
|
||||
val tm = AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
|
||||
try {
|
||||
val tm =
|
||||
AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
|
||||
?: return null
|
||||
//用于判断拨号那张卡的运营商
|
||||
val networkOperator = tm.networkOperator
|
||||
@@ -78,6 +89,10 @@ object TelephonyUtils : ILog {
|
||||
logD("getNetworkOperatorName()方法获取的网络类型名称是: ${tm.networkOperatorName}")
|
||||
logD("通过getNetWorkOperator()人为判断的运营商名称是: ${getOperatorName(networkOperator)}")
|
||||
return tm.networkOperator
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user