use CryptoOperationFragment for linked id fragments, and some warning cleanup

This commit is contained in:
Vincent Breitmoser 2015-04-24 15:44:33 +02:00
parent b4aec3114d
commit b12aa63cb3
6 changed files with 38 additions and 80 deletions

View File

@ -88,7 +88,9 @@ public class CertifyKeyFragment extends CryptoOperationFragment
};
private static final int INDEX_MASTER_KEY_ID = 1;
private static final int INDEX_USER_ID = 2;
@SuppressWarnings("unused")
private static final int INDEX_IS_PRIMARY = 3;
@SuppressWarnings("unused")
private static final int INDEX_IS_REVOKED = 4;
private MultiUserIdsAdapter mUserIdsAdapter;

View File

@ -312,10 +312,10 @@ public class ViewKeyActivity extends BaseNfcActivity implements
.replace(R.id.view_key_fragment, frag)
.commit();
manager.popBackStack();
} else {
} /* else {
// not sure yet if we actually want this!
// manager.popBackStack();
}
manager.popBackStack();
} */
}
});

View File

@ -1,6 +1,5 @@
package org.sufficientlysecure.keychain.ui.linked;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.PorterDuff;
@ -8,7 +7,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@ -28,14 +26,11 @@ import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment.ServiceType;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Passphrase;
public abstract class LinkedIdCreateFinalFragment extends Fragment {
protected static final int REQUEST_CODE_PASSPHRASE = 0x00007008;
public abstract class LinkedIdCreateFinalFragment extends CryptoOperationFragment {
protected LinkedIdWizard mLinkedIdWizard;
@ -63,7 +58,7 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startCertify();
cryptoOperation();
}
});
@ -174,29 +169,28 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
}
private void startCertify() {
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
if (mVerifiedResource == null) {
Notify.create(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR).show();
return;
}
Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mLinkedIdWizard.mMasterKeyId);
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
}
private void certifyLinkedIdentity (CryptoInputParcel cryptoInput) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_saving),
ProgressDialog.STYLE_HORIZONTAL,
true, ServiceType.KEYCHAIN_INTENT) {
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
// handle pending messages
if (handlePendingMessage(message)) {
return;
}
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
// get returned data bundle
@ -252,20 +246,4 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_PASSPHRASE:
if (resultCode == Activity.RESULT_OK && data != null) {
CryptoInputParcel cryptoInput =
data.getParcelableExtra(PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
certifyLinkedIdentity(cryptoInput);
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
}

View File

@ -4,7 +4,6 @@ import java.io.IOException;
import java.util.Collections;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
@ -16,7 +15,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v4.app.LoaderManager;
@ -45,12 +43,11 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.linked.LinkedIdViewFragment.ViewHolder.VerifyState;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
@ -60,14 +57,11 @@ import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker;
import org.sufficientlysecure.keychain.ui.widget.CertListWidget;
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
public class LinkedIdViewFragment extends Fragment implements
public class LinkedIdViewFragment extends CryptoOperationFragment implements
LoaderManager.LoaderCallbacks<Cursor>, OnBackStackChangedListener {
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
private static final String ARG_DATA_URI = "data_uri";
private static final String ARG_LID_RANK = "rank";
private static final String ARG_IS_SECRET = "verified";
@ -512,44 +506,20 @@ public class LinkedIdViewFragment extends Fragment implements
return;
}
Passphrase passphrase;
try {
passphrase = PassphraseCacheService.getCachedPassphrase(
getActivity(), mCertifyKeyId, mCertifyKeyId);
} catch (PassphraseCacheService.KeyNotFoundException e) {
Log.e(Constants.TAG, "Key not found!", e);
getActivity().finish();
return;
}
if (passphrase == null) {
Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mCertifyKeyId);
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
// bail out; need to wait until the user has entered the passphrase before trying again
} else {
certifyResource(new CryptoInputParcel());
}
cryptoOperation();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_PASSPHRASE: {
if (resultCode == Activity.RESULT_OK && data != null) {
CryptoInputParcel cryptoInput = data.getParcelableExtra(
PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
certifyResource(cryptoInput);
}
return;
}
protected void onCryptoOperationCancelled() {
super.onCryptoOperationCancelled();
// go back to 'verified ok'
setShowVerifying(false);
default: {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
private void certifyResource(CryptoInputParcel cryptoInput) {
@Override
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
if (mIsSecret) {
return;
@ -588,9 +558,13 @@ public class LinkedIdViewFragment extends Fragment implements
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
Bundle data = message.getData();
// handle pending messages
if (handlePendingMessage(message)) {
return;
}
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
Bundle data = message.getData();
CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
result.createNotify(getActivity()).show();
// no need to do anything else, we will get a loader refresh!

View File

@ -1,7 +1,8 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
@ -48,6 +49,8 @@
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
@ -84,7 +87,7 @@
android:drawablePadding="3dp"
android:clickable="true"
android:textColor="@color/tertiary_text_light"
android:text="%d more unknown identity types"
android:text="@string/linked_ids_more_unknown"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:background="?android:selectableItemBackground" />

View File

@ -1370,5 +1370,6 @@
<string name="linked_text_verifying">Verifying…</string>
<string name="linked_text_error">Error</string>
<string name="linked_text_confirming">Confirming…</string>
<string name="linked_ids_more_unknown">%d more unknown identity types</string>
</resources>