Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create destination class instead of specific createIntentTo* function #295

Merged
merged 1 commit into from
Nov 1, 2024
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
16 changes: 5 additions & 11 deletions app/src/main/java/soup/movie/di/ApplicationModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@
*/
package soup.movie.di

import android.content.Context
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import soup.movie.feature.navigator.MainNavigator
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class ApplicationModule {
interface ApplicationModule {

@Singleton
@Provides
@Binds
fun provideMainNavigator(
@ApplicationContext context: Context,
): MainNavigator {
return MainNavigatorImpl(context)
}
impl: MainNavigatorImpl,
): MainNavigator
}
9 changes: 6 additions & 3 deletions app/src/main/java/soup/movie/di/MainNavigatorImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ package soup.movie.di

import android.content.Context
import android.content.Intent
import dagger.hilt.android.qualifiers.ApplicationContext
import soup.movie.feature.navigator.Destination
import soup.movie.feature.navigator.MainNavigator
import soup.movie.ui.main.MainActivity
import javax.inject.Inject

class MainNavigatorImpl(
private val context: Context,
class MainNavigatorImpl @Inject constructor(
@ApplicationContext private val context: Context,
) : MainNavigator {

override fun createIntentToMain(): Intent {
override fun createIntent(destination: Destination.Main): Intent {
return Intent(context, MainActivity::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
*/
package soup.movie.feature.navigator

interface AppNavigator : MainNavigator
import android.content.Intent

interface AppNavigator {
fun createIntent(destination: Destination): Intent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024 SOUP
*
* 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 soup.movie.feature.navigator

sealed interface Destination {
data object Main : Destination
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ package soup.movie.feature.navigator
import android.content.Intent

interface MainNavigator {
fun createIntentToMain(): Intent
fun createIntent(destination: Destination.Main): Intent
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
*/
package soup.movie.feature.navigator.impl

import android.content.Intent
import soup.movie.feature.navigator.AppNavigator
import soup.movie.feature.navigator.Destination
import soup.movie.feature.navigator.MainNavigator
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AppNavigatorImpl @Inject constructor(
private val mainNavigator: MainNavigator,
) : AppNavigator, MainNavigator by mainNavigator
) : AppNavigator {
override fun createIntent(destination: Destination): Intent {
return when (destination) {
is Destination.Main -> mainNavigator.createIntent(destination)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import soup.movie.feature.navigator.AppNavigator
import soup.movie.feature.navigator.impl.AppNavigatorImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface NavigatorModule {

@Singleton
@Binds
fun bindsAppNavigator(
impl: AppNavigatorImpl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import dagger.hilt.android.qualifiers.ApplicationContext
import soup.movie.feature.navigator.AppNavigator
import soup.movie.feature.navigator.Destination
import soup.movie.feature.notification.NotificationBuilder
import soup.movie.model.MovieModel
import soup.movie.model.OpenDateAlarmModel
Expand Down Expand Up @@ -57,7 +58,7 @@ class NotificationBuilderImpl @Inject constructor(
}

private fun Context.createLauncherIntent(): PendingIntent {
val intent = navigator.createIntentToMain()
val intent = navigator.createIntent(Destination.Main)
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Context
import android.os.Build
import dagger.hilt.android.qualifiers.ApplicationContext
import soup.movie.feature.navigator.AppNavigator
import soup.movie.feature.navigator.Destination
import soup.movie.feature.notification.ShowPushNotificationUseCase
import soup.movie.log.Logger
import soup.movie.resources.R
Expand Down Expand Up @@ -64,7 +65,7 @@ class ShowPushNotificationUseCaseImpl @Inject constructor(
}

private fun createLauncherIntent(): PendingIntent {
val intent = navigator.createIntentToMain()
val intent = navigator.createIntent(Destination.Main)
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
} else {
Expand Down
Loading