Skip to content
Snippets Groups Projects
Commit 82c7c03e authored by Taras's avatar Taras
Browse files

Handle ui updates for validation

parent dfd8da64
No related branches found
No related tags found
No related merge requests found
package org.futo.circles.auth.feature.workspace package org.futo.circles.auth.feature.workspace
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
...@@ -30,6 +32,13 @@ class ConfigureWorkspaceFragment : Fragment(R.layout.fragment_configure_workspac ...@@ -30,6 +32,13 @@ class ConfigureWorkspaceFragment : Fragment(R.layout.fragment_configure_workspac
WorkspaceTasksListAdapter { viewModel.onOptionalTaskSelectionChanged(it) } WorkspaceTasksListAdapter { viewModel.onOptionalTaskSelectionChanged(it) }
} }
private var configureWorkspaceListener: ConfigureWorkspaceListener? = null
override fun onAttach(context: Context) {
super.onAttach(context)
configureWorkspaceListener = (parentFragment as? ConfigureWorkspaceListener)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
setupViews() setupViews()
...@@ -38,6 +47,12 @@ class ConfigureWorkspaceFragment : Fragment(R.layout.fragment_configure_workspac ...@@ -38,6 +47,12 @@ class ConfigureWorkspaceFragment : Fragment(R.layout.fragment_configure_workspac
private fun setupViews() { private fun setupViews() {
with(binding) { with(binding) {
val shouldValidate = arguments?.getBoolean(SHOULD_VALIDATE) ?: false
toolbar.title =
getString(if (shouldValidate) R.string.validating_workspace else R.string.configure_workspace)
if (shouldValidate) startLoading(btbCreate)
rvWorkspaceTasks.apply { rvWorkspaceTasks.apply {
adapter = tasksAdapter adapter = tasksAdapter
addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL)) addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
...@@ -55,12 +70,27 @@ class ConfigureWorkspaceFragment : Fragment(R.layout.fragment_configure_workspac ...@@ -55,12 +70,27 @@ class ConfigureWorkspaceFragment : Fragment(R.layout.fragment_configure_workspac
} }
viewModel.workspaceResultLiveData.observeResponse(this, viewModel.workspaceResultLiveData.observeResponse(this,
success = { success = {
findNavController() configureWorkspaceListener?.onWorkspaceConfigured() ?: kotlin.run {
.navigateSafe(ConfigureWorkspaceFragmentDirections.toSetupProfileFragment()) findNavController()
.navigateSafe(ConfigureWorkspaceFragmentDirections.toSetupProfileFragment())
}
}, },
error = { error = {
showError(it) showError(it)
binding.btbCreate.setText(getString(R.string.retry)) binding.btbCreate.setText(getString(R.string.retry))
}) })
viewModel.validateWorkspaceResultLiveData.observeResponse(this,
success = { configureWorkspaceListener?.onWorkspaceConfigured() },
error = {
binding.toolbar.title = getString(R.string.configure_workspace)
}
)
}
companion object {
const val SHOULD_VALIDATE = "should_validate"
fun create(shouldValidate: Boolean) = ConfigureWorkspaceFragment().apply {
arguments = bundleOf(SHOULD_VALIDATE to shouldValidate)
}
} }
} }
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