Skip to content

Commit 3ef0563

Browse files
committed
Merge branch 'experimental/shift_to_room_db'
refactor: Migrate caching from SharedPreferences to Room This commit refactors the application's caching mechanism, replacing `SharedPreferences` with a local Room database to improve performance and data management. **Key Changes:** - **Added Room Dependencies**: Integrated `room.runtime` and `room.compiler` to enable local database functionality. - **Replaced `SharedPreferenceManager`**: The existing `SharedPreferenceManager` has been completely rewritten to use a Room database with a key-value table as its backend, while maintaining the original public API for compatibility. - **Implemented Migration Logic**: - Added a `migrateFromOldPrefs()` method to transfer existing cached data from `SharedPreferences` to the new Room database upon app launch. - Implemented `clearOldPrefsAsync()` to remove the old SharedPreferences file after a successful migration. - **Updated Settings**: The "Clear Cache" option in settings now calls `clearOldPrefsAsync()` to clear the database. - **Bumped App Version**: Incremented the app version to `1.0.12`.
2 parents 8496a7a + f68a347 commit 3ef0563

13 files changed

Lines changed: 346 additions & 36 deletions

app/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId "com.harsh.shah.saavnmp3"
1212
minSdk 23
1313
targetSdk 36
14-
versionCode 6
15-
versionName "1.0.12"
14+
versionCode 7
15+
versionName "1.0.13"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
//Universal APK Supporting All ABIs
@@ -146,4 +146,9 @@ dependencies {
146146

147147
// FOR TAGGING METADATA INTO MP3 FILES
148148
implementation libs.jaudiotagger
149+
150+
// LOCAL DATABASE FOR CACHING DATA
151+
implementation libs.room.runtime
152+
annotationProcessor libs.room.compiler
153+
149154
}
10.2 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": 3,
3+
"artifactType": {
4+
"type": "APK",
5+
"kind": "Directory"
6+
},
7+
"applicationId": "com.harsh.shah.saavnmp3",
8+
"variantName": "nofirebaseRelease",
9+
"elements": [
10+
{
11+
"type": "SINGLE",
12+
"filters": [],
13+
"attributes": [],
14+
"versionCode": 7,
15+
"versionName": "1.0.13",
16+
"outputFile": "Melotune-1.0.13-nofirebaseRelease.apk"
17+
}
18+
],
19+
"elementType": "File",
20+
"baselineProfiles": [
21+
{
22+
"minApi": 28,
23+
"maxApi": 30,
24+
"baselineProfiles": [
25+
"baselineProfiles/1/Melotune-1.0.13-nofirebaseRelease.dm"
26+
]
27+
},
28+
{
29+
"minApi": 31,
30+
"maxApi": 2147483647,
31+
"baselineProfiles": [
32+
"baselineProfiles/0/Melotune-1.0.13-nofirebaseRelease.dm"
33+
]
34+
}
35+
],
36+
"minSdkVersionForDexing": 23
37+
}
11.8 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": 3,
3+
"artifactType": {
4+
"type": "APK",
5+
"kind": "Directory"
6+
},
7+
"applicationId": "com.harsh.shah.saavnmp3",
8+
"variantName": "prodRelease",
9+
"elements": [
10+
{
11+
"type": "SINGLE",
12+
"filters": [],
13+
"attributes": [],
14+
"versionCode": 7,
15+
"versionName": "1.0.13",
16+
"outputFile": "Melotune-1.0.13-prodRelease.apk"
17+
}
18+
],
19+
"elementType": "File",
20+
"baselineProfiles": [
21+
{
22+
"minApi": 28,
23+
"maxApi": 30,
24+
"baselineProfiles": [
25+
"baselineProfiles/1/Melotune-1.0.13-prodRelease.dm"
26+
]
27+
},
28+
{
29+
"minApi": 31,
30+
"maxApi": 2147483647,
31+
"baselineProfiles": [
32+
"baselineProfiles/0/Melotune-1.0.13-prodRelease.dm"
33+
]
34+
}
35+
],
36+
"minSdkVersionForDexing": 23
37+
}

app/src/main/java/com/harsh/shah/saavnmp3/BaseApplicationClass.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ public void onSkipToPrevious() {
227227
createNotificationChannel();
228228
sharedPreferenceManager = SharedPreferenceManager.getInstance(this);
229229
TRACK_QUALITY = sharedPreferenceManager.getTrackQuality();
230+
231+
sharedPreferenceManager.migrateFromOldPrefs(this, () -> sharedPreferenceManager.clearOldPrefsAsync(this, null));
230232
}
231233

232234
public static void updateTheme() {

0 commit comments

Comments
 (0)