-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow programmatically showing/hiding categories
- Loading branch information
Showing
13 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...n/kotlin/ch/rmy/android/http_shortcuts/scripting/actions/types/SetCategoryHiddenAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ch.rmy.android.http_shortcuts.scripting.actions.types | ||
|
||
import ch.rmy.android.http_shortcuts.R | ||
import ch.rmy.android.http_shortcuts.data.domains.categories.CategoryRepository | ||
import ch.rmy.android.http_shortcuts.exceptions.ActionException | ||
import ch.rmy.android.http_shortcuts.scripting.ExecutionContext | ||
import javax.inject.Inject | ||
|
||
class SetCategoryHiddenAction | ||
@Inject | ||
constructor( | ||
private val categoryRepository: CategoryRepository, | ||
) : Action<SetCategoryHiddenAction.Params> { | ||
override suspend fun Params.execute(executionContext: ExecutionContext) { | ||
setHidden(this.categoryNameOrId ?: "") | ||
} | ||
|
||
private suspend fun Params.setHidden(categoryNameOrId: String) { | ||
val category = try { | ||
categoryRepository.getCategoryByNameOrId(categoryNameOrId) | ||
} catch (_: NoSuchElementException) { | ||
throw ActionException { | ||
getString(R.string.error_category_not_found_for_set_visible, categoryNameOrId) | ||
} | ||
} | ||
categoryRepository.setCategoryHidden(category.id, hidden) | ||
} | ||
|
||
data class Params( | ||
val categoryNameOrId: String?, | ||
val hidden: Boolean, | ||
) | ||
} |
34 changes: 34 additions & 0 deletions
34
...tlin/ch/rmy/android/http_shortcuts/scripting/actions/types/SetCategoryHiddenActionType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ch.rmy.android.http_shortcuts.scripting.actions.types | ||
|
||
import ch.rmy.android.framework.extensions.takeUnlessEmpty | ||
import ch.rmy.android.http_shortcuts.scripting.ActionAlias | ||
import ch.rmy.android.http_shortcuts.scripting.actions.ActionData | ||
import ch.rmy.android.http_shortcuts.scripting.actions.ActionRunnable | ||
import javax.inject.Inject | ||
|
||
class SetCategoryHiddenActionType | ||
@Inject | ||
constructor( | ||
private val setCategoryHiddenAction: SetCategoryHiddenAction, | ||
) : ActionType { | ||
override val type = TYPE | ||
|
||
override fun getActionRunnable(actionDTO: ActionData) = | ||
ActionRunnable( | ||
action = setCategoryHiddenAction, | ||
params = SetCategoryHiddenAction.Params( | ||
categoryNameOrId = actionDTO.getString(0)?.takeUnlessEmpty(), | ||
hidden = actionDTO.getBoolean(1) != false, | ||
), | ||
) | ||
|
||
override fun getAlias() = ActionAlias( | ||
functionName = FUNCTION_NAME, | ||
parameters = 2, | ||
) | ||
|
||
companion object { | ||
private const val TYPE = "set_category_hidden" | ||
private const val FUNCTION_NAME = "setCategoryHidden" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters