From 9a54c425f6d96e1872899eabf78fb60082a8d234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 29 Apr 2015 18:21:03 +0200 Subject: Functional. --- .../se/leap/bitmaskclient/ConfigurationWizard.java | 3 +- .../main/java/se/leap/bitmaskclient/Dashboard.java | 7 +++-- .../java/se/leap/bitmaskclient/EipFragment.java | 12 ++++---- .../bitmaskclient/ProviderAPIResultReceiver.java | 3 +- .../userstatus/UserSessionFragment.java | 35 +++++++++++++++------- app/src/main/res/layout/fragment_user_session.xml | 3 +- .../se/leap/bitmaskclient/ConfigurationWizard.java | 3 +- 7 files changed, 41 insertions(+), 25 deletions(-) (limited to 'app') diff --git a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java index 4a75b49c..2505d37b 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -165,8 +165,7 @@ public class ConfigurationWizard extends Activity } private void setUpProviderAPIResultReceiver() { - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); - providerAPI_result_receiver.setReceiver(this); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this); providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update(); IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_PROGRESSBAR); diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index a854ffd4..f87c9f94 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -82,8 +82,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec User.init(); ProviderAPICommand.initialize(this); - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); - providerAPI_result_receiver.setReceiver(this); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this); restoreProvider(savedInstanceState); if (!provider.isConfigured()) @@ -199,7 +198,11 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec ButterKnife.inject(this); provider_name.setText(provider.getDomain()); + user_session_fragment = new UserSessionFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(Provider.ALLOW_REGISTRATION, provider.allowsRegistration()); + user_session_fragment.setArguments(bundle); fragment_manager.replace(R.id.user_session_fragment, user_session_fragment, UserSessionFragment.TAG); if (provider.hasEIP()) { diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 4d1eb4bf..5a7b2ced 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -45,7 +45,7 @@ public class EipFragment extends Fragment implements Observer { Button main_button; private static Dashboard dashboard; - private static EIPReceiver provider_api_receiver; + private static EIPReceiver eip_receiver; private static EipStatus eip_status; private boolean wants_to_connect; @@ -53,7 +53,9 @@ public class EipFragment extends Fragment implements Observer { super.onAttach(activity); dashboard = (Dashboard) activity; - if(provider_api_receiver != null) + ProviderAPIResultReceiver provider_api_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); + + if(eip_receiver != null) ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_EIP_SERVICE, provider_api_receiver); } @@ -62,7 +64,7 @@ public class EipFragment extends Fragment implements Observer { super.onCreate(savedInstanceState); eip_status = EipStatus.getInstance(); eip_status.addObserver(this); - provider_api_receiver = new EIPReceiver(new Handler()); + eip_receiver = new EIPReceiver(new Handler()); } @Override @@ -220,7 +222,7 @@ public class EipFragment extends Fragment implements Observer { // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); vpn_intent.setAction(action); - vpn_intent.putExtra(Constants.RECEIVER_TAG, provider_api_receiver); + vpn_intent.putExtra(Constants.RECEIVER_TAG, eip_receiver); dashboard.startService(vpn_intent); } @@ -336,6 +338,6 @@ public class EipFragment extends Fragment implements Observer { public static EIPReceiver getReceiver() { - return provider_api_receiver; + return eip_receiver; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java index 533e5caf..9b880f89 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java @@ -26,8 +26,9 @@ import android.os.*; public class ProviderAPIResultReceiver extends ResultReceiver { private Receiver mReceiver; - public ProviderAPIResultReceiver(Handler handler) { + public ProviderAPIResultReceiver(Handler handler, Receiver receiver) { super(handler); + setReceiver(receiver); // TODO Auto-generated constructor stub } diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java index 02b9fbeb..dc334c3d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java @@ -15,8 +15,6 @@ import se.leap.bitmaskclient.eip.EipStatus; public class UserSessionFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface { - private static View view; - public static String TAG = UserSessionFragment.class.getSimpleName(); private static Dashboard dashboard; private ProviderAPIResultReceiver providerAPI_result_receiver; @@ -37,8 +35,6 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi user_session_status = UserSessionStatus.getInstance(getResources()); user_session_status.addObserver(this); - - handleNewUserSessionStatus(user_session_status); } @Override @@ -52,7 +48,15 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_user_session, container, false); + + View view = inflater.inflate(R.layout.fragment_user_session, container, false); + ButterKnife.inject(this, view); + + Bundle arguments = getArguments(); + allows_registration = arguments.getBoolean(Provider.ALLOW_REGISTRATION); + handleNewUserSessionStatus(user_session_status); + + return view; } @Override @@ -69,8 +73,7 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi super.onAttach(activity); dashboard = (Dashboard) activity; - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); - providerAPI_result_receiver.setReceiver(dashboard); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); } public void restoreSessionStatus(Bundle savedInstanceState) { @@ -106,7 +109,7 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi showUserSessionProgressBar(); else hideUserSessionProgressBar(); - changeSessionStatusMessage(); + changeMessage(); updateButton(); } } @@ -129,7 +132,7 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi }); } - private void changeSessionStatusMessage() { + private void changeMessage() { final String message = user_session_status.toString(); dashboard.runOnUiThread(new Runnable() { @Override @@ -141,9 +144,19 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi private void updateButton() { if(User.loggedIn()) - main_button.setText(getString(R.string.logout_button)); + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + main_button.setText(dashboard.getString(R.string.logout_button)); + } + }); else if(allows_registration) - main_button.setText(getString(R.string.login_button)); + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + main_button.setText(dashboard.getString(R.string.login_button)); + } + }); } diff --git a/app/src/main/res/layout/fragment_user_session.xml b/app/src/main/res/layout/fragment_user_session.xml index 2abd6f22..0d2a1840 100644 --- a/app/src/main/res/layout/fragment_user_session.xml +++ b/app/src/main/res/layout/fragment_user_session.xml @@ -13,8 +13,7 @@ android:id="@+id/user_session_status_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:indeterminate="true" - android:visibility="gone"/> + android:indeterminate="true"/>