This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.github.harmittaa.koinexample.networking.WeatherApi | |
import org.koin.dsl.module | |
val forecastModule = module { | |
factory { WeatherRepository(get()) } | |
} | |
class WeatherRepository(private val weatherApi: WeatherApi) { | |
suspend fun getWeather() = weatherApi.getForecast() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.github.harmittaa.koinexample.model.Weather | |
import retrofit2.http.GET | |
interface WeatherApi { | |
@GET("weather?q=Helsinki&units=metric") | |
suspend fun getForecast(): Weather | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import okhttp3.Interceptor | |
import okhttp3.Response | |
class AuthInterceptor() : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
var req = chain.request() | |
// DONT INCLUDE API KEYS IN YOUR SOURCE CODE | |
val url = req.url().newBuilder().addQueryParameter("APPID", "your_key_here").build() | |
req = req.newBuilder().url(url).build() | |
return chain.proceed(req) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.github.harmittaa.koinexample.BuildConfig | |
import okhttp3.OkHttpClient | |
import org.koin.dsl.module | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
val networkModule = module { | |
factory { AuthInterceptor() } | |
factory { provideOkHttpClient(get()) } | |
factory { provideForecastApi(get()) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.MutableLiveData | |
import androidx.lifecycle.ViewModel | |
import com.github.harmittaa.koinexample.persistence.ExamplePreferences | |
import org.koin.dsl.module | |
val viewModelModule = module { | |
factory { ExampleViewModel(get()) } | |
} | |
class ExampleViewModel(preferences: ExamplePreferences) : ViewModel() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.fragment.app.Fragment | |
import androidx.lifecycle.Observer | |
import com.github.harmittaa.koinexample.R | |
import org.koin.androidx.viewmodel.ext.android.viewModel | |
import org.koin.dsl.module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import com.github.harmittaa.koinexample.R | |
import com.github.harmittaa.koinexample.fragment.ExampleFragment | |
import com.github.harmittaa.koinexample.persistence.ExamplePreferences | |
import org.koin.android.ext.android.inject | |
class MainActivity : AppCompatActivity() { | |
private val preferences: ExamplePreferences by inject() | |
private val exampleFragment: ExampleFragment by inject() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.content.SharedPreferences | |
import org.koin.android.ext.koin.androidContext | |
import org.koin.dsl.module | |
val prefModule = module { | |
single { ExamplePreferences(androidContext()) } | |
} | |
class ExamplePreferences(context: Context) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// full tutorial here: | |
// https://medium.com/@harmittaa/setting-camera-focus-mode-for-vuforia-arcamera-in-unity-6b3745297c3d | |
using UnityEngine; | |
using System.Collections; | |
using Vuforia; | |
public class CameraFocusController: MonoBehaviour { | |
// code from Vuforia Developer Library |