### Setup SafeBox with Dagger Source: https://github.com/harrytmthy/safebox/blob/main/docs/MIGRATION.md Demonstrates the Dagger module setup for creating an instance of SafeBox. This is a simplified replacement for EncryptedSharedPreferences, requiring only the context and file name. ```kotlin @Singleton @Provides fun provideEncryptedSharedPreferences(context: Context): SharedPreferences = SafeBox.create(context, PREF_FILE_NAME) ``` -------------------------------- ### Setup SafeBox with Koin Source: https://github.com/harrytmthy/safebox/blob/main/docs/MIGRATION.md Shows how to configure SafeBox using Koin dependency injection. It creates a singleton instance of SharedPreferences using SafeBox.create with the application context and file name. ```kotlin single { SafeBox.create(androidContext(), PREF_FILE_NAME) } ``` -------------------------------- ### Update Installation Version in README Source: https://github.com/harrytmthy/safebox/blob/main/CONTRIBUTING.md Modifies the `README.md` file to reflect the correct version of the SafeBox library in the installation instructions. ```kotlin implementation("io.github.harrytmthy:safebox:1.2.0-alpha01") ``` -------------------------------- ### Setup EncryptedSharedPreferences with Dagger Source: https://github.com/harrytmthy/safebox/blob/main/docs/MIGRATION.md Provides the Dagger module setup for creating an instance of EncryptedSharedPreferences. It requires building a MasterKey with AES256_GCM scheme and configuring key and value encryption schemes. ```kotlin @Singleton @Provides fun provideEncryptedSharedPreferences(context: Context): SharedPreferences { val masterKey = MasterKey.Builder(context) .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) .build() return EncryptedSharedPreferences.create( context, PREF_FILE_NAME, masterKey, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM ) } ``` -------------------------------- ### SafeBox Create and Basic Usage (Kotlin) Source: https://github.com/harrytmthy/safebox/blob/main/README.md Demonstrates how to create a SafeBox instance using a Context and then use it like a standard SharedPreferences object for putting and getting data. ```kotlin val prefs: SharedPreferences = SafeBox.create(context, PREF_FILE_NAME) prefs.edit() .putInt("userId", 123) .putString("name", "Luna Moonlight") .apply() val userId = prefs.getInt("userId", -1) val email = prefs.getString("email", null) ``` -------------------------------- ### Observe SafeBox State with Instance-Bound Listener (Kotlin) Source: https://github.com/harrytmthy/safebox/blob/main/docs/OBSERVABILITY.md This snippet shows how to observe SafeBox lifecycle state transitions by providing a listener during SafeBox creation. It tracks states like STARTING, IDLE, and WRITING. ```kotlin val safeBox = SafeBox.create( context = context, fileName = PREF_FILE_NAME, stateListener = SafeBoxStateListener { state -> when (state) { SafeBoxState.STARTING -> trackStart() // Loading from disk SafeBoxState.IDLE -> trackIdle() // No active persistence SafeBoxState.WRITING -> trackWrite() // Persisting to disk } } ) ``` -------------------------------- ### Apply Code Formatting with Spotless Source: https://github.com/harrytmthy/safebox/blob/main/CONTRIBUTING.md Runs the Spotless Gradle task to apply code formatting rules across the project. It uses an initialization script and disables configuration cache for a clean application. ```bash ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache ``` -------------------------------- ### Clone SafeBox Repository Source: https://github.com/harrytmthy/safebox/blob/main/CONTRIBUTING.md Clones the SafeBox project from GitHub to your local machine. This is the first step for any contribution. ```bash git clone https://github.com/harrytmthy/safebox.git ``` -------------------------------- ### Create and Push Git Tag for Release Source: https://github.com/harrytmthy/safebox/blob/main/CONTRIBUTING.md Creates a Git tag for a specific release version and pushes it to the remote repository, which triggers the CI/CD pipeline for publishing. ```bash git tag v1.2.0-alpha01 git push origin v1.2.0-alpha01 ``` -------------------------------- ### SafeBox Retrieve Existing Instance (Kotlin) Source: https://github.com/harrytmthy/safebox/blob/main/README.md Shows how to retrieve an existing SafeBox instance for a given filename without needing a Context, and how to perform operations like clearing the preferences. ```kotlin SafeBox.get(PREF_FILE_NAME) // or SafeBox.create(context, PREF_FILE_NAME) .edit() .clear() .commit() ``` -------------------------------- ### Run Local Unit and Instrumented Tests Source: https://github.com/harrytmthy/safebox/blob/main/CONTRIBUTING.md Executes local unit tests and connected Android instrumented tests to verify functionality. These commands are used to ensure code quality before submitting changes. ```bash ./gradlew testDebugUnitTest ./gradlew connectedAndroidTest ``` -------------------------------- ### Configure Git Pre-hook Path Source: https://github.com/harrytmthy/safebox/blob/main/CONTRIBUTING.md Sets the local Git configuration to use the 'scripts/' directory for pre-commit and pre-push hooks, ensuring code quality checks are performed before commits. ```bash git config --local core.hooksPath scripts chmod +x scripts/pre-commit chmod +x scripts/pre-push ``` -------------------------------- ### SafeBox Kotlin Dependencies Source: https://github.com/harrytmthy/safebox/blob/main/README.md Adds the SafeBox library and its optional standalone crypto helper to your Android project's dependencies. ```kotlin dependencies { implementation("io.github.harrytmthy:safebox:1.3.0-alpha01") // Optional: standalone crypto helper implementation("io.github.harrytmthy:safebox-crypto:1.3.0-alpha01") } ``` -------------------------------- ### MIT License Source: https://github.com/harrytmthy/safebox/blob/main/README.md The project is licensed under the MIT License, allowing for free use, modification, and distribution. This section shows the copyright notice. ```plaintext MIT License Copyright (c) 2025 Harry Timothy Tumalewa ``` -------------------------------- ### SafeBox Instance Uniqueness (Kotlin) Source: https://github.com/harrytmthy/safebox/blob/main/README.md Illustrates that SafeBox maintains a single instance per filename, ensuring consistency when retrieving the same preferences multiple times. ```kotlin val a1 = SafeBox.create(context, "fileA") val a2 = SafeBox.create(context, "fileA") val a3 = SafeBox.get("fileA") assertTrue(a1 === a2) // same reference assertTrue(a1 === a3) // same reference val b = SafeBox.create(context, "fileB") assertTrue(a1 !== b) // different filenames = different instances ``` -------------------------------- ### Encrypt and Decrypt Text with SafeBoxCrypto Source: https://github.com/harrytmthy/safebox/blob/main/README.md Demonstrates how to use SafeBoxCrypto to create a secret key, encrypt user data (like an ID), and decrypt it. This helper can be used for securing data stored in databases like Room or transmitted over networks. The standalone ':safebox-crypto' module can be used if only cryptographic functionalities are needed. ```kotlin val secret: String = SafeBoxCrypto.createSecret() val userEntity = UserEntity( id = SafeBoxCrypto.encrypt(userId, secret), // ... ) val userId: String = SafeBoxCrypto.decrypt(userEntity.id, secret) ``` -------------------------------- ### Migrate Data from EncryptedSharedPreferences to SafeBox Source: https://github.com/harrytmthy/safebox/blob/main/docs/MIGRATION.md Illustrates the data migration process from existing SharedPreferences (either encrypted or plain) to SafeBox. This is achieved using the SafeBoxMigrationHelper.migrate function with the source and destination SharedPreferences objects. ```kotlin SafeBoxMigrationHelper.migrate(from = encryptedPrefs, to = safeBox) ``` -------------------------------- ### Observe SafeBox State with Global Observer (Kotlin) Source: https://github.com/harrytmthy/safebox/blob/main/docs/OBSERVABILITY.md This snippet demonstrates how to register and unregister a global listener for SafeBox state changes and how to query the current state. It allows observing state transitions across different SafeBox instances. ```kotlin val listener = SafeBoxStateListener { state -> when (state) { SafeBoxState.STARTING -> onStart() SafeBoxState.IDLE -> onIdle() SafeBoxState.WRITING -> onWrite() } } SafeBoxGlobalStateObserver.addListener(PREF_FILE_NAME, listener) // later SafeBoxGlobalStateObserver.removeListener(PREF_FILE_NAME, listener) ``` ```kotlin val state = SafeBoxGlobalStateObserver.getCurrentState(PREF_FILE_NAME) ``` -------------------------------- ### Set Library Version in Gradle Build File Source: https://github.com/harrytmthy/safebox/blob/main/CONTRIBUTING.md Updates the `version` property in the Safebox module's `build.gradle.kts` file to match the new library release version. ```kotlin version = "1.2.0-alpha01" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.