Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

implementing-android-code

БесплатноБез исполняемых скриптовНе проверен

This skill should be used when implementing Android code in Bitwarden. Covers critical patterns, gotchas, and anti-patterns unique to this codebase. Triggered…

bitwardenот bitwarden★ 9 728 звёзд на GitHub

Об этом скилле

Implementing Android Code - Bitwarden Quick Reference

This skill provides tactical guidance for Bitwarden-specific patterns. For comprehensive architecture decisions and complete code style rules, consult docs/ARCHITECTURE.md and docs/STYLE_AND_BEST_PRACTICES.md.


Critical Patterns Reference

A. ViewModel Implementation (State-Action-Event Pattern)

All ViewModels follow the State-Action-Event (SAE) pattern via BaseViewModel<State, Event, Action>.

Key Requirements:

  • Annotate with @HiltViewModel
  • ViewModels that need navigation arguments receive their route via assisted injection (@HiltViewModel(assistedFactory = ...), @AssistedInject constructor(@Assisted route: XGraph.XRoute))
  • State class MUST be @Parcelize data class : Parcelable
  • Implement handleAction(action: A) - MUST be synchronous
  • Post internal actions from coroutines using sendAction()
  • Save/restore state via SavedStateHandle[KEY_STATE]
  • Private action handlers: private fun handle* naming convention

Template: See ViewModel template

Pattern Summary:

@HiltViewModel
class ExampleViewModel @Inject constructor(
    savedStateHandle: SavedStateHandle,
    private val repository: ExampleRepository,
) : BaseViewModel<ExampleState, ExampleEvent, ExampleAction>(
    initialState = savedStateHandle[KEY_STATE] ?: ExampleState(),
) {
    init {
        stateFlow.onEach { savedStateHandle[KEY_STATE] = it }.launchIn(viewModelScope)
    }

    override fun handleAction(action: ExampleAction) {
        // Synchronous dispatch only
        when (action) {
            is Action.Click -> handleClick()
            is Action.Internal.DataReceived -> handleDataReceived(action)
        }
    }

    private fun handleClick() {
        viewModelScope.launch {
            val result = repository.fetchData()
            sendAction(Action.Internal.DataReceived(result))  // Post internal action
        }
    }

    private fun handleDataReceived(action: Action.Internal.DataReceived) {
        mutableStateFlow.update { it.copy(data = action.result) }
    }
}

ViewModel with navigation arguments (assisted injection):

@HiltViewModel(assistedFactory = ExampleViewModel.Factory::class)
class ExampleViewModel @AssistedInject constructor(
    @Assisted route: ExampleGraph.ExampleRoute,
    savedStateHandle: SavedStateHandle,
    private val repository: ExampleRepository,
) : BaseViewModel<ExampleState, ExampleEvent, ExampleAction>(
    initialState = savedStateHandle[KEY_STATE] ?: ExampleState(userId = route.userId),
) {
    /**
     * Factory for creating an [ExampleViewModel] for a specific [ExampleGraph.ExampleRoute].
     */
    @AssistedFactory
    interface Factory {
        /**
         * Creates an [ExampleViewModel] for the given [route].
         */
        fun create(route: ExampleGraph.ExampleRoute): ExampleViewModel
    }
    // ...
}

Reference:

  • ui/src/main/kotlin/com/bitwarden/ui/platform/base/BaseViewModel.kt (see handleAction method)
  • app/src/main/kotlin/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt (see class declaration)
  • app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt (assisted injection of the route)

Critical Gotchas:

  • ❌ NEVER update mutableStateFlow directly inside coroutines
  • ✅ ALWAYS post internal actions from coroutines, update state in handleAction()
  • ❌ NEVER forget @IgnoredOnParcel for sensitive data (causes security leak)
  • ✅ ALWAYS use @Parcelize on state classes for process death recovery
  • ✅ State restoration happens automatically if properly saved to SavedStateHandle

B. Navigation Implementation (Navigation 3, Type-Safe)

All navigation uses Navigation 3 with type-safe @Serializable routes. Every NavDisplay displays one navigation graph: a @Serializable sealed class {Name}Graph : NavKey whose nested subclasses are its routes (e.g. AuthGraph.LoginRoute). The back stack is owned by a NavigationController<{Name}Graph> (ui/.../platform/navigation/NavigationController.kt); never touch a NavBackStack directly. A route may host a nested graph (e.g. RootNavGraph.AuthRoute hosts the AuthGraph, each nav bar tab hosts its own graph).

Pattern Structure:

  1. @Serializable route nested in the graph of the NavDisplay that shows the screen, holding every argument (any @Serializable type)
  2. EntryProviderScope<{Name}Graph>.{screen}Destination() extension that adds the entry, declares its transitions in metadata, and creates the ViewModel for the route (assisted injection)
  3. NavigationController<{Name}Graph>.navigateTo{Screen}() extension for navigation calls
  4. Groups of related destinations (a "flow") are added with EntryProviderScope<{Name}Graph>.{flow}Destinations(navigationController), and a route hosting a nested graph is added with
Полный SKILL.md на GitHub

Установить implementing-android-code в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

templates.md

FAQ

Что делает скилл implementing-android-code?

This skill should be used when implementing Android code in Bitwarden. Covers critical patterns, gotchas, and anti-patterns unique to this codebase. Triggered by "How do I implement a ViewModel?", "Create a new screen", "Add navigation", "Write a repository", "BaseViewModel pattern", "State-Action-Event", "type-safe navigation", "@Serializable route", "SavedStateHandle persistence", "process death recovery", "handleAction", "sendAction", "Hilt module", "Repository pattern", "implementing a screen", "adding a data source", "handling navigation", "encrypted storage", "security patterns", "Clock injection", "DataState", or any questions about implementing features, screens, ViewModels, data sources, or navigation in the Bitwarden Android app.

Как установить скилл implementing-android-code?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл implementing-android-code запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить implementing-android-code с