Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ fun KotlinMultiplatformExtension.iosTarget() {
iosTarget.binaries.framework {
baseName = Config.appName
isStatic = true

export("io.github.mirzemehdi:kmpnotifier:1.5.1")
}
}
}
2 changes: 1 addition & 1 deletion build/kotlin/commonizedNativeDistributionLocation.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/Users/pedroalvarez/.konan/kotlin-native-prebuilt-macos-aarch64-2.1.10/klib/commonized/2.1.10
/Users/junior/.konan/kotlin-native-prebuilt-macos-aarch64-2.1.10/klib/commonized/2.1.10
2 changes: 2 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ kotlin {
implementation(projects.coreNavigation)
implementation(projects.coreNetworking)
implementation(projects.coreLocalStorage)
implementation(projects.coreBackgroundWork)

implementation(libs.navigation.compose)

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

implementation(libs.koin.core)
api(libs.kmpnotifier)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.codandotv.streamplayerapp.presentation

import android.app.Application
import com.codandotv.streamplayerapp.core.shared.ui.R
import com.codandotv.streamplayerapp.core_background_work.worker.WorkScheduler
import com.codandotv.streamplayerapp.di.AppModule
import com.mmk.kmpnotifier.notification.NotifierManager
import com.mmk.kmpnotifier.notification.configuration.NotificationPlatformConfiguration
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

Expand All @@ -13,5 +17,16 @@ class CustomApplication : Application() {
androidContext(this@CustomApplication.applicationContext)
modules(AppModule.list)
}
WorkScheduler.scheduleSync(this)
initializeNotification()
}

fun initializeNotification() {
NotifierManager.initialize(
configuration = NotificationPlatformConfiguration.Android(
notificationIconResId = R.mipmap.ic_netflix,
showPushNotification = true,
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ import androidx.activity.compose.setContent
import com.codandotv.streamplayerapp.StreamPlayerApp
import com.google.firebase.Firebase
import com.google.firebase.initialize
import com.mmk.kmpnotifier.permission.permissionUtil

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Firebase.initialize(this)
requestNotificationPermission()
setContent {
StreamPlayerApp()
}
}

private fun requestNotificationPermission() {
val permissionUtil by permissionUtil()
permissionUtil.askNotificationPermission()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.codandotv.streamplayerapp

import com.codandotv.streamplayerapp.core_background_work.SyncManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.core.context.startKoin
import org.koin.dsl.module
import org.koin.mp.KoinPlatform.getKoin

object SyncBridge {
suspend fun syncData() {
getKoin().get<SyncManager>().syncData()
}

fun syncData(completionHandler: () -> Unit) {
CoroutineScope(Dispatchers.Default).launch {
try {
syncData()
} finally {
completionHandler()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.codandotv.streamplayerapp.di

import PermissionsModule
import com.codandotv.streamplayerapp.core_background_work.di.SyncModule
import com.codandotv.streamplayerapp.core_local_storage.di.LocalStorageModule
import com.codandotv.streamplayerapp.core_networking.di.NetworkModule
import com.codandotv.streamplayerapp.core_shared.qualifier.QualifierDispatcherIO
import com.codandotv.streamplayerapp.feature_list_streams.list.di.ListStreamModule
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import org.koin.dsl.module
Expand All @@ -12,5 +13,5 @@ object AppModule {
private val module = module {
single(QualifierDispatcherIO) { Dispatchers.IO }
}
val list = module + NetworkModule.module + LocalStorageModule.module
val list = module + NetworkModule.module + LocalStorageModule.module + SyncModule.module + ListStreamModule.module
}
1 change: 1 addition & 0 deletions core-background-work/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions core-background-work/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:Suppress("UnstableApiUsage")

plugins {
id("com.streamplayer.kmp-library")
id("com.google.devtools.ksp")
}

kotlin {
sourceSets {
androidMain.dependencies {
implementation(libs.work.runtime)
}

commonMain.dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.koin.core)
implementation(projects.coreShared)
implementation(projects.featureListStreams)
api(libs.kmpnotifier)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#question

Can we use implementation instead of api here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to access the notifications lib in different modules (background, general and in the IOS APP), hence the use of the API

}
}
}
Empty file.
21 changes: 21 additions & 0 deletions core-background-work/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.codandotv.streamplayerapp.core_background_work.worker

import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.codandotv.streamplayerapp.core_background_work.SyncManager
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

class SyncWorker(
context: Context,
params: WorkerParameters
) : CoroutineWorker(context, params), KoinComponent {

private val syncManager: SyncManager by inject()

override suspend fun doWork(): Result {
return try {
syncManager.syncData()
Result.success()
} catch (e: Exception) {
println("Erro no SyncWorker ${e.message}")
Result.retry()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.codandotv.streamplayerapp.core_background_work.worker

import android.content.Context
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import java.util.concurrent.TimeUnit

object WorkScheduler {
fun scheduleSync(context: Context) {
val workRequest = PeriodicWorkRequestBuilder<SyncWorker>(
15, TimeUnit.MINUTES
).build()

WorkManager.getInstance(context).enqueueUniquePeriodicWork(
"SyncWorker",
ExistingPeriodicWorkPolicy.KEEP,
workRequest
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.codandotv.streamplayerapp.core_background_work

import com.mmk.kmpnotifier.notification.NotificationImage
import com.mmk.kmpnotifier.notification.Notifier
import com.mmk.kmpnotifier.notification.NotifierManager
import kotlin.random.Random

object NotifierHelper {
fun showSimpleNotification(
title: String = "Notificação Simples",
body: String = "Corpo da Notificação Simples",
imageUrl: String = "https://github.com/user-attachments/assets/a0f38159-b31d-4a47-97a7-cc230e15d30b"
) {
val notifier = NotifierManager.getLocalNotifier()
notifier.notify {
id = Random.Default.nextInt(0, Int.MAX_VALUE)
this.title = title
this.body = body
payloadData = mapOf(
Notifier.Companion.KEY_URL to imageUrl,
"extraKey" to "randomValue"
)
image = NotificationImage.Url(imageUrl)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.codandotv.streamplayerapp.core_background_work

import com.codandotv.streamplayerapp.feature_list_streams.list.data.ListStreamRepository
import com.codandotv.streamplayerapp.feature_list_streams.list.domain.model.Stream
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first

class SyncManager(
private val repository: ListStreamRepository
) {
suspend fun syncData() {

val title: Stream = repository.topRatedStream().first()
val messageTitle = "${title.name} -Já disponível no app!"
val messageBody = "Confira a sinopse: ${title.description}"
val imageUrl = title.posterPathUrl

NotifierHelper.showSimpleNotification(
title = messageTitle,
body = messageBody,
imageUrl = imageUrl
)

println("SyncManager: Fazendo alguma tarefa de sincronização...")
delay(2000)
println("SyncManager: Sincronização concluída!")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.codandotv.streamplayerapp.core_background_work.di

import com.codandotv.streamplayerapp.core_background_work.SyncManager
import org.koin.dsl.module

object SyncModule {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be easier we have SyncManager as an interface, both implementations be defined at androidMain, and iosMain.

You can achieve that by using:

expect fun provideSyncManagerInstance(): SyncManager

val module = module { single { provideSyncManagerInstance() }

In the androidMain, you can define an actual (the same on iOS).

val module = module {
single { SyncManager(get()) }
}
}
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ accompanist = "0.31.3-beta"
activity-compose = "1.8.2"
popcorngp = "3.1.2"

work-runtime = "2.10.1"
kmpnotifier = "1.5.1"

#Firebase
google-services = "4.4.2"
firebase-bom = "33.13.0"
Expand Down Expand Up @@ -121,6 +124,10 @@ coroutines_test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-

popcorn_guineapig = { group = "io.github.codandotv", name = "popcornguineapig", version.ref = "popcorngp" }

work-runtime = { module = "androidx.work:work-runtime-ktx", version.ref = "work-runtime" }
kmpnotifier = { module = "io.github.mirzemehdi:kmpnotifier", version.ref = "kmpnotifier" }


[bundles]
test = ["junit", "mockk", "mockk_android", "viewmodel_test", "koin_test", "coroutines_test"]
test_multiplatform = ["kotlin_test", "kotlin_test_common", "coroutines_test",]
Expand Down
8 changes: 6 additions & 2 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
5BAD97872D7CCDDA00D93987 /* Lottie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BAD97862D7CCDDA00D93987 /* Lottie.swift */; };
5BAD97892D7CCEA700D93987 /* Lottie in Frameworks */ = {isa = PBXBuildFile; productRef = 5BAD97882D7CCEA700D93987 /* Lottie */; };
7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
7908F1992DE366F100D2455C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7908F1982DE366EC00D2455C /* AppDelegate.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -64,6 +65,7 @@
7555FF7B242A565900829871 /* KotlinProject.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KotlinProject.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7908F1982DE366EC00D2455C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -156,6 +158,7 @@
7555FF7D242A565900829871 /* iosApp */ = {
isa = PBXGroup;
children = (
7908F1982DE366EC00D2455C /* AppDelegate.swift */,
3FD330BB2DD2CFC300633ECC /* GoogleService-Info.plist */,
5BAD97862D7CCDDA00D93987 /* Lottie.swift */,
5BA9B50C2DA887EE00EF12ED /* iosApp.xctestplan */,
Expand Down Expand Up @@ -340,6 +343,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7908F1992DE366F100D2455C /* AppDelegate.swift in Sources */,
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
7555FF83242A565900829871 /* ContentView.swift in Sources */,
5BAD97872D7CCDDA00D93987 /* Lottie.swift in Sources */,
Expand Down Expand Up @@ -537,7 +541,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = "${TEAM_ID}";
DEVELOPMENT_TEAM = 4U9U2835SF;
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -565,7 +569,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = "${TEAM_ID}";
DEVELOPMENT_TEAM = 4U9U2835SF;
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
Loading