-
Notifications
You must be signed in to change notification settings - Fork 31
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
DApp bottom sheet entry point #1731
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.novafoundation.nova.app.root.data.browser | ||
|
||
import io.novafoundation.nova.common.utils.mapList | ||
import io.novafoundation.nova.core_db.dao.BrowserTabsDao | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class TabsRepository(private val tabsDao: BrowserTabsDao) { | ||
|
||
fun observeTabIds(): Flow<List<String>> { | ||
return tabsDao.observeAllTabs().mapList { it.id } | ||
} | ||
|
||
suspend fun removeAllTabs() { | ||
tabsDao.removeAllTabs() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.novafoundation.nova.app.root.domain | ||
|
||
import io.novafoundation.nova.app.root.data.browser.TabsRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class SplitScreenInteractor(val repository: TabsRepository) { | ||
|
||
fun observeTabIds(): Flow<List<String>> { | ||
return repository.observeTabIds() | ||
} | ||
|
||
suspend fun removeAllTabs() { | ||
repository.removeAllTabs() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.novafoundation.nova.app.root.presentation.splitScreen | ||
|
||
import android.graphics.Outline | ||
import android.view.View | ||
import android.view.ViewOutlineProvider | ||
|
||
class RoundCornersOutlineProvider( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be in |
||
private val cornerRadius: Float | ||
) : ViewOutlineProvider() { | ||
|
||
override fun getOutline(view: View, outline: Outline) { | ||
outline.setRoundRect(0, 0, view.width, view.height, cornerRadius) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import android.os.Bundle | |
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.navigation.NavController | ||
import androidx.navigation.fragment.NavHostFragment | ||
import io.novafoundation.nova.app.R | ||
|
@@ -12,7 +13,12 @@ import io.novafoundation.nova.app.root.di.RootComponent | |
import io.novafoundation.nova.app.root.navigation.holders.MainNavigationHolder | ||
import io.novafoundation.nova.common.base.BaseFragment | ||
import io.novafoundation.nova.common.di.FeatureUtils | ||
import io.novafoundation.nova.feature_dapp_impl.presentation.tab.setupCloseAllDappTabsDialogue | ||
import javax.inject.Inject | ||
import kotlinx.android.synthetic.main.fragment_split_screen.dappEntryPoint | ||
import kotlinx.android.synthetic.main.fragment_split_screen.dappEntryPointClose | ||
import kotlinx.android.synthetic.main.fragment_split_screen.dappEntryPointText | ||
import kotlinx.android.synthetic.main.fragment_split_screen.mainNavHost | ||
|
||
class SplitScreenFragment : BaseFragment<SplitScreenViewModel>() { | ||
|
||
|
@@ -43,14 +49,37 @@ class SplitScreenFragment : BaseFragment<SplitScreenViewModel>() { | |
} | ||
|
||
override fun initViews() { | ||
dappEntryPoint.setOnClickListener { viewModel.onTabsClicked() } | ||
dappEntryPointClose.setOnClickListener { viewModel.onTabsCloseClicked() } | ||
} | ||
|
||
override fun subscribe(viewModel: SplitScreenViewModel) { | ||
setupCloseAllDappTabsDialogue(viewModel.closeAllTabsConfirmation) | ||
|
||
viewModel.dappTabsQuantity.observe { | ||
val shouldBeVisible = it > 0 | ||
val isVisibilityChanged = dappEntryPoint.isVisible != shouldBeVisible | ||
|
||
if (isVisibilityChanged) { | ||
mainNavHost.outlineProvider = RoundCornersOutlineProvider(getOutlineCornerRadius(shouldBeVisible)) | ||
} | ||
|
||
dappEntryPoint.isVisible = it > 0 | ||
dappEntryPointText.text = getString(R.string.dapp_entry_point_title, it) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldnt we display a proper tab name in case there's only one tab? |
||
} | ||
} | ||
|
||
private val mainNavController: NavController by lazy { | ||
val navHostFragment = childFragmentManager.findFragmentById(R.id.mainNavHost) as NavHostFragment | ||
|
||
navHostFragment.navController | ||
} | ||
|
||
private fun getOutlineCornerRadius(isRounded: Boolean): Float { | ||
return if (isRounded) { | ||
12f | ||
} else { | ||
0f | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
package io.novafoundation.nova.app.root.presentation.splitScreen | ||
|
||
import io.novafoundation.nova.app.root.domain.SplitScreenInteractor | ||
import io.novafoundation.nova.common.base.BaseViewModel | ||
import io.novafoundation.nova.common.mixin.actionAwaitable.ActionAwaitableMixin | ||
import io.novafoundation.nova.common.mixin.actionAwaitable.awaitAction | ||
import io.novafoundation.nova.common.mixin.actionAwaitable.confirmingAction | ||
import io.novafoundation.nova.feature_dapp_api.DAppRouter | ||
import io.novafoundation.nova.feature_dapp_api.presentation.browser.main.DAppBrowserPayload | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.launch | ||
|
||
class SplitScreenViewModel() : BaseViewModel() | ||
class SplitScreenViewModel( | ||
private val interactor: SplitScreenInteractor, | ||
private val router: DAppRouter, | ||
private val actionAwaitableMixinFactory: ActionAwaitableMixin.Factory, | ||
) : BaseViewModel() { | ||
|
||
val closeAllTabsConfirmation = actionAwaitableMixinFactory.confirmingAction<Unit>() | ||
|
||
private val tabIdsFlow = interactor.observeTabIds() | ||
.shareInBackground() | ||
|
||
val dappTabsQuantity = tabIdsFlow.map { it.size } | ||
|
||
fun onTabsClicked() = launch { | ||
val tabIds = tabIdsFlow.first() | ||
|
||
if (tabIds.size == 1) { | ||
val payload = DAppBrowserPayload.Tab(tabIds.single()) | ||
router.openDAppBrowser(payload) | ||
} else { | ||
router.openTabs() | ||
} | ||
} | ||
|
||
fun onTabsCloseClicked() = launch { | ||
closeAllTabsConfirmation.awaitAction() | ||
|
||
interactor.removeAllTabs() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have an interface in dapp browser api and implementation in dapp browser impl and be provided to root