chore: init repo with devshell, gradle wrapper, and release workflow

This commit is contained in:
Lukas Holzner
2026-05-23 01:19:06 +02:00
commit 4496ebcec4
57 changed files with 3112 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/build
+125
View File
@@ -0,0 +1,125 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.google.devtools.ksp)
alias(libs.plugins.roborazzi)
alias(libs.plugins.secrets)
}
android {
namespace = "com.example"
compileSdk = 36
defaultConfig {
applicationId = "com.aistudio.munichdepartures.clnzs"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
val keystorePath = System.getenv("KEYSTORE_PATH") ?: "${rootDir}/my-upload-key.jks"
val keystoreFile = file(keystorePath)
if (keystoreFile.exists()) {
create("release") {
storeFile = keystoreFile
storePassword = System.getenv("STORE_PASSWORD")
keyAlias = "upload"
keyPassword = System.getenv("KEY_PASSWORD")
}
}
create("debugConfig") {
storeFile = file("${rootDir}/debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}
buildTypes {
release {
isCrunchPngs = false
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
val releaseSigning = signingConfigs.findByName("release")
signingConfig = releaseSigning ?: signingConfigs.getByName("debugConfig")
}
debug {
signingConfig = signingConfigs.getByName("debugConfig")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildFeatures {
compose = true
buildConfig = true
}
testOptions { unitTests { isIncludeAndroidResources = true } }
}
// Configure the Secrets Gradle Plugin to use .env and .env.example files
// to match the convention used in Web projects.
secrets {
propertiesFileName = ".env"
defaultPropertiesFileName = ".env.example"
}
// Some unused dependencies are commented out below instead of being removed.
// This makes it easy to add them back in the future if needed.
dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(platform(libs.firebase.bom))
// implementation(libs.accompanist.permissions)
implementation(libs.androidx.activity.compose)
// implementation(libs.androidx.camera.camera2)
// implementation(libs.androidx.camera.core)
// implementation(libs.androidx.camera.lifecycle)
// implementation(libs.androidx.camera.view)
implementation(libs.androidx.compose.material.icons.core)
// implementation(libs.androidx.compose.material.icons.extended)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.graphics)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.core.ktx)
// implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.viewmodel.compose)
// implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.room.ktx)
implementation(libs.androidx.room.runtime)
// implementation(libs.coil.compose)
implementation(libs.converter.moshi)
// implementation(libs.firebase.ai)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.logging.interceptor)
implementation(libs.moshi.kotlin)
implementation(libs.okhttp)
// implementation(libs.play.services.location)
implementation(libs.retrofit)
testImplementation(libs.androidx.compose.ui.test.junit4)
testImplementation(libs.androidx.core)
testImplementation(libs.androidx.junit)
testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.robolectric)
testImplementation(libs.roborazzi)
testImplementation(libs.roborazzi.compose)
testImplementation(libs.roborazzi.junit.rule)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.runner)
debugImplementation(libs.androidx.compose.ui.test.manifest)
debugImplementation(libs.androidx.compose.ui.tooling)
"ksp"(libs.androidx.room.compiler)
"ksp"(libs.moshi.kotlin.codegen)
}
+21
View File
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,22 @@
package com.example
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example", appContext.packageName)
}
}
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.MyApplication">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,74 @@
package com.example.data.api
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query
@JsonClass(generateAdapter = true)
data class MvgLocationDto(
@Json(name = "type") val type: String?, // "STATION", "POINTER", etc.
@Json(name = "latitude") val latitude: Double?,
@Json(name = "longitude") val longitude: Double?,
@Json(name = "globalId") val id: String?, // The globalId needed for departures!
@Json(name = "name") val name: String?,
@Json(name = "mvg") val mvg: Boolean?,
@Json(name = "mvv") val mvv: Boolean?
)
@JsonClass(generateAdapter = true)
data class MvgDepartureDto(
@Json(name = "plannedDepartureTime") val plannedDepartureTime: Long?,
@Json(name = "realtimeDepartureTime") val realtimeDepartureTime: Long?,
@Json(name = "realtime") val realtime: Boolean?,
@Json(name = "line") val line: String?,
@Json(name = "destination") val destination: String?,
@Json(name = "transportType") val transportType: String?, // "METRO", "BUS", "TRAM", "SUBURBAN", "REGIONAL_TRAIN"
@Json(name = "label") val label: String?,
@Json(name = "sev") val sev: Boolean?,
@Json(name = "cancelled") val cancelled: Boolean? = false
)
interface MvgApiService {
@GET("api/bgw-pt/v3/locations")
suspend fun searchLocations(
@Query("query") query: String,
@Query("locationTypes") locationTypes: String = "STATION",
@Header("User-Agent") userAgent: String = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
@Header("X-MVG-Authorization-Key") apiKey: String = "5kaY6p6F7uqSjnd98374sao234"
): List<MvgLocationDto>
@GET("api/bgw-pt/v3/departures")
suspend fun getDepartures(
@Query("globalId") globalId: String,
@Query("limit") limit: Int = 40,
@Header("User-Agent") userAgent: String = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
@Header("X-MVG-Authorization-Key") apiKey: String = "5kaY6p6F7uqSjnd98374sao234"
): List<MvgDepartureDto>
}
object MvgApiClient {
private const val BASE_URL = "https://www.mvg.de/"
private val okHttpClient by lazy {
OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
.build()
}
val service: MvgApiService by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create())
.build()
.create(MvgApiService::class.java)
}
}
@@ -0,0 +1,9 @@
package com.example.data.db
import androidx.room.Database
import androidx.room.RoomDatabase
@Database(entities = [SavedStop::class], version = 1, exportSchema = false)
abstract class MvgDatabase : RoomDatabase() {
abstract fun savedStopDao(): SavedStopDao
}
@@ -0,0 +1,13 @@
package com.example.data.db
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "saved_stops")
data class SavedStop(
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val name: String, // Stop Name (e.g. Johann-Clanze-Straße)
val globalId: String, // Official Stop ID (e.g. de:09162:150)
val walkingTimeMinutes: Int, // User's walking time to the stop
val isCustomOrder: Int = 0 // Custom list ordering
)
@@ -0,0 +1,25 @@
package com.example.data.db
import androidx.room.*
import kotlinx.coroutines.flow.Flow
@Dao
interface SavedStopDao {
@Query("SELECT * FROM saved_stops ORDER BY isCustomOrder ASC, id ASC")
fun getAllSavedStops(): Flow<List<SavedStop>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertSavedStop(stop: SavedStop): Long
@Update
suspend fun updateSavedStop(stop: SavedStop)
@Delete
suspend fun deleteSavedStop(stop: SavedStop)
@Query("DELETE FROM saved_stops WHERE id = :id")
suspend fun deleteById(id: Long)
@Query("SELECT COUNT(*) FROM saved_stops")
suspend fun getCount(): Int
}
@@ -0,0 +1,51 @@
package com.example.data.repository
import com.example.data.api.MvgApiClient
import com.example.data.api.MvgDepartureDto
import com.example.data.api.MvgLocationDto
import com.example.data.db.SavedStop
import com.example.data.db.SavedStopDao
import kotlinx.coroutines.flow.Flow
class MvgRepository(private val savedStopDao: SavedStopDao) {
val allSavedStops: Flow<List<SavedStop>> = savedStopDao.getAllSavedStops()
suspend fun insertSavedStop(stop: SavedStop): Long {
return savedStopDao.insertSavedStop(stop)
}
suspend fun updateSavedStop(stop: SavedStop) {
savedStopDao.updateSavedStop(stop)
}
suspend fun deleteSavedStop(stop: SavedStop) {
savedStopDao.deleteSavedStop(stop)
}
suspend fun deleteById(id: Long) {
savedStopDao.deleteById(id)
}
suspend fun getSavedStopsCount(): Int {
return savedStopDao.getCount()
}
suspend fun searchLocations(query: String): List<MvgLocationDto> {
return try {
MvgApiClient.service.searchLocations(query)
} catch (e: Exception) {
e.printStackTrace()
emptyList()
}
}
suspend fun getDepartures(globalId: String): List<MvgDepartureDto> {
return try {
MvgApiClient.service.getDepartures(globalId)
} catch (e: Exception) {
e.printStackTrace()
emptyList()
}
}
}
@@ -0,0 +1,30 @@
package com.example.ui.theme
import androidx.compose.ui.graphics.Color
// Munich public transit inspired brand colors
val MvgBlue = Color(0xFF0F437D) // Official MVG U-Bahn Indigo Blue
val MvgTeal = Color(0xFF00827F) // Official MVG Bus Teal
val MvgRed = Color(0xFFD11119) // Official MVG Tram Red
val MvgGreen = Color(0xFF008F45) // S-Bahn Green
val TransitYellow = Color(0xFFFFCC00) // High-contrast warning/indicator yellow
// Elegant Dark Design Theme Colors
val ElegantDarkBg = Color(0xFF1C1B1F) // #1C1B1F
val ElegantDarkSurface = Color(0xFF2B2930) // #2B2930
val ElegantDarkBorder = Color(0xFF49454F) // #49454F
val ElegantDarkOnSurface = Color(0xFFE6E1E5) // #E6E1E5
val ElegantDarkSubText = Color(0xFFCAC4D0) // #CAC4D0
val ElegantDarkPurple = Color(0xFFD0BCFF) // #D0BCFF
val ElegantDarkPurpleContainer = Color(0xFF381E72)
val ElegantDarkActivePill = Color(0xFFE8DEF8)
val ElegantDarkOnActivePill = Color(0xFF1D192B)
val ElegantDarkButtonInactive = Color(0xFF353439)
// Light theme color override tokens
val PrimaryLight = Color(0xFF0F437D)
val SecondaryLight = Color(0xFF00827F)
val TertiaryLight = Color(0xFFB45309)
val BackgroundLight = Color(0xFFF8FAFC)
val SurfaceLight = Color(0xFFFFFFFF)
val SurfaceCardLight = Color(0xFFEDF2F7)
@@ -0,0 +1,64 @@
package com.example.ui.theme
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.graphics.Color
private val DarkColorScheme =
darkColorScheme(
primary = ElegantDarkPurple,
primaryContainer = ElegantDarkPurpleContainer,
secondary = MvgTeal,
tertiary = MvgGreen,
background = ElegantDarkBg,
surface = ElegantDarkSurface,
onBackground = ElegantDarkOnSurface,
onSurface = ElegantDarkOnSurface,
surfaceVariant = ElegantDarkSurface,
onSurfaceVariant = ElegantDarkSubText,
outline = ElegantDarkBorder,
outlineVariant = ElegantDarkBorder
)
private val LightColorScheme =
lightColorScheme(
primary = PrimaryLight,
primaryContainer = Color(0xFFEFF6FF),
secondary = SecondaryLight,
tertiary = MvgGreen,
background = BackgroundLight,
surface = SurfaceLight,
onBackground = Color(0xFF0F172A),
onSurface = Color(0xFF0F172A),
surfaceVariant = SurfaceCardLight,
onSurfaceVariant = Color(0xFF1E293B)
)
@Composable
fun MyApplicationTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+ (set to false by default for customized premium theme consistency)
dynamicColor: Boolean = false,
content: @Composable () -> Unit,
) {
val colorScheme =
when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content)
}
@@ -0,0 +1,36 @@
package com.example.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
// Set of Material typography styles to start with
val Typography =
Typography(
bodyLarge =
TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp,
)
/* Other default text styles to override
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 22.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 11.sp,
lineHeight = 16.sp,
letterSpacing = 0.5.sp
)
*/
)
@@ -0,0 +1,237 @@
package com.example.ui.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.data.api.MvgLocationDto
import com.example.data.db.SavedStop
import com.example.data.repository.MvgRepository
import kotlinx.coroutines.delay
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
sealed interface DeparturesUiState {
object Idle : DeparturesUiState
object Loading : DeparturesUiState
data class Success(val departures: List<DepartureUiModel>) : DeparturesUiState
data class Error(val message: String) : DeparturesUiState
}
data class DepartureUiModel(
val line: String,
val destination: String,
val plannedTimeMillis: Long,
val realtimeTimeMillis: Long,
val realtime: Boolean,
val transportType: String,
val stopName: String,
val stopWalkingTimeMinutes: Int,
val label: String
) {
fun minutesRemaining(nowMillis: Long): Int {
val diff = realtimeTimeMillis - nowMillis
return (diff / 60000).toInt().coerceAtLeast(0)
}
fun catchMinutesRemaining(nowMillis: Long): Int {
return minutesRemaining(nowMillis) - stopWalkingTimeMinutes
}
fun isReachable(nowMillis: Long): Boolean {
return minutesRemaining(nowMillis) >= stopWalkingTimeMinutes
}
}
class MvgViewModel(private val repository: MvgRepository) : ViewModel() {
val savedStops: StateFlow<List<SavedStop>> = repository.allSavedStops
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = emptyList()
)
private val _departuresState = MutableStateFlow<DeparturesUiState>(DeparturesUiState.Idle)
val departuresState: StateFlow<DeparturesUiState> = _departuresState.asStateFlow()
private val _isRefreshing = MutableStateFlow(false)
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
private val _lastUpdatedMillis = MutableStateFlow(0L)
val lastUpdatedMillis: StateFlow<Long> = _lastUpdatedMillis.asStateFlow()
// Filters and Display settings
private val _hideUnreachable = MutableStateFlow(false)
val hideUnreachable: StateFlow<Boolean> = _hideUnreachable.asStateFlow()
private val _selectedStopFilter = MutableStateFlow<String?>(null) // null means show "All Saved Stops"
val selectedStopFilter: StateFlow<String?> = _selectedStopFilter.asStateFlow()
// Stop Search
private val _stopSearchQuery = MutableStateFlow("")
val stopSearchQuery: StateFlow<String> = _stopSearchQuery.asStateFlow()
private val _stopSearchResults = MutableStateFlow<List<MvgLocationDto>>(emptyList())
val stopSearchResults: StateFlow<List<MvgLocationDto>> = _stopSearchResults.asStateFlow()
private val _isSearchingStops = MutableStateFlow(false)
val isSearchingStops: StateFlow<Boolean> = _isSearchingStops.asStateFlow()
init {
viewModelScope.launch {
// Check if database needs pre-population
if (repository.getSavedStopsCount() == 0) {
repository.insertSavedStop(
SavedStop(
name = "Johann-Clanze-Straße",
globalId = "de:09162:1335",
walkingTimeMinutes = 3,
isCustomOrder = 0
)
)
repository.insertSavedStop(
SavedStop(
name = "Harras",
globalId = "de:09162:1130",
walkingTimeMinutes = 12,
isCustomOrder = 1
)
)
}
}
// Auto-refresh departures whenever stops list changes
viewModelScope.launch {
savedStops.collect { stops ->
if (stops.isNotEmpty() && _departuresState.value is DeparturesUiState.Idle) {
refreshDepartures()
}
}
}
// Auto-refresh departures every 30 seconds
viewModelScope.launch {
while (true) {
delay(30000)
if (savedStops.value.isNotEmpty()) {
refreshDepartures(quiet = true)
}
}
}
}
fun setHideUnreachable(hide: Boolean) {
_hideUnreachable.value = hide
}
fun setSelectedStopFilter(stopGlobalId: String?) {
_selectedStopFilter.value = stopGlobalId
}
fun refreshDepartures(quiet: Boolean = false) {
val stops = savedStops.value
if (stops.isEmpty()) {
_departuresState.value = DeparturesUiState.Success(emptyList())
return
}
if (!quiet || _departuresState.value !is DeparturesUiState.Success) {
_departuresState.value = DeparturesUiState.Loading
}
viewModelScope.launch {
try {
val deferredList = stops.map { stop ->
async {
val dtoList = repository.getDepartures(stop.globalId)
dtoList.map { dto ->
// Use planned time as fallback if realtime is null
val fallbackTime = dto.realtimeDepartureTime ?: dto.plannedDepartureTime ?: System.currentTimeMillis()
DepartureUiModel(
line = dto.line ?: "Bus",
destination = dto.destination ?: "Unknown",
plannedTimeMillis = dto.plannedDepartureTime ?: fallbackTime,
realtimeTimeMillis = fallbackTime,
realtime = dto.realtime ?: false,
transportType = dto.transportType ?: "BUS",
stopName = stop.name,
stopWalkingTimeMinutes = stop.walkingTimeMinutes,
label = dto.label ?: dto.line ?: ""
)
}
}
}
val allResults = deferredList.awaitAll().flatten()
_departuresState.value = DeparturesUiState.Success(allResults)
_lastUpdatedMillis.value = System.currentTimeMillis()
} catch (e: Exception) {
e.printStackTrace()
_departuresState.value = DeparturesUiState.Error(e.message ?: "Failed to retrieve departures")
} finally {
_isRefreshing.value = false
}
}
}
fun triggerPullToRefresh() {
_isRefreshing.value = true
refreshDepartures()
}
// Settings adjustments
fun addStop(name: String, globalId: String, walkingTime: Int) {
viewModelScope.launch {
repository.insertSavedStop(
SavedStop(
name = name,
globalId = globalId,
walkingTimeMinutes = walkingTime,
isCustomOrder = savedStops.value.size
)
)
refreshDepartures()
}
}
fun deleteStop(stop: SavedStop) {
viewModelScope.launch {
repository.deleteSavedStop(stop)
refreshDepartures()
}
}
fun updateWalkingTime(stop: SavedStop, newWalkingTime: Int) {
viewModelScope.launch {
repository.updateSavedStop(stop.copy(walkingTimeMinutes = newWalkingTime))
refreshDepartures()
}
}
// Stop Search operations
fun updateSearchQuery(query: String) {
_stopSearchQuery.value = query
if (query.length >= 3) {
performStopSearch(query)
} else {
_stopSearchResults.value = emptyList()
}
}
private fun performStopSearch(query: String) {
_isSearchingStops.value = true
viewModelScope.launch {
try {
val results = repository.searchLocations(query)
// Filter to keep only STATION items for accuracy
val filtered = results.filter { it.type == "STATION" && !it.id.isNullOrEmpty() }
_stopSearchResults.value = filtered
} catch (e: Exception) {
e.printStackTrace()
} finally {
_isSearchingStops.value = false
}
}
}
}
@@ -0,0 +1,15 @@
package com.example.ui.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.example.data.repository.MvgRepository
class MvgViewModelFactory(private val repository: MvgRepository) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(MvgViewModel::class.java)) {
@Suppress("UNCHECKED_CAST")
return MvgViewModel(repository) as T
}
throw IllegalArgumentException("Unknown ViewModel class")
}
}
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
+3
View File
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Munich Departures</string>
</resources>
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyApplication" parent="android:Theme.DeviceDefault.NoActionBar" />
</resources>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample backup rules file; uncomment and customize as necessary.
See https://developer.android.com/guide/topics/data/autobackup
for details.
Note: This file is ignored for devices older than API 31
See https://developer.android.com/about/versions/12/backup-restore
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->
</full-backup-content>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!-- TODO: Use <include> and <exclude> to control what is backed up.
<include .../>
<exclude .../>
-->
</cloud-backup>
<!--
<device-transfer>
<include .../>
<exclude .../>
</device-transfer>
-->
</data-extraction-rules>
@@ -0,0 +1,30 @@
package com.example
import android.content.Context
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [36])
class ExampleRobolectricTest {
@Test
fun `read string from context`() {
val context = ApplicationProvider.getApplicationContext<Context>()
val appName = context.getString(R.string.app_name)
assertEquals("Munich Departures", appName)
}
@Test
fun `launch main activity does not crash`() {
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
assertNotNull(scenario)
}
}
}
@@ -0,0 +1,16 @@
package com.example
import org.junit.Assert.*
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
@@ -0,0 +1,32 @@
package com.example
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import com.example.ui.theme.MyApplicationTheme
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.captureRoboImage
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(qualifiers = RobolectricDeviceQualifiers.Pixel8, sdk = [36])
class GreetingScreenshotTest {
@get:Rule val composeTestRule = createComposeRule()
@Test
fun empty_state_screenshot() {
composeTestRule.setContent {
MyApplicationTheme {
EmptySavedStopsState(onNavigateToSettings = {})
}
}
composeTestRule.onRoot().captureRoboImage(filePath = "src/test/screenshots/empty_state.png")
}
}
Binary file not shown.