feat: toast

This commit is contained in:
2025-11-13 16:04:13 +08:00
parent 1b0e5ec8ab
commit ca99eaa3e4
5 changed files with 71 additions and 35 deletions
@@ -6,21 +6,6 @@ import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.yuanxuan.rokid.network.http.ApiResponse
import com.yuanxuan.rokid.network.http.Test
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import timber.log.Timber
import java.lang.reflect.Type
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@@ -32,26 +17,8 @@ class MainActivity : AppCompatActivity() {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
val json = "{\n" +
" \"code\": 0,\n" +
" \"msg\": \"success\",\n" +
" \"data\": {\n" +
" \"userId\": \"123\",\n" +
" \"name\": \"Alice\"\n" +
" }\n" +
"}"
val x = test<Test>(json)
// onBackPressedDispatcher.addCallback {
// }
}
private inline fun <reified T> test(responseBody: String): T {
val typeToken = object : TypeToken<ApiResponse<T>>() {}
val typeOfT: Type = typeToken.type
val apiResponse: ApiResponse<T> = Gson().fromJson(responseBody, typeOfT)
return apiResponse.data
onBackPressedDispatcher.addCallback {
}
}
}