extract UpdatedKeys access from KeychainProvider into KeyMetadataDao
This commit is contained in:
@@ -43,7 +43,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
||||
import org.sufficientlysecure.keychain.provider.LastUpdateInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.KeyMetadataDao;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.AddEditKeyserverDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
@@ -63,7 +63,7 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
|
||||
private List<HkpKeyserverAddress> mKeyservers;
|
||||
private KeyserverListAdapter mAdapter;
|
||||
|
||||
private LastUpdateInteractor lastUpdateInteractor;
|
||||
private KeyMetadataDao keyMetadataDao;
|
||||
|
||||
public static SettingsKeyserverFragment newInstance(ArrayList<HkpKeyserverAddress> keyservers) {
|
||||
Bundle args = new Bundle();
|
||||
@@ -78,7 +78,7 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
|
||||
savedInstanceState) {
|
||||
lastUpdateInteractor = LastUpdateInteractor.create(getContext());
|
||||
keyMetadataDao = KeyMetadataDao.create(getContext());
|
||||
|
||||
return inflater.inflate(R.layout.settings_keyserver_fragment, null);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
|
||||
Preferences.getPreferences(getActivity()).setKeyServers(mKeyserversMutable);
|
||||
mKeyservers = Collections.unmodifiableList(new ArrayList<>(mKeyserversMutable));
|
||||
|
||||
lastUpdateInteractor.resetAllLastUpdatedTimes();
|
||||
keyMetadataDao.resetAllLastUpdatedTimes();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,10 +39,10 @@ import android.view.ViewGroup;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||
import org.sufficientlysecure.keychain.model.KeyMetadata;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.ui.base.LoaderFragment;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityDao.IdentityInfo;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusDao.KeyserverStatus;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.SubkeyStatusDao.KeySubkeyStatus;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.SystemContactDao.SystemContactInfo;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.presenter.IdentitiesPresenter;
|
||||
@@ -108,7 +108,7 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView, O
|
||||
private LiveData<List<IdentityInfo>> identityInfo;
|
||||
private LiveData<KeySubkeyStatus> subkeyStatus;
|
||||
private LiveData<SystemContactInfo> systemContactInfo;
|
||||
private LiveData<KeyserverStatus> keyserverStatus;
|
||||
private LiveData<KeyMetadata> keyserverStatus;
|
||||
|
||||
LiveData<List<IdentityInfo>> getIdentityInfo(IdentitiesPresenter identitiesPresenter) {
|
||||
if (identityInfo == null) {
|
||||
@@ -131,7 +131,7 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView, O
|
||||
return systemContactInfo;
|
||||
}
|
||||
|
||||
LiveData<KeyserverStatus> getKeyserverStatus(KeyserverStatusPresenter keyserverStatusPresenter) {
|
||||
LiveData<KeyMetadata> getKeyserverStatus(KeyserverStatusPresenter keyserverStatusPresenter) {
|
||||
if (keyserverStatus == null) {
|
||||
keyserverStatus = keyserverStatusPresenter.getLiveDataInstance();
|
||||
}
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Schürmann & Breitmoser GbR
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.keyview.loader;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class KeyserverStatusDao {
|
||||
public static final String[] PROJECTION = new String[] {
|
||||
UpdatedKeys.LAST_UPDATED,
|
||||
UpdatedKeys.SEEN_ON_KEYSERVERS
|
||||
};
|
||||
private static final int INDEX_LAST_UPDATED = 0;
|
||||
private static final int INDEX_SEEN_ON_KEYSERVERS = 1;
|
||||
|
||||
|
||||
private final ContentResolver contentResolver;
|
||||
|
||||
public static KeyserverStatusDao getInstance(Context context) {
|
||||
ContentResolver contentResolver = context.getContentResolver();
|
||||
return new KeyserverStatusDao(contentResolver);
|
||||
}
|
||||
|
||||
private KeyserverStatusDao(ContentResolver contentResolver) {
|
||||
this.contentResolver = contentResolver;
|
||||
}
|
||||
|
||||
public KeyserverStatus getKeyserverStatus(long masterKeyId) {
|
||||
Cursor cursor = contentResolver.query(UpdatedKeys.CONTENT_URI, PROJECTION,
|
||||
Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID + " = ?", new String[] { Long.toString(masterKeyId) }, null);
|
||||
if (cursor == null) {
|
||||
Timber.e("Error loading key items!");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (cursor.moveToFirst()) {
|
||||
if (cursor.isNull(INDEX_SEEN_ON_KEYSERVERS) || cursor.isNull(INDEX_LAST_UPDATED)) {
|
||||
return new KeyserverStatus(masterKeyId);
|
||||
}
|
||||
|
||||
boolean isPublished = cursor.getInt(INDEX_SEEN_ON_KEYSERVERS) != 0;
|
||||
Date lastUpdated = new Date(cursor.getLong(INDEX_LAST_UPDATED) * 1000);
|
||||
|
||||
return new KeyserverStatus(masterKeyId, isPublished, lastUpdated);
|
||||
}
|
||||
|
||||
return new KeyserverStatus(masterKeyId);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static class KeyserverStatus {
|
||||
private final long masterKeyId;
|
||||
private final boolean isPublished;
|
||||
private final Date lastUpdated;
|
||||
|
||||
KeyserverStatus(long masterKeyId, boolean isPublished, Date lastUpdated) {
|
||||
this.masterKeyId = masterKeyId;
|
||||
this.isPublished = isPublished;
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
KeyserverStatus(long masterKeyId) {
|
||||
this.masterKeyId = masterKeyId;
|
||||
this.isPublished = false;
|
||||
this.lastUpdated = null;
|
||||
}
|
||||
|
||||
long getMasterKeyId() {
|
||||
return masterKeyId;
|
||||
}
|
||||
|
||||
public boolean hasBeenUpdated() {
|
||||
return lastUpdated != null;
|
||||
}
|
||||
|
||||
public boolean isPublished() {
|
||||
if (lastUpdated == null) {
|
||||
throw new IllegalStateException("Cannot get publication state if key has never been updated!");
|
||||
}
|
||||
return isPublished;
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,10 @@ import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.sufficientlysecure.keychain.model.KeyMetadata;
|
||||
import org.sufficientlysecure.keychain.provider.KeyMetadataDao;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityDao.IdentityInfo;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusDao.KeyserverStatus;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.SubkeyStatusDao.KeySubkeyStatus;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.SubkeyStatusDao.SubKeyItem;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.SystemContactDao.SystemContactInfo;
|
||||
@@ -78,21 +79,21 @@ public class ViewKeyLiveData {
|
||||
}
|
||||
}
|
||||
|
||||
public static class KeyserverStatusLiveData extends AsyncTaskLiveData<KeyserverStatus> {
|
||||
private final KeyserverStatusDao keyserverStatusDao;
|
||||
public static class KeyserverStatusLiveData extends AsyncTaskLiveData<KeyMetadata> {
|
||||
private final KeyMetadataDao keyMetadataDao;
|
||||
|
||||
private final long masterKeyId;
|
||||
|
||||
public KeyserverStatusLiveData(Context context, long masterKeyId) {
|
||||
super(context, KeyRings.buildGenericKeyRingUri(masterKeyId));
|
||||
|
||||
this.keyserverStatusDao = KeyserverStatusDao.getInstance(context);
|
||||
this.keyMetadataDao = KeyMetadataDao.create(context);
|
||||
this.masterKeyId = masterKeyId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyserverStatus asyncLoadData() {
|
||||
return keyserverStatusDao.getKeyserverStatus(masterKeyId);
|
||||
public KeyMetadata asyncLoadData() {
|
||||
return keyMetadataDao.getKeyMetadata(masterKeyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ import android.arch.lifecycle.Observer;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusDao.KeyserverStatus;
|
||||
import org.sufficientlysecure.keychain.model.KeyMetadata;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.loader.ViewKeyLiveData.KeyserverStatusLiveData;
|
||||
|
||||
|
||||
public class KeyserverStatusPresenter implements Observer<KeyserverStatus> {
|
||||
public class KeyserverStatusPresenter implements Observer<KeyMetadata> {
|
||||
private final Context context;
|
||||
private final KeyserverStatusMvpView view;
|
||||
|
||||
@@ -46,12 +46,12 @@ public class KeyserverStatusPresenter implements Observer<KeyserverStatus> {
|
||||
this.isSecret = isSecret;
|
||||
}
|
||||
|
||||
public LiveData<KeyserverStatus> getLiveDataInstance() {
|
||||
public LiveData<KeyMetadata> getLiveDataInstance() {
|
||||
return new KeyserverStatusLiveData(context, masterKeyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nullable KeyserverStatus keyserverStatus) {
|
||||
public void onChanged(@Nullable KeyMetadata keyserverStatus) {
|
||||
if (keyserverStatus == null) {
|
||||
view.setDisplayStatusUnknown();
|
||||
return;
|
||||
@@ -63,7 +63,7 @@ public class KeyserverStatusPresenter implements Observer<KeyserverStatus> {
|
||||
} else {
|
||||
view.setDisplayStatusNotPublished();
|
||||
}
|
||||
view.setLastUpdated(keyserverStatus.getLastUpdated());
|
||||
view.setLastUpdated(keyserverStatus.last_updated());
|
||||
} else {
|
||||
view.setDisplayStatusUnknown();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user