Skip to content

Commit

Permalink
[feature/#835] Add appContext props && remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
l2hyunwoo committed Sep 8, 2024
1 parent e783c79 commit ee19ab6
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 54 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ dependencies {

implementation(libs.bundles.compose)

implementation(libs.bundles.mavericks)

implementation(platform(libs.firebase))
implementation(libs.bundles.firebase)
implementation(libs.process.phoenix)
Expand Down
50 changes: 25 additions & 25 deletions app/src/main/java/org/sopt/official/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,45 @@ package org.sopt.official
import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.airbnb.mvrx.mocking.MockableMavericks
import com.google.firebase.messaging.FirebaseMessaging
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import org.sopt.official.common.context.appContext
import org.sopt.official.network.FlipperInitializer
import org.sopt.official.network.persistence.SoptDataStore
import timber.log.Timber
import javax.inject.Inject

@HiltAndroidApp
class App : Application() {
@Inject
lateinit var dataStore: SoptDataStore
@Inject
lateinit var dataStore: SoptDataStore
private val lifecycleOwner: LifecycleOwner
get() = ProcessLifecycleOwner.get()

override fun onCreate() {
super.onCreate()
initFlipper()
initMavericks()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
ProcessLifecycleOwner.get().lifecycle.coroutineScope.launch {
ProcessLifecycleOwner.get().lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
runCatching {
FirebaseMessaging.getInstance().token.await()
}.onSuccess {
dataStore.pushToken = it
}.onFailure(Timber::e)
}
}
}
override fun onCreate() {
super.onCreate()
appContext = this.applicationContext

private fun initMavericks() {
MockableMavericks.initialize(this)
initFlipper()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
runCatching {
FirebaseMessaging.getInstance().token.await()
}.onSuccess {
dataStore.pushToken = it
}.onFailure(Timber::e)
}
}
}

private fun initFlipper() {
FlipperInitializer.init(this)
}
private fun initFlipper() {
FlipperInitializer.init(this)
}
}
7 changes: 0 additions & 7 deletions app/src/main/java/org/sopt/official/di/NavigatorModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ package org.sopt.official.di

import dagger.Binds
import dagger.Module
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.official.common.navigator.NavigatorProvider
Expand All @@ -41,9 +40,3 @@ interface NavigationModule {
fun bindNavigatorIntent(navigatorProviderIntent: NavigatorProviderIntent): NavigatorProvider
}

@InstallIn(SingletonComponent::class)
@EntryPoint
interface NavigatorEntryPoint {
fun navigatorProvider(): NavigatorProvider
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sopt.official.common.context

import android.content.Context

lateinit var appContext: Context
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ package org.sopt.official.common.navigator

import android.content.Context
import android.content.Intent
import dagger.hilt.android.EntryPointAccessors
import org.sopt.official.auth.model.UserActiveState
import org.sopt.official.auth.model.UserStatus
import org.sopt.official.common.context.appContext
import org.sopt.official.common.util.extractQueryParameter
import org.sopt.official.feature.attendance.AttendanceActivity
import org.sopt.official.feature.auth.AuthActivity
import org.sopt.official.feature.home.HomeActivity
import org.sopt.official.feature.mypage.mypage.MyPageActivity
import org.sopt.official.feature.notification.NotificationDetailActivity
Expand All @@ -39,6 +40,10 @@ import org.sopt.official.feature.poke.notification.PokeNotificationActivity
import org.sopt.official.stamp.SoptampActivity
import timber.log.Timber

internal val navigator by lazy {
EntryPointAccessors.fromApplication(appContext, NavigatorEntryPoint::class.java).navigatorProvider()
}

enum class DeepLinkType(
val link: String
) {
Expand All @@ -50,15 +55,15 @@ enum class DeepLinkType(
NOTIFICATION_LIST("home/notification") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, Intent(context, NotificationHistoryActivity::class.java)
Intent(context, NotificationHistoryActivity::class.java)
)
}
},
NOTIFICATION_DETAIL("home/notification/detail") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
val notificationId = deepLink.extractQueryParameter("id")
return userStatus.setIntent(
context, NotificationDetailActivity.getIntent(
NotificationDetailActivity.getIntent(
context, NotificationDetailActivity.StartArgs(notificationId)
)
)
Expand All @@ -67,7 +72,7 @@ enum class DeepLinkType(
MY_PAGE("home/mypage") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, MyPageActivity.getIntent(
MyPageActivity.getIntent(
context, MyPageActivity.StartArgs(UserActiveState.valueOf(userStatus.name))
)
)
Expand All @@ -76,42 +81,42 @@ enum class DeepLinkType(
ATTENDANCE("home/attendance") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, Intent(context, AttendanceActivity::class.java)
Intent(context, AttendanceActivity::class.java)
)
}
},
ATTENDANCE_MODAL("home/attendance/attendance-modal") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, Intent(context, AttendanceActivity::class.java)
Intent(context, AttendanceActivity::class.java)
)
}
},
SOPTAMP("home/soptamp") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, Intent(context, SoptampActivity::class.java)
Intent(context, SoptampActivity::class.java)
)
}
},
SOPTAMP_ENTIRE_RANKING("home/soptamp/entire-ranking") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, Intent(context, SoptampActivity::class.java)
Intent(context, SoptampActivity::class.java)
)
}
},
SOPTAMP_CURRENT_GENERATION_RANKING("home/soptamp/current-generation-ranking") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, Intent(context, SoptampActivity::class.java)
Intent(context, SoptampActivity::class.java)
)
}
},
POKE_NOTIFICATION_LIST("home/poke/notification-list") {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent {
return userStatus.setIntent(
context, PokeNotificationActivity.getIntent(
PokeNotificationActivity.getIntent(
context, PokeNotificationActivity.StartArgs(userStatus.name)
)
)
Expand All @@ -131,16 +136,16 @@ enum class DeepLinkType(
abstract fun getIntent(context: Context, userStatus: UserStatus, deepLink: String): Intent

companion object {
private fun UserStatus.setIntent(context: Context, intent: Intent): Intent {
private fun UserStatus.setIntent(intent: Intent): Intent {
return when (this == UserStatus.UNAUTHENTICATED) {
true -> AuthActivity.newInstance(context)
true -> navigator.getAuthActivityIntent()
false -> intent
}
}

fun getHomeIntent(context: Context, userStatus: UserStatus, deepLinkType: DeepLinkType? = null): Intent {
return userStatus.setIntent(
context, HomeActivity.getIntent(
HomeActivity.getIntent(
context, HomeActivity.StartArgs(
userStatus = userStatus, deepLinkType = deepLinkType
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
package org.sopt.official.common.navigator

import android.content.Intent
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.official.auth.model.UserStatus

interface NavigatorProvider {
Expand All @@ -37,3 +40,9 @@ interface NavigatorProvider {
fun getPokeNotificationActivityIntent(name: String): Intent
fun getHomeActivityIntent(userStatus: UserStatus, deepLinkType: DeepLinkType): Intent
}

@InstallIn(SingletonComponent::class)
@EntryPoint
interface NavigatorEntryPoint {
fun navigatorProvider(): NavigatorProvider
}
7 changes: 0 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ okhttp = "4.12.0"
retrofit = "2.11.0"
timber = "5.0.1"
compose-destination = "1.10.2"
mavericks = "3.0.9"
coil = "2.7.0"
lottie = "6.5.2"
dotsindicator = "5.0"
Expand Down Expand Up @@ -155,11 +154,6 @@ retrofit-response-type-keeper = { module = "com.squareup.retrofit2:response-type

timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }

mavericks = { module = "com.airbnb.android:mavericks", version.ref = "mavericks" }
mavericks-compose = { module = "com.airbnb.android:mavericks-compose", version.ref = "mavericks" }
mavericks-navigation = { module = "com.airbnb.android:mavericks-navigation", version.ref = "mavericks" }
mavericks-mockable = { module = "com.airbnb.android:mavericks-mocking", version.ref = "mavericks" }

hilt = { module = "com.google.dagger:hilt-android", version.ref = "dagger-hilt" }
hilt-ksp = { module = "com.google.dagger:hilt-compiler", version.ref = "dagger-hilt" }
hilt-plugin = { group = "com.google.dagger", name = "hilt-android-gradle-plugin", version.ref = "dagger-hilt" }
Expand Down Expand Up @@ -208,7 +202,6 @@ android-test = ["androidx-test-junit", "androidx-test-espresso"]
okhttp = ["okhttp", "okhttp-logging-interceptor"]
flipper = ["flipper", "soloader"]
firebase = ["firebase-analytics", "firebase-crashlytics", "firebase-messaging"]
mavericks = ["mavericks", "mavericks-compose", "mavericks-navigation", "mavericks-mockable"]
junit5-test = ["junit5", "junit5-engine", "junit5-params", "junit5-vintage"]
androidx-android-test = ["androidx-test-runner", "androidx-test-rules", "androidx-uiautomator"]

Expand Down

0 comments on commit ee19ab6

Please sign in to comment.