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
/** | |
* Credit https://github.com/dbottillo/Blog/blob/espresso_match_imageview/app/src/androidTest/java/com/danielebottillo/blog/config/DrawableMatcher.java | |
* Original Author: https://github.com/dbottillo | |
* Converted to Kotlin by Hardik Trivedi | |
*/ | |
class DrawableMatcher internal constructor(private val expectedId: Int) : | |
TypeSafeMatcher<View>(View::class.java) { | |
private var resourceName: String? = null | |
override fun matchesSafely(target: View): Boolean { |
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
:shared:commonMain:OSInformation.kt | |
expect fun getOSInformation(): String | |
:shared:androidMain:OSInformation.kt | |
actual fun getOSInformation(): String { | |
print(Build.VERSION_CODES::class.java.fields) | |
return "${Build.VERSION_CODES::class.java.fields[Build.VERSION.SDK_INT].name} ${Build.VERSION.SDK_INT}" | |
} | |
:shared:iOSMain:OSInformation.kt |
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 Foundation | |
import shared | |
struct CountryListApiManager: CountryListApiManaging { | |
let client: NovelCovidApiClient | |
init(client: NovelCovidApiClient) { | |
self.client = client | |
} |
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
class CountryListViewModel(private val apiClient: NovelCovidApiClient) : ViewModel() { | |
val countries: LiveData<List<CountryItem>> = liveData { | |
emit(apiClient.getAffectedCountries()) | |
} | |
} |
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
class NovelCovidApiClient() { | |
companion object { | |
private const val URL = "https://corona.lmao.ninja/v2/countries" | |
} | |
private val httpApiClient: HttpClient = HttpClient { | |
install(JsonFeature) { | |
val json = kotlinx.serialization.json.Json { ignoreUnknownKeys = true } | |
serializer = KotlinxSerializer(json) | |
} |
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 org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | |
plugins { | |
kotlin("multiplatform") | |
id("com.android.library") | |
id("kotlin-android-extensions") | |
kotlin("plugin.serialization") version "1.4.10" | |
} | |
group = "com.hardiktrivedi.kmmnovelcovid" | |
version = "1.0-SNAPSHOT" |
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.annotation.SuppressLint | |
import android.content.Context | |
import android.content.SharedPreferences | |
import com.hardiktrivedi.gdg_pune_kotlin_workshop.R | |
import kotlin.reflect.KProperty | |
class PreferenceExtension<T>(val context: Context, val key: String, val defaultValue: T) { | |
val prefs: SharedPreferences by lazy { context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE) } | |
operator fun getValue(thisRef: Any?, property: KProperty<*>): T { |