Skip to content
Snippets Groups Projects
Commit 90f4c9ef authored by Taras's avatar Taras
Browse files

Show configure workspace only if user need to fix it

parent dfa1c0af
No related branches found
No related tags found
No related merge requests found
......@@ -23,15 +23,18 @@ import org.futo.circles.core.SHARE_PROFILE_URL_PREFIX
import org.futo.circles.core.SHARE_ROOM_URL_PREFIX
import org.futo.circles.core.extensions.navigateSafe
import org.futo.circles.core.extensions.observeData
import org.futo.circles.core.extensions.observeResponse
import org.futo.circles.core.extensions.setSupportActionBar
import org.futo.circles.core.model.CircleRoomTypeArg
import org.futo.circles.core.model.GROUP_TYPE
import org.futo.circles.core.model.LoadingData
import org.futo.circles.core.model.TIMELINE_TYPE
import org.futo.circles.core.notices.SystemNoticesCountSharedViewModel
import org.futo.circles.core.picker.helper.RuntimePermissionHelper
import org.futo.circles.core.provider.MatrixSessionProvider
import org.futo.circles.core.view.LoadingDialog
import org.futo.circles.databinding.FragmentBottomNavigationBinding
import org.futo.circles.gallery.feature.backup.service.MediaBackupServiceManager
import org.futo.circles.core.notices.SystemNoticesCountSharedViewModel
import org.matrix.android.sdk.api.session.getRoomSummary
import javax.inject.Inject
......@@ -50,6 +53,7 @@ class HomeFragment : Fragment(R.layout.fragment_bottom_navigation), DeepLinkInte
private val viewModel by viewModels<HomeViewModel>()
private val systemNoticesCountViewModel by activityViewModels<SystemNoticesCountSharedViewModel>()
private val loadingDialog by lazy { LoadingDialog(requireContext()) }
@Inject
lateinit var mediaBackupServiceManager: MediaBackupServiceManager
......@@ -60,7 +64,7 @@ class HomeFragment : Fragment(R.layout.fragment_bottom_navigation), DeepLinkInte
binding.bottomNavigationView.setupWithNavController(controller)
setupToolBar(controller)
}
WorkspaceDialogFragment().show(childFragmentManager,"workspace")
loadingDialog.handleLoading(LoadingData(org.futo.circles.auth.R.string.validating_workspace))
setupObservers()
registerPushNotifications()
handleDeepLinks()
......@@ -127,6 +131,9 @@ class HomeFragment : Fragment(R.layout.fragment_bottom_navigation), DeepLinkInte
viewModel.mediaBackupSettingsLiveData?.observeData(this) {
mediaBackupServiceManager.bindMediaServiceIfNeeded(requireContext(), it)
}
viewModel.validateWorkspaceResultLiveData.observeResponse(this,
error = { WorkspaceDialogFragment().show(childFragmentManager, "workspace") },
onRequestInvoked = { loadingDialog.dismiss() })
}
private fun registerPushNotifications() {
......
......@@ -4,13 +4,15 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import org.futo.circles.auth.feature.workspace.data_source.ConfigureWorkspaceDataSource
import org.futo.circles.auth.feature.workspace.data_source.WorkspaceTasksProvider
import org.futo.circles.core.SingleEventLiveData
import org.futo.circles.core.extensions.Response
import org.futo.circles.core.extensions.createResult
import org.futo.circles.core.extensions.launchBg
import org.futo.circles.core.model.CIRCLE_TAG
import org.futo.circles.core.model.GROUP_TYPE
import org.futo.circles.core.model.SharedCirclesSpace
import org.futo.circles.core.provider.MatrixSessionProvider
import org.futo.circles.core.room.CreateRoomDataSource
import org.futo.circles.core.utils.getSharedCirclesSpaceId
import org.futo.circles.feature.notifications.PushersManager
import org.futo.circles.feature.notifications.ShortcutsHandler
import org.futo.circles.gallery.feature.backup.RoomAccountDataSource
......@@ -23,11 +25,13 @@ import javax.inject.Inject
@HiltViewModel
class HomeViewModel @Inject constructor(
private val pushersManager: PushersManager,
private val createRoomDataSource: CreateRoomDataSource,
private val workspaceTasksProvider: WorkspaceTasksProvider,
private val workspaceDataSource: ConfigureWorkspaceDataSource,
roomAccountDataSource: RoomAccountDataSource,
shortcutsHandler: ShortcutsHandler
) : ViewModel() {
val validateWorkspaceResultLiveData = SingleEventLiveData<Response<Unit>>()
val mediaBackupSettingsLiveData = roomAccountDataSource.getMediaBackupSettingsLive()
val inviteIntoSharedSpaceLiveData = MatrixSessionProvider.currentSession?.roomService()
?.getRoomSummariesLive(roomSummaryQueryParams {
......@@ -37,14 +41,31 @@ class HomeViewModel @Inject constructor(
init {
shortcutsHandler.observeRoomsAndBuildShortcuts(viewModelScope)
createSharedCirclesSpaceIfNotExist()
validateWorkspace()
}
private fun createSharedCirclesSpaceIfNotExist() {
if (getSharedCirclesSpaceId() != null) return
launchBg { createRoomDataSource.createRoom(SharedCirclesSpace()) }
private fun validateWorkspace() = launchBg {
val tasks = workspaceTasksProvider.getMandatoryTasks()
tasks.forEachIndexed { i, item ->
when (val validationResponse =
createResult { workspaceDataSource.validate(item.room) }) {
is Response.Error -> {
validateWorkspaceResultLiveData.postValue(Response.Error(""))
return@launchBg
}
is Response.Success -> if (!validationResponse.data) {
validateWorkspaceResultLiveData.postValue(Response.Error(""))
return@launchBg
}
}
}
validateWorkspaceResultLiveData.postValue(Response.Success(Unit))
}
fun registerPushNotifications() {
pushersManager.registerPushNotifications()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment