better state management in LinkedIdView, move confirm progress into card

This commit is contained in:
Vincent Breitmoser 2015-03-10 19:02:51 +01:00
parent f58ab3e439
commit 8d71a3fa92
2 changed files with 79 additions and 50 deletions

View File

@ -47,6 +47,7 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
import org.sufficientlysecure.keychain.ui.linked.LinkedIdViewFragment.ViewHolder.VerifyState;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
import org.sufficientlysecure.keychain.ui.widget.CertListWidget; import org.sufficientlysecure.keychain.ui.widget.CertListWidget;
@ -242,7 +243,6 @@ public class LinkedIdViewFragment extends Fragment implements
private final View vButtonBack; private final View vButtonBack;
private final ViewAnimator vProgress; private final ViewAnimator vProgress;
private final ImageView vIcon;
private final TextView vText; private final TextView vText;
ViewHolder(View root) { ViewHolder(View root) {
@ -261,12 +261,41 @@ public class LinkedIdViewFragment extends Fragment implements
vVerifyingContainer = (ViewAnimator) root.findViewById(R.id.linked_verify_container); vVerifyingContainer = (ViewAnimator) root.findViewById(R.id.linked_verify_container);
vProgress = (ViewAnimator) root.findViewById(R.id.linked_cert_progress); vProgress = (ViewAnimator) root.findViewById(R.id.linked_cert_progress);
vIcon = (ImageView) root.findViewById(R.id.linked_cert_icon);
vText = (TextView) root.findViewById(R.id.linked_cert_text); vText = (TextView) root.findViewById(R.id.linked_cert_text);
} }
void setShowProgress(boolean show) { enum VerifyState {
vProgress.setDisplayedChild(show ? 0 : 1); VERIFYING, VERIFY_OK, VERIFY_ERROR, CERTIFYING
}
void setVerifyingState(VerifyState state) {
switch (state) {
case VERIFYING:
vProgress.setDisplayedChild(0);
vText.setText("Verifying…");
vKeySpinner.setVisibility(View.GONE);
break;
case VERIFY_OK:
showButton(2);
vText.setText("Ok");
vProgress.setDisplayedChild(1);
vKeySpinner.setVisibility(View.VISIBLE);
break;
case VERIFY_ERROR:
showButton(1);
vProgress.setDisplayedChild(2);
vText.setText("Error");
vKeySpinner.setVisibility(View.GONE);
break;
case CERTIFYING:
vProgress.setDisplayedChild(0);
vText.setText("Confirming…");
vKeySpinner.setVisibility(View.GONE);
break;
}
} }
void showButton(int which) { void showButton(int which) {
@ -384,8 +413,7 @@ public class LinkedIdViewFragment extends Fragment implements
setShowVerifying(true); setShowVerifying(true);
mViewHolder.vKeySpinner.setVisibility(View.GONE); mViewHolder.vKeySpinner.setVisibility(View.GONE);
mViewHolder.setShowProgress(true); mViewHolder.setVerifyingState(VerifyState.VERIFYING);
mViewHolder.vText.setText("Verifying…");
mInProgress = new AsyncTask<Void,Void,LinkedVerifyResult>() { mInProgress = new AsyncTask<Void,Void,LinkedVerifyResult>() {
@Override @Override
@ -406,16 +434,13 @@ public class LinkedIdViewFragment extends Fragment implements
@Override @Override
protected void onPostExecute(LinkedVerifyResult result) { protected void onPostExecute(LinkedVerifyResult result) {
mViewHolder.setShowProgress(false);
if (isCancelled()) { if (isCancelled()) {
return; return;
} }
if (result.success()) { if (result.success()) {
mViewHolder.vText.setText("Ok"); mViewHolder.setVerifyingState(VerifyState.VERIFY_OK);
setupForConfirmation();
} else { } else {
mViewHolder.showButton(1); mViewHolder.setVerifyingState(VerifyState.VERIFY_ERROR);
mViewHolder.vText.setText("Error");
} }
mInProgress = null; mInProgress = null;
} }
@ -423,15 +448,6 @@ public class LinkedIdViewFragment extends Fragment implements
} }
void setupForConfirmation() {
// button is 'confirm'
mViewHolder.showButton(2);
mViewHolder.vKeySpinner.setVisibility(View.VISIBLE);
}
private void initiateCertifying() { private void initiateCertifying() {
// get the user's passphrase for this key (if required) // get the user's passphrase for this key (if required)
String passphrase; String passphrase;
@ -478,6 +494,8 @@ public class LinkedIdViewFragment extends Fragment implements
private void certifyResource(long certifyKeyId, String passphrase) { private void certifyResource(long certifyKeyId, String passphrase) {
mViewHolder.setVerifyingState(VerifyState.CERTIFYING);
Bundle data = new Bundle(); Bundle data = new Bundle();
{ {
@ -502,16 +520,24 @@ public class LinkedIdViewFragment extends Fragment implements
intent.putExtra(KeychainIntentService.EXTRA_DATA, data); intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
// Message is received after signing is done in KeychainIntentService // Message is received after signing is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(), KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity()) {
getString(R.string.progress_certifying), ProgressDialog.STYLE_SPINNER, false) {
public void handleMessage(Message message) { public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first // handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message); super.handleMessage(message);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
Bundle data = message.getData(); Bundle data = message.getData();
CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_UPDATE_PROGRESS) {
if (data.containsKey(DATA_MESSAGE)) {
mViewHolder.vText.setText(data.getString(DATA_MESSAGE));
} else if (data.containsKey(DATA_MESSAGE_ID)) {
mViewHolder.vText.setText(data.getString(DATA_MESSAGE_ID));
}
return;
}
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
result.createNotify(getActivity()).show(); result.createNotify(getActivity()).show();
} }
} }
@ -521,9 +547,6 @@ public class LinkedIdViewFragment extends Fragment implements
Messenger messenger = new Messenger(saveHandler); Messenger messenger = new Messenger(saveHandler);
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(getActivity());
// start service with intent // start service with intent
getActivity().startService(intent); getActivity().startService(intent);

View File

@ -48,30 +48,11 @@
android:orientation="horizontal" android:orientation="horizontal"
android:singleLine="true"> android:singleLine="true">
<LinearLayout
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="0dip"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/linked_cert_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Verifying…"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<ViewAnimator <ViewAnimator
android:layout_width="22dp" android:layout_width="22dp"
android:layout_height="22dp" android:layout_height="22dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="8dp"
android:layout_gravity="center" android:layout_gravity="center"
android:id="@+id/linked_cert_progress" android:id="@+id/linked_cert_progress"
android:inAnimation="@anim/fade_in" android:inAnimation="@anim/fade_in"
@ -86,11 +67,36 @@
<ImageView <ImageView
android:layout_width="22dp" android:layout_width="22dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/status_signature_unknown_cutout_24dp" android:src="@drawable/status_signature_verified_cutout_24dp"
android:id="@+id/linked_cert_icon"
/> />
<ImageView
android:layout_width="22dp"
android:layout_height="wrap_content"
android:src="@drawable/status_signature_unknown_cutout_24dp"
/>
</ViewAnimator> </ViewAnimator>
<LinearLayout
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="0dip"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/linked_cert_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Verifying…"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</ViewAnimator> </ViewAnimator>