Skip to content

Commit

Permalink
[FIX/#123] NavigationManager context 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Sep 8, 2024
1 parent a83e0df commit 009555c
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package co.orange.ddanzi.di.module

import android.content.Context
import co.orange.core.navigation.NavigationManager
import co.orange.ddanzi.di.navigate.NavigationManagerImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
@InstallIn(SingletonComponent::class)
object NavigationModule {
@Provides
@Singleton
fun provideNavigationManager(
@ApplicationContext context: Context,
): NavigationManager = NavigationManagerImpl(context)
fun provideNavigationManager(navigationManagerImpl: NavigationManagerImpl): NavigationManager = navigationManagerImpl
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ import javax.inject.Inject

class NavigationManagerImpl
@Inject
constructor(
private val context: Context,
) : NavigationManager {
constructor() : NavigationManager {
/** To Main Module**/
override fun toMainViewWIthClearing() {
override fun toMainViewWIthClearing(context: Context) {
Intent(context, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
context.startActivity(this)
}
}

override fun toDetailView(productId: String) {
override fun toDetailView(
context: Context,
productId: String,
) {
context.startActivity(DetailActivity.createIntent(context, productId))
}

override fun toPushViewWithIntent(
context: Context,
isBuying: Boolean,
orderId: String?,
itemId: String?,
Expand All @@ -59,48 +61,56 @@ class NavigationManagerImpl

/** To Auth Module**/

override fun toLoginView() {
override fun toLoginView(context: Context) {
context.startActivity(Intent(context, LoginActivity::class.java))
}

/** To Setting Module**/

override fun toSettingView() {
override fun toSettingView(context: Context) {
context.startActivity(Intent(context, SettingActivity::class.java))
}

override fun toHistoryView(type: Int) {
override fun toHistoryView(
context: Context,
type: Int,
) {
context.startActivity(HistoryActivity.createIntent(context, type))
}

override fun toDeliveryView() {
override fun toDeliveryView(context: Context) {
context.startActivity(Intent(context, DeliveryActivity::class.java))
}

override fun toBankView() {
override fun toBankView(context: Context) {
context.startActivity(Intent(context, BankActivity::class.java))
}

/** To Buy Module**/

override fun toBuyProgressView(
context: Context,
productId: String,
optionList: ArrayList<Int>,
) {
context.startActivity(BuyProgressActivity.createIntent(context, productId, optionList))
}

override fun toBuyFinishedView(orderId: String) {
override fun toBuyFinishedView(
context: Context,
orderId: String,
) {
context.startActivity(BuyFinishedActivity.createIntent(context, orderId))
}

/** To Sell Module**/

override fun toSellOnboardingView() {
override fun toSellOnboardingView(context: Context) {
context.startActivity(Intent(context, SellOnboardingActivity::class.java))
}

override fun toSellFinishedView(
context: Context,
itemId: String,
productName: String,
productImage: String,
Expand All @@ -117,7 +127,10 @@ class NavigationManagerImpl
)
}

override fun toSellInfoView(itemId: String) {
override fun toSellInfoView(
context: Context,
itemId: String,
) {
context.startActivity(SellInfoActivity.createIntent(context, itemId))
}
}
37 changes: 27 additions & 10 deletions core/src/main/java/co/orange/core/navigation/NavigationManager.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package co.orange.core.navigation

import android.content.Context

interface NavigationManager {
/** To Main Module**/
fun toMainViewWIthClearing()
fun toMainViewWIthClearing(context: Context)

fun toDetailView(productId: String)
fun toDetailView(
context: Context,
productId: String,
)

fun toPushViewWithIntent(
context: Context,
isBuying: Boolean,
orderId: String?,
itemId: String?,
Expand All @@ -17,37 +23,48 @@ interface NavigationManager {

/** To Auth Module**/

fun toLoginView()
fun toLoginView(context: Context)

/** To Setting Module**/

fun toSettingView()
fun toSettingView(context: Context)

fun toHistoryView(type: Int)
fun toHistoryView(
context: Context,
type: Int,
)

fun toDeliveryView()
fun toDeliveryView(context: Context)

fun toBankView()
fun toBankView(context: Context)

/** To Buy Module**/

fun toBuyProgressView(
context: Context,
productId: String,
optionList: ArrayList<Int>,
)

fun toBuyFinishedView(orderId: String)
fun toBuyFinishedView(
context: Context,
orderId: String,
)

/** To Sell Module**/

fun toSellOnboardingView()
fun toSellOnboardingView(context: Context)

fun toSellFinishedView(
context: Context,
itemId: String,
productName: String,
productImage: String,
salePrice: Int,
)

fun toSellInfoView(itemId: String)
fun toSellInfoView(
context: Context,
itemId: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BuyFinishedActivity :
}

private fun navigateToHome() {
navigationManager.toMainViewWIthClearing()
navigationManager.toMainViewWIthClearing(this)
}

private fun initDetailBtnListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class BuyInfoActivity :
.onEach { isSuccess ->
if (isSuccess) {
toast(stringOf(R.string.buy_order_fix_msg))
navigationManager.toMainViewWIthClearing()
navigationManager.toMainViewWIthClearing(this)
} else {
toast(stringOf(R.string.error_msg))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class BuyProgressActivity :
}

private fun navigateToAddAddress() {
navigationManager.toDeliveryView()
navigationManager.toDeliveryView(this)
}

private fun initTermDetailBtnListener() {
Expand Down Expand Up @@ -251,7 +251,7 @@ class BuyProgressActivity :
}

private fun navigateToPushActivity(orderId: String) {
navigationManager.toPushViewWithIntent(true, orderId, null, null, null, null)
navigationManager.toPushViewWithIntent(this, true, orderId, null, null, null, null)
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DetailActivity : BaseActivity<ActivityDetailBinding>(featureR.layout.activ
private fun initLikeBtnListener() {
binding.btnLike.setOnSingleClickShortListener {
if (!viewModel.getUserLogined()) {
navigationManager.toLoginView()
navigationManager.toLoginView(this)
return@setOnSingleClickShortListener
}
viewModel.setLikeStateWithServer()
Expand All @@ -77,11 +77,11 @@ class DetailActivity : BaseActivity<ActivityDetailBinding>(featureR.layout.activ
private fun initPurchaseBtnListener() {
binding.btnPurchase.setOnSingleClickListener {
if (!viewModel.getUserLogined()) {
navigationManager.toLoginView()
navigationManager.toLoginView(this)
return@setOnSingleClickListener
}
if (viewModel.optionList.isEmpty()) {
navigationManager.toBuyProgressView(viewModel.productId, arrayListOf())
navigationManager.toBuyProgressView(this, viewModel.productId, arrayListOf())
} else {
optionBottomSheet = OptionBottomSheet()
optionBottomSheet?.show(supportFragmentManager, BOTTOM_SHEET_OPTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class OptionBottomSheet :

private fun initPurchaseBtnListener() {
binding.btnPurchase.setOnSingleClickListener {
navigationManager.toBuyProgressView(viewModel.productId, viewModel.selectedOptionList)
navigationManager.toBuyProgressView(
requireContext(),
viewModel.productId,
viewModel.selectedOptionList,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding>(featureR.layout.fragmen
position: Int,
) {
if (!viewModel.getUserLogined()) {
navigationManager.toLoginView()
navigationManager.toLoginView(requireContext())
return
}
viewModel.setLikeStateWithServer(productId, isInterested, position)
Expand All @@ -108,9 +108,9 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding>(featureR.layout.fragmen
private fun initSellBtnListener() {
binding.btnSell.setOnSingleClickListener {
if (viewModel.getUserLogined()) {
navigationManager.toSellOnboardingView()
navigationManager.toSellOnboardingView(requireContext())
} else {
navigationManager.toLoginView()
navigationManager.toLoginView(requireContext())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(featureR.layout.f

private fun initSettingBtnListener() {
binding.btnSetting.setOnSingleClickListener {
navigationManager.toSettingView()
navigationManager.toSettingView(requireContext())
}
}

private fun initLoginBtnListener() {
binding.btnLogin.setOnSingleClickListener {
navigationManager.toLoginView()
navigationManager.toLoginView(requireContext())
}
}

Expand Down Expand Up @@ -87,7 +87,7 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(featureR.layout.f
}

private fun navigateToHistory(type: Int) {
navigationManager.toHistoryView(type)
navigationManager.toHistoryView(requireContext(), type)
}

private fun checkIsLogined() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ class PushActivity : BaseActivity<ActivityPushBinding>(featureR.layout.activity_

private fun navigateToBuyFinishedActivity() {
navigationManager.toBuyFinishedView(
this,
intent.getStringExtra(EXTRA_ORDER_ID).orEmpty(),
)
}

private fun navigateToSellFinishedActivity() {
navigationManager.toSellFinishedView(
this,
intent.getStringExtra(EXTRA_ITEM_ID).orEmpty(),
intent.getStringExtra(EXTRA_PRODUCT_NAME).orEmpty(),
intent.getStringExtra(EXTRA_PRODUCT_IMAGE).orEmpty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ class SearchActivity :
}

private fun initItemClickListener(item: ProductModel) {
DetailActivity.createIntent(
this,
item.productId,
).apply { startActivity(this) }
startActivity(DetailActivity.createIntent(this, item.productId))
}

private fun initLikeClickListener(
Expand All @@ -138,7 +135,7 @@ class SearchActivity :
position: Int,
) {
if (!viewModel.getUserLogined()) {
navigationManager.toLoginView()
navigationManager.toLoginView(this)
return
}
viewModel.setLikeStateWithServer(productId, isInterested, position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SellConfirmActivity :
.onEach { isSuccess ->
if (isSuccess) {
toast(stringOf(R.string.sell_order_fix_msg))
navigationManager.toMainViewWIthClearing()
navigationManager.toMainViewWIthClearing(this)
} else {
toast(stringOf(R.string.error_msg))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class SellFinishedActivity :

private fun initReturnBtnListener() {
with(binding) {
btnExit.setOnSingleClickListener { navigationManager.toMainViewWIthClearing() }
btnSellMore.setOnSingleClickListener { navigationManager.toMainViewWIthClearing() }
btnExit.setOnSingleClickListener { navigationManager.toMainViewWIthClearing(this@SellFinishedActivity) }
btnSellMore.setOnSingleClickListener { navigationManager.toMainViewWIthClearing(this@SellFinishedActivity) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BankDialog :
private fun initSubmitBtnListener() {
binding.btnSubmit.setOnSingleClickListener {
viewModel.isSentToBank = true
navigationManager.toBankView()
navigationManager.toBankView(requireContext())
dismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class SellProgressActivity :

private fun navigateToPushActivity(item: SellRegisteredModel) {
navigationManager.toPushViewWithIntent(
this,
false,
null,
item.itemId,
Expand Down
Loading

0 comments on commit 009555c

Please sign in to comment.