Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORM: simplify SupportSQLiteOpenHelper and BriteDatabase provideDatabase #2017

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions app/src/main/java/com/money/manager/ex/core/ioc/DbModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import androidx.sqlite.db.SupportSQLiteOpenHelper;

// import com.money.manager.ex.sqlite3mc.SupportFactory;
import net.sqlcipher.database.SupportFactory;
import com.money.manager.ex.MmexApplication;
import com.money.manager.ex.database.MmxOpenHelper;
import com.squareup.sqlbrite3.BriteDatabase;
Expand Down Expand Up @@ -50,23 +48,18 @@ MmxOpenHelper provideOpenHelper(MmexApplication app) {
return app.openHelperAtomicReference.get();
}

@Provides SqlBrite provideSqlBrite() {
@Provides
SqlBrite provideSqlBrite() {
return new SqlBrite.Builder().logger(new SqlBrite.Logger() {
@Override public void log(String message) {
Timber.tag("Database").v(message);
}
}).build();
}

@Provides BriteDatabase provideDatabase(SqlBrite sqlBrite, MmxOpenHelper helper) {
SupportSQLiteOpenHelper.Factory factory = new SupportFactory(helper.getPassword().getBytes());
SupportSQLiteOpenHelper.Configuration configuration =
SupportSQLiteOpenHelper.Configuration.builder(helper.getContext())
.name(helper.getDbPath())
.callback(helper)
.build();
BriteDatabase db = sqlBrite.wrapDatabaseHelper(factory.create(configuration), Schedulers.io());
db.setLoggingEnabled(true);
return db;
@Provides
BriteDatabase provideDatabase(SqlBrite sqlBrite, MmxOpenHelper helper) {
SupportSQLiteOpenHelper supportHelper = helper.provideSupportSQLiteOpenHelper();
return sqlBrite.wrapDatabaseHelper(supportHelper, Schedulers.io());
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/money/manager/ex/database/MmxOpenHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ protected void finalize() throws Throwable {
super.finalize();
}

public SupportSQLiteOpenHelper provideSupportSQLiteOpenHelper() {
SupportSQLiteOpenHelper.Factory factory = new SupportFactory(this.mPassword.getBytes());
SupportSQLiteOpenHelper.Configuration configuration =
SupportSQLiteOpenHelper.Configuration.builder(mContext)
.name(this.dbPath)
.callback(this)
.build();

return factory.create(configuration);
}

public static void createDatabaseBackupOnUpgrade(String currentDbFile, long oldVersion) throws IOException {
File in = new File(currentDbFile);
String backupFileNameWithExtension = in.getName();
Expand Down
Loading