Skip to content

Commit 49804a5

Browse files
authored
Merge pull request #65 from CodandoTV/feature/background-work
Feature/background work
2 parents 6804574 + a663a0f commit 49804a5

File tree

23 files changed

+304
-8
lines changed

23 files changed

+304
-8
lines changed

build-logic/src/main/java/extensions/KotlinMultiPlatformExt.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fun KotlinMultiplatformExtension.iosTarget() {
1212
iosTarget.binaries.framework {
1313
baseName = Config.appName
1414
isStatic = true
15+
16+
export("io.github.mirzemehdi:kmpnotifier:1.5.1")
1517
}
1618
}
1719
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/Users/pedroalvarez/.konan/kotlin-native-prebuilt-macos-aarch64-2.1.10/klib/commonized/2.1.10
1+
/Users/junior/.konan/kotlin-native-prebuilt-macos-aarch64-2.1.10/klib/commonized/2.1.10

composeApp/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ kotlin {
2727
implementation(projects.coreNavigation)
2828
implementation(projects.coreNetworking)
2929
implementation(projects.coreLocalStorage)
30+
implementation(projects.coreBackgroundWork)
3031

3132
implementation(libs.navigation.compose)
3233

@@ -35,6 +36,7 @@ kotlin {
3536
implementation(compose.components.resources)
3637

3738
implementation(libs.koin.core)
39+
api(libs.kmpnotifier)
3840
}
3941
}
4042
}

composeApp/src/androidMain/kotlin/com.codandotv.streamplayerapp/presentation/CustomApplication.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.codandotv.streamplayerapp.presentation
22

33
import android.app.Application
4+
import com.codandotv.streamplayerapp.core.shared.ui.R
5+
import com.codandotv.streamplayerapp.core_background_work.worker.WorkScheduler
46
import com.codandotv.streamplayerapp.di.AppModule
7+
import com.mmk.kmpnotifier.notification.NotifierManager
8+
import com.mmk.kmpnotifier.notification.configuration.NotificationPlatformConfiguration
59
import org.koin.android.ext.koin.androidContext
610
import org.koin.core.context.startKoin
711

@@ -13,5 +17,16 @@ class CustomApplication : Application() {
1317
androidContext(this@CustomApplication.applicationContext)
1418
modules(AppModule.list)
1519
}
20+
WorkScheduler.scheduleSync(this)
21+
initializeNotification()
22+
}
23+
24+
fun initializeNotification() {
25+
NotifierManager.initialize(
26+
configuration = NotificationPlatformConfiguration.Android(
27+
notificationIconResId = R.mipmap.ic_netflix,
28+
showPushNotification = true,
29+
)
30+
)
1631
}
1732
}

composeApp/src/androidMain/kotlin/com.codandotv.streamplayerapp/presentation/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ import androidx.activity.compose.setContent
66
import com.codandotv.streamplayerapp.StreamPlayerApp
77
import com.google.firebase.Firebase
88
import com.google.firebase.initialize
9+
import com.mmk.kmpnotifier.permission.permissionUtil
910

1011
class MainActivity : ComponentActivity() {
12+
1113
override fun onCreate(savedInstanceState: Bundle?) {
1214
super.onCreate(savedInstanceState)
1315
Firebase.initialize(this)
16+
requestNotificationPermission()
1417
setContent {
1518
StreamPlayerApp()
1619
}
1720
}
21+
22+
private fun requestNotificationPermission() {
23+
val permissionUtil by permissionUtil()
24+
permissionUtil.askNotificationPermission()
25+
}
1826
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.codandotv.streamplayerapp
2+
3+
import com.codandotv.streamplayerapp.core_background_work.SyncManager
4+
import kotlinx.coroutines.CoroutineScope
5+
import kotlinx.coroutines.Dispatchers
6+
import kotlinx.coroutines.launch
7+
import org.koin.core.context.startKoin
8+
import org.koin.dsl.module
9+
import org.koin.mp.KoinPlatform.getKoin
10+
11+
object SyncBridge {
12+
suspend fun syncData() {
13+
getKoin().get<SyncManager>().syncData()
14+
}
15+
16+
fun syncData(completionHandler: () -> Unit) {
17+
CoroutineScope(Dispatchers.Default).launch {
18+
try {
19+
syncData()
20+
} finally {
21+
completionHandler()
22+
}
23+
}
24+
}
25+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.codandotv.streamplayerapp.di
22

3-
import PermissionsModule
3+
import com.codandotv.streamplayerapp.core_background_work.di.SyncModule
44
import com.codandotv.streamplayerapp.core_local_storage.di.LocalStorageModule
55
import com.codandotv.streamplayerapp.core_networking.di.NetworkModule
66
import com.codandotv.streamplayerapp.core_shared.qualifier.QualifierDispatcherIO
7+
import com.codandotv.streamplayerapp.feature_list_streams.list.di.ListStreamModule
78
import kotlinx.coroutines.Dispatchers
89
import kotlinx.coroutines.IO
910
import org.koin.dsl.module
@@ -12,5 +13,5 @@ object AppModule {
1213
private val module = module {
1314
single(QualifierDispatcherIO) { Dispatchers.IO }
1415
}
15-
val list = module + NetworkModule.module + LocalStorageModule.module
16+
val list = module + NetworkModule.module + LocalStorageModule.module + SyncModule.module + ListStreamModule.module
1617
}

core-background-work/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@file:Suppress("UnstableApiUsage")
2+
3+
plugins {
4+
id("com.streamplayer.kmp-library")
5+
id("com.google.devtools.ksp")
6+
}
7+
8+
kotlin {
9+
sourceSets {
10+
androidMain.dependencies {
11+
implementation(libs.work.runtime)
12+
}
13+
14+
commonMain.dependencies {
15+
implementation(libs.kotlin.stdlib)
16+
implementation(libs.kotlinx.coroutines.core)
17+
implementation(libs.koin.core)
18+
implementation(projects.coreShared)
19+
implementation(projects.featureListStreams)
20+
api(libs.kmpnotifier)
21+
}
22+
}
23+
}

core-background-work/consumer-rules.pro

Whitespace-only changes.

0 commit comments

Comments
 (0)