|
|
@@ -24,7 +24,6 @@ import androidx.core.content.ContextCompat
|
|
|
import androidx.fragment.app.Fragment
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import com.example.modifier.Global
|
|
|
-import com.example.modifier.Global.load
|
|
|
import com.example.modifier.Global.save
|
|
|
import com.example.modifier.Global.saveServer
|
|
|
import com.example.modifier.Global.servers
|
|
|
@@ -93,6 +92,13 @@ class SettingsFragment : Fragment() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ override fun onResume() {
|
|
|
+ super.onResume()
|
|
|
+ lifecycleScope.launch {
|
|
|
+ loadConfigs()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override fun onCreateView(
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
savedInstanceState: Bundle?
|
|
|
@@ -167,56 +173,63 @@ class SettingsFragment : Fragment() {
|
|
|
Utils.makeLoadingButton(context, binding.btnRequest)
|
|
|
binding.btnRequest.isEnabled = false
|
|
|
|
|
|
- val response: HttpResponse
|
|
|
- try {
|
|
|
- response = KtorClient.put(
|
|
|
- RcsNumberApi()
|
|
|
- ) {
|
|
|
- contentType(ContentType.Application.Json)
|
|
|
- setBody(
|
|
|
- RcsNumberRequest(
|
|
|
- deviceId = Utils.getUniqueID()
|
|
|
+ withContext(Dispatchers.IO) req@{
|
|
|
+ val response: HttpResponse
|
|
|
+ try {
|
|
|
+ response = KtorClient.put(
|
|
|
+ RcsNumberApi()
|
|
|
+ ) {
|
|
|
+ contentType(ContentType.Application.Json)
|
|
|
+ setBody(
|
|
|
+ RcsNumberRequest(
|
|
|
+ deviceId = Utils.getUniqueID()
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
- }
|
|
|
- } catch (e: Exception) {
|
|
|
- MaterialAlertDialogBuilder(requireContext())
|
|
|
- .setTitle("Error")
|
|
|
- .setMessage(e.message)
|
|
|
- .setPositiveButton("OK") { dialog: DialogInterface, which: Int ->
|
|
|
- dialog.dismiss()
|
|
|
}
|
|
|
- .show()
|
|
|
- binding.btnRequest.isEnabled = true
|
|
|
- binding.btnRequest.text = "Request"
|
|
|
- binding.btnRequest.icon = null
|
|
|
- return@launch
|
|
|
- }
|
|
|
- Log.i(TAG, "response: ${response.bodyAsText()}")
|
|
|
- var res = response.body<RcsNumberResponse>()
|
|
|
- val id = res.id
|
|
|
- val expiryTime = res.expiryTime
|
|
|
- val number = res.number
|
|
|
- val mcc = res.mcc
|
|
|
- val mnc = res.mnc
|
|
|
- val country = res.country
|
|
|
- val areaCode = res.areaCode
|
|
|
- val iccid = Global.genICCID(mnc, areaCode)
|
|
|
- val imsi =
|
|
|
- mcc + mnc + RandomStringUtils.randomNumeric(15 - mcc.length - mnc.length)
|
|
|
- val imei = Utils.generateIMEI()
|
|
|
- save(TelephonyConfig(number, mcc, mnc, iccid, imsi, imei, country, areaCode))
|
|
|
-
|
|
|
- val telephonyConfig = Global.telephonyConfig
|
|
|
- binding.etNumber.setText(telephonyConfig.number)
|
|
|
- binding.etMcc.setText(telephonyConfig.mcc)
|
|
|
- binding.etMnc.setText(telephonyConfig.mnc)
|
|
|
- binding.etIccid.setText(telephonyConfig.iccid)
|
|
|
- binding.etImsi.setText(telephonyConfig.imsi)
|
|
|
- binding.etImei.setText(telephonyConfig.imei)
|
|
|
- binding.etCountry.setText(telephonyConfig.country)
|
|
|
- binding.etAreaCode.setText(telephonyConfig.areaCode)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ MaterialAlertDialogBuilder(requireContext())
|
|
|
+ .setTitle("Error")
|
|
|
+ .setMessage(e.message)
|
|
|
+ .setPositiveButton("OK") { dialog: DialogInterface, which: Int ->
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ .show()
|
|
|
+ binding.btnRequest.isEnabled = true
|
|
|
+ binding.btnRequest.text = "Request"
|
|
|
+ binding.btnRequest.icon = null
|
|
|
+ }
|
|
|
+ return@req
|
|
|
+ }
|
|
|
+ Log.i(TAG, "response: ${response.bodyAsText()}")
|
|
|
+ val res = response.body<RcsNumberResponse>()
|
|
|
+ val number = res.number
|
|
|
+ val mcc = res.mcc
|
|
|
+ val mnc = res.mnc
|
|
|
+ val country = res.country
|
|
|
+ val areaCode = res.areaCode
|
|
|
+ val iccid = Global.genICCID(mnc, areaCode)
|
|
|
+ val imsi =
|
|
|
+ mcc + mnc + RandomStringUtils.randomNumeric(15 - mcc.length - mnc.length)
|
|
|
+ val imei = Utils.generateIMEI()
|
|
|
+ save(
|
|
|
+ TelephonyConfig(
|
|
|
+ number,
|
|
|
+ mcc,
|
|
|
+ mnc,
|
|
|
+ iccid,
|
|
|
+ imsi,
|
|
|
+ imei,
|
|
|
+ country,
|
|
|
+ areaCode,
|
|
|
+ false,
|
|
|
+ res.carrierId,
|
|
|
+ res.carrierName
|
|
|
+ )
|
|
|
+ )
|
|
|
|
|
|
+ loadConfigs()
|
|
|
+ }
|
|
|
binding.btnRequest.icon = null
|
|
|
binding.btnRequest.isEnabled = true
|
|
|
binding.btnRequest.text = "Request"
|
|
|
@@ -308,10 +321,17 @@ class SettingsFragment : Fragment() {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ lifecycleScope.launch {
|
|
|
+ loadConfigs()
|
|
|
+ }
|
|
|
|
|
|
- executor.execute {
|
|
|
- load()
|
|
|
- handler.post {
|
|
|
+ return binding.root
|
|
|
+ }
|
|
|
+
|
|
|
+ private suspend fun loadConfigs() {
|
|
|
+ withContext(Dispatchers.IO) {
|
|
|
+ Global.load()
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
binding.etServer.setText(Global.serverUrl)
|
|
|
binding.etServer.setSimpleItems(servers.toTypedArray<String>())
|
|
|
binding.etDeviceLabel.setText(Global.name)
|
|
|
@@ -324,38 +344,10 @@ class SettingsFragment : Fragment() {
|
|
|
binding.etImei.setText(telephonyConfig.imei)
|
|
|
binding.etCountry.setText(telephonyConfig.country)
|
|
|
binding.etAreaCode.setText(telephonyConfig.areaCode)
|
|
|
+ binding.etCarrierId.setText(telephonyConfig.carrierId)
|
|
|
+ binding.etCarrierName.setText(telephonyConfig.carrierName)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- CoroutineScope(Dispatchers.IO).launch {
|
|
|
- try {
|
|
|
- val response = KtorClient.post(
|
|
|
- ChannelApi()
|
|
|
- ) {
|
|
|
- contentType(ContentType.Application.Json)
|
|
|
- }
|
|
|
- Log.i(TAG, "response: ${response.bodyAsText()}")
|
|
|
- val res = response.body<GetChannelListResponse>()
|
|
|
- channels = res.items
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- if (isAdded) {
|
|
|
- binding.etChannel.threshold = 1000
|
|
|
- binding.etChannel.setSimpleItems(res.items.map { "${it.country}-${it.mcc}-${it.mnc}-${it.operator}" }
|
|
|
- .toTypedArray())
|
|
|
- binding.etChannel.setOnItemClickListener { parent, view, position, id ->
|
|
|
- val channel = channels[position]
|
|
|
- binding.etMcc.setText(channel.mcc)
|
|
|
- binding.etMnc.setText(channel.mnc)
|
|
|
- binding.etCountry.setText(channel.country)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e: Exception) {
|
|
|
- e.printStackTrace()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return binding.root
|
|
|
}
|
|
|
|
|
|
private fun onSave() {
|
|
|
@@ -371,7 +363,10 @@ class SettingsFragment : Fragment() {
|
|
|
binding.etImsi.text.toString(),
|
|
|
binding.etImei.text.toString(),
|
|
|
binding.etCountry.text.toString(),
|
|
|
- binding.etAreaCode.text.toString()
|
|
|
+ binding.etAreaCode.text.toString(),
|
|
|
+ false,
|
|
|
+ binding.etCarrierId.text.toString(),
|
|
|
+ binding.etCarrierName.text.toString()
|
|
|
)
|
|
|
)
|
|
|
handler.post {
|