Skip to content

Instantly share code, notes, and snippets.

View igorescodro's full-sized avatar
♥️
Coding with love

Igor Escodro igorescodro

♥️
Coding with love
View GitHub Profile
package com.escodro.task.presentation.detail.main
//...
import dev.icerock.moko.mvvm.viewmodel.ViewModel
internal class TaskViewModel : ViewModel() {
fun loadTaskInfo() {
// Everything an Android ViewModel has
viewModelScope.launch { doSuspendStuff() }
//...
androidDependencies {
// Module responsible to download from Google Play
implementation(projects.libraries.splitInstall)
}
iosDependencies {
// Dynamic Module always available
implementation(projects.features.tracker)
}
@Composable
fun AlkaaNavGraph() {
ScreenRegistry {
taskScreenModule()
categoryScreenModule()
preferencesScreenModule()
}
BottomSheetNavigator {
Navigator(HomeScreen())
override fun scheduleTaskNotification(task: Task, timeInMillis: Long) {
val content = UNMutableNotificationContent()
content.setBody(task.title)
content.setCategoryIdentifier(CATEGORY_IDENTIFIER_TASK)
content.setUserInfo(mapOf(USER_INFO_TASK_ID to task.id))
val nsDate = NSDate.dateWithTimeIntervalSince1970(timeInMillis / 1000.0)
val dateComponents = NSCalendar.currentCalendar.components(
NSCalendarUnitYear or NSCalendarUnitMonth or NSCalendarUnitDay
or NSCalendarUnitHour or NSCalendarUnitMinute,
// Android
val string = MR.strings.category_default_personal.desc().toString(context)
// iOS
val string = MR.strings.category_default_personal.desc().localized()
@OptIn(ExperimentalForeignApi::class)
fun getDataStore(): DataStore<Preferences> = getDataStore(
producePath = {
val documentDirectory: NSURL? = NSFileManager.defaultManager.URLForDirectory(
directory = NSDocumentDirectory,
inDomain = NSUserDomainMask,
appropriateForURL = null,
create = false,
error = null,
)
fun getDataStore(): DataStore<Preferences> = getDataStore(
producePath = { context.filesDir.resolve("datastore/$dataStoreFileName").absolutePath },
)
private lateinit var dataStore: DataStore<Preferences>
private val lock = SynchronizedObject()
fun getDataStore(producePath: () -> String): DataStore<Preferences> =
synchronized(lock) {
if (::dataStore.isInitialized) {
dataStore
} else {
PreferenceDataStoreFactory.createWithPath(
override fun shouldPrepopulateDatabase(databaseName: String): Boolean =
!databaseExists(databaseName)
private fun databaseExists(databaseName: String): Boolean {
val fileManager = NSFileManager.defaultManager
val documentDirectory = NSFileManager.defaultManager.URLsForDirectory(
NSLibraryDirectory,
NSUserDomainMask,
).last() as NSURL
val file = documentDirectory
override fun shouldPrepopulateDatabase(databaseName: String): Boolean =
!context.getDatabasePath(databaseName).exists()