mirror of
https://github.com/StepanovPlaton/SSAU_Schedule.git
synced 2026-04-03 20:30:40 +04:00
15.12
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
android:theme="@style/Theme.SSAU_Schedule"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:name=".AuthActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.SSAU_Schedule"
|
||||
android:screenOrientation="portrait">
|
||||
@@ -27,7 +27,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AuthActivity"
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.SSAU_Schedule"
|
||||
android:screenOrientation="portrait">
|
||||
|
||||
@@ -21,9 +21,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
|
||||
@@ -95,38 +95,38 @@ class MainActivity : ComponentActivity() {
|
||||
val pagerState = rememberPagerState(
|
||||
initialPage = currentDayOfWeek.intValue-1, pageCount = {Int.MAX_VALUE})
|
||||
|
||||
LaunchedEffect(false) {
|
||||
lessons.value = database.lessonDao().getAll()
|
||||
}
|
||||
|
||||
// LaunchedEffect(false) {
|
||||
// val generalData = StoreUtils.getGeneralData(applicationContext)
|
||||
// if(generalData == null)
|
||||
// startActivity(Intent(applicationContext, AuthActivity::class.java))
|
||||
// else {
|
||||
// val week = generalData.year.getWeekOfDate(Date())
|
||||
// val (apiLessons, apiError) = lessonAPI.getLessons(
|
||||
// generalData.token, generalData.group, generalData.year, week)
|
||||
// if(apiLessons != null && apiError == null) {
|
||||
// val (databaseLessons, converterErrors) = apiLessons.toLessons(week)
|
||||
// Log.i("Lessons", Json.encodeToString(apiLessons))
|
||||
// database.lessonDao().insert(*databaseLessons.toTypedArray())
|
||||
// converterErrors.forEach { error ->
|
||||
// val message = error.getMessage(applicationContext)
|
||||
// if(message != null) snackbarHostState.showSnackbar(message)
|
||||
// }
|
||||
// lessons.value = databaseLessons
|
||||
// } else {
|
||||
// if(apiError == LessonAPIErrorMessage.USER_NOT_AUTHORIZED) {
|
||||
// startActivity(Intent(applicationContext, AuthActivity::class.java))
|
||||
// } else {
|
||||
// val message = apiError?.getMessage(applicationContext)
|
||||
// if(message != null) snackbarHostState.showSnackbar(message)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// lessons.value = database.lessonDao().getAll()
|
||||
// }
|
||||
|
||||
LaunchedEffect(false) {
|
||||
val generalData = StoreUtils.getGeneralData(applicationContext)
|
||||
if(generalData == null)
|
||||
startActivity(Intent(applicationContext, AuthActivity::class.java))
|
||||
else {
|
||||
val week = generalData.year.getWeekOfDate(Date())
|
||||
val (apiLessons, apiError) = lessonAPI.getLessons(
|
||||
generalData.token, generalData.group, generalData.year, week)
|
||||
if(apiLessons != null && apiError == null) {
|
||||
val (databaseLessons, converterErrors) = apiLessons.toLessons(week)
|
||||
Log.i("Lessons", Json.encodeToString(apiLessons))
|
||||
database.lessonDao().insert(*databaseLessons.toTypedArray())
|
||||
converterErrors.forEach { error ->
|
||||
val message = error.getMessage(applicationContext)
|
||||
if(message != null) snackbarHostState.showSnackbar(message)
|
||||
}
|
||||
lessons.value = databaseLessons
|
||||
} else {
|
||||
if(apiError == LessonAPIErrorMessage.USER_NOT_AUTHORIZED) {
|
||||
startActivity(Intent(applicationContext, AuthActivity::class.java))
|
||||
} else {
|
||||
val message = apiError?.getMessage(applicationContext)
|
||||
if(message != null) snackbarHostState.showSnackbar(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
SnackbarHost(hostState = snackbarHostState) {
|
||||
|
||||
Reference in New Issue
Block a user