Skip to content

Commit c5f8592

Browse files
committed
Update Koin to release 2.2.2
Signed-off-by: Rafael Chagas <chagas@gmail.com>
1 parent e9be060 commit c5f8592

6 files changed

Lines changed: 48 additions & 53 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.72'
4+
ext.kotlin_version = '1.4.21'
55

66
repositories {
77
google()

library/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ android {
1414

1515
kotlinOptions {
1616
jvmTarget = "1.8"
17+
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
1718
}
1819

1920
defaultConfig {
@@ -50,7 +51,7 @@ dependencies {
5051
// Support library
5152
implementation 'androidx.appcompat:appcompat:1.2.0'
5253
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
53-
implementation 'com.google.android.material:material:1.3.0-alpha03'
54+
implementation 'com.google.android.material:material:1.3.0-beta01'
5455

5556
// Android architecture components
5657
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
@@ -63,8 +64,8 @@ dependencies {
6364
implementation 'com.google.android.libraries.places:places:2.4.0'
6465

6566
// Koin for Android
66-
implementation 'org.koin:koin-android:2.1.5'
67-
implementation 'org.koin:koin-android-viewmodel:2.1.5'
67+
implementation 'org.koin:koin-android:2.2.2'
68+
implementation 'org.koin:koin-android-viewmodel:2.2.2'
6869

6970
// Rx
7071
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'

library/src/main/java/com/rtchagas/pingplacepicker/PingPlacePicker.kt

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
package com.rtchagas.pingplacepicker
22

33
import android.app.Activity
4-
import android.app.Application
54
import android.content.Intent
65
import com.google.android.gms.common.ConnectionResult
76
import com.google.android.gms.common.GoogleApiAvailability
87
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
98
import com.google.android.gms.maps.model.LatLng
109
import com.google.android.libraries.places.api.model.Place
1110
import com.rtchagas.pingplacepicker.inject.PingKoinContext
12-
import com.rtchagas.pingplacepicker.inject.repositoryModule
13-
import com.rtchagas.pingplacepicker.inject.viewModelModule
1411
import com.rtchagas.pingplacepicker.ui.PlacePickerActivity
15-
import org.koin.android.ext.koin.androidContext
16-
import org.koin.android.ext.koin.androidLogger
17-
import org.koin.dsl.koinApplication
1812

1913
class PingPlacePicker private constructor() {
2014

@@ -64,17 +58,20 @@ class PingPlacePicker private constructor() {
6458
* Set whether the library should return the place coordinate retrieved from GooglePlace or the actual selected location from google map
6559
*/
6660
fun setShouldReturnActualLatLng(shouldReturnActualLatLng: Boolean): IntentBuilder {
67-
intent.putExtra(PlacePickerActivity.EXTRA_RETURN_ACTUAL_LATLNG, shouldReturnActualLatLng)
61+
intent.putExtra(
62+
PlacePickerActivity.EXTRA_RETURN_ACTUAL_LATLNG,
63+
shouldReturnActualLatLng
64+
)
6865
return this
6966
}
7067

7168
@Throws(GooglePlayServicesNotAvailableException::class)
7269
fun build(activity: Activity): Intent {
7370

74-
initKoin(activity.application)
71+
PingKoinContext.init(activity.application)
7572

7673
val result: Int =
77-
GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity)
74+
GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity)
7875

7976
if (ConnectionResult.SUCCESS != result) {
8077
throw GooglePlayServicesNotAvailableException(result)
@@ -85,21 +82,6 @@ class PingPlacePicker private constructor() {
8582
intent.setClass(activity, PlacePickerActivity::class.java)
8683
return intent
8784
}
88-
89-
/**
90-
* Initializes the Dependency Injection framework by passing
91-
* the current application context.
92-
*/
93-
private fun initKoin(application: Application) {
94-
PingKoinContext.koinApp = koinApplication {
95-
androidLogger()
96-
androidContext(application)
97-
modules(listOf(
98-
repositoryModule,
99-
viewModelModule)
100-
)
101-
}
102-
}
10385
}
10486

10587
companion object {
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
package com.rtchagas.pingplacepicker.inject
22

3+
import android.content.Context
4+
import org.koin.android.ext.koin.androidContext
5+
import org.koin.android.ext.koin.androidLogger
36
import org.koin.core.Koin
4-
import org.koin.core.KoinApplication
5-
import org.koin.core.KoinComponent
7+
import org.koin.core.component.KoinApiExtension
8+
import org.koin.core.component.KoinComponent
9+
import org.koin.dsl.koinApplication
610

711
object PingKoinContext {
812

9-
var koinApp: KoinApplication? = null
13+
private lateinit var appContext: Context
1014

15+
val koin: Koin by lazy {
16+
koinApplication {
17+
androidLogger()
18+
androidContext(appContext)
19+
modules(listOf(repositoryModule, viewModelModule))
20+
}.koin
21+
}
22+
23+
/**
24+
* Initializes the Dependency Injection framework by passing
25+
* the current application context.
26+
*/
27+
@Synchronized
28+
fun init(context: Context) {
29+
appContext = context.applicationContext
30+
}
1131
}
1232

33+
@OptIn(KoinApiExtension::class)
1334
interface PingKoinComponent : KoinComponent {
1435

15-
override fun getKoin(): Koin = PingKoinContext.koinApp?.koin!!
36+
override fun getKoin(): Koin = PingKoinContext.koin
1637

17-
}
38+
}

library/src/main/java/com/rtchagas/pingplacepicker/ui/PlacePickerActivity.kt

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import androidx.core.content.res.ResourcesCompat
1818
import androidx.core.graphics.drawable.DrawableCompat
1919
import androidx.core.view.doOnLayout
2020
import androidx.core.view.isVisible
21-
import androidx.lifecycle.Observer
2221
import androidx.recyclerview.widget.LinearLayoutManager
2322
import com.google.android.gms.location.FusedLocationProviderClient
2423
import com.google.android.gms.location.LocationServices
@@ -42,7 +41,6 @@ import com.rtchagas.pingplacepicker.PingPlacePicker
4241
import com.rtchagas.pingplacepicker.R
4342
import com.rtchagas.pingplacepicker.helper.PermissionsHelper
4443
import com.rtchagas.pingplacepicker.inject.PingKoinComponent
45-
import com.rtchagas.pingplacepicker.inject.PingKoinContext
4644
import com.rtchagas.pingplacepicker.viewmodel.PlacePickerViewModel
4745
import com.rtchagas.pingplacepicker.viewmodel.Resource
4846
import io.reactivex.disposables.CompositeDisposable
@@ -51,7 +49,8 @@ import org.jetbrains.anko.toast
5149
import org.koin.android.viewmodel.ext.android.viewModel
5250
import kotlin.math.abs
5351

54-
class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
52+
class PlacePickerActivity : AppCompatActivity(),
53+
PingKoinComponent,
5554
OnMapReadyCallback,
5655
GoogleMap.OnMarkerClickListener,
5756
PlaceConfirmDialogFragment.OnPlaceConfirmedListener {
@@ -101,13 +100,6 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
101100
super.onCreate(savedInstanceState)
102101
setContentView(R.layout.activity_place_picker)
103102

104-
// Check if PING was killed for some reason.
105-
// If so, should restart the activity and init everything again.
106-
if (PingKoinContext.koinApp == null) {
107-
finish()
108-
return
109-
}
110-
111103
// Configure the toolbar
112104
setSupportActionBar(toolbar)
113105
supportActionBar?.setDisplayHomeAsUpEnabled(true)
@@ -204,10 +196,9 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
204196
override fun onPlaceConfirmed(place: Place) {
205197
val data = Intent()
206198

207-
if (intent.getBooleanExtra(EXTRA_RETURN_ACTUAL_LATLNG, false)){
199+
if (intent.getBooleanExtra(EXTRA_RETURN_ACTUAL_LATLNG, false)) {
208200
data.putExtra(PingPlacePicker.EXTRA_ACTUAL_LATLNG, selectedLatLng)
209-
}
210-
else {
201+
} else {
211202
data.putExtra(PingPlacePicker.EXTRA_ACTUAL_LATLNG, place.latLng)
212203
}
213204

@@ -255,9 +246,9 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
255246
for (place in places) {
256247
place.latLng?.let {
257248
val marker: Marker = addMarker(
258-
MarkerOptions()
259-
.position(it)
260-
.icon(getPlaceMarkerBitmap(place))
249+
MarkerOptions()
250+
.position(it)
251+
.icon(getPlaceMarkerBitmap(place))
261252
)
262253

263254
marker.tag = place
@@ -499,7 +490,7 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
499490

500491
private fun loadNearbyPlaces() {
501492
viewModel.getNearbyPlaces(lastKnownLocation ?: defaultLocation)
502-
.observe(this, Observer { handlePlacesLoaded(it) })
493+
.observe(this, { handlePlacesLoaded(it) })
503494
}
504495

505496
private fun moveCameraToSelectedPlace(place: Place) {
@@ -511,7 +502,7 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
511502
private fun refreshNearbyPlaces() {
512503
googleMap?.cameraPosition?.run {
513504
viewModel.getNearbyPlaces(target)
514-
.observe(this@PlacePickerActivity, Observer { handlePlacesLoaded(it) })
505+
.observe(this@PlacePickerActivity, { handlePlacesLoaded(it) })
515506
}
516507
}
517508

@@ -567,7 +558,7 @@ class PlacePickerActivity : AppCompatActivity(), PingKoinComponent,
567558
googleMap?.cameraPosition?.run {
568559
selectedLatLng = target
569560
viewModel.getPlaceByLocation(target).observe(this@PlacePickerActivity,
570-
Observer { handlePlaceByLocation(it) })
561+
{ handlePlaceByLocation(it) })
571562
}
572563
}
573564

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies {
4343
// Support library
4444
implementation 'androidx.appcompat:appcompat:1.2.0'
4545
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
46-
implementation 'com.google.android.material:material:1.3.0-alpha03'
46+
implementation 'com.google.android.material:material:1.3.0-beta01'
4747

4848
// Places library
4949
implementation 'com.google.android.libraries.places:places:2.4.0'

0 commit comments

Comments
 (0)