|
|
@ -7,21 +7,23 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Surface
|
|
|
|
import androidx.compose.material3.Surface
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
|
|
|
import androidx.compose.runtime.MutableState
|
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import com.google.gson.Gson
|
|
|
|
import com.google.gson.Gson
|
|
|
|
import com.google.gson.GsonBuilder
|
|
|
|
|
|
|
|
import com.iqball.app.api.EitherBodyConverter
|
|
|
|
import com.iqball.app.api.EitherBodyConverter
|
|
|
|
import com.iqball.app.api.EitherCallAdapterFactory
|
|
|
|
import com.iqball.app.api.EitherCallAdapterFactory
|
|
|
|
import com.iqball.app.api.service.IQBallService
|
|
|
|
import com.iqball.app.api.service.IQBallService
|
|
|
|
import com.iqball.app.page.RegisterPage
|
|
|
|
import com.iqball.app.page.HomePage
|
|
|
|
|
|
|
|
import com.iqball.app.page.LoginPage
|
|
|
|
|
|
|
|
import com.iqball.app.session.DataSession
|
|
|
|
|
|
|
|
import com.iqball.app.session.Session
|
|
|
|
import com.iqball.app.ui.theme.IQBallTheme
|
|
|
|
import com.iqball.app.ui.theme.IQBallTheme
|
|
|
|
import okhttp3.OkHttpClient
|
|
|
|
import okhttp3.OkHttpClient
|
|
|
|
import okhttp3.ResponseBody
|
|
|
|
|
|
|
|
import retrofit2.Converter
|
|
|
|
|
|
|
|
import retrofit2.Retrofit
|
|
|
|
import retrofit2.Retrofit
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory
|
|
|
|
import retrofit2.create
|
|
|
|
import retrofit2.create
|
|
|
|
import java.lang.reflect.Type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
@ -46,8 +48,12 @@ class MainActivity : ComponentActivity() {
|
|
|
|
setContent {
|
|
|
|
setContent {
|
|
|
|
IQBallTheme {
|
|
|
|
IQBallTheme {
|
|
|
|
// A surface container using the 'background' color from the theme
|
|
|
|
// A surface container using the 'background' color from the theme
|
|
|
|
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
|
|
|
Surface(
|
|
|
|
App(service)
|
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
|
|
|
|
|
color = MaterialTheme.colorScheme.background
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
val sessionState = remember { mutableStateOf<Session>(DataSession()) }
|
|
|
|
|
|
|
|
App(service, sessionState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -55,6 +61,16 @@ class MainActivity : ComponentActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun App(service: IQBallService) {
|
|
|
|
fun App(service: IQBallService, sessionState: MutableState<Session>) {
|
|
|
|
RegisterPage(service)
|
|
|
|
|
|
|
|
|
|
|
|
val loginPage: @Composable () -> Unit = {
|
|
|
|
|
|
|
|
LoginPage(service = service, onLoginSuccess = { auth ->
|
|
|
|
|
|
|
|
sessionState.value = DataSession(auth)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val homePage : @Composable () -> Unit = { HomePage(service, sessionState.value) }
|
|
|
|
|
|
|
|
val currentPage = remember(sessionState.value.auth) { if (sessionState.value.auth == null) loginPage else homePage }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentPage()
|
|
|
|
}
|
|
|
|
}
|