|
@@ -12,7 +12,6 @@ import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
|
-import androidx.core.content.ContextCompat
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.Fragment
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import com.example.modifier.Global
|
|
import com.example.modifier.Global
|
|
@@ -26,26 +25,32 @@ import com.example.modifier.R
|
|
|
import com.example.modifier.Utils
|
|
import com.example.modifier.Utils
|
|
|
import com.example.modifier.databinding.FragmentSettingsBinding
|
|
import com.example.modifier.databinding.FragmentSettingsBinding
|
|
|
import com.example.modifier.http.KtorClient
|
|
import com.example.modifier.http.KtorClient
|
|
|
-import com.example.modifier.http.RcsNumberApi
|
|
|
|
|
|
|
+import com.example.modifier.http.api.ChannelApi
|
|
|
|
|
+import com.example.modifier.http.api.RcsNumberApi
|
|
|
import com.example.modifier.http.request.RcsNumberRequest
|
|
import com.example.modifier.http.request.RcsNumberRequest
|
|
|
|
|
+import com.example.modifier.http.response.GetChannelListResponse
|
|
|
import com.example.modifier.http.response.RcsNumberResponse
|
|
import com.example.modifier.http.response.RcsNumberResponse
|
|
|
|
|
+import com.example.modifier.model.Channel
|
|
|
import com.example.modifier.model.TelephonyConfig
|
|
import com.example.modifier.model.TelephonyConfig
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
-import com.google.gson.Gson
|
|
|
|
|
import io.ktor.client.call.body
|
|
import io.ktor.client.call.body
|
|
|
import io.ktor.client.plugins.resources.get
|
|
import io.ktor.client.plugins.resources.get
|
|
|
import io.ktor.client.plugins.resources.put
|
|
import io.ktor.client.plugins.resources.put
|
|
|
|
|
+import io.ktor.client.plugins.resources.post
|
|
|
|
|
+import io.ktor.client.request.post
|
|
|
import io.ktor.client.request.setBody
|
|
import io.ktor.client.request.setBody
|
|
|
|
|
+import io.ktor.client.statement.bodyAsText
|
|
|
import io.ktor.http.ContentType
|
|
import io.ktor.http.ContentType
|
|
|
import io.ktor.http.contentType
|
|
import io.ktor.http.contentType
|
|
|
|
|
+import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
import kotlinx.coroutines.withTimeout
|
|
import kotlinx.coroutines.withTimeout
|
|
|
import org.apache.commons.lang3.RandomStringUtils
|
|
import org.apache.commons.lang3.RandomStringUtils
|
|
|
import org.apache.commons.lang3.StringUtils
|
|
import org.apache.commons.lang3.StringUtils
|
|
|
import org.apache.commons.validator.routines.UrlValidator
|
|
import org.apache.commons.validator.routines.UrlValidator
|
|
|
-import java.io.File
|
|
|
|
|
-import java.io.FileWriter
|
|
|
|
|
import java.time.LocalDateTime
|
|
import java.time.LocalDateTime
|
|
|
import java.time.temporal.ChronoUnit
|
|
import java.time.temporal.ChronoUnit
|
|
|
import java.util.Objects
|
|
import java.util.Objects
|
|
@@ -59,6 +64,8 @@ class SettingsFragment : Fragment() {
|
|
|
|
|
|
|
|
var handler: Handler = Handler(Looper.getMainLooper())
|
|
var handler: Handler = Handler(Looper.getMainLooper())
|
|
|
var executor: ScheduledThreadPoolExecutor = ScheduledThreadPoolExecutor(8)
|
|
var executor: ScheduledThreadPoolExecutor = ScheduledThreadPoolExecutor(8)
|
|
|
|
|
+ var channels: List<Channel> = emptyList()
|
|
|
|
|
+ var channelId: Int? = null
|
|
|
|
|
|
|
|
init {
|
|
init {
|
|
|
Log.i("SettingsFragment", "SettingsFragment")
|
|
Log.i("SettingsFragment", "SettingsFragment")
|
|
@@ -136,10 +143,12 @@ class SettingsFragment : Fragment() {
|
|
|
contentType(ContentType.Application.Json)
|
|
contentType(ContentType.Application.Json)
|
|
|
setBody(
|
|
setBody(
|
|
|
RcsNumberRequest(
|
|
RcsNumberRequest(
|
|
|
- deviceId = Utils.getUniqueID()
|
|
|
|
|
|
|
+ deviceId = Utils.getUniqueID(),
|
|
|
|
|
+ channelId = channelId
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
+ Log.i(TAG, "response: ${response.bodyAsText()}")
|
|
|
var res = response.body<RcsNumberResponse>()
|
|
var res = response.body<RcsNumberResponse>()
|
|
|
val id = res.id
|
|
val id = res.id
|
|
|
val expiryTime = res.expiryTime
|
|
val expiryTime = res.expiryTime
|
|
@@ -240,6 +249,35 @@ class SettingsFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ 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)
|
|
|
|
|
+ channelId = channel.id
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e: Exception) {
|
|
|
|
|
+ e.printStackTrace()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return binding.root
|
|
return binding.root
|
|
|
}
|
|
}
|
|
|
|
|
|