Skip to content

Commit

Permalink
Create :core:utils (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz authored Aug 30, 2024
1 parent 5ba2454 commit ba188fd
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 40 deletions.
3 changes: 2 additions & 1 deletion core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ dependencies {
implementation(projects.core.coroutinesExt)
implementation(projects.core.network)
implementation(projects.core.model)
implementation(projects.core.utils)

implementation(libs.androidx.core.ktx)
implementation(libs.kotlinx.serialization.json)
implementation("com.opencsv:opencsv:5.5.2")
implementation(libs.opencsv)
implementation(libs.okhttp)
implementation(libs.timber)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import okhttp3.Response
import timber.log.Timber
import xyz.ksharma.krail.coroutines.ext.safeResult
import xyz.ksharma.krail.network.files.toPath
import xyz.ksharma.krail.utils.toPath
import java.io.File
import java.io.IOException
import java.nio.file.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import kotlinx.coroutines.withContext
import okhttp3.Response
import timber.log.Timber
import xyz.ksharma.krail.data.cacheZipResponse
import xyz.ksharma.krail.data.gtfs_static.parser.AgencyParser.parseAgency
import xyz.ksharma.krail.di.AppDispatchers
import xyz.ksharma.krail.di.Dispatcher
import xyz.ksharma.krail.model.sydneytrains.GTFSFeedFileNames
import xyz.ksharma.krail.network.GtfsService
import xyz.ksharma.krail.network.files.toPath
import javax.inject.Inject

class SydneyTrainsRepositoryImpl @Inject constructor(
Expand All @@ -27,18 +24,5 @@ class SydneyTrainsRepositoryImpl @Inject constructor(
response.cacheZipResponse(dispatcher = ioDispatcher, context = context)

// TODO - provide boolean response if files were cached successfully.
//val stopsList = context.toPath(GTFSFeedFileNames.STOPS.fileName).parseStops()
//Timber.d("stopsList: $stopsList")
//val tripsList = context.toPath(GTFSFeedFileNames.TRIPS.fileName).parseTrips()
//val stopTimesList = context.toPath(GTFSFeedFileNames.STOP_TIMES.fileName).parseStopTimes()
//Timber.d("stopTimesList: ${stopTimesList.size}") Huge data do not log.
//val routesList = context.toPath(GTFSFeedFileNames.ROUTES.fileName).parseRoutes()
// Timber.d("routesList: $routesList")
//val occupancyList = context.toPath(GTFSFeedFileNames.OCCUPANCIES.fileName).parseOccupancy()
//Timber.d("occupancyList: ${occupancyList.size}")
//val calendarList = context.toPath(GTFSFeedFileNames.CALENDAR.fileName).parseCalendar()
//Timber.d("calendarList: ${calendarList}")
val agencyList = context.toPath(GTFSFeedFileNames.AGENCY.fileName).parseAgency()
Timber.d("agencyList: $agencyList")
}
}
1 change: 1 addition & 0 deletions core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ android {
dependencies {
api(projects.core.data)
api(projects.core.model)
implementation(projects.core.utils)

testImplementation(libs.junit)
testImplementation(libs.turbine)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package xyz.ksharma.krail.domain

import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import timber.log.Timber
import xyz.ksharma.krail.data.repository.SydneyTrainsRepository
import xyz.ksharma.krail.domain.parser.AgencyParser.parseAgency
import xyz.ksharma.krail.model.sydneytrains.GTFSFeedFileNames
import xyz.ksharma.krail.utils.toPath
import javax.inject.Inject

/**
Expand All @@ -16,8 +22,23 @@ interface DemoUseCase {

class DemoUseCaseImpl @Inject constructor(
private val sydneyTrainsRepository: SydneyTrainsRepository,
@ApplicationContext private val context: Context,
) : DemoUseCase {
override suspend operator fun invoke() {
sydneyTrainsRepository.fetchStaticSydneyTrainsScheduleAndCache()

//val stopsList = context.toPath(GTFSFeedFileNames.STOPS.fileName).parseStops()
//Timber.d("stopsList: $stopsList")
//val tripsList = context.toPath(GTFSFeedFileNames.TRIPS.fileName).parseTrips()
//val stopTimesList = context.toPath(GTFSFeedFileNames.STOP_TIMES.fileName).parseStopTimes()
//Timber.d("stopTimesList: ${stopTimesList.size}") Huge data do not log.
//val routesList = context.toPath(GTFSFeedFileNames.ROUTES.fileName).parseRoutes()
// Timber.d("routesList: $routesList")
//val occupancyList = context.toPath(GTFSFeedFileNames.OCCUPANCIES.fileName).parseOccupancy()
//Timber.d("occupancyList: ${occupancyList.size}")
//val calendarList = context.toPath(GTFSFeedFileNames.CALENDAR.fileName).parseCalendar()
//Timber.d("calendarList: ${calendarList}")
val agencyList = context.toPath(GTFSFeedFileNames.AGENCY.fileName).parseAgency()
Timber.d("agencyList: $agencyList")
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.ksharma.krail.data.gtfs_static.parser
package xyz.ksharma.krail.domain.parser

import timber.log.Timber
import xyz.ksharma.krail.model.gtfs_static.Agency
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.ksharma.krail.data.gtfs_static.parser
package xyz.ksharma.krail.domain.parser

import timber.log.Timber
import xyz.ksharma.krail.model.gtfs_static.Calendar
Expand Down Expand Up @@ -48,11 +48,4 @@ object CalendarParser {

return calendarList
}

private fun Int.toWheelchairBoarding() = when (this) {
0 -> xyz.ksharma.krail.model.gtfs_realtime.proto.Stop.WheelchairBoarding.UNKNOWN
1 -> xyz.ksharma.krail.model.gtfs_realtime.proto.Stop.WheelchairBoarding.AVAILABLE
2 -> xyz.ksharma.krail.model.gtfs_realtime.proto.Stop.WheelchairBoarding.NOT_AVAILABLE
else -> null
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.ksharma.krail.data.gtfs_static.parser
package xyz.ksharma.krail.domain.parser

import timber.log.Timber
import xyz.ksharma.krail.model.gtfs_static.Occupancy
Expand Down Expand Up @@ -80,5 +80,4 @@ object OccupancyParser {

return occupancyList
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package xyz.ksharma.krail.data.gtfs_static.parser
package xyz.ksharma.krail.domain.parser

internal fun List<String>.trimQuotes(): List<String> = this.map { it.trim('\"') }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package xyz.ksharma.krail.data.gtfs_static.parser

package xyz.ksharma.krail.domain.parser

import timber.log.Timber
import xyz.ksharma.krail.model.gtfs_static.Route
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.ksharma.krail.data.gtfs_static.parser
package xyz.ksharma.krail.domain.parser

import timber.log.Timber
import xyz.ksharma.krail.model.gtfs_static.StopTimes
Expand Down Expand Up @@ -75,5 +75,4 @@ object StopTimesParser {

return stopTimesList
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.ksharma.krail.data.gtfs_static.parser
package xyz.ksharma.krail.domain.parser

import timber.log.Timber
import xyz.ksharma.krail.model.gtfs_static.Stop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.ksharma.krail.data.gtfs_static.parser
package xyz.ksharma.krail.domain.parser

import timber.log.Timber
import xyz.ksharma.krail.model.gtfs_static.Trip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package xyz.ksharma.krail.network

import android.content.ContentValues.TAG
import android.util.Log
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import timber.log.Timber
import xyz.ksharma.krail.network.di.NetworkModule.Companion.BASE_URL
import xyz.ksharma.krail.network.interceptor.AuthInterceptor.Companion.API_KEY
import javax.inject.Inject
Expand All @@ -24,7 +23,7 @@ class GtfsServiceImpl @Inject constructor(

val response = okHttpClient.newCall(request).execute()
// don't log it's entire response body,which is huge.
Log.d(TAG, "fetchSydneyTrains: ${response.body?.string()?.take(500)}")
Timber.d("fetchSydneyTrains: " + response.body?.string()?.take(500))
return response
}
}
7 changes: 7 additions & 0 deletions core/utils/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
alias(libs.plugins.krail.android.library)
}

android {
namespace = "xyz.ksharma.krail.utils"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.ksharma.krail.network.files
package xyz.ksharma.krail.utils

import android.content.Context
import java.nio.file.Path
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ hilt = "2.51.1"
okhttpBom = "4.12.0"
kotlinxSerializationJson = "1.7.0"
ksp = "2.0.0-1.0.22"
opencsv = "5.5.2"
paparazzi = "1.3.2"
wire = "5.0.0-alpha04"

Expand All @@ -33,6 +34,7 @@ activity-compose = { group = "androidx.activity", name = "activity-compose", ver
lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "android-lifecycle" }
lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "android-lifecycle" }
lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "android-lifecycle" }
opencsv = { module = "com.opencsv:opencsv", version.ref = "opencsv" }
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }

#Compose
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ include(":core:domain")
include(":core:design-system")
include(":core:model")
include(":core:network")
include(":core:utils")
include(":feature:feature1")

0 comments on commit ba188fd

Please sign in to comment.