diff options
author | Fup Duck <fupduck@sacknagel.com> | 2018-01-09 14:02:57 +0100 |
---|---|---|
committer | Fup Duck <fupduck@sacknagel.com> | 2018-01-09 14:02:57 +0100 |
commit | 3addd20598f7fee2d41a24d64b375a2f63874457 (patch) | |
tree | c6127e66e2b0c6857a38879dc935a1196727a9f7 /app | |
parent | bc9c6ef38348af8719358aa7d8426439519bc7f1 (diff) |
create ProviderDetail Activity
Diffstat (limited to 'app')
14 files changed, 282 insertions, 294 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java index d0b8cf6f..956049dc 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java @@ -84,7 +84,7 @@ public abstract class BaseTestDashboardFragment extends ActivityInstrumentationT } private void waitForProviderDetails() { - String text = solo.getString(R.string.provider_details_fragment_title); + String text = solo.getString(R.string.provider_details_title); assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000)); Screenshot.take("Provider details"); } diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java index b224ecd3..c0d3aab1 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java @@ -7,7 +7,6 @@ import com.robotium.solo.Solo; import java.io.IOException; -import se.leap.bitmaskclient.fragments.AboutFragment; import se.leap.bitmaskclient.ConfigurationWizard; import se.leap.bitmaskclient.R; @@ -71,7 +70,7 @@ public class TestConfigurationWizard extends ActivityInstrumentationTestCase2<Co } private void waitForProviderDetails() { - String text = solo.getString(R.string.provider_details_fragment_title); + String text = solo.getString(R.string.provider_details_title); assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000)); Screenshot.take("Provider details"); } diff --git a/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java b/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java index 4b7edb58..d7d9eec5 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java @@ -16,11 +16,12 @@ */ package se.leap.bitmaskclient; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; @@ -37,33 +38,35 @@ import se.leap.bitmaskclient.ProviderListContent.ProviderItem; * * @author parmegv */ -public class NewProviderDialog extends DialogFragment{ +public class NewProviderDialog extends DialogFragment { final public static String TAG = "newProviderDialog"; @InjectView(R.id.new_provider_url) EditText url_input_field; + @InjectView(R.id.danger_checkbox) CheckBox danger_checkbox; public interface NewProviderDialogInterface { - public void showAndSelectProvider(String url_provider, boolean danger_on); + void showAndSelectProvider(String url_provider, boolean danger_on); } NewProviderDialogInterface interface_with_ConfigurationWizard; @Override - public void onAttach(Activity activity) { - super.onAttach(activity); + public void onAttach(Context context) { + super.onAttach(context); try { - interface_with_ConfigurationWizard = (NewProviderDialogInterface) activity; + interface_with_ConfigurationWizard = (NewProviderDialogInterface) context; } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + throw new ClassCastException(context.toString() + " must implement NoticeDialogListener"); } } @Override + @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); @@ -107,7 +110,6 @@ public class NewProviderDialog extends DialogFragment{ url_input_field.setText(""); danger_checkbox.setChecked(false); Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show(); - ; } } diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java new file mode 100644 index 00000000..c97daea6 --- /dev/null +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java @@ -0,0 +1,115 @@ +package se.leap.bitmaskclient; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + +import butterknife.ButterKnife; +import butterknife.InjectView; + +public class ProviderDetailActivity extends Activity { + + final public static String TAG = "providerDetailActivity"; + private SharedPreferences preferences; + + @InjectView(R.id.provider_detail_domain) + TextView domain; + + @InjectView(R.id.provider_detail_name) + TextView name; + + @InjectView(R.id.provider_detail_description) + TextView description; + + @InjectView(R.id.provider_detail_options) + ListView options; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.provider_detail_fragment); + ButterKnife.inject(this); + + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + try { + JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); + domain.setText(provider_json.getString(Provider.DOMAIN)); + name.setText(provider_json.getJSONObject(Provider.NAME).getString("en")); + description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en")); + + setTitle(R.string.provider_details_title); + + ArrayList<String> optionsList = new ArrayList<>(); + optionsList.add(getString(R.string.login_button)); + if (registration_allowed(provider_json)) { + optionsList.add(getString(R.string.signup_button)); + } + if (anon_allowed(provider_json)) { + optionsList.add(getString(R.string.use_anonymously_button)); + } + + options.setAdapter(new ArrayAdapter<>( + this, + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + optionsList.toArray(new String[optionsList.size()]) + )); + options.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + String text = ((TextView) view).getText().toString(); + if (text.equals(getString(R.string.login_button))) { + Log.d(TAG, "login selected"); + } else if (text.equals(getString(R.string.signup_button))) { + Log.d(TAG, "signup selected"); + } else if (text.equals(getString(R.string.use_anonymously_button))) { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + } + }); + } catch (JSONException e) { + // TODO show error and return + } + } + + private boolean anon_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); + } catch (JSONException e) { + return false; + } + } + + private boolean registration_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); + } catch (JSONException e) { + return false; + } + } + + @Override + public void onBackPressed() { + SharedPreferences.Editor editor = preferences.edit(); + editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply(); + super.onBackPressed(); + } + +} diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java deleted file mode 100644 index 8c61ecc8..00000000 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ /dev/null @@ -1,116 +0,0 @@ -package se.leap.bitmaskclient; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; - -import org.json.JSONException; -import org.json.JSONObject; - -import se.leap.bitmaskclient.ProviderListContent.ProviderItem; - -public class ProviderDetailFragment extends DialogFragment { - - final public static String TAG = "providerDetailFragment"; - - @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 = new JSONObject(getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); - - final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain); - domain.setText(provider_json.getString(Provider.DOMAIN)); - final TextView name = (TextView) provider_detail_view.findViewById(R.id.provider_detail_name); - name.setText(provider_json.getJSONObject(Provider.NAME).getString("en")); - final TextView description = (TextView) provider_detail_view.findViewById(R.id.provider_detail_description); - description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en")); - - builder.setView(provider_detail_view); - builder.setTitle(R.string.provider_details_fragment_title); - - 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.signup_or_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(Provider.SERVICE); - return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); - } catch (JSONException e) { - return false; - } - } - - private boolean registration_allowed(JSONObject provider_json) { - try { - JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); - } catch (JSONException e) { - return false; - } - } - - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).commit(); - interface_with_configuration_wizard.cancelAndShowAllProviders(); - } - - public static DialogFragment newInstance() { - 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(); - - public void cancelAndShowAllProviders(); - } - - ProviderDetailFragmentInterface interface_with_configuration_wizard; -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 43c31a88..8407d76d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -91,11 +91,11 @@ </activity> <activity android:name=".ConfigurationWizard" - android:label="@string/configuration_wizard_title" - android:uiOptions="splitActionBarWhenNarrow"></activity> + android:label="@string/configuration_wizard_title" /> + <activity - android:name=".fragments.AboutFragment" - android:label="@string/about_fragment_title"></activity> + android:name=".ProviderDetailActivity" + android:label="@string/provider_details_title" /> <service android:name=".eip.EIP" diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 9f12ed9a..601615b6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -70,7 +70,7 @@ import static android.view.View.VISIBLE; */ public abstract class BaseConfigurationWizard extends AppCompatActivity - implements NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, DownloadFailedDialog.DownloadFailedDialogInterface, ProviderAPIResultReceiver.Receiver { + implements NewProviderDialog.NewProviderDialogInterface, DownloadFailedDialog.DownloadFailedDialogInterface, ProviderAPIResultReceiver.Receiver { @InjectView(R.id.progressbar_configuration_wizard) protected ProgressBar mProgressBar; @InjectView(R.id.progressbar_description) @@ -150,22 +150,13 @@ public abstract class BaseConfigurationWizard extends AppCompatActivity private void restoreState(Bundle savedInstanceState) { progressbar_text = savedInstanceState.getString(PROGRESSBAR_TEXT, ""); selected_provider = savedInstanceState.getParcelable(Provider.KEY); - - if (fragment_manager.findFragmentByTag(ProviderDetailFragment.TAG) == null && - (SETTING_UP_PROVIDER.equals(mConfigState.getAction()) || - PENDING_SHOW_PROVIDER_DETAILS.equals(mConfigState.getAction()) || - PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction()) - )) { - onItemSelectedUi(); - } } @Override protected void onResume() { super.onResume(); if (SETTING_UP_PROVIDER.equals(mConfigState.getAction())) { - showProgressBar(); - adapter.hideAllBut(adapter.indexOf(selected_provider)); + cancelAndShowAllProviders(); } else if (PENDING_SHOW_PROVIDER_DETAILS.equals(mConfigState.getAction())) { showProviderDetails(); } else if (PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) { @@ -396,15 +387,9 @@ public abstract class BaseConfigurationWizard extends AppCompatActivity * */ public void showProviderDetails() { - try { - FragmentTransaction fragment_transaction = fragment_manager.removePreviousFragment(ProviderDetailFragment.TAG); - - DialogFragment newFragment = ProviderDetailFragment.newInstance(); - newFragment.show(fragment_transaction, ProviderDetailFragment.TAG); - } catch (IllegalStateException e) { - e.printStackTrace(); - mConfigState.setAction(PENDING_SHOW_PROVIDER_DETAILS); - } + Intent intent = new Intent(this, ProviderDetailActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); } @@ -428,32 +413,12 @@ public abstract class BaseConfigurationWizard extends AppCompatActivity } } - @Override public void cancelAndShowAllProviders() { mConfigState.setAction(PROVIDER_NOT_SET); selected_provider = null; adapter.showAllProviders(); } - @Override - public void login() { - mConfigState.setAction(PROVIDER_SET); - Intent ask_login = new Intent(); - ask_login.putExtra(Provider.KEY, selected_provider); - ask_login.putExtra(SessionDialog.TAG, SessionDialog.TAG); - setResult(RESULT_OK, ask_login); - finish(); - } - - @Override - public void use_anonymously() { - mConfigState.setAction(PROVIDER_SET); - Intent pass_provider = new Intent(); - pass_provider.putExtra(Provider.KEY, selected_provider); - setResult(RESULT_OK, pass_provider); - finish(); - } - public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/res/layout-xlarge/provider_detail_fragment.xml b/app/src/main/res/layout-xlarge/provider_detail_fragment.xml index 4abbaa17..860f99d9 100644 --- a/app/src/main/res/layout-xlarge/provider_detail_fragment.xml +++ b/app/src/main/res/layout-xlarge/provider_detail_fragment.xml @@ -40,4 +40,9 @@ android:textStyle="normal" android:textAppearance="?android:attr/textAppearanceSmall" /> + <ListView + android:id="@+id/provider_detail_options" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + </LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/provider_detail_fragment.xml b/app/src/main/res/layout/provider_detail_fragment.xml index 3b35bae7..3db32b2c 100644 --- a/app/src/main/res/layout/provider_detail_fragment.xml +++ b/app/src/main/res/layout/provider_detail_fragment.xml @@ -38,4 +38,9 @@ android:textStyle="normal" android:textAppearance="?android:attr/textAppearanceSmall" /> + <ListView + android:id="@+id/provider_detail_options" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + </LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 11fe31a1..6355ce62 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -25,7 +25,7 @@ <string name="new_provider_uri">Dominio</string> <string name="valid_url_entered">El dominio está bien formado</string> <string name="not_valid_url_entered">Dominio no válido</string> - <string name="provider_details_fragment_title">Detalles del proveedor</string> + <string name="provider_details_title">Detalles del proveedor</string> <string name="use_anonymously_button">Utilizar sin registrarse</string> <string name="username_hint">usuario</string> <string name="username_ask">Por favor, introduce tu usuario</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38e47f1d..22736245 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,7 +23,7 @@ <string name="new_provider_uri">Domain name</string> <string name="valid_url_entered">It seems your URL is well formed</string> <string name="not_valid_url_entered">It seems your URL is not well formed</string> - <string name="provider_details_fragment_title">Provider details</string> + <string name="provider_details_title">Provider details</string> <string name="use_anonymously_button">Use anonymously</string> <string name="username_hint">username</string> <string name="username_ask">Please enter your username</string> diff --git a/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java b/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java index 1823d3e3..fc7c9ede 100644 --- a/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java +++ b/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java @@ -16,14 +16,20 @@ */ package se.leap.bitmaskclient; -import butterknife.*; -import se.leap.bitmaskclient.ProviderListContent.ProviderItem; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; -import android.app.*; -import android.content.*; -import android.os.*; -import android.view.*; -import android.widget.*; +import butterknife.ButterKnife; +import butterknife.InjectView; /** * Implements the new custom provider dialog. @@ -38,23 +44,24 @@ public class NewProviderDialog extends DialogFragment { EditText url_input_field; public interface NewProviderDialogInterface { - public void showAndSelectProvider(String url_provider); + void showAndSelectProvider(String url_provider); } NewProviderDialogInterface interface_with_ConfigurationWizard; @Override - public void onAttach(Activity activity) { - super.onAttach(activity); + public void onAttach(Context context) { + super.onAttach(context); try { - interface_with_ConfigurationWizard = (NewProviderDialogInterface) activity; + interface_with_ConfigurationWizard = (NewProviderDialogInterface) context; } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + throw new ClassCastException(context.toString() + " must implement NoticeDialogListener"); } } @Override + @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); @@ -96,7 +103,6 @@ public class NewProviderDialog extends DialogFragment { } else { url_input_field.setText(""); Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show(); - ; } } diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java new file mode 100644 index 00000000..0c5b1957 --- /dev/null +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java @@ -0,0 +1,115 @@ +package se.leap.bitmaskclient; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + +import butterknife.ButterKnife; +import butterknife.InjectView; + +public class ProviderDetailActivity extends Activity { + + final public static String TAG = "providerDetailActivity"; + private SharedPreferences preferences; + + @InjectView(R.id.provider_detail_domain) + TextView domain; + + @InjectView(R.id.provider_detail_name) + TextView name; + + @InjectView(R.id.provider_detail_description) + TextView description; + + @InjectView(R.id.provider_detail_options) + ListView options; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.provider_detail_fragment); + ButterKnife.inject(this); + + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + try { + JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); + domain.setText(provider_json.getString(Provider.DOMAIN)); + name.setText(provider_json.getJSONObject(Provider.NAME).getString("en")); + description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en")); + + setTitle(R.string.provider_details_title); + + ArrayList<String> optionsList = new ArrayList<>(); + optionsList.add(getString(R.string.login_button)); + if (registration_allowed(provider_json)) { + optionsList.add(getString(R.string.signup_button)); + } + if (anon_allowed(provider_json)) { + optionsList.add(getString(R.string.use_anonymously_button)); + } + + options.setAdapter(new ArrayAdapter<>( + this, + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + optionsList.toArray(new String[optionsList.size()]) + )); + options.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + String text = ((TextView) view).getText().toString(); + if (text.equals(getString(R.string.login_button))) { + Log.d(TAG, "login selected"); + } else if (text.equals(getString(R.string.signup_button))) { + Log.d(TAG, "signup selected"); + } else if (text.equals(getString(R.string.use_anonymously_button))) { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + } + }); + } catch (JSONException e) { + // TODO show error and return + } + } + + private boolean anon_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); + } catch (JSONException e) { + return false; + } + } + + private boolean registration_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); + } catch (JSONException e) { + return false; + } + } + + @Override + public void onBackPressed() { + SharedPreferences.Editor editor = preferences.edit(); + editor.remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply(); + super.onBackPressed(); + } + +} diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java deleted file mode 100644 index c7224ede..00000000 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ /dev/null @@ -1,108 +0,0 @@ -package se.leap.bitmaskclient; - -import org.json.*; - -import android.app.*; -import android.content.*; -import android.os.*; -import android.view.*; -import android.widget.*; - -public class ProviderDetailFragment extends DialogFragment { - - final public static String TAG = "providerDetailFragment"; - - @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 = new JSONObject(getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); - - final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain); - domain.setText(provider_json.getString(Provider.DOMAIN)); - final TextView name = (TextView) provider_detail_view.findViewById(R.id.provider_detail_name); - name.setText(provider_json.getJSONObject(Provider.NAME).getString("en")); - final TextView description = (TextView) provider_detail_view.findViewById(R.id.provider_detail_description); - description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en")); - - builder.setView(provider_detail_view); - builder.setTitle(R.string.provider_details_fragment_title); - - 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.signup_or_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(Provider.SERVICE); - return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); - } catch (JSONException e) { - return false; - } - } - - private boolean registration_allowed(JSONObject provider_json) { - try { - JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); - } catch (JSONException e) { - return false; - } - } - - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).commit(); - interface_with_configuration_wizard.cancelAndShowAllProviders(); - } - - public static DialogFragment newInstance() { - 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(); - - public void cancelAndShowAllProviders(); - } - - ProviderDetailFragmentInterface interface_with_configuration_wizard; -} |