move loading of certs into CertificationDao
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package org.sufficientlysecure.keychain.livedata;
|
||||
|
||||
|
||||
import android.arch.persistence.db.SupportSQLiteDatabase;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
||||
import com.squareup.sqldelight.SqlDelightQuery;
|
||||
import org.sufficientlysecure.keychain.model.Certification;
|
||||
import org.sufficientlysecure.keychain.model.Certification.CertDetails;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseNotifyManager;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||
|
||||
|
||||
public class CertificationDao {
|
||||
private final SupportSQLiteDatabase db;
|
||||
private final DatabaseNotifyManager databaseNotifyManager;
|
||||
|
||||
public static CertificationDao getInstance(Context context) {
|
||||
KeychainDatabase keychainDatabase = new KeychainDatabase(context);
|
||||
DatabaseNotifyManager databaseNotifyManager = DatabaseNotifyManager.create(context);
|
||||
|
||||
return new CertificationDao(keychainDatabase.getWritableDatabase(), databaseNotifyManager);
|
||||
}
|
||||
|
||||
private CertificationDao(SupportSQLiteDatabase writableDatabase, DatabaseNotifyManager databaseNotifyManager) {
|
||||
this.db = writableDatabase;
|
||||
this.databaseNotifyManager = databaseNotifyManager;
|
||||
}
|
||||
|
||||
public CertDetails getVerifyingCertDetails(long masterKeyId, int userPacketRank) {
|
||||
SqlDelightQuery query = Certification.FACTORY.selectVerifyingCertDetails(masterKeyId, userPacketRank);
|
||||
try (Cursor cursor = db.query(query)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
return Certification.CERT_DETAILS_MAPPER.map(cursor);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.sufficientlysecure.keychain.livedata;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.AsyncTaskLiveData;
|
||||
|
||||
|
||||
public class GenericLiveData<T> extends AsyncTaskLiveData<T> {
|
||||
private GenericDataLoader<T> genericDataLoader;
|
||||
|
||||
public GenericLiveData(Context context, Uri uri, GenericDataLoader<T> genericDataLoader) {
|
||||
super(context, uri);
|
||||
this.genericDataLoader = genericDataLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T asyncLoadData() {
|
||||
return genericDataLoader.loadData();
|
||||
}
|
||||
|
||||
public interface GenericDataLoader<T> {
|
||||
T loadData();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user