Skip to content

Commit 7c06ce7

Browse files
committed
start of cleanup/restucturing of code
1 parent d31aa72 commit 7c06ce7

File tree

127 files changed

+410
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+410
-747
lines changed

README.md

+1-24
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,14 @@
44
[![Get it on Google Play](https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png)](https://play.google.com/store/apps/details?id=com.surrus.galwaybus)
55

66

7-
This was created as part of effort to get more familiar with developing Android apps using
8-
Kotlin and the new [Android Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html),
9-
and also to explore use of the increasingly popular [Clean Architecture](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html) approach. It's heavily based on https://github.com/bufferapp/clean-architecture-components-boilerplate.
10-
This is stil work in progress and also, at least for now,
11-
have omitted formal `Mapper` classes (though some data model translation does occur between the layers).
12-
13-
As I'm pretty new to Kotlin and some of the libraries used I'm sure
14-
there are better ways of implementing some of the code I have so feedback (and PRs!)
15-
are very welcome. I also continue to incorporate changes based on articles and other
16-
repos I come across.
17-
187
Note also that this is using [REST endpoint](https://github.com/appsandwich/galwaybus) provided by @appsandwich to retrieve
198
Galway Bus route/timetable info (Thanks Vinny!)
209

2110

2211

23-
### Use of Clean Architecture
24-
25-
For an app of this size and complexity it can be argued that full use
26-
of Clean Architecture abstractions is overkill....at least right now method implementations
27-
in many of the layers simply delegate to corresponding method in layer below (though
28-
starting to see a few exceptions to that).
29-
A reasonable approach for an app like this might be, for example, to have `ViewModel`
30-
implementations interact directly with the `Repository`. In either case,
31-
a key important benefit of this architecture is that code below the UI layer should not have
32-
any dependencies on Android framework and can be easily unit tested.
33-
34-
3512
### Kotlin Multiplatform
3613

37-
More recently I've also been using this project to explore some of the relatively new Kotlin Multiplatform
14+
Currently this project is being mostly used as platform to explore some of the relatively new Kotlin Multiplatform
3815
capabilities. There is now **kotlin-multiplatform** `ShareCode` module for example and some sample iOS apps in `ios` folder. Have also
3916
written a couple of post about some of my experiences doing this so far
4017

SharedCode/build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ kotlin {
114114

115115
iOSMain.dependencies {
116116
// Coroutines
117-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:${Versions.kotlinCoroutines}"
118-
117+
implementation('org.jetbrains.kotlinx:kotlinx-coroutines-core-native') {
118+
version {
119+
strictly '1.3.3-native-mt'
120+
}
121+
}
119122
// Ktor
120123
implementation "io.ktor:ktor-client-ios:${Versions.ktor}"
121124
implementation "io.ktor:ktor-client-core-native:${Versions.ktor}"

SharedCode/src/androidMain/kotlin/com/surrus/galwaybus/common/Dispatcher.kt

-5
This file was deleted.

SharedCode/src/commonMain/kotlin/com/surrus/galwaybus/common/Dispatcher.kt

-5
This file was deleted.

SharedCode/src/commonMain/kotlin/com/surrus/galwaybus/common/GalwayBusRepository.kt

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.surrus.galwaybus.common.model.BusRoute
66
import com.surrus.galwaybus.common.model.BusStop
77
import com.surrus.galwaybus.common.remote.GalwayBusApi
88
import com.surrus.galwaybus.db.MyDatabase
9+
import kotlinx.coroutines.Dispatchers
910
import kotlinx.coroutines.ExperimentalCoroutinesApi
1011
import kotlinx.coroutines.GlobalScope
1112
import kotlinx.coroutines.launch
@@ -21,13 +22,13 @@ class GalwayBusRepository {
2122
private val galwayBusQueries = galwayBusDb?.galwayBusQueries
2223

2324
init {
24-
GlobalScope.launch (ApplicationDispatcher) {
25-
//fetchAndStoreBusStops()
25+
GlobalScope.launch (Dispatchers.Main) {
26+
fetchAndStoreBusStops()
2627
}
2728
}
2829

2930

30-
suspend fun fetchAndStoreBusStops() {
31+
private suspend fun fetchAndStoreBusStops() {
3132
val busStops = galwayBusApi.fetchBusStops()
3233

3334
busStops.forEach {
@@ -42,16 +43,14 @@ class GalwayBusRepository {
4243

4344

4445
suspend fun getBusStops(): List<BusStop> {
45-
return galwayBusQueries?.let {
46-
it.selectAll(mapper = { stop_id, short_name, irish_short_name ->
47-
BusStop(stop_id.toInt(), short_name, irish_short_name)
48-
}).executeAsList()
49-
} ?: emptyList<BusStop>()
46+
return galwayBusQueries?.selectAll(mapper = { stop_id, short_name, irish_short_name ->
47+
BusStop(stop_id.toInt(), short_name, irish_short_name)
48+
})?.executeAsList() ?: emptyList<BusStop>()
5049
}
5150

5251

5352
fun getBusStops(success: (List<BusStop>) -> Unit) {
54-
GlobalScope.launch(ApplicationDispatcher) {
53+
GlobalScope.launch(Dispatchers.Main) {
5554
success(getBusStops())
5655
}
5756
}
@@ -62,7 +61,7 @@ class GalwayBusRepository {
6261
}
6362

6463
fun fetchBusRoutes(success: (List<BusRoute>) -> Unit) {
65-
GlobalScope.launch(ApplicationDispatcher) {
64+
GlobalScope.launch(Dispatchers.Main) {
6665
success(fetchBusRoutes())
6766
}
6867
}
@@ -72,7 +71,7 @@ class GalwayBusRepository {
7271
}
7372

7473
fun getNearestStops(latitude: Double, longitude: Double, success: (List<BusStop>) -> Unit) {
75-
GlobalScope.launch(ApplicationDispatcher) {
74+
GlobalScope.launch(Dispatchers.Main) {
7675
success(getNearestStops(latitude, longitude))
7776
}
7877
}

SharedCode/src/commonMain/kotlin/com/surrus/galwaybus/common/remote/GalwayBusApi.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GalwayBusApi(val baseUrl: String = "https://galwaybus.herokuapp.com") {
2323
private val client by lazy {
2424
HttpClient() {
2525
install(JsonFeature) {
26-
serializer = KotlinxSerializer(Json(JsonConfiguration(strictMode = false))).apply {
26+
serializer = KotlinxSerializer(Json.nonstrict).apply {
2727
setMapper(BusRoute::class, BusRoute.serializer())
2828
setMapper(BusStop::class, BusStop.serializer())
2929
//setListMapper(BusStop::class, BusStop.serializer())

SharedCode/src/iosMain/kotlin/com/surrus/galwaybus/common/Dispatcher.kt

-22
This file was deleted.

SharedCode/src/jsMain/kotlin/com/surrus/galwaybus/common/Dispatcher.kt

-5
This file was deleted.

app/build.gradle

+70-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
apply plugin: 'com.android.application'
22
//apply plugin: 'com.google.firebase.firebase-perf'
33
apply plugin: 'io.fabric'
4+
apply plugin: 'kotlin-android'
5+
apply plugin: 'kotlin-android-extensions'
6+
apply plugin: 'kotlin-kapt'
7+
apply plugin: 'kotlinx-serialization'
8+
apply plugin: "androidx.navigation.safeargs"
49

510

611
def keystorePropertiesFile = rootProject.file("keystore.properties")
@@ -65,6 +70,9 @@ android {
6570
versionName this.versionName()
6671

6772
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
73+
74+
final String googleMapsKey = System.getenv('GOOGLE_API_KEY') ?: 'test'
75+
resValue 'string', 'google_maps_key', googleMapsKey
6876
}
6977

7078
buildTypes {
@@ -87,14 +95,6 @@ android {
8795
}
8896
}
8997

90-
flavorDimensions "experience"
91-
productFlavors {
92-
instant {
93-
}
94-
installed {
95-
}
96-
}
97-
9898
packagingOptions {
9999
exclude 'META-INF/common.kotlin_module'
100100
exclude 'META-INF/*.kotlin_module'
@@ -103,10 +103,69 @@ android {
103103
}
104104

105105
dependencies {
106-
implementation project(':base')
107-
//implementation project(':ar')
106+
implementation fileTree(dir: 'libs', include: ['*.jar'])
107+
108+
implementation Kotlin.stdLib
109+
implementation Kotlin.coroutinesCore
110+
implementation Kotlin.coroutinesAndroid
111+
112+
implementation Koin.core
113+
implementation Koin.android
114+
implementation Koin.androidViewModel
115+
116+
implementation "com.crashlytics.sdk.android:crashlytics:2.10.1"
117+
118+
implementation Firebase.core
119+
implementation PlayServices.location
120+
implementation PlayServices.maps
121+
122+
implementation 'com.karumi:dexter:4.2.0'
123+
implementation 'net.danlew:android.joda:2.10.1.2'
124+
implementation 'com.orhanobut:logger:1.15'
125+
126+
implementation 'es.voghdev.pdfviewpager:library:1.0.6'
127+
implementation "com.google.code.gson:gson:2.8.5"
128+
129+
implementation Okhttp.okhttp
130+
implementation Okhttp.loggingInterceptor
131+
132+
implementation Retrofit.retrofit
133+
implementation Retrofit.converterGson
134+
implementation Retrofit.converterScalars
135+
implementation Retrofit.coroutinesAdapter
136+
137+
138+
implementation ArchComponents.navFragmentKtx
139+
implementation ArchComponents.navUiKtx
140+
implementation ArchComponents.work
141+
implementation ArchComponents.fragment
142+
143+
implementation ArchComponents.lifecycleExtensions
144+
implementation ArchComponents.roomRuntime
145+
kapt ArchComponents.roomCompiler
146+
kapt ArchComponents.lifecycleCompiler
147+
148+
implementation "com.squareup.sqldelight:android-driver:${Versions.sqlDelight}"
149+
150+
// Testing
151+
testImplementation Testing.junit
152+
testImplementation Testing.robolectric
153+
testImplementation Testing.mockWebServer
154+
testImplementation Mockito.core
155+
testImplementation Mockito.kotlin
156+
testImplementation Testing.coreTesting
157+
testImplementation Testing.couroutinesTest
158+
159+
androidTestImplementation Testing.screengrab
160+
androidTestImplementation Mockito.android
161+
androidTestImplementation Mockito.kotlin
162+
androidTestImplementation Testing.fragmentTesting
163+
androidTestImplementation 'androidx.test:rules:1.2.0'
164+
165+
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
166+
108167

109-
//implementation Firebase.performance
168+
implementation project(":SharedCode")
110169
}
111170

112171
apply plugin: 'com.google.gms.google-services'

base/src/androidTest/java/com/surrus/galwaybus/ui/RouteListFragmentTest.kt renamed to app/src/androidTest/java/com/surrus/galwaybus/ui/RouteListFragmentTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
1010
import com.nhaarman.mockitokotlin2.doReturn
1111
import com.nhaarman.mockitokotlin2.mock
1212
import com.nhaarman.mockitokotlin2.whenever
13-
import com.surrus.galwaybus.base.R
13+
import com.surrus.galwaybus.R
1414
import com.surrus.galwaybus.domain.model.BusRouteSchedule
1515
import com.surrus.galwaybus.support.RecyclerViewMatchers.withRecyclerView
1616
import com.surrus.galwaybus.ui.viewmodel.BusRoutesViewModel

base/src/debug/AndroidManifest.xml renamed to app/src/debug/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.surrus.galwaybus.base">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.surrus.galwaybus">
33

44

55
<!-- Needed for fastlane screengrab -->

app/src/instant/AndroidManifest.xml

-8
This file was deleted.

app/src/instant/res/values/strings.xml

-2
This file was deleted.

app/src/main/AndroidManifest.xml

+78
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,82 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
23
package="com.surrus.galwaybus">
34

5+
6+
<!-- <uses-permission android:name="android.permission.CAMERA" /> -->
7+
<uses-permission android:name="android.permission.INTERNET" />
8+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9+
<uses-permission android:name="android.permission.WAKE_LOCK" />
10+
11+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
12+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
13+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
14+
15+
<application
16+
android:name="com.surrus.galwaybus.GalwayBusApplication"
17+
android:allowBackup="true"
18+
android:icon="@mipmap/ic_launcher"
19+
android:label="@string/app_name"
20+
android:supportsRtl="true"
21+
android:theme="@style/AppTheme">
22+
23+
<uses-library android:name="org.apache.http.legacy" android:required="false" />
24+
25+
<meta-data
26+
android:name="com.google.android.geo.API_KEY"
27+
android:value="@string/google_maps_key" />
28+
29+
30+
<meta-data
31+
android:name="firebase_crashlytics_collection_enabled"
32+
android:value="false" />
33+
34+
35+
<activity
36+
android:name="com.surrus.galwaybus.ui.HomeActivity"
37+
android:launchMode="singleTop"
38+
android:label="@string/title_activity_home">
39+
40+
<meta-data android:name="android.app.searchable"
41+
android:resource="@xml/searchable" />
42+
43+
<intent-filter>
44+
<action android:name="android.intent.action.SEARCH" />
45+
</intent-filter>
46+
47+
<intent-filter>
48+
<action android:name="android.intent.action.MAIN" />
49+
<category android:name="android.intent.category.LAUNCHER" />
50+
</intent-filter>
51+
52+
<intent-filter android:autoVerify="true">
53+
<action android:name="android.intent.action.VIEW"/>
54+
<category android:name="android.intent.category.DEFAULT"/>
55+
<category android:name="android.intent.category.BROWSABLE"/>
56+
<data android:host="www.surrus.com" android:pathPrefix="/galwaybus" android:scheme="http"/>
57+
<data android:host="www.surrus.com" android:pathPrefix="/galwaybus" android:scheme="https"/>
58+
</intent-filter>
59+
60+
<meta-data android:name="default-url" android:value="https://www.surrus.com/galwaybus" />
61+
62+
</activity>
63+
64+
<activity
65+
android:name="com.surrus.galwaybus.ui.SettingsActivity"
66+
android:label="@string/title_activity_settings"
67+
android:parentActivityName="com.surrus.galwaybus.ui.HomeActivity" />
68+
<activity
69+
android:name="com.surrus.galwaybus.ui.SchedulePdfActivity"
70+
android:parentActivityName="com.surrus.galwaybus.ui.HomeActivity" />
71+
72+
73+
<provider
74+
android:name="com.google.firebase.provider.FirebaseInitProvider"
75+
android:authorities="com.surrus.galwaybus.firebaseinitprovider"
76+
android:exported="false"
77+
tools:node="merge"/>
78+
79+
</application>
80+
81+
482
</manifest>

0 commit comments

Comments
 (0)