Skip to content

Commit 286c46b

Browse files
author
mat-in
committed
WIP: local changes before rebase
1 parent 44ac259 commit 286c46b

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

docs/MIGRATION.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ to your `putString().commit()` or `getInt()` usage.
77

88
## What changes?
99

10-
### Setup
10+
### Dagger Setup Example
1111

12-
If you're using **Dagger**, you only need to change this:
12+
If you're using **Dagger**:
1313

1414
```kotlin
1515
@Singleton
@@ -29,7 +29,7 @@ fun provideEncryptedSharedPreferences(context: Context): SharedPreferences {
2929
}
3030
```
3131

32-
to this (SafeBox):
32+
### To this (SafeBox):
3333

3434
```kotlin
3535
@Singleton
@@ -38,30 +38,48 @@ fun provideEncryptedSharedPreferences(context: Context): SharedPreferences =
3838
SafeBox.create(context, PREF_FILE_NAME)
3939
```
4040

41-
Or if you're using **Koin**:
41+
No changes to the rest of your code.
42+
43+
### Koin Setup Example
44+
45+
If you're using **Koin**, the migration is just as seamless:
4246

4347
```kotlin
4448
single<SharedPreferences> {
4549
SafeBox.create(androidContext(), PREF_FILE_NAME)
4650
}
4751
```
4852

49-
### Existing Data Migration
53+
## Using Singleton Access (Optional)
5054

51-
If your app already stores data in `EncryptedSharedPreferences` or even plain `SharedPreferences`, you can migrate them into SafeBox with one line:
55+
For apps that prefer a **singleton-style instance**, SafeBox provides `SafeBoxProvider`, which can be initialized once and accessed anywhere.
56+
57+
### Initialization (in `Application` class)
5258

5359
```kotlin
54-
SafeBoxMigrationHelper.migrate(from = encryptedPrefs, to = safeBox)
60+
class MyApp : Application() {
61+
override fun onCreate() {
62+
super.onCreate()
63+
64+
SafeBoxProvider.init(
65+
context = this,
66+
fileName = PREF_FILE_NAME
67+
)
68+
}
69+
}
5570
```
5671

57-
✅ This helper is available in version 1.1.0-alpha01:
72+
### Usage (Anywhere in your app)
5873

5974
```kotlin
60-
dependencies {
61-
implementation("io.github.harrytmthy-dev:safebox:1.1.0-alpha01")
62-
}
75+
val prefs = SafeBoxProvider.get()
76+
val name = prefs.getString("name", null)
6377
```
6478

79+
> You can still call `SafeBox.create(...)` directly if you prefer not to use a singleton.
80+
81+
---
82+
6583
## Still unsure?
6684

6785
- SafeBox is open-source and MIT licensed

safebox/src/main/java/com/harrytmthy/safebox/SafeBox.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,6 @@ public class SafeBox private constructor(
328328
*/
329329
@JvmOverloads
330330
@JvmStatic
331-
@Deprecated(
332-
message = "Use SafeBoxProvider.init(...) and SafeBoxProvider.get() instead.",
333-
replaceWith = ReplaceWith("SafeBoxProvider.get()"),
334-
)
335331
public fun create(
336332
context: Context,
337333
fileName: String,
@@ -372,10 +368,6 @@ public class SafeBox private constructor(
372368
*/
373369
@JvmOverloads
374370
@JvmStatic
375-
@Deprecated(
376-
message = "Use SafeBoxProvider.init(...) and SafeBoxProvider.get() instead.",
377-
replaceWith = ReplaceWith("SafeBoxProvider.get()"),
378-
)
379371
public fun create(
380372
context: Context,
381373
fileName: String,

0 commit comments

Comments
 (0)