Make notification module as the multiplatform library

pull/1323/head
lihenggui 2 years ago
parent 1f2b720636
commit 61b2b5e436

@ -14,19 +14,22 @@
* limitations under the License.
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.kmp.library)
alias(libs.plugins.nowinandroid.kotlin.inject)
}
android {
namespace = "com.google.samples.apps.nowinandroid.core.notifications"
}
dependencies {
api(projects.core.model)
implementation(projects.core.common)
compileOnly(platform(libs.androidx.compose.bom))
compileOnly(libs.androidx.compose.runtime)
kotlin {
sourceSets {
commonMain.dependencies {
api(projects.core.model)
implementation(projects.core.common)
}
androidMain.dependencies {
implementation(libs.androidx.core.ktx)
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,9 +33,6 @@ import androidx.core.app.NotificationCompat.InboxStyle
import androidx.core.app.NotificationManagerCompat
import androidx.core.net.toUri
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton
private const val MAX_NUM_NOTIFICATIONS = 5
private const val TARGET_ACTIVITY_NAME = "com.google.samples.apps.nowinandroid.MainActivity"
@ -49,9 +46,9 @@ private const val FOR_YOU_PATH = "foryou"
/**
* Implementation of [Notifier] that displays notifications in the system tray.
*/
@Singleton
internal class SystemTrayNotifier @Inject constructor(
@ApplicationContext private val context: Context,
internal class SystemTrayNotifier constructor(
private val context: Context,
) : Notifier {
override fun postNewsNotifications(

@ -17,11 +17,10 @@
package com.google.samples.apps.nowinandroid.core.notifications
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
import javax.inject.Inject
/**
* Implementation of [Notifier] which does nothing. Useful for tests and previews.
*/
internal class NoOpNotifier @Inject constructor() : Notifier {
internal class NoOpNotifier : Notifier {
override fun postNewsNotifications(newsResources: List<NewsResource>) = Unit
}

@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,18 +14,14 @@
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.core.notifications
package com.google.samples.apps.nowinandroid.core.notifications.di
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import com.google.samples.apps.nowinandroid.core.notifications.NoOpNotifier
import com.google.samples.apps.nowinandroid.core.notifications.Notifier
import me.tatarka.inject.annotations.Provides
@Module
@InstallIn(SingletonComponent::class)
internal abstract class NotificationsModule {
@Binds
abstract fun bindNotifier(
notifier: NoOpNotifier,
): Notifier
@Provides
internal fun provideNotifier(): Notifier = NoOpNotifier()
}

@ -1,31 +0,0 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.core.notifications
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
internal abstract class NotificationsModule {
@Binds
abstract fun bindNotifier(
notifier: SystemTrayNotifier,
): Notifier
}
Loading…
Cancel
Save