@@ -7,9 +7,9 @@ to your `putString().commit()` or `getInt()` usage.
7
7
8
8
## What changes?
9
9
10
- ### Setup
10
+ ### Dagger Setup Example
11
11
12
- If you're using ** Dagger** , you only need to change this :
12
+ If you're using ** Dagger** :
13
13
14
14
``` kotlin
15
15
@Singleton
@@ -29,7 +29,7 @@ fun provideEncryptedSharedPreferences(context: Context): SharedPreferences {
29
29
}
30
30
```
31
31
32
- to this (SafeBox):
32
+ ### To this (SafeBox):
33
33
34
34
``` kotlin
35
35
@Singleton
@@ -38,30 +38,48 @@ fun provideEncryptedSharedPreferences(context: Context): SharedPreferences =
38
38
SafeBox .create(context, PREF_FILE_NAME )
39
39
```
40
40
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:
42
46
43
47
``` kotlin
44
48
single<SharedPreferences > {
45
49
SafeBox .create(androidContext(), PREF_FILE_NAME )
46
50
}
47
51
```
48
52
49
- ### Existing Data Migration
53
+ ## Using Singleton Access (Optional)
50
54
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)
52
58
53
59
``` 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
+ }
55
70
```
56
71
57
- ✅ This helper is available in version 1.1.0-alpha01:
72
+ ### Usage (Anywhere in your app)
58
73
59
74
``` 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 )
63
77
```
64
78
79
+ > You can still call ` SafeBox.create(...) ` directly if you prefer not to use a singleton.
80
+
81
+ ---
82
+
65
83
## Still unsure?
66
84
67
85
- SafeBox is open-source and MIT licensed
0 commit comments