Skip to content

Commit

Permalink
style: config spotless, ktlint and format all ❤️ (#57)
Browse files Browse the repository at this point in the history
* style: config spotless, ktlint and format all ❤️

* ci: update

* ci: update

* ci: update

* ci: paths-ignore: [ '**.md' ]
  • Loading branch information
hoc081098 authored Oct 9, 2022
1 parent 939b9cb commit 515fc1a
Show file tree
Hide file tree
Showing 150 changed files with 2,649 additions and 2,360 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root=true
[*]
indent_size=2
end_of_line=lf
charset=utf-8
trim_trailing_whitespace=true
insert_final_newline=true
[*.{kt,kts}]
ij_kotlin_imports_layout=*
[*.xml]
indent_size=4
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ name: Build CI
on:
push:
branches: [ try_mvi ]
paths-ignore: [ '**.md' ]
pull_request:
branches: [ try_mvi ]
paths-ignore: [ '**.md' ]

jobs:
build:
Expand All @@ -25,9 +27,6 @@ jobs:
env:
BASEURL: ${{ secrets.PLACE_API_KEY }}
run: echo PLACE_API_KEY="$PLACE_API_KEY" > ./local.properties

# - name: Spotless check
# run: ./gradlew spotlessCheck

- name: Build debug APK
uses: gradle/gradle-build-action@v2
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/remove-old-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Remove old artifacts

on:
schedule:
# Runs at 01:00 UTC on the 1, 8, 15, 22 and 29th of every month.
- cron: '0 1 */7 * *'

jobs:
remove-old-artifacts:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Remove old artifacts
uses: c-hive/gha-remove-artifacts@v1
with:
age: '7 days'
skip-tags: true
skip-recent: 5
57 changes: 57 additions & 0 deletions .github/workflows/reviewdog-suggester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: reviewdog-suggester
on:
pull_request:
types: [ opened, synchronize, reopened ]
paths-ignore: [ '**.md' ]

jobs:
kotlin:
name: runner / suggester / spotless
runs-on: ubuntu-latest
steps:
- name: Check try_mvi branch
uses: actions/checkout@v3
with:
ref: try_mvi

- name: Checkout current branch
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Cache gradle, wrapper and buildSrc
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-
- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Decode PLACE_API_KEY
env:
BASEURL: ${{ secrets.PLACE_API_KEY }}
run: echo PLACE_API_KEY="$PLACE_API_KEY" > ./local.properties

- name: Spotless apply
run: ./gradlew spotlessKotlinApply

- name: Reviewdog
uses: reviewdog/action-suggester@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tool_name: spotless

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Spotless check
run: ./gradlew spotlessKotlinCheck
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import org.junit.runner.RunWith
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.hoc.weatherapp", appContext.packageName)
}
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.hoc.weatherapp", appContext.packageName)
}
}
30 changes: 15 additions & 15 deletions app/src/main/java/com/hoc/weatherapp/CancelNotificationReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ class CancelNotificationReceiver : BroadcastReceiver(), KoinComponent {
context.cancelNotificationById(WEATHER_NOTIFICATION_ID)

Completable
.fromCallable { settingPreferences.showNotificationPreference.saveActual(false) }
.subscribeOn(Schedulers.single())
.observeOn(AndroidSchedulers.mainThread())
.doOnComplete { settingPreferences.showNotificationPreference.save(false) }
.doOnTerminate { pendingResult.finish() }
.subscribe(object : CompletableObserver {
override fun onComplete() {
LocalBroadcastManager
.getInstance(context)
.sendBroadcast(Intent(ACTION_CANCEL_NOTIFICATION))
debug("[SUCCESS] showNotificationPreference", TAG)
}
.fromCallable { settingPreferences.showNotificationPreference.saveActual(false) }
.subscribeOn(Schedulers.single())
.observeOn(AndroidSchedulers.mainThread())
.doOnComplete { settingPreferences.showNotificationPreference.save(false) }
.doOnTerminate { pendingResult.finish() }
.subscribe(object : CompletableObserver {
override fun onComplete() {
LocalBroadcastManager
.getInstance(context)
.sendBroadcast(Intent(ACTION_CANCEL_NOTIFICATION))
debug("[SUCCESS] showNotificationPreference", TAG)
}

override fun onSubscribe(d: Disposable) = Unit
override fun onError(e: Throwable) = Unit
})
override fun onSubscribe(d: Disposable) = Unit
override fun onError(e: Throwable) = Unit
})
}
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/hoc/weatherapp/data/CityRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.reactivex.Completable
import io.reactivex.Observable
import io.reactivex.Single


interface CityRepository {
/**
* Change selected city to [city]
Expand Down Expand Up @@ -40,4 +39,4 @@ interface CityRepository {
* Synchronous access selected city
*/
val selectedCity: City?
}
}
88 changes: 46 additions & 42 deletions app/src/main/java/com/hoc/weatherapp/data/CityRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ import com.hoc.weatherapp.data.models.entity.City
import com.hoc.weatherapp.data.remote.OpenWeatherMapApiService
import com.hoc.weatherapp.data.remote.TimezoneDbApiService
import com.hoc.weatherapp.data.remote.getZoneId
import com.hoc.weatherapp.utils.*
import com.hoc.weatherapp.utils.None
import com.hoc.weatherapp.utils.Optional
import com.hoc.weatherapp.utils.Some
import com.hoc.weatherapp.utils.debug
import com.hoc.weatherapp.utils.getOrNull
import io.reactivex.Completable
import io.reactivex.Single
import io.reactivex.rxkotlin.Singles
import io.reactivex.schedulers.Schedulers

class CityRepositoryImpl(
private val openWeatherMapApiService: OpenWeatherMapApiService,
private val timezoneDbApiService: TimezoneDbApiService,
private val cityLocalDataSource: CityLocalDataSource,
private val fiveDayForecastLocalDataSource: FiveDayForecastLocalDataSource,
private val currentWeatherLocalDataSource: CurrentWeatherLocalDataSource,
private val selectedCityPreference: SelectedCityPreference
private val openWeatherMapApiService: OpenWeatherMapApiService,
private val timezoneDbApiService: TimezoneDbApiService,
private val cityLocalDataSource: CityLocalDataSource,
private val fiveDayForecastLocalDataSource: FiveDayForecastLocalDataSource,
private val currentWeatherLocalDataSource: CurrentWeatherLocalDataSource,
private val selectedCityPreference: SelectedCityPreference
) : CityRepository {

override val selectedCity get() = selectedCityPreference.value.getOrNull()
Expand All @@ -31,51 +35,51 @@ class CityRepositoryImpl(

override fun deleteCity(city: City): Single<City> {
return Completable.mergeArray(
cityLocalDataSource
.deleteCity(city)
.subscribeOn(Schedulers.io()),
/**
* If [city] is current selected city, then [changeSelectedCity] to null
*/
Single
.fromCallable { selectedCityPreference.value }
.filter { it.getOrNull() == city }
.flatMapCompletable { changeSelectedCity(None) }
cityLocalDataSource
.deleteCity(city)
.subscribeOn(Schedulers.io()),
/**
* If [city] is current selected city, then [changeSelectedCity] to null
*/
Single
.fromCallable { selectedCityPreference.value }
.filter { it.getOrNull() == city }
.flatMapCompletable { changeSelectedCity(None) }
).toSingleDefault(city)
}

override fun addCityByLatLng(latitude: Double, longitude: Double): Single<City> {
return Singles.zip(
openWeatherMapApiService
.getCurrentWeatherByLatLng(latitude, longitude)
.subscribeOn(Schedulers.io()),
getZoneId(timezoneDbApiService, latitude, longitude)
openWeatherMapApiService
.getCurrentWeatherByLatLng(latitude, longitude)
.subscribeOn(Schedulers.io()),
getZoneId(timezoneDbApiService, latitude, longitude)
)
.flatMap {
debug("@@@@@@@$it", "@@@@")
saveCityAndCurrentWeather(
cityLocalDataSource,
currentWeatherLocalDataSource,
it.first,
it.second
)
.flatMap {
debug("@@@@@@@$it", "@@@@")
saveCityAndCurrentWeather(
cityLocalDataSource,
currentWeatherLocalDataSource,
it.first,
it.second
)
}
.map { it.city }
.flatMap { city ->
openWeatherMapApiService
.get5DayEvery3HourForecastByCityId(city.id)
.subscribeOn(Schedulers.io())
.flatMap { saveFiveDayForecastWeather(fiveDayForecastLocalDataSource, it) }
.map { city }
}
}
.map { it.city }
.flatMap { city ->
openWeatherMapApiService
.get5DayEvery3HourForecastByCityId(city.id)
.subscribeOn(Schedulers.io())
.flatMap { saveFiveDayForecastWeather(fiveDayForecastLocalDataSource, it) }
.map { city }
}
}

override fun changeSelectedCity(city: City) = changeSelectedCity(Some(city))

private fun changeSelectedCity(optionalCity: Optional<City>): Completable {
return Completable
.fromCallable { selectedCityPreference.save(optionalCity) }
.subscribeOn(Schedulers.single())
.onErrorResumeNext { Completable.error(SaveSelectedCityError(it)) }
.fromCallable { selectedCityPreference.save(optionalCity) }
.subscribeOn(Schedulers.single())
.onErrorResumeNext { Completable.error(SaveSelectedCityError(it)) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface CurrentWeatherRepository {
*/
fun refreshCurrentWeatherOfSelectedCity(): Single<CityAndCurrentWeather>


/**
* Get pair of selected city and current weather, get from local database
* @return [Observable] that emits [Optional]s of [CityAndCurrentWeather], None when having no selected city
Expand All @@ -32,4 +31,4 @@ interface CurrentWeatherRepository {
* @return [Observable] that emits [List]s of [CityAndCurrentWeather]
*/
fun getAllCityAndCurrentWeathers(querySearch: String): Observable<List<CityAndCurrentWeather>>
}
}
Loading

0 comments on commit 515fc1a

Please sign in to comment.