Skip to content

Commit

Permalink
code optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Mar 28, 2024
1 parent 8061039 commit 90d0d85
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ interface EntryListener {
* It will get called on tap of start workflow on the option list
*/
fun onProcessStart(entries: List<ParentEntry>) {}

fun onAttachFolder(entry: ParentEntry) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ data class DatePickerBuilder(
timePicker.addOnPositiveButtonClickListener {
val hour = timePicker.hour
val minute = timePicker.minute
println("string date $stringDateTime || $hour || $minute")
val combinedDateTime = "$stringDateTime $hour:$minute"
onSuccess?.invoke(combinedDateTime)
}
Expand Down
8 changes: 0 additions & 8 deletions move/src/main/java/com/alfresco/content/move/MoveFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.alfresco.content.move

import android.content.Context
import android.os.Bundle
import android.os.Parcelable
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -46,14 +45,8 @@ class MoveFragment : Fragment(), MavericksView {
@OptIn(InternalMavericksApi::class)
val viewModel: MoveViewModel by fragmentViewModelWithArgs { args }

override fun onAttach(context: Context) {
super.onAttach(context)
println("MoveFragment.onAttach")
}

override fun onStart() {
super.onStart()
println("MoveFragment.onStart")
val nodeId = viewModel.getMyFilesNodeId()
args.entryObj?.let {
findNavController().navigateToMoveParent(nodeId, it.id, getString(R.string.browse_menu_personal))
Expand All @@ -62,7 +55,6 @@ class MoveFragment : Fragment(), MavericksView {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
println("MoveFragment.onCreate")
args = MoveArgs.with(requireArguments())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.alfresco.content.data.Entry
import com.alfresco.content.data.payloads.FieldsData
import com.alfresco.content.navigateToContextualSearch
import com.alfresco.content.process.R
Expand All @@ -35,7 +34,6 @@ import com.alfresco.content.process.ui.theme.AlfrescoError

@Composable
fun AttachFolderField(
contents: List<Entry> = emptyList(),
fieldsData: FieldsData = FieldsData(),
onUserTap: (Boolean) -> Unit = { },
navController: NavController,
Expand All @@ -50,10 +48,10 @@ fun AttachFolderField(
}
}

val contentValue = if (contents.isEmpty()) {
val contentValue = if (fieldsData.value == null) {
stringResource(id = R.string.no_attached_folder)
} else {
stringResource(id = R.string.text_attached_folder, contents.size)
stringResource(id = R.string.text_attached_folder, 1)
}

val context = LocalContext.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ fun FormScrollContent(field: FieldsData, viewModel: FormViewModel, state: FormVi

FieldType.SELECT_FOLDER.value() -> {
AttachFolderField(
contents = state.listContents,
fieldsData = field,
navController = navController,
onUserTap = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.ViewModelContext
import com.alfresco.content.DATE_FORMAT_4
import com.alfresco.content.DATE_FORMAT_5
import com.alfresco.content.common.EntryListener
import com.alfresco.content.data.AttachFolderSearchData
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.OptionsModel
Expand All @@ -34,17 +35,15 @@ class FormViewModel(
private var observeUploadsJob: Job? = null
var observerID: String = ""
var folderFieldId = ""
private var entryListener: EntryListener? = null

init {
observerID = UUID.randomUUID().toString()
singleProcessDefinition(state.parent.id)

viewModelScope.on<AttachFolderSearchData> {
it.entry?.let { entry ->
println("FormViewModel 1 == $entry")
println("FormViewModel 2 == $folderFieldId")
updateFieldValue(folderFieldId, entry.id, state, Pair(false, ""))
folderFieldId = ""
entryListener?.onAttachFolder(entry)
}
}
}
Expand Down Expand Up @@ -234,6 +233,10 @@ class FormViewModel(
return (hasValidDataInRequiredFields && hasValidDataInOtherFields)
}

fun setListener(listener: EntryListener) {
entryListener = listener
}

companion object : MavericksViewModelFactory<FormViewModel, FormViewState> {

override fun create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import com.alfresco.content.common.EntryListener
import com.alfresco.content.data.Entry
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.process.R
import com.alfresco.content.process.databinding.FragmentProcessBinding
import com.alfresco.content.process.ui.composeviews.FormScreen
import com.alfresco.content.process.ui.theme.AlfrescoBaseTheme

class ProcessFragment : Fragment(), MavericksView {
class ProcessFragment : Fragment(), MavericksView, EntryListener {

val viewModel: FormViewModel by activityViewModel()
lateinit var binding: FragmentProcessBinding
Expand All @@ -37,6 +40,8 @@ class ProcessFragment : Fragment(), MavericksView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.setListener(this)

val supportActionBar = (requireActivity() as AppCompatActivity).supportActionBar
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
Expand All @@ -58,4 +63,16 @@ class ProcessFragment : Fragment(), MavericksView {
override fun invalidate() = withState(viewModel) { state ->
binding.loading.isVisible = state.requestStartForm is Loading || state.requestStartWorkflow is Loading
}

override fun onAttachFolder(entry: ParentEntry) = withState(viewModel) {
if (isAdded) {
viewModel.updateFieldValue(
viewModel.folderFieldId,
(entry as Entry).id,
it,
Pair(false, ""),
)
viewModel.folderFieldId = ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fun integerInputError(value: String?, fieldsData: FieldsData, context: Context):
}
}

println("IntegerInputField 3 == $errorData")

return errorData
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class SearchFragment : Fragment(), MavericksView {
binding.recyclerViewChips.setController(epoxyController)

withState(viewModel) { state ->
println("SearchFragment.onViewCreated ${state.isProcess}")

if (state.isProcess == true) {
binding.parentAdvanceSearch.visibility = View.GONE
Expand Down Expand Up @@ -539,7 +538,7 @@ class SearchFragment : Fragment(), MavericksView {
resultsFragment.setFilters(advanceSearchFilter, facetData)
}

fun clearMultiSelection() {
private fun clearMultiSelection() {
resultsFragment.clearMultiSelection()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.alfresco.content.listview.ListFragment
import com.alfresco.content.navigateTo
import com.alfresco.content.navigateToExtensionFolder
import com.alfresco.content.navigateToFolder
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -80,27 +79,30 @@ class SearchResultsFragment : ListFragment<SearchViewModel, SearchResultsState>(
viewModel.saveSearch()
}

@OptIn(DelicateCoroutinesApi::class)
override fun onItemClicked(entry: Entry) {
viewModel.saveSearch()
withState(viewModel) { state ->

if (state.isProcess != null) {
viewModel.setSearchResult(entry)
requireActivity().onBackPressed()
} else {
if (!state.isExtension) {
findNavController().navigateTo(entry)
} else if (entry.isFolder) {
when {
state.moveId.isNotEmpty() -> {
val parentId = entry.parentPaths.find { it == state.moveId }
if (parentId.isNullOrEmpty()) {
findNavController().navigateToFolder(entry, state.moveId)
} else Toast.makeText(requireContext(), getString(R.string.search_move_warning), Toast.LENGTH_SHORT).show()
when {
state.isProcess != null -> {
if (entry.isFolder) {
viewModel.setSearchResult(entry)
requireActivity().onBackPressed()
}
}
else -> {
if (!state.isExtension) {
findNavController().navigateTo(entry)
} else if (entry.isFolder) {
when {
state.moveId.isNotEmpty() -> {
val parentId = entry.parentPaths.find { it == state.moveId }
if (parentId.isNullOrEmpty()) {
findNavController().navigateToFolder(entry, state.moveId)
} else Toast.makeText(requireContext(), getString(R.string.search_move_warning), Toast.LENGTH_SHORT).show()
}

else -> findNavController().navigateToExtensionFolder(entry)
}

else -> findNavController().navigateToExtensionFolder(entry)
}
}
}
Expand Down

0 comments on commit 90d0d85

Please sign in to comment.