diff options
author | Parménides GV <parmegv@sdf.org> | 2013-06-29 11:48:15 +0200 |
---|---|---|
committer | Sean Leonard <meanderingcode@aetherislands.net> | 2013-07-12 11:38:45 -0600 |
commit | dd9f4b8f26debbbea034d00db85fe123cab5619d (patch) | |
tree | 2a0e101acc60fd7836c88305c1a46d1d07e50f6d /src | |
parent | 74f95b56051c5c313febdc59f14e0e9077935817 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/se/leap/leapclient/ProviderDetailFragment.java | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/src/se/leap/leapclient/ProviderDetailFragment.java b/src/se/leap/leapclient/ProviderDetailFragment.java index ebd1139..3b6cf83 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();
|