/*
 * Copyright (c) 2015, the IRMA Team
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 *  Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 *  Neither the name of the IRMA project nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.irmacard.cardemu.disclosuredialog;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.irmacard.cardemu.CredentialManager;
import org.irmacard.cardemu.R;
import org.irmacard.api.common.AttributeDisjunction;
import org.irmacard.credentials.info.AttributeIdentifier;

public class DisjunctionFragment extends Fragment {
	AttributeDisjunction disjunction;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		this.disjunction = (AttributeDisjunction) getArguments().getSerializable("disjunction");
		LinearLayout list = (LinearLayout) inflater.inflate(R.layout.disjunction_fragment, container, false);

		TextView title = (TextView) list.findViewById(R.id.disjunction_title);
		title.setText(disjunction.getLabel());
		if (CredentialManager.getCandidates(disjunction).isEmpty()) {
			title.setTextColor(getResources().getColor(R.color.irmared));
		}

		LinearLayout content = (LinearLayout) list.findViewById(R.id.disjunction_content);
		for (AttributeIdentifier ai : disjunction) {
			View view = inflater.inflate(R.layout.disjunction_item, container, false);

			String text = ai.getIssuerName() + " - " + ai.getCredentialName();
			if (ai.isCredential())
				text += " (possession of credential)";
			else {
				text += " - " + ai.getAttributeName();
				if (disjunction.hasValues())
					text += ": " + disjunction.getValues().get(ai);
			}

			((TextView) view.findViewById(R.id.disjunction_title)).setText(text);

			if (!CredentialManager.getCandidates(disjunction).containsKey(ai)) {
				ImageView image = (ImageView) view.findViewById(R.id.disjunction_icon);
				image.setImageResource(R.drawable.irma_icon_missing_064px);
			}

			content.addView(view);
		}

		return list;
	}
}

@@ -1989,16 +1989,145 @@
 nction;%0A
+import org.irmacard.cardemu.identifiers.IdemixAttributeIdentifier;%0Aimport org.irmacard.cardemu.identifiers.IdemixIdentifierList;%0A
 import o
@@ -2177,16 +2177,49 @@
 ifier;%0A%0A
+import java.util.LinkedHashMap;%0A%0A
 public c
@@ -2600,24 +2600,241 @@
 ner, false);
+%0A%09%09LinkedHashMap%3CIdemixAttributeIdentifier, String%3E candidates = CredentialManager.getCandidates(disjunction);%0A%09%09IdemixIdentifierList%3CAttributeIdentifier%3E identifiers = new IdemixIdentifierList%3C%3E(candidates.keySet());
 %0A%0A%09%09TextView
@@ -2947,52 +2947,18 @@
 if (
-CredentialManager.getCandidates(disjunction)
+candidates
 .isE
@@ -3617,69 +3617,34 @@
 if (
-!Cre
+i
 denti
-alManager.getCandidates(disjunction)
+fiers
 .co
+u
 nt
-ainsKey(ai)
+(ai) == 0
 ) %7B%0A

Fix presence icon in disclosure info activity