From dd9f4b8f26debbbea034d00db85fe123cab5619d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Sat, 29 Jun 2013 11:48:15 +0200 Subject: JSONExceptions from ProviderDetail returns false. Buttons from this fragment are shown if the key is present and contains a "true" value, but if an exception occurs the button it's not showed. --- src/se/leap/leapclient/ProviderDetailFragment.java | 45 +++++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/se/leap/leapclient/ProviderDetailFragment.java b/src/se/leap/leapclient/ProviderDetailFragment.java index ebd11391..3b6cf83c 100644 --- a/src/se/leap/leapclient/ProviderDetailFragment.java +++ b/src/se/leap/leapclient/ProviderDetailFragment.java @@ -33,22 +33,47 @@ public class ProviderDetailFragment extends DialogFragment { builder.setView(provider_detail_view); builder.setTitle(R.string.provider_details_fragment_title); - builder.setPositiveButton(R.string.use_anonymously_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - interface_with_configuration_wizard.use_anonymously(); - } - }); - builder.setNegativeButton(R.string.login_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - interface_with_configuration_wizard.login(); - } - }); + + if(anon_allowed(provider_json)) { + builder.setPositiveButton(R.string.use_anonymously_button, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + interface_with_configuration_wizard.use_anonymously(); + } + }); + } + + if(registration_allowed(provider_json)) { + + builder.setNegativeButton(R.string.login_button, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + interface_with_configuration_wizard.login(); + } + }); + } return builder.create(); } catch (JSONException e) { return null; } } + + private boolean anon_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(ConfigHelper.SERVICE_KEY); + return service_description.has(ConfigHelper.ALLOWED_ANON) && service_description.getBoolean(ConfigHelper.ALLOWED_ANON); + } catch (JSONException e) { + return false; + } + } + + private boolean registration_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(ConfigHelper.SERVICE_KEY); + return service_description.has(ConfigHelper.ALLOW_REGISTRATION_KEY) && service_description.getBoolean(ConfigHelper.ALLOW_REGISTRATION_KEY); + } catch (JSONException e) { + return false; + } + } public static DialogFragment newInstance() { ProviderDetailFragment provider_detail_fragment = new ProviderDetailFragment(); -- cgit v1.2.3