Updated AndroidX

This commit is contained in:
M66B
2021-12-15 21:33:14 +01:00
parent b99088d1ad
commit 5a5d3ee1a0
18 changed files with 613 additions and 95 deletions

View File

@@ -248,18 +248,16 @@ class SQLiteCopyOpenHelper implements SupportSQLiteOpenHelper, DelegatingOpenHel
}
private SupportSQLiteOpenHelper createFrameworkOpenHelper(File databaseFile) {
String databaseName = databaseFile.getName();
int version;
final int version;
try {
version = DBUtil.readVersion(databaseFile);
} catch (IOException e) {
throw new RuntimeException("Malformed database file, unable to read version.", e);
}
FrameworkSQLiteOpenHelperFactory factory = new FrameworkSQLiteOpenHelperFactory();
Configuration configuration = Configuration.builder(mContext)
.name(databaseName)
.callback(new Callback(version) {
.name(databaseFile.getAbsolutePath())
.callback(new Callback(Math.max(version, 1)) {
@Override
public void onCreate(@NonNull SupportSQLiteDatabase db) {
}
@@ -268,6 +266,18 @@ class SQLiteCopyOpenHelper implements SupportSQLiteOpenHelper, DelegatingOpenHel
public void onUpgrade(@NonNull SupportSQLiteDatabase db, int oldVersion,
int newVersion) {
}
@Override
public void onOpen(@NonNull SupportSQLiteDatabase db) {
// If pre-packaged database has a version < 1 we will open it as if it was
// version 1 because the framework open helper does not allow version < 1.
// The database will be considered as newly created and onCreate() will be
// invoked, but we do nothing and reset the version back so Room later runs
// migrations as usual.
if (version < 1) {
db.setVersion(version);
}
}
})
.build();
return factory.create(configuration);