Skip to content

Commit

Permalink
Merge branch 'dev' into 223-replace-rxjava-with-coroutines-radar
Browse files Browse the repository at this point in the history
  • Loading branch information
sphrak committed Dec 19, 2020
2 parents d147bca + 9ae71ab commit d96c7a6
Show file tree
Hide file tree
Showing 36 changed files with 244 additions and 823 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Setup environment
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: |
echo "${GOOGLE_SERVICES_JSON}" | base64 --decode > app/google-services.json
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
- run: |
echo "${{ secrets.KEYSTORE_FILE_BASE64 }}" > keystore.asc
gpg -d --passphrase "${{ secrets.KEYSTORE_FILE_DECRYPT_PASSWORD }}" --batch keystore.asc > .keystore
- name: Setup environment
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: |
echo "${GOOGLE_SERVICES_JSON}" | base64 --decode > app/google-services.json
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
Expand All @@ -26,10 +31,6 @@ jobs:
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
run: |
./gradlew assembleGithubRelease
sudo apt-get -y install tree
tree app/build/outputs
ls -lah app/build/
ls -lah
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[![github-ci](https://github.com/vadret/android/workflows/V%C3%A4dret%20Android%20App/badge.svg)](https://github.com/vadret/android/actions)
[![github-releases](https://img.shields.io/github/v/release/sphrak/vadret)](https://github.com/vadret/android/releases/)
[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/vadret/android/blob/master/LICENSE)
[![CodeFactor](https://www.codefactor.io/repository/github/vadret/android/badge)](https://www.codefactor.io/repository/github/vadret/android)

![Vädret](https://raw.githubusercontent.com/vadret/android/master/assets/logo.png)

# Vädret
A simple weather app that uses the Swedish weather service [SMHI](https://opendata-download-metfcst.smhi.se/) to fetch weather data, and [Krisinformation](https://www.krisinformation.se/en) for emergency information from Swedish authorities. Built with MVI/MVVM in mind on top of RxJava2, written entirely in Kotlin. Icons used in this project can be found [here](https://github.com/vadret/assets). The data is licensed under [Creative commons Erkännande 4.0 SE](https://www.smhi.se/klimatdata/oppna-data/information-om-oppna-data/villkor-for-anvandning-1.30622).
A simple weather app that uses the Swedish weather service [SMHI](https://opendata-download-metfcst.smhi.se/) to fetch weather data, and [Krisinformation](https://www.krisinformation.se/en) for emergency information from Swedish authorities. MVI written entirely in Kotlin. Icons used in this project can be found [here](https://github.com/vadret/assets). The data is licensed under [Creative commons Erkännande 4.0 SE](https://www.smhi.se/klimatdata/oppna-data/information-om-oppna-data/villkor-for-anvandning-1.30622).

![Weather](https://raw.githubusercontent.com/vadret/android/master/assets/weather.png)
![Warning](https://raw.githubusercontent.com/vadret/android/master/assets/warning.png)
Expand Down
33 changes: 23 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

def static loadFromEnvironment(String key) {
return System.getenv(key)
Expand Down Expand Up @@ -39,8 +42,8 @@ android {
applicationId "fi.kroon.vadret"
minSdkVersion 21
targetSdkVersion 30
versionCode 26
versionName "1.2.10"
versionCode 27
versionName "2.0.0"
vectorDrawables.useSupportLibrary = true
flavorDimensions "default"
testInstrumentationRunner "androidx.top.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -96,6 +99,9 @@ android {
productFlavors {
google {
signingConfig signingConfigs.release
firebaseCrashlytics {
mappingFileUploadEnabled true
}
}
fdroid {
signingConfig fdroid.signingConfig
Expand Down Expand Up @@ -131,18 +137,18 @@ dependencies {
def CONSTRAINT_LAYOUT_VERSION = "2.0.2"
def CORBIND_VERSION = "1.4.0"
def CORE_KTX_VERSION = "1.3.2"
def COROUTINES_VERSION = "1.4.0-M1"
def CRASHLYTICS_VERSION = "2.10.1"
def DAGGER_VERSION = "2.29.1"
def COROUTINES_VERSION = "1.4.2"
def DAGGER_VERSION = "2.30.1"
def EITHER_VERSION = "1.2.0"
def FRAGMENT_VERSION = "1.3.0-beta01"
def JUNIT_VERSION = "4.13"
def KOTLIN_STDLIB_VERSION = "1.4.10"
def KTLINT_VERSION = "0.39.0"
def KOTLINX_SERIALIZATION = "1.0.1"
def KTLINT_VERSION = "0.40.0"
def MATERIAL_VERSION = "1.2.1"
def MOCKITO_CORE_VERSION = "3.1.0"
def MOSHI_VERSION = "1.9.2"
def NAVIGATION_VERSION = "2.3.1"
def NAVIGATION_VERSION = "2.3.2"
def OKHTTP_VERSION = "4.2.2"
def OKIO_VERSION = "2.6.0"
def OSMDROID_VERSION = "6.1.2"
Expand All @@ -158,6 +164,7 @@ dependencies {
def THREETEN_ABP_VERSION = "1.2.1"
def THREETEN_BP_VERSION = "1.4.0"
def TIMBER_VERSION = "4.7.1"
def LIFECYCLE_VERSION = "2.2.0"

implementation fileTree(dir: 'libs', include: ['*.jar'])

Expand All @@ -171,6 +178,11 @@ dependencies {
implementation "androidx.preference:preference-ktx:${PREFERENCE_VERSION}"
implementation "com.google.android.material:material:${MATERIAL_VERSION}"

// Lifecycle
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$LIFECYCLE_VERSION"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$LIFECYCLE_VERSION"
kapt "androidx.lifecycle:lifecycle-compiler:$LIFECYCLE_VERSION"

// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${COROUTINES_VERSION}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${COROUTINES_VERSION}"
Expand All @@ -196,6 +208,7 @@ dependencies {
implementation "com.squareup.retrofit2:adapter-rxjava2:${RETROFIT_VERSION}"
implementation "com.squareup.retrofit2:converter-moshi:${RETROFIT_VERSION}"
implementation "com.squareup.retrofit2:retrofit:${RETROFIT_VERSION}"
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"

// Database
implementation "androidx.room:room-runtime:${ROOM_VERSION}"
Expand All @@ -208,6 +221,7 @@ dependencies {
implementation "com.squareup.moshi:moshi:${MOSHI_VERSION}"
implementation "com.squareup.retrofit2:converter-moshi:${RETROFIT_VERSION}"
kapt "com.squareup.moshi:moshi-kotlin-codegen:${MOSHI_VERSION}"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:${KOTLINX_SERIALIZATION}"

// Dependency Injection
implementation "com.google.dagger:dagger:${DAGGER_VERSION}"
Expand All @@ -229,9 +243,8 @@ dependencies {

// Debugging, Testing, Linting, Analytics
debugImplementation "com.squareup.leakcanary:leakcanary-android:2.5"
googleImplementation("com.crashlytics.sdk.android:crashlytics:${CRASHLYTICS_VERSION}@aar") {
transitive = true
}
googleImplementation platform('com.google.firebase:firebase-bom:26.0.0')
googleImplementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation "com.jakewharton.timber:timber:${TIMBER_VERSION}"
ktlint "com.pinterest:ktlint:${KTLINT_VERSION}"
testImplementation "junit:junit:${JUNIT_VERSION}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package fi.kroon.vadret

import android.content.Context
import com.crashlytics.android.Crashlytics
import com.crashlytics.android.core.CrashlyticsCore
import io.fabric.sdk.android.Fabric
import com.google.firebase.crashlytics.FirebaseCrashlytics

class VadretApplication : BaseApplication() {

Expand All @@ -19,9 +17,6 @@ class VadretApplication : BaseApplication() {
}

private fun initCrashlytics() {
val crashlyticsKit = Crashlytics.Builder()
.core(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build()
Fabric.with(this, crashlyticsKit)
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
}
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ import fi.kroon.vadret.data.weatherforecast.model.Weather
import fi.kroon.vadret.data.weatherforecast.model.WeatherOut
import fi.kroon.vadret.data.weatherforecast.net.WeatherForecastNetDataSource
import fi.kroon.vadret.util.HTTP_200_OK
import fi.kroon.vadret.util.HTTP_204_NO_CONTENT
import fi.kroon.vadret.util.HTTP_400_BAD_REQUEST
import fi.kroon.vadret.util.HTTP_403_FORBIDDEN
import fi.kroon.vadret.util.HTTP_404_NOT_FOUND
import fi.kroon.vadret.util.HTTP_500_INTERNAL_SERVER_ERROR
import fi.kroon.vadret.util.HTTP_503_SERVICE_UNAVAILABLE
import fi.kroon.vadret.util.HTTP_504_GATEWAY_TIMEOUT
import fi.kroon.vadret.util.NetworkHandler
import fi.kroon.vadret.util.extension.asLeft
import fi.kroon.vadret.util.extension.asRight
import fi.kroon.vadret.util.extension.toCoordinate
import io.github.sphrak.either.Either
import io.reactivex.Single
import retrofit2.Response
import timber.log.Timber
import javax.inject.Inject

class WeatherForecastRepository @Inject constructor(
Expand All @@ -33,32 +27,30 @@ class WeatherForecastRepository @Inject constructor(
private val exceptionHandler: ExceptionHandler
) : IErrorHandler by errorHandler, IExceptionHandler<Failure> by exceptionHandler {

operator fun invoke(request: WeatherOut): Single<Either<Failure, Weather>> =
when (networkHandler.isConnected) {
true ->
suspend operator fun invoke(request: WeatherOut): Either<Failure, Weather> =
try {
if (networkHandler.isConnected) {
weatherForecastNetDataSource
.get()
.getWeatherForecast(
request.category,
request.version,
request.longitude.toCoordinate(),
request.latitude.toCoordinate()
).map { response: Response<Weather> ->
when (response.code()) {
HTTP_200_OK -> Either.Right(response.body()!!)
HTTP_204_NO_CONTENT -> WeatherForecastFailure.NoWeatherAvailable.asLeft()
HTTP_403_FORBIDDEN -> Failure.HttpForbidden403.asLeft()
HTTP_404_NOT_FOUND -> WeatherForecastFailure.NoWeatherAvailableForThisLocation.asLeft()
HTTP_400_BAD_REQUEST -> Failure.HttpBadRequest400.asLeft()
HTTP_500_INTERNAL_SERVER_ERROR -> Failure.HttpInternalServerError500.asLeft()
HTTP_503_SERVICE_UNAVAILABLE -> Failure.HttpServiceUnavailable503.asLeft()
HTTP_504_GATEWAY_TIMEOUT -> Failure.HttpGatewayTimeout504.asLeft()
else -> WeatherForecastFailure.NoWeatherAvailable.asLeft()
).let { response: Response<Weather> ->
if (response.code() == HTTP_200_OK) {
response.body()?.asRight() ?: WeatherForecastFailure.NoWeatherAvailable.asLeft()
} else {
WeatherForecastFailure.NoWeatherAvailable.asLeft()
}
}
false -> getNetworkOfflineError()
}.onErrorReturn {
exceptionHandler(it)
.asLeft()
} else {
Failure
.NetworkOfflineError("error: network offline or not available")
.asLeft()
}
} catch (exception: Exception) {
Timber.e(exception)
Failure.NetworkError().asLeft()
}
}

This file was deleted.

Loading

0 comments on commit d96c7a6

Please sign in to comment.