Skip to content

Commit

Permalink
some more mobiel stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
prapooskur committed Jan 21, 2024
1 parent 3947810 commit 6b48a3e
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 51 deletions.
6 changes: 3 additions & 3 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.8"
kotlinCompilerExtensionVersion = "1.5.5"
}
packaging {
resources {
Expand All @@ -57,7 +57,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
Expand All @@ -67,7 +67,7 @@ dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.pras.slugcourses.api.ClassAPIResponse
import com.pras.slugcourses.api.CourseInfo
Expand All @@ -27,7 +27,7 @@ import kotlinx.coroutines.withContext
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DetailedResultsScreen(
navController: NavHostController,
navController: NavController,
term: String,
courseNumber: String
) {
Expand Down
23 changes: 9 additions & 14 deletions android/app/src/main/java/com/pras/slugcourses/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import com.pras.slugcourses.api.Status
import com.pras.slugcourses.api.Type
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -47,23 +51,14 @@ fun HomeScreen(navController: NavController) {
active = false,
onActiveChange = { searchActive = it },
onSearch = {
val status = Json.encodeToString(Status.ALL)
val type = Json.encodeToString(listOf(Type.HYBRID, Type.ASYNC, Type.IN_PERSON, Type.SYNC))
val gelist = Json.encodeToString(GEList.value)
navController.navigate(

"results/${termMap[termChosen.value]}/${searchText}/${status}/${type}/${gelist}"
)
}
)
if (searchActive) {
SearchFilters(
searchAsyncOnline = searchAsyncOnline,
searchHybrid = searchHybrid,
searchSynchOnline = searchSynchOnline,
searchInPerson = searchInPerson,
searchOpen = searchOpen,
termChosen = termChosen,
GEList = GEList,
showAdvanced = showAdvanced
)
}
) { /* do nothing */ }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,20 @@ fun Init(startDestination: String) {
ResultsScreen(
navController = navController,
term = term,
query = query ?: "",
query = query,
status = status,
type = type,
genEd = gened
)
}
composable(
"detailed/{courseNumber}",
"detailed/{term}/{courseNumber}",
enterTransition = { fadeIn() },
exitTransition = { fadeOut() }
) { backStackEntry ->
val term = backStackEntry.arguments?.getString("term") ?: "2240"
val courseNumber = backStackEntry.arguments?.getString("courseNumber") ?: ""
DetailedResultsScreen(navController = navController, courseNumber = courseNumber)
DetailedResultsScreen(navController = navController, term = term, courseNumber = courseNumber)
}
composable(
"chat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import com.pras.slugcourses.api.Course
import com.pras.slugcourses.api.Status
import com.pras.slugcourses.api.SupabaseQuery
import com.pras.slugcourses.api.supabaseQuery
import com.pras.slugcourses.api.Type
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -56,7 +56,7 @@ fun ResultsScreen(

LaunchedEffect(Unit) {
withContext(Dispatchers.IO) {
response = SupabaseQuery(
response = supabaseQuery(
term = term,
status = status,
department = if (useDepartment) department else "",
Expand All @@ -67,4 +67,4 @@ fun ResultsScreen(
dataLoaded = true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ data class CourseInfo(

@Serializable
data class PrimarySection(
val strm: String,
val session_code: String,
val class_nbr: String,
val component: String,
val acad_career: String,
val subject: String,
val class_section: String,
val start_date: String,
val end_date: String,
val capacity: String,
val enrl_total: String,
val waitlist_capacity: String,
val waitlist_total: String,
val enrl_status: String,
val credits: String,
val grading: String,
val title: String,
val title_long: String,
val description: String,
val gened: String,
val requirements: String,
val catalog_nbr: String
val strm: String = "",
val session_code: String = "",
val class_nbr: String = "",
val component: String = "",
val acad_career: String = "",
val subject: String = "",
val class_section: String = "",
val start_date: String = "",
val end_date: String = "",
val capacity: String = "",
val enrl_total: String = "",
val waitlist_capacity: String = "",
val waitlist_total: String = "",
val enrl_status: String = "",
val credits: String = "",
val grading: String = "",
val title: String = "",
val title_long: String = "",
val description: String = "",
val gened: String = "",
val requirements: String = "",
val catalog_nbr: String = "",
)

@Serializable
Expand Down Expand Up @@ -71,7 +71,7 @@ data class SecondarySection(
val meetings: List<Meeting>
)

suspend fun APIResponse(term: String, courseNum: String): CourseInfo {
suspend fun classAPIResponse(term: String, courseNum: String): CourseInfo {
val client = HttpClient(CIO)
val url = "https://my.ucsc.edu/PSIGW/RESTListeningConnector/PSFT_CSPRD/SCX_CLASS_DETAIL.v1/${term}/${courseNum}"
val response = client.get(url).body<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum class Type {
IN_PERSON,
}

suspend fun SupabaseQuery(
suspend fun supabaseQuery(
term: Int = 2240,
status: Status = Status.ALL,
department: String = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.pras.slugcourses.ui.elements

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.pras.slugcourses.R
import com.pras.slugcourses.api.Course

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CourseCard(course: Course, uriHandler: UriHandler) {
val uri = "https://pisa.ucsc.edu/class_search/"+course.url
Card(onClick = { uriHandler.openUri(uri) },modifier = Modifier.padding(6.dp).widthIn(max=800.dp)) {
Column(modifier = Modifier.fillMaxSize().padding(8.dp)) {
SectionTitle(course.description)
SectionSubtitle(Icons.Default.Person, course.instructor)
if (course.location.contains("Online") || course.location.contains("Remote Instruction")) {
SectionSubtitle(painterResource(R.drawable.chat_filled), course.location)
} else {
SectionSubtitle(painterResource(R.drawable.chat_filled), course.location)
}
SectionSubtitle(painterResource(R.drawable.chat_filled), course.time)
if (course.alt_location != "Not Found") {
if (course.alt_location.contains("Online") || course.alt_location.contains("Remote Instruction")) {
SectionSubtitle(painterResource(R.drawable.chat_filled), course.alt_location)
} else {
SectionSubtitle(painterResource(R.drawable.chat_filled), course.alt_location)
}
}
if (course.alt_time != "Not Found") {
SectionSubtitle(painterResource(R.drawable.chat_filled), course.alt_time)
}
SectionSubtitle(painterResource(R.drawable.chat_filled), course.enrolled)
}
}
}



@Composable
fun SectionTitle(title: String) {
Text(
text = title,
fontWeight = FontWeight.SemiBold,
fontSize = 20.sp
)
}

val ROW_PADDING = 4.dp

@Composable
fun SectionSubtitle(icon: ImageVector, subtitle: String) {
Row {
Icon(icon,null, modifier = Modifier.padding(end = ROW_PADDING))
Text(
text = subtitle,
fontSize = 16.sp
)
}
}

@Composable
fun SectionSubtitle(icon: Painter, subtitle: String) {
Row {
Icon(icon,null, modifier = Modifier.padding(end = ROW_PADDING))
Text(
text = subtitle,
fontSize = 16.sp
)
}
}

@Preview
@Composable
fun CoursePreview() {
CourseCard(
Course(
1,
2240,
"Patrick Tantalo",
"Remote Instruction",
"MWF 10:00AM - 10:50AM",
"Remote Instruction",
"MWF 10:00AM - 10:50AM",
"0",
"",
"",
"",
"",
"",
"",
"",
"",
"",
),
object : UriHandler {
override fun openUri(uri: String) {

}
}
)
}
4 changes: 2 additions & 2 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.2.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.22" apply false
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20" apply false
}

0 comments on commit 6b48a3e

Please sign in to comment.