Skip to content

Commit

Permalink
Pass task id if a pending action exists to edit the current one (inst…
Browse files Browse the repository at this point in the history
…ead of sending new one) when:

- edit action are unique task is enabled and we have an edit action
- action has boolean to define task as unique
  • Loading branch information
e-marchand committed Jan 4, 2024
1 parent cca6eb5 commit f61bc13
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.qmobile.qmobileui.action.model.Action

interface ActionNavigable : ActionProvider {

fun navigateToActionForm(action: Action, itemId: String?)
fun navigateToActionForm(action: Action, itemId: String?, taskId: String?)

fun navigateToPendingTasks()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ open class Action(
val parameters: JSONArray,
val uuid: String,
val description: String? = null,
val sortFields: LinkedHashMap<String, String>
val sortFields: LinkedHashMap<String, String>,
val hasUniqueTask: Boolean
) {

fun getIconDrawablePath(): String? =
Expand All @@ -46,6 +47,8 @@ open class Action(
TABLE, CURRENT_RECORD
}

fun isAddAction() = preset == "add"
fun isEditAction() = preset == "edit"
fun isSortAction() = preset == "sort"
fun isOpenUrlAction() = preset == "openURL"
fun isOfflineCompatible() = preset?.lowercase(Locale.getDefault()) != "share"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import com.qmobile.qmobileapi.utils.getJSONObjectList
import com.qmobile.qmobileapi.utils.getSafeArray
import com.qmobile.qmobileapi.utils.getSafeString
import com.qmobile.qmobileapi.utils.parseToString
import com.qmobile.qmobileapi.model.entity.EntityModel
import com.qmobile.qmobileapi.utils.getSafeBoolean
import com.qmobile.qmobiledatastore.dao.ActionTask
import com.qmobile.qmobiledatastore.data.RoomEntity
import com.qmobile.qmobiledatasync.app.BaseApp
import com.qmobile.qmobiledatasync.relation.Relation
import com.qmobile.qmobiledatasync.utils.fieldAdjustment
Expand Down Expand Up @@ -100,7 +103,8 @@ object ActionHelper {
parameters = parameters,
uuid = getSafeString("uuid") ?: "",
description = getSafeString("description") ?: "",
sortFields = getSortFields(parameters)
sortFields = getSortFields(parameters),
hasUniqueTask = getSafeBoolean("hasUniqueTask") ?: false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,16 @@ class MainActivity :
}
}
action.parameters.length() > 0 -> {
actionNavigable.navigateToActionForm(action, (currentEntity?.__entity as? EntityModel)?.__KEY)
val itemId = (currentEntity?.__entity as? EntityModel)?.__KEY

var pendingTaskId: String? = null
if (action.hasUniqueTask || (BaseApp.runtimeDataHolder.editActionHasUniqueTask && (action.scope == Action.Scope.CURRENT_RECORD) && action.isEditAction())) {
pendingTaskId = this.getTaskVM().pendingTasks.value?.firstOrNull {
it.isPending() && it.match(action.name, actionNavigable.tableName, itemId)
}?.id
}

actionNavigable.navigateToActionForm(action, itemId, pendingTaskId)
}
action.isOfflineCompatible() || connectivityViewModel.isConnected() -> {
val task = ActionTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ open class EntityDetailFragment : BaseFragment(), ActionNavigable, MenuProvider
)
}

override fun navigateToActionForm(action: Action, itemId: String?) {
override fun navigateToActionForm(action: Action, itemId: String?, taskId: String?) {
setFadeThroughExitTransition()
BaseApp.genericNavigationResolver.navigateToActionForm(
viewDataBinding = binding,
tableName = tableName,
itemId = itemId ?: this.itemId,
relationName = "",
parentItemId = "",
pendingTaskId = "",
pendingTaskId = taskId ?: "",
actionUUID = action.uuid,
navbarTitle = action.getPreferredShortName()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,15 @@ abstract class ListFormFragment : BaseFragment(), ActionNavigable, MenuProvider
)
}

override fun navigateToActionForm(action: Action, itemId: String?) {
override fun navigateToActionForm(action: Action, itemId: String?, taskId: String?) {
setFadeThroughExitTransition()
BaseApp.genericNavigationResolver.navigateToActionForm(
viewDataBinding = binding,
tableName = relation?.source ?: tableName,
itemId = itemId ?: "",
relationName = relation?.name ?: "",
parentItemId = parentItemId,
pendingTaskId = "",
pendingTaskId = taskId ?: "",
actionUUID = action.uuid,
navbarTitle = action.getPreferredShortName()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.qmobile.qmobileui.ActionActivity
import com.qmobile.qmobileui.FragmentCommunication
import com.qmobile.qmobileui.R
import com.qmobile.qmobileui.SettingsActivity
import com.qmobile.qmobileui.action.utils.ActionHelper
import com.qmobile.qmobileui.activity.BaseActivity
import com.qmobile.qmobileui.feedback.FeedbackHandler
import com.qmobile.qmobileui.network.RemoteUrlChanger
Expand Down Expand Up @@ -149,6 +150,9 @@ class SettingsFragment :
} else {
getString(R.string.logout_dialog_title)
}
// actionActivity.getTaskVM().pendingTasks.value?.filter { it.isPending() && ActionHelper.match(it, entity = )}


MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_QMobile_MaterialAlertDialog_FullWidthButtons)
.setTitle(title)
.setMessage(getString(R.string.logout_dialog_message))
Expand Down

0 comments on commit f61bc13

Please sign in to comment.