Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class BaseFragment : Fragment(R.layout.fragment_base) {
if (authStore.signedInProjectId.isNotEmpty()) {
findNavController().navigateSafely(this, BaseFragmentDirections.actionBaseFragmentToMainFragment())
} else {
findNavController().navigateSafely(this, BaseFragmentDirections.actionBaseFragmentToRequestLoginFragment())
findNavController().navigateSafely(this, BaseFragmentDirections.actionToRequestLoginFragment())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -52,9 +51,7 @@ internal class LogoutSyncViewModel @Inject constructor(
}

fun logout() {
viewModelScope.launch {
logoutUseCase()
}
logoutUseCase()
}

private companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,5 @@ class LogoutSyncFragment : Fragment(R.layout.fragment_logout_sync) {
}
}
}
viewModel.logoutEventLiveData.observe(viewLifecycleOwner) {
findNavController().navigateSafely(
this@LogoutSyncFragment,
R.id.action_logoutSyncFragment_to_requestLoginFragment,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LogoutSyncDeclineFragment : Fragment(R.layout.fragment_logout_sync_decline
viewModel.logoutEventLiveData.observe(viewLifecycleOwner) {
findNavController().navigateSafely(
this@LogoutSyncDeclineFragment,
LogoutSyncDeclineFragmentDirections.actionLogoutSyncDeclineFragmentToRequestLoginFragment(),
LogoutSyncDeclineFragmentDirections.actionToRequestLoginFragment(null),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.simprints.infra.enrolment.records.repository.EnrolmentRecordRepositor
import com.simprints.infra.enrolment.records.repository.local.migration.RealmToRoomMigrationFlagsStore
import com.simprints.infra.sync.SyncOrchestrator
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

internal class LogoutUseCase @Inject constructor(
Expand All @@ -16,7 +16,8 @@ internal class LogoutUseCase @Inject constructor(
private val enrolmentRecordRepository: EnrolmentRecordRepository,
@DispatcherIO private val ioDispatcher: CoroutineDispatcher,
) {
suspend operator fun invoke() = withContext(ioDispatcher) {
// To prevent a race between wiping data and navigation, this use case must block the executing thread
operator fun invoke() = runBlocking(ioDispatcher) {
// Cancel all background sync
syncOrchestrator.cancelBackgroundWork()
syncOrchestrator.deleteEventSyncInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import com.simprints.feature.dashboard.R
import com.simprints.feature.dashboard.databinding.FragmentSettingsAboutBinding
import com.simprints.feature.dashboard.settings.password.SettingsPasswordDialogFragment
import com.simprints.infra.config.store.models.GeneralConfiguration.Modality.FINGERPRINT
import com.simprints.infra.uibase.view.applySystemBarInsets
import com.simprints.infra.uibase.navigation.navigateSafely
import com.simprints.infra.uibase.system.Clipboard
import com.simprints.infra.uibase.view.applySystemBarInsets
import com.simprints.infra.uibase.viewbinding.viewBinding
import dagger.hilt.android.AndroidEntryPoint
import java.util.Locale
Expand Down Expand Up @@ -96,7 +96,7 @@ internal class AboutFragment : PreferenceFragmentCompat() {
LiveDataEventWithContentObserver {
val destination = when (it) {
LogoutDestination.LogoutDataSyncScreen -> AboutFragmentDirections.actionAboutFragmentToLogoutNavigation()
LogoutDestination.LoginScreen -> AboutFragmentDirections.actionAboutFragmentToRequestLoginFragment()
LogoutDestination.LoginScreen -> AboutFragmentDirections.actionToRequestLoginFragment()
}
findNavController().navigateSafely(this, destination)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal class SyncInfoViewModel @Inject constructor(
}

fun performLogout() {
viewModelScope.launch { logoutUseCase() }
logoutUseCase()
}

fun requestNavigationToLogin() {
Expand Down
23 changes: 1 addition & 22 deletions feature/dashboard/src/main/res/navigation/graph_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
android:name="com.simprints.feature.dashboard.base.BaseFragment"
android:label="BaseFragment"
tools:layout="@layout/fragment_base">
<action
android:id="@+id/action_baseFragment_to_requestLoginFragment"
app:destination="@id/requestLoginFragment"
app:popUpTo="@id/dashboard_navigation"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_baseFragment_to_mainFragment"
app:destination="@id/mainFragment"
Expand Down Expand Up @@ -97,11 +92,6 @@
<action
android:id="@+id/action_aboutFragment_to_logout_navigation"
app:destination="@id/logout_navigation" />
<action
android:id="@+id/action_aboutFragment_to_requestLoginFragment"
app:destination="@id/requestLoginFragment"
app:popUpTo="@id/dashboard_navigation"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_aboutFragment_to_troubleshooting"
app:destination="@id/graph_troubleshooting" />
Expand Down Expand Up @@ -141,11 +131,6 @@
<action
android:id="@+id/action_logoutSyncFragment_to_logoutSyncDeclineFragment"
app:destination="@id/logOutSyncDeclineFragment" />
<action
android:id="@+id/action_logoutSyncFragment_to_requestLoginFragment"
app:destination="@id/requestLoginFragment"
app:popUpTo="@id/dashboard_navigation"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_logoutSyncFragment_to_moduleSelectionFragment"
app:destination="@id/moduleSelectionFragment" />
Expand All @@ -157,13 +142,7 @@
android:id="@+id/logOutSyncDeclineFragment"
android:name="com.simprints.feature.dashboard.logout.syncdecline.LogoutSyncDeclineFragment"
android:label="LogoutSyncDeclineFragment"
tools:layout="@layout/fragment_logout_sync_decline">
<action
android:id="@+id/action_logoutSyncDeclineFragment_to_requestLoginFragment"
app:destination="@id/requestLoginFragment"
app:popUpTo="@id/dashboard_navigation"
app:popUpToInclusive="true" />
</fragment>
tools:layout="@layout/fragment_logout_sync_decline" />
</navigation>

<action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,4 @@ internal class LogoutSyncFragmentTest {
onView(withId(R.id.logout_sync_info)).check(matches(not(isDisplayed())))
onView(withId(R.id.logoutWithoutSyncButton)).check(matches(not(isDisplayed())))
}

@Test
fun `should navigate to requestLoginFragment when logout event received`() {
every { logoutSyncViewModel.logoutEventLiveData } returns mockk {
every { observe(any(), any()) } answers {
secondArg<Observer<Unit>>().onChanged(Unit)
}
}
val navController = testNavController(R.navigation.graph_dashboard, R.id.logout_navigation)
launchFragmentInHiltContainer<LogoutSyncFragment>(navController = navController)

assertThat(navController.currentDestination?.id)
.isEqualTo(R.id.requestLoginFragment)
}
}