fix:调整RegionBean等错误包位置
This commit is contained in:
@@ -12,7 +12,7 @@ import com.chwl.app.databinding.ActivityAreaCodeBinding
|
||||
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 com.chwl.core.RegionHelper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
@@ -16,14 +16,13 @@ import com.trello.rxlifecycle3.android.ActivityEvent
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.base.BaseViewBindingActivity
|
||||
import com.chwl.app.databinding.ActivityBindPhoneBinding
|
||||
import com.chwl.app.ui.login.BindPhoneActivity
|
||||
import com.chwl.core.auth.AuthModel
|
||||
import com.chwl.core.code.CodeType
|
||||
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 com.chwl.core.RegionHelper
|
||||
import io.reactivex.SingleObserver
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
@@ -34,7 +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 com.chwl.core.RegionHelper;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
@@ -16,7 +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 com.chwl.core.RegionHelper
|
||||
import io.reactivex.SingleObserver
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
@@ -3,7 +3,7 @@ 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
|
||||
import com.chwl.core.bean.RegionBean
|
||||
|
||||
/**
|
||||
* Created by Max on 2023/12/7 19:34
|
||||
|
@@ -23,7 +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 com.chwl.core.RegionHelper
|
||||
import io.reactivex.SingleObserver
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
@@ -21,7 +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
|
||||
import com.chwl.core.RegionHelper
|
||||
|
||||
class VerifyPhoneActivity : BaseViewBindingActivity<ActivityVerifyPhoneBinding>(),
|
||||
View.OnClickListener, TextWatcher {
|
||||
|
118
core/src/main/java/com/chwl/core/RegionHelper.kt
Normal file
118
core/src/main/java/com/chwl/core/RegionHelper.kt
Normal file
@@ -0,0 +1,118 @@
|
||||
package com.chwl.core
|
||||
|
||||
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.chwl.core.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()
|
||||
}
|
||||
}
|
47
core/src/main/java/com/chwl/core/bean/RegionBean.kt
Normal file
47
core/src/main/java/com/chwl/core/bean/RegionBean.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.chwl.core.bean
|
||||
|
||||
import com.chad.library.adapter.base.entity.MultiItemEntity
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user