From 9e7693c112a7c85cae998ae538643cda9660ff7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 27 Jun 2013 20:29:33 +0200 Subject: Coded new fragment appearance Domain, name and description come from provider.json Next step: code buttons to login or to use anonymously. --- src/se/leap/leapclient/ProviderDetailFragment.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/se/leap/leapclient/ProviderDetailFragment.java (limited to 'src/se/leap/leapclient/ProviderDetailFragment.java') diff --git a/src/se/leap/leapclient/ProviderDetailFragment.java b/src/se/leap/leapclient/ProviderDetailFragment.java new file mode 100644 index 0000000..d061a70 --- /dev/null +++ b/src/se/leap/leapclient/ProviderDetailFragment.java @@ -0,0 +1,54 @@ +package se.leap.leapclient; + +import org.json.JSONException; +import org.json.JSONObject; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +public class ProviderDetailFragment extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + try { + + LayoutInflater inflater = getActivity().getLayoutInflater(); + View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null); + + JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(ConfigHelper.PROVIDER_KEY); + + final TextView domain = (TextView)provider_detail_view.findViewById(R.id.provider_detail_domain); + domain.setText(provider_json.getString(ConfigHelper.DOMAIN)); + final TextView name = (TextView)provider_detail_view.findViewById(R.id.provider_detail_name); + name.setText(provider_json.getJSONObject(ConfigHelper.NAME).getString("en")); + final TextView description = (TextView)provider_detail_view.findViewById(R.id.provider_detail_description); + description.setText(provider_json.getJSONObject(ConfigHelper.DESCRIPTION).getString("en")); + + 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) { + } + }); + builder.setNegativeButton(R.string.login_button, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + } + }); + + return builder.create(); + } catch (JSONException e) { + return null; + } + } + + public static DialogFragment newInstance() { + ProviderDetailFragment provider_detail_fragment = new ProviderDetailFragment(); + return provider_detail_fragment; + } +} -- cgit v1.2.3 From 36b3b30960bb7c07d3ca4c3a748334627ecb8003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 27 Jun 2013 21:23:49 +0200 Subject: Use anonymously from ProviderDetail works OK. Tested with dev.bitmask.net, I use the previously downloaded certificate (I should not do that, I'll file an issue because I should download it once the user has requested to do so). Next step: login button from ProviderDetailFragment. --- src/se/leap/leapclient/ProviderDetailFragment.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/se/leap/leapclient/ProviderDetailFragment.java') diff --git a/src/se/leap/leapclient/ProviderDetailFragment.java b/src/se/leap/leapclient/ProviderDetailFragment.java index d061a70..6121ac7 100644 --- a/src/se/leap/leapclient/ProviderDetailFragment.java +++ b/src/se/leap/leapclient/ProviderDetailFragment.java @@ -3,6 +3,9 @@ package se.leap.leapclient; import org.json.JSONException; import org.json.JSONObject; +import se.leap.leapclient.LogInDialog.LogInDialogInterface; + +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; @@ -34,10 +37,12 @@ public class ProviderDetailFragment extends DialogFragment { 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(); } }); @@ -51,4 +56,22 @@ public class ProviderDetailFragment extends DialogFragment { ProviderDetailFragment provider_detail_fragment = new ProviderDetailFragment(); return provider_detail_fragment; } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + interface_with_configuration_wizard = (ProviderDetailFragmentInterface) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement LogInDialogListener"); + } + } + + public interface ProviderDetailFragmentInterface { + public void login(); + public void use_anonymously(); + } + + ProviderDetailFragmentInterface interface_with_configuration_wizard; } -- cgit v1.2.3 From 74f95b56051c5c313febdc59f14e0e9077935817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 27 Jun 2013 21:56:37 +0200 Subject: Removed unnecessary toasts. They are commented, just in case we decide to include any of them before releasing 0.2.0. --- src/se/leap/leapclient/ProviderDetailFragment.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/se/leap/leapclient/ProviderDetailFragment.java') diff --git a/src/se/leap/leapclient/ProviderDetailFragment.java b/src/se/leap/leapclient/ProviderDetailFragment.java index 6121ac7..ebd1139 100644 --- a/src/se/leap/leapclient/ProviderDetailFragment.java +++ b/src/se/leap/leapclient/ProviderDetailFragment.java @@ -3,8 +3,6 @@ package se.leap.leapclient; import org.json.JSONException; import org.json.JSONObject; -import se.leap.leapclient.LogInDialog.LogInDialogInterface; - import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -- cgit v1.2.3 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/se/leap/leapclient/ProviderDetailFragment.java') 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(); -- cgit v1.2.3