[카테고리:] 미분류

  • API Key Centralization Plan

    The goal is to centralize the API key management into a new object HJHKeys as requested. This will ensure that changing the key (or the default key) only needs to happen in one place, and all components (Repository, ViewModel, Service) access it utilizing the same logic (checking SharedPreferences first).

    User Review Required

    IMPORTANT

    A new file HJHKeys.kt will be created. 

    Repository.kt, AIChatViewModel.kt, CAGEManager.kt, and SettingsFragment.kt will be modified to reference this new file.

    Proposed Changes

    Utils Layer

    [NEW] HJHKeys.kt

    • Create a singleton object HJHKeys.
    • Constants:
      • DEFAULT_API_KEY: The hardcoded “sk-…” key.
      • PREF_NAME: “how.naver.translator1.prefs”
      • KEY_OPENAI_API_KEY: “openai_api_key”
    • Methods:
      • getApiKey(context: Context): String: Returns the saved key from prefs, or DEFAULT_API_KEY if empty.

    Data Layer

    [MODIFY] Repository.kt

    • Remove DEFAULT_API_KEY constant.
    • Replace getApiKey() implementation to delegate to HJHKeys.getApiKey(context).

    [MODIFY] CAGEManager.kt

    • Remove DEFAULT_API_KEY constant.
    • Replace getApiKey() implementation to delegate to HJHKeys.getApiKey(context).

    UI Layer

    [MODIFY] AIChatViewModel.kt

    • Remove DEFAULT_API_KEY constant.
    • Update initialization and preference listeners to use constants from HJHKeys.

    [MODIFY] SettingsFragment.kt

    • Use constants from HJHKeys for preference lookups (optional but recommended for consistency).

    Verification Plan

    Automated Tests

    • None existing for this specific logic.

    Manual Verification

    1. Default Key Check: Clear app data or ensure no key is saved in settings. Run the app and use a feature requiring the ID (e.g., Chat). It should work using the default key.
    2. Custom Key Check: Go to Settings, enter a “fake” key or a different valid key.
      • Verify that the features now use the new key (logs might show this, or behavior might fail if key is invalid).
      • In this case, since we are just trying to ensure the code compiles and runs without hitting “OpenAPI 키가 설정되지 않았습니다”, successful chat response is the success metric.