Skip to content

Commit

Permalink
- generalization of goBack behaviour with default basePresenter impl…
Browse files Browse the repository at this point in the history
…ementation.
  • Loading branch information
rodvar committed Dec 18, 2024
1 parent fa4cc68 commit 9be18e1
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ interface ViewPresenter {
* @return main app tab nav controller
*/
fun getRootTabNavController(): NavHostController

/**
* Navigate back in the stack
*/
fun goBack()

/**
* This can be used as initialization method AFTER view gets attached (so view is available)
*/
Expand Down Expand Up @@ -93,6 +99,15 @@ abstract class BasePresenter(private val rootPresenter: MainPresenter?): ViewPre
return rootPresenter!!.getRootTabNavController()
}

override fun goBack() {
try {
log.i { "goBack defaut implementation" }
rootNavigator.popBackStack()
} catch (e: Exception) {
log.e(e) { "Faled to navigate back" }
}
}

@CallSuper
override fun onViewAttached() {
log.i { "Lifecycle: View attached to presenter" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class MainPresenter(private val notificationServiceController: Notification
companion object {
// FIXME this will be erased eventually, for now you can turn on to see the notifications working
// it will push a notification every 60 sec
const val testNotifications = false
const val testNotifications = true
const val PUSH_DELAY = 60000L
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fun TopBar(
val defaultBackButton: @Composable () -> Unit = {
IconButton(onClick = {
if (navController.previousBackStackEntry != null) {
navController.popBackStack()
presenter.goBack()
}
}) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ interface ICreateOfferPresenter : ViewPresenter {

fun onSelectAmountType(amountType: AmountType)

fun goBack()

fun navigateToCurrencySelector()

fun buyBitcoinClicked()
Expand Down Expand Up @@ -158,11 +156,6 @@ open class CreateOfferPresenter(
navigateToCurrencySelector()
}

override fun goBack() {
log.i { "goBack" }
rootNavigator.popBackStack()
}

override fun navigateToCurrencySelector() {
log.i { "navigateToCurrencySelector" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ open class PaymentMethodPresenter(
override fun onViewUnattaching() {
}

override fun goBack() {
log.i { "goBack" }
rootNavigator.popBackStack()
}

override fun paymentMethodConfirmed() {
log.i { "Payment method selected" }
rootNavigator.navigate(Routes.TakeOfferReviewTrade.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface ITakeOfferPaymentMethodPresenter : ViewPresenter {
// TODO: Update later to refer to a single OfferListItem
val offerListItems: StateFlow<List<OfferListItem>>

fun goBack()
fun paymentMethodConfirmed()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ open class ReviewTradePresenter(
override fun onViewUnattaching() {
}

override fun goBack() {
log.i { "goBack" }
rootNavigator.popBackStack()
}

override fun tradeConfirmed() {
log.i { "Trade confirmed" }
// TODO: Confirmation popup goes here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import org.koin.compose.koinInject
interface ITakeOfferReviewTradePresenter : ViewPresenter {
// TODO: Update later to refer to a single OfferListItem
val offerListItems: StateFlow<List<OfferListItem>>

fun goBack()
fun tradeConfirmed()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ open class TradeAmountPresenter(

override fun onViewUnattaching() {
}

override fun goBack() {
log.i { "goBack" }
rootNavigator.popBackStack()
}

override fun amountConfirmed() {
log.i { "Amount selected" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import org.koin.compose.koinInject
interface ITakeOfferTradeAmountPresenter : ViewPresenter {
// TODO: Update later to refer to a single OfferListItem
val offerListItems: StateFlow<List<OfferListItem>>

fun goBack()
fun amountConfirmed()

fun onFixedAmountChange(amount: Float)
Expand Down

0 comments on commit 9be18e1

Please sign in to comment.