cleaner handling of verification state
This commit is contained in:
@@ -71,7 +71,6 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private byte[] mFingerprint;
|
private byte[] mFingerprint;
|
||||||
private LayoutInflater mInflater;
|
|
||||||
|
|
||||||
private AsyncTask mInProgress;
|
private AsyncTask mInProgress;
|
||||||
|
|
||||||
@@ -106,9 +105,9 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
mFingerprint = args.getByteArray(ARG_FINGERPRINT);
|
mFingerprint = args.getByteArray(ARG_FINGERPRINT);
|
||||||
|
|
||||||
mContext = getActivity();
|
mContext = getActivity();
|
||||||
mInflater = getLayoutInflater(savedInstanceState);
|
|
||||||
|
|
||||||
getLoaderManager().initLoader(LOADER_ID_LINKED_ID, null, this);
|
getLoaderManager().initLoader(LOADER_ID_LINKED_ID, null, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -169,22 +168,7 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
private void loadIdentity(RawLinkedIdentity linkedId, int certStatus) {
|
private void loadIdentity(RawLinkedIdentity linkedId, int certStatus) {
|
||||||
mLinkedId = linkedId;
|
mLinkedId = linkedId;
|
||||||
|
|
||||||
new Handler().post(new Runnable() {
|
setShowVerifying(false);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
getFragmentManager().popBackStack("verification",
|
|
||||||
FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mViewHolder.setShowVerifying(false);
|
|
||||||
|
|
||||||
{
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putParcelable(CertListWidget.ARG_URI, mDataUri);
|
|
||||||
args.putInt(CertListWidget.ARG_RANK, mLidRank);
|
|
||||||
getLoaderManager().initLoader(CertListWidget.LOADER_ID_LINKED_CERTS,
|
|
||||||
args, mViewHolder.vLinkedCerts);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mLinkedId instanceof LinkedIdentity) {
|
if (mLinkedId instanceof LinkedIdentity) {
|
||||||
LinkedResource res = ((LinkedIdentity) mLinkedId).mResource;
|
LinkedResource res = ((LinkedIdentity) mLinkedId).mResource;
|
||||||
@@ -281,17 +265,6 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
vText = (TextView) root.findViewById(R.id.linked_cert_text);
|
vText = (TextView) root.findViewById(R.id.linked_cert_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setShowVerifying(boolean show) {
|
|
||||||
int child = show ? 1 : 0;
|
|
||||||
if (vVerifyingContainer.getDisplayedChild() != child) {
|
|
||||||
vVerifyingContainer.setDisplayedChild(child);
|
|
||||||
}
|
|
||||||
if (!show) {
|
|
||||||
vKeySpinner.setVisibility(View.GONE);
|
|
||||||
showButton(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setShowProgress(boolean show) {
|
void setShowProgress(boolean show) {
|
||||||
vProgress.setDisplayedChild(show ? 0 : 1);
|
vProgress.setDisplayedChild(show ? 0 : 1);
|
||||||
}
|
}
|
||||||
@@ -305,6 +278,58 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean mVerificationState = false;
|
||||||
|
/** Switches between the 'verifying' ui bit and certificate status. This method
|
||||||
|
* must behave correctly in all states, showing or hiding the appropriate views
|
||||||
|
* and cancelling pending operations where necessary.
|
||||||
|
*
|
||||||
|
* This method also handles back button functionality in combination with
|
||||||
|
* onBackStateChanged.
|
||||||
|
*/
|
||||||
|
void setShowVerifying(boolean show) {
|
||||||
|
if (!show) {
|
||||||
|
if (mInProgress != null) {
|
||||||
|
mInProgress.cancel(false);
|
||||||
|
mInProgress = null;
|
||||||
|
}
|
||||||
|
getFragmentManager().removeOnBackStackChangedListener(this);
|
||||||
|
new Handler().post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
getFragmentManager().popBackStack("verification",
|
||||||
|
FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!mVerificationState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mVerificationState = false;
|
||||||
|
|
||||||
|
mViewHolder.showButton(0);
|
||||||
|
mViewHolder.vKeySpinner.setVisibility(View.GONE);
|
||||||
|
mViewHolder.vVerifyingContainer.setDisplayedChild(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mVerificationState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mVerificationState = true;
|
||||||
|
|
||||||
|
FragmentManager manager = getFragmentManager();
|
||||||
|
manager.beginTransaction().addToBackStack("verification").commit();
|
||||||
|
manager.executePendingTransactions();
|
||||||
|
manager.addOnBackStackChangedListener(this);
|
||||||
|
mViewHolder.vVerifyingContainer.setDisplayedChild(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackStackChanged() {
|
||||||
|
setShowVerifying(false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
|
||||||
View root = inflater.inflate(R.layout.linked_id_view_fragment, null);
|
View root = inflater.inflate(R.layout.linked_id_view_fragment, null);
|
||||||
@@ -339,22 +364,25 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable(CertListWidget.ARG_URI, mDataUri);
|
||||||
|
args.putInt(CertListWidget.ARG_RANK, mLidRank);
|
||||||
|
getLoaderManager().initLoader(CertListWidget.LOADER_ID_LINKED_CERTS,
|
||||||
|
args, mViewHolder.vLinkedCerts);
|
||||||
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyResource() {
|
void verifyResource() {
|
||||||
|
|
||||||
// only one at a time
|
// only one at a time (no sync needed, mInProgress is only touched in ui thread)
|
||||||
if (mInProgress != null) {
|
if (mInProgress != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FragmentManager manager = getFragmentManager();
|
setShowVerifying(true);
|
||||||
manager.beginTransaction().addToBackStack("verification").commit();
|
|
||||||
manager.executePendingTransactions();
|
|
||||||
manager.addOnBackStackChangedListener(this);
|
|
||||||
|
|
||||||
mViewHolder.setShowVerifying(true);
|
|
||||||
|
|
||||||
mViewHolder.vKeySpinner.setVisibility(View.GONE);
|
mViewHolder.vKeySpinner.setVisibility(View.GONE);
|
||||||
mViewHolder.setShowProgress(true);
|
mViewHolder.setShowProgress(true);
|
||||||
@@ -427,16 +455,6 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackStackChanged() {
|
|
||||||
mViewHolder.setShowVerifying(false);
|
|
||||||
getFragmentManager().removeOnBackStackChangedListener(LinkedIdViewFragment.this);
|
|
||||||
if (mInProgress != null) {
|
|
||||||
mInProgress.cancel(false);
|
|
||||||
mInProgress = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
|
|||||||
@@ -113,7 +113,8 @@
|
|||||||
android:id="@+id/back_button"
|
android:id="@+id/back_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/ic_arrow_back_white_24dp"
|
android:src="@drawable/ic_chevron_left_grey_24dp"
|
||||||
|
android:visibility="gone"
|
||||||
style="?android:attr/borderlessButtonStyle" />
|
style="?android:attr/borderlessButtonStyle" />
|
||||||
|
|
||||||
<Space
|
<Space
|
||||||
|
|||||||
Reference in New Issue
Block a user