Skip to content

Instantly share code, notes, and snippets.

View 0xZhangKe's full-sized avatar
💔
Working from home

ZhangKe 0xZhangKe

💔
Working from home
View GitHub Profile
@0xZhangKe
0xZhangKe / UiStateCopyUsageSample.kt
Created December 3, 2023 02:47
UiState copy usage
data class LoginUiState(
val name:String,
val avatar: String,
val consentAgreed: Boolean
)
fun onAgreeChecked(){
uistate = uiState.copy(
consentAgreed = true,
)
@0xZhangKe
0xZhangKe / UseCaseUsageForViewModel.kt
Created December 3, 2023 02:46
usecase usage for viewmodel
class LoginViewModel @Inject constructor(
private val doSomething: DoSomethingUseCase,
): ViewModel(){
fun onLoginClick(){
doSomething()
}
}
@0xZhangKe
0xZhangKe / clean_usecase_sample.kt
Created December 3, 2023 02:45
usecase-sample.kt
class DoSomethingUseCase {
operator fun invoke(xxx: Foo): Bar {
// ...
}
}
@0xZhangKe
0xZhangKe / clean-adapter-sample.kt
Created December 3, 2023 02:44
clean-adapter-sample
data class UserEntity(val name: String, val avatar: String)
interface UserService {
@GET("/user")
suspend fun getUserInfo(@query("id") id: String): UserEntity
}
data class User(val name: String, val avatar: String)
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
BezierCurve(
modifier = Modifier
.fillMaxWidth()
.padding(start = 30.dp, end = 30.dp)
.height(100.dp),
package com.zhangke.framework.composable
import androidx.compose.foundation.Canvas
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
class NotionResponse<T> : Response<T, ErrorEntry>()
...
@POST("v1/search")
suspend fun queryAllPages(@Body body: RequestBody): NotionResponse<NotionListEntry<NotionPage>>
// {"object":"error","status":401,"code":"unauthorized","message":"API token is invalid."}
data class ErrorEntry(
@SerializedName("object")
val objectType: String,
val status: Int,
val code: String?,
override fun enqueue(callback: Callback<Response<S, E>>) {
return delegate.enqueue(object : Callback<S> {
override fun onResponse(call: Call<S>, response: retrofit2.Response<S>) {
if (response.isSuccessful) {
val body = response.body()
responseInstance.success = true
responseInstance.successData = body
} else {
val error = response.errorBody()
class ResponseCall<S, E : ErrorResponse.ErrorEntryWithMessage>(
private val delegate: Call<S>,
private val responseInstance: Response<S, E>,
private val errorConverter: Converter<ResponseBody, E>
) : Call<Response<S, E>> {
override fun enqueue(callback: Callback<Response<S, E>>) {
TODO("Not yet implemented")
}