use notification uris mostly correctly
This commit is contained in:
@@ -4,14 +4,25 @@ package org.sufficientlysecure.keychain.livedata;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseNotifyManager;
|
||||
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);
|
||||
public GenericLiveData(Context context, GenericDataLoader<T> genericDataLoader) {
|
||||
super(context, null);
|
||||
this.genericDataLoader = genericDataLoader;
|
||||
}
|
||||
|
||||
public GenericLiveData(Context context, Uri notifyUri, GenericDataLoader<T> genericDataLoader) {
|
||||
super(context, notifyUri);
|
||||
this.genericDataLoader = genericDataLoader;
|
||||
}
|
||||
|
||||
public GenericLiveData(Context context, long notifyMasterKeyId, GenericDataLoader<T> genericDataLoader) {
|
||||
super(context, DatabaseNotifyManager.getNotifyUriMasterKeyId(notifyMasterKeyId));
|
||||
this.genericDataLoader = genericDataLoader;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public class RemoteDeduplicateActivity extends FragmentActivity {
|
||||
|
||||
public LiveData<List<UnifiedKeyInfo>> getKeyInfoLiveData(Context context) {
|
||||
if (keyInfoLiveData == null) {
|
||||
keyInfoLiveData = new GenericLiveData<>(context, null, () -> {
|
||||
keyInfoLiveData = new GenericLiveData<>(context, () -> {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
return keyRepository.getUnifiedKeyInfosByMailAddress(duplicateAddress);
|
||||
});
|
||||
|
||||
@@ -106,7 +106,7 @@ public class RemoteSelectAuthenticationKeyActivity extends FragmentActivity {
|
||||
|
||||
public LiveData<List<UnifiedKeyInfo>> getKeyInfoLiveData(Context context) {
|
||||
if (keyInfoLiveData == null) {
|
||||
keyInfoLiveData = new GenericLiveData<>(context, null, () -> {
|
||||
keyInfoLiveData = new GenericLiveData<>(context, () -> {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
return keyRepository.getAllUnifiedKeyInfoWithSecret();
|
||||
});
|
||||
|
||||
@@ -135,7 +135,7 @@ public class RemoteSelectIdKeyActivity extends FragmentActivity {
|
||||
public LiveData<List<UnifiedKeyInfo>> getSecretUnifiedKeyInfo(Context context) {
|
||||
if (keyInfo == null) {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
keyInfo = new GenericLiveData<>(context, null, keyRepository::getAllUnifiedKeyInfoWithSecret);
|
||||
keyInfo = new GenericLiveData<>(context, keyRepository::getAllUnifiedKeyInfoWithSecret);
|
||||
}
|
||||
return keyInfo;
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public abstract class DecryptFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
unifiedKeyInfoLiveData = new GenericLiveData<>(requireContext(), null, () -> {
|
||||
unifiedKeyInfoLiveData = new GenericLiveData<>(requireContext(), () -> {
|
||||
KeyRepository keyRepository = KeyRepository.create(requireContext());
|
||||
Long masterKeyId = keyRepository.getMasterKeyIdBySubkeyId(mSignatureResult.getKeyId());
|
||||
return keyRepository.getUnifiedKeyInfo(masterKeyId);
|
||||
|
||||
@@ -155,7 +155,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
||||
|
||||
LiveData<List<UnifiedKeyInfo>> getSignKeyLiveData(Context context) {
|
||||
if (signKeyLiveData == null) {
|
||||
signKeyLiveData = new GenericLiveData<>(context, null, () -> {
|
||||
signKeyLiveData = new GenericLiveData<>(context, () -> {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
return keyRepository.getAllUnifiedKeyInfoWithSecret();
|
||||
});
|
||||
@@ -165,7 +165,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
||||
|
||||
LiveData<List<Chip>> getEncryptRecipientLiveData(Context context) {
|
||||
if (encryptRecipientLiveData == null) {
|
||||
encryptRecipientLiveData = new GenericLiveData<>(context, null, () -> {
|
||||
encryptRecipientLiveData = new GenericLiveData<>(context, () -> {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
List<UnifiedKeyInfo> keyInfos = keyRepository.getAllUnifiedKeyInfo();
|
||||
ArrayList<Chip> result = new ArrayList<>();
|
||||
|
||||
@@ -84,7 +84,7 @@ public class MultiUserIdsFragment extends Fragment {
|
||||
|
||||
KeyRepository keyRepository = KeyRepository.create(activity);
|
||||
LiveData<List<UserId>> userIdLiveData =
|
||||
new GenericLiveData<>(getContext(), null, () -> keyRepository.getUserIds(pubMasterKeyIds));
|
||||
new GenericLiveData<>(getContext(), () -> keyRepository.getUserIds(pubMasterKeyIds));
|
||||
userIdLiveData.observe(this, this::onUserIdsLoaded);
|
||||
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements OnPageChangeList
|
||||
}
|
||||
if (unifiedKeyInfoLiveData == null) {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
unifiedKeyInfoLiveData = new GenericLiveData<>(context, null,
|
||||
unifiedKeyInfoLiveData = new GenericLiveData<>(context, masterKeyId,
|
||||
() -> keyRepository.getUnifiedKeyInfo(masterKeyId));
|
||||
}
|
||||
return unifiedKeyInfoLiveData;
|
||||
@@ -137,7 +137,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements OnPageChangeList
|
||||
if (subKeyLiveData == null) {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
subKeyLiveData = Transformations.switchMap(getUnifiedKeyInfoLiveData(context),
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context, null,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context,
|
||||
() -> keyRepository.getSubKeysByMasterKeyId(unifiedKeyInfo.master_key_id())));
|
||||
}
|
||||
return subKeyLiveData;
|
||||
@@ -147,7 +147,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements OnPageChangeList
|
||||
if (userIdsLiveData == null) {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
userIdsLiveData = Transformations.switchMap(getUnifiedKeyInfoLiveData(context),
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context, null,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context,
|
||||
() -> keyRepository.getUserIds(unifiedKeyInfo.master_key_id())));
|
||||
}
|
||||
return userIdsLiveData;
|
||||
|
||||
@@ -292,7 +292,7 @@ public class ViewKeyAdvShareFragment extends Fragment {
|
||||
unifiedKeyInfoLiveData.observe(this, this::onLoadUnifiedKeyInfo);
|
||||
|
||||
LiveData<Bitmap> qrCodeLiveData = Transformations.switchMap(unifiedKeyInfoLiveData,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(getContext(), null,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(getContext(),
|
||||
() -> {
|
||||
String fingerprintHex = KeyFormattingUtils.convertFingerprintToHex(unifiedKeyInfo.fingerprint());
|
||||
Uri uri = new Uri.Builder().scheme(Constants.FINGERPRINT_SCHEME).opaquePart(fingerprintHex).build();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class KeyFragmentViewModel extends ViewModel {
|
||||
if (identityInfo == null) {
|
||||
IdentityDao identityDao = IdentityDao.getInstance(context);
|
||||
identityInfo = Transformations.switchMap(unifiedKeyInfoLiveData,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context, null,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context,
|
||||
() -> identityDao.getIdentityInfos(unifiedKeyInfo.master_key_id(), showLinkedIds)));
|
||||
}
|
||||
return identityInfo;
|
||||
@@ -41,7 +41,7 @@ public class KeyFragmentViewModel extends ViewModel {
|
||||
if (subkeyStatus == null) {
|
||||
SubkeyStatusDao subkeyStatusDao = SubkeyStatusDao.getInstance(context);
|
||||
subkeyStatus = Transformations.switchMap(unifiedKeyInfoLiveData,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context, null,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context,
|
||||
() -> subkeyStatusDao.getSubkeyStatus(unifiedKeyInfo.master_key_id())));
|
||||
}
|
||||
return subkeyStatus;
|
||||
@@ -51,7 +51,7 @@ public class KeyFragmentViewModel extends ViewModel {
|
||||
if (systemContactInfo == null) {
|
||||
SystemContactDao systemContactDao = SystemContactDao.getInstance(context);
|
||||
systemContactInfo = Transformations.switchMap(unifiedKeyInfoLiveData,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context, null,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context,
|
||||
() -> systemContactDao.getSystemContactInfo(unifiedKeyInfo.master_key_id(),
|
||||
unifiedKeyInfo.has_any_secret())));
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class KeyFragmentViewModel extends ViewModel {
|
||||
if (keyserverStatus == null) {
|
||||
KeyMetadataDao keyMetadataDao = KeyMetadataDao.create(context);
|
||||
keyserverStatus = Transformations.switchMap(unifiedKeyInfoLiveData,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context, null,
|
||||
(unifiedKeyInfo) -> new GenericLiveData<>(context,
|
||||
() -> keyMetadataDao.getKeyMetadata(unifiedKeyInfo.master_key_id())));
|
||||
}
|
||||
return keyserverStatus;
|
||||
|
||||
@@ -497,7 +497,7 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements OnB
|
||||
|
||||
LiveData<List<UnifiedKeyInfo>> getCertifyingKeys(Context context) {
|
||||
if (certifyingKeysLiveData == null) {
|
||||
certifyingKeysLiveData = new GenericLiveData<>(context, null, () -> {
|
||||
certifyingKeysLiveData = new GenericLiveData<>(context, () -> {
|
||||
KeyRepository keyRepository = KeyRepository.create(context);
|
||||
return keyRepository.getAllUnifiedKeyInfoWithSecret();
|
||||
});
|
||||
@@ -508,7 +508,7 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements OnB
|
||||
LiveData<CertDetails> getCertDetails(Context context, long masterKeyId, int lidRank) {
|
||||
if (certDetailsLiveData == null) {
|
||||
CertificationDao certificationDao = CertificationDao.getInstance(context);
|
||||
certDetailsLiveData = new GenericLiveData<>(context, null,
|
||||
certDetailsLiveData = new GenericLiveData<>(context, masterKeyId,
|
||||
() -> certificationDao.getVerifyingCertDetails(masterKeyId, lidRank));
|
||||
}
|
||||
return certDetailsLiveData;
|
||||
@@ -517,7 +517,7 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements OnB
|
||||
public LiveData<LinkedIdInfo> getLinkedIdInfo(Context context, long masterKeyId, int lidRank) {
|
||||
if (linkedIfInfoLiveData == null) {
|
||||
IdentityDao identityDao = IdentityDao.getInstance(context);
|
||||
linkedIfInfoLiveData = new GenericLiveData<>(context, null,
|
||||
linkedIfInfoLiveData = new GenericLiveData<>(context, masterKeyId,
|
||||
() -> identityDao.getLinkedIdInfo(masterKeyId, lidRank));
|
||||
}
|
||||
return linkedIfInfoLiveData;
|
||||
|
||||
Reference in New Issue
Block a user