added a refresh button to the timetable

This commit is contained in:
Odweta
2024-11-26 18:04:05 +01:00
parent fd788195c5
commit ed981f89de
10 changed files with 78 additions and 17 deletions
+3 -1
View File
@@ -3,7 +3,9 @@
<component name="MaterialThemeProjectNewConfig"> <component name="MaterialThemeProjectNewConfig">
<option name="metadata"> <option name="metadata">
<MTProjectMetadataState> <MTProjectMetadataState>
<option name="userId" value="35ed75a3:192c279f3e0:-7ffa" /> <option name="migrated" value="true" />
<option name="pristineConfig" value="false" />
<option name="userId" value="-239e49af:192a4be9597:-7ffe" />
</MTProjectMetadataState> </MTProjectMetadataState>
</option> </option>
</component> </component>
+1 -1
View File
@@ -262,7 +262,7 @@
<option name="codename" value="q6q" /> <option name="codename" value="q6q" />
<option name="id" value="q6q" /> <option name="id" value="q6q" />
<option name="manufacturer" value="Samsung" /> <option name="manufacturer" value="Samsung" />
<option name="name" value="SM-F956B" /> <option name="name" value="Galaxy Z Fold6" />
<option name="screenDensity" value="420" /> <option name="screenDensity" value="420" />
<option name="screenX" value="1856" /> <option name="screenX" value="1856" />
<option name="screenY" value="2160" /> <option name="screenY" value="2160" />
+2 -2
View File
@@ -13,10 +13,10 @@
</DropdownSelection> </DropdownSelection>
<DialogSelection /> <DialogSelection />
</SelectionState> </SelectionState>
<SelectionState runConfigName="DefaultPreview"> <SelectionState runConfigName="TimetablePreview">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
</SelectionState> </SelectionState>
<SelectionState runConfigName="Preview"> <SelectionState runConfigName="RBPreview">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
</SelectionState> </SelectionState>
</selectionStates> </selectionStates>
-1
View File
@@ -2,6 +2,5 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" /> <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>
@@ -1,22 +1,18 @@
package com.odweta.solon package com.odweta.solon
import android.view.Window import android.view.Window
import androidx.compose.foundation.background
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import com.odweta.solon.ui.theme.PastelYellow import com.odweta.solon.ui.theme.PastelYellow
import com.odweta.solon.ui.theme.PastelYellowTransparent
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import java.io.File import java.io.File
@@ -37,7 +37,7 @@ private fun setOnInternetAvailListener(ctx: Context, coscope: CoroutineScope) {
} }
} }
private fun fetchNewData(ctx: Context, coscope: CoroutineScope) { fun fetchNewData(ctx: Context, coscope: CoroutineScope) {
coscope.launch { coscope.launch {
done = false done = false
@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@@ -1,7 +1,6 @@
package com.odweta.solon package com.odweta.solon
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.text.format.Time
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
@@ -14,22 +13,33 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Shapes
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.odweta.solon.ui.theme.PastelGreen import com.odweta.solon.ui.theme.PastelGreen
@@ -38,16 +48,33 @@ import com.odweta.solon.ui.theme.PastelRed
import com.odweta.solon.ui.theme.PastelRedTransparent import com.odweta.solon.ui.theme.PastelRedTransparent
import com.odweta.solon.ui.theme.PastelYellow import com.odweta.solon.ui.theme.PastelYellow
import com.odweta.solon.ui.theme.PastelYellowTransparent import com.odweta.solon.ui.theme.PastelYellowTransparent
import kotlinx.coroutines.delay import kotlinx.coroutines.launch
import java.time.LocalDate import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime import java.time.LocalTime
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
fun TimetableScreen() { fun TimetableScreen() {
val pagerState = rememberPagerState( pageCount = { days.size } ) Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.BottomCenter
) {
DayPager()
Box(
modifier = Modifier
.padding(bottom = 10.dp)
.background(color = Color.Black, shape = RoundedCornerShape(roundedCornerDimen))
) {
RefreshButton()
}
}
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun DayPager(modifier: Modifier = Modifier) {
val pagerState = rememberPagerState(pageCount = { days.size })
HorizontalPager( HorizontalPager(
state = pagerState, state = pagerState,
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
@@ -56,6 +83,37 @@ fun TimetableScreen() {
} }
} }
@Composable
fun RefreshButton(modifier: Modifier = Modifier) {
val coscope = rememberCoroutineScope()
val ctx = LocalContext.current
Button(
onClick = {
coscope.launch {
fetchNewData(ctx, coscope)
}
},
colors = ButtonDefaults.buttonColors(
contentColor = Color.White,
containerColor = Color.Black
),
modifier = Modifier
.border(
width = 5.dp,
shape = RoundedCornerShape(roundedCornerDimen),
color = PastelYellow
)
.padding(vertical = 10.dp)
) {
Icon(
imageVector = Icons.Default.Refresh,
contentDescription = "Refresh icon",
modifier = Modifier.size(25.dp)
)
}
}
private fun getSubjectColor(s: Subject, transparent: Boolean): Color { private fun getSubjectColor(s: Subject, transparent: Boolean): Color {
return if (s.free) { return if (s.free) {
if (transparent) { if (transparent) {
@@ -287,6 +345,8 @@ private fun DayScreen(day: Day) {
} }
} }
} }
// TODO: remove when added settings to turn the refresh button on/off
Spacer(modifier = Modifier.height(90.dp))
} }
} }
} }
@@ -1,6 +1,8 @@
package com.odweta.solon package com.odweta.solon
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
+1
View File
@@ -21,3 +21,4 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies, # resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library # thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true android.nonTransitiveRClass=true
sdk.dir=/home/thinker/Android/Sdk