This file contains 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
fun example() { | |
//once your isGameAvailableListener being called it will return inside of isGameAvailableListener | |
ifgameavailable(gamecode = "CODE", isGameAvailableListener = { isGameAvailable -> | |
}) | |
} | |
fun ifgameavailable(gamecode: String, isGameAvailableListener: (Boolean) -> Unit) { | |
isGameAvailableListener.invoke(true) | |
} |
This file contains 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
interface AndroidJobsRepository { | |
fun getJobs(): Flow<List<AndroidJob>> | |
suspend fun fetchFreshJobs() | |
fun add() | |
} |
This file contains 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
@JsonClass(generateAdapter = true) | |
data class AndroidJob( | |
@Json(name = "title") val title: String, | |
@Json(name = "required_experience_years") val experienceTimeRequired: String, | |
@Json(name = "native") val native: Boolean, | |
@Json(name = "country") val country: String | |
) |
This file contains 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 AndroidJobsRepositoryImpl @Inject constructor( | |
@IoDispatcher | |
private val coroutineDispatcher: CoroutineDispatcher |
This file contains 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
@DefaultDispatcher | |
@Provides | |
fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default | |
@IoDispatcher | |
@Provides | |
fun providesIoDispatcher(): CoroutineDispatcher = Dispatchers.IO | |
@MainDispatcher | |
@Provides |
This file contains 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
@Qualifier | |
@Retention(AnnotationRetention.BINARY) | |
annotation class IoDispatcher | |
@Qualifier | |
@Retention(AnnotationRetention.BINARY) | |
annotation class MainDispatcher | |
@Qualifier | |
@Retention(AnnotationRetention.BINARY) | |
annotation class DefaultDispatcher |
This file contains 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
@Module | |
@InstallIn(SingletonComponent::class) | |
object DispatcherModule |
This file contains 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
override suspend fun fetchFreshJobs() { | |
withContext(coroutineDispatcher) { | |
serverApi.fetchJobs() | |
.also { jobs -> | |
jobsDao.updateData(jobs.map { it.asCache() }) | |
} | |
} | |
} |
This file contains 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
override fun getJobs(): Flow<List<AndroidJob>> { | |
return jobsDao.getJobs().map { jobs -> | |
jobs.map(AndroidJobCache::asExternalModel) | |
}.onEach { | |
if (it.isEmpty()) { | |
fetchFreshJobs() | |
} | |
} | |
} |
This file contains 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
@IoDispatcher | |
private val coroutineDispatcher: CoroutineDispatcher |
NewerOlder