extract UpdatedKeys access from KeychainProvider into KeyMetadataDao
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package org.sufficientlysecure.keychain.model;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.squareup.sqldelight.ColumnAdapter;
|
||||
|
||||
|
||||
public final class CustomColumnAdapters {
|
||||
|
||||
private CustomColumnAdapters() { }
|
||||
|
||||
static final ColumnAdapter<Date,Long> DATE_ADAPTER = new ColumnAdapter<Date,Long>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Date decode(Long databaseValue) {
|
||||
// Both SQLite and OpenPGP prefer a second granularity for timestamps - so we'll translate here
|
||||
return new Date(databaseValue * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long encode(@NonNull Date value) {
|
||||
return value.getTime() / 1000;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.sufficientlysecure.keychain.model;
|
||||
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import org.sufficientlysecure.keychain.KeyMetadataModel;
|
||||
|
||||
|
||||
@AutoValue
|
||||
public abstract class KeyMetadata implements KeyMetadataModel {
|
||||
public static final Factory<KeyMetadata> FACTORY = new Factory<>(
|
||||
AutoValue_KeyMetadata::new, CustomColumnAdapters.DATE_ADAPTER);
|
||||
|
||||
public boolean hasBeenUpdated() {
|
||||
return last_updated() != null;
|
||||
}
|
||||
|
||||
public boolean isPublished() {
|
||||
if (last_updated() == null) {
|
||||
throw new IllegalStateException("Cannot get publication state if key has never been updated!");
|
||||
}
|
||||
Boolean seenOnKeyservers = seen_on_keyservers();
|
||||
return seenOnKeyservers != null && seenOnKeyservers;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user