summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-09 18:57:35 +0100
committerParménides GV <parmegv@sdf.org>2014-12-09 18:57:35 +0100
commit062e4c4597f947816282b1c9c5e63c034549f057 (patch)
treef66170fd661f658beca3f941b6ee7b097bcd842d /app/src/main/java
parente980e1f888f29806ab0933495fdb0dd383c944e7 (diff)
Final refactoring for this bug.
Removed the sign up dialog, log in one is enough with the third button I added some time ago to sign up. Removed classes we don't need due to the libraries I have recently introduced.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java148
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java107
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java216
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SessionDialog.java (renamed from app/src/main/java/se/leap/bitmaskclient/LogInDialog.java)57
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SessionDialogInterface.java37
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java132
6 files changed, 147 insertions, 550 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index b84b834c..c7691ed4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -40,6 +40,8 @@ import org.json.JSONObject;
import java.net.MalformedURLException;
import java.net.URL;
+import butterknife.ButterKnife;
+import butterknife.InjectView;
import de.blinkt.openvpn.activities.LogWindow;
import se.leap.bitmaskclient.eip.Constants;
import se.leap.bitmaskclient.eip.EIP;
@@ -52,7 +54,7 @@ import se.leap.bitmaskclient.eip.EipStatus;
* @author Sean Leonard <meanderingcode@aetherislands.net>
* @author parmegv
*/
-public class Dashboard extends Activity implements LogInDialog.LogInDialogInterface, SignUpDialog.SignUpDialogInterface, ProviderAPIResultReceiver.Receiver {
+public class Dashboard extends Activity implements SessionDialog.LogInDialogInterface, ProviderAPIResultReceiver.Receiver {
protected static final int CONFIGURE_LEAP = 0;
protected static final int SWITCH_PROVIDER = 1;
@@ -70,12 +72,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
protected static SharedPreferences preferences;
private FragmentManagerEnhanced fragment_manager;
- private ProgressBar mProgressBar;
- private TextView status_message;
- public ProviderAPIResultReceiver providerAPI_result_receiver;
+ @InjectView(R.id.providerName)
+ TextView provider_name;
+ EipServiceFragment eip_fragment;
private Provider provider;
private static boolean authed_eip;
+ public ProviderAPIResultReceiver providerAPI_result_receiver;
@Override
protected void onSaveInstanceState(Bundle outState) {
@@ -91,8 +94,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
app = this;
PRNGFixes.apply();
-
- mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
@@ -157,7 +158,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
}
buildDashboard(false);
invalidateOptionsMenu();
- if (data.hasExtra(LogInDialog.TAG)) {
+ if (data.hasExtra(SessionDialog.TAG)) {
logInDialog(Bundle.EMPTY);
}
} else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) {
@@ -200,24 +201,21 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
* service dependent UI elements to include.
*/
private void buildDashboard(boolean hide_and_turn_on_eip) {
- setContentView(R.layout.client_dashboard);
-
- TextView providerNameTV = (TextView) findViewById(R.id.providerName);
- providerNameTV.setText(provider.getDomain());
- providerNameTV.setTextSize(28);
-
- mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
+ setContentView(R.layout.dashboard);
+ ButterKnife.inject(this);
+
+ provider_name.setText(provider.getDomain());
if ( provider.hasEIP()){
fragment_manager.removePreviousFragment(EipServiceFragment.TAG);
- EipServiceFragment eip_fragment = new EipServiceFragment();
+ eip_fragment = new EipServiceFragment();
if (hide_and_turn_on_eip) {
preferences.edit().remove(Dashboard.START_ON_BOOT).apply();
Bundle arguments = new Bundle();
arguments.putBoolean(EipServiceFragment.START_ON_BOOT, true);
- eip_fragment.setArguments(arguments);
+ if(eip_fragment != null) eip_fragment.setArguments(arguments);
}
fragment_manager.replace(R.id.servicesCollection, eip_fragment, EipServiceFragment.TAG);
@@ -279,10 +277,10 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
return true;
case R.id.switch_provider:
if (provider.hasEIP()){
- if (preferences.getBoolean(Constants.AUTHED_EIP, false)){
- logOut();
- }
- eipStop();
+ if (preferences.getBoolean(Constants.AUTHED_EIP, false)) {
+ logOut();
+ }
+ eip_fragment.stopEIP();
}
preferences.edit().clear().apply();
startActivityForResult(new Intent(this,ConfigurationWizard.class), SWITCH_PROVIDER);
@@ -302,10 +300,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
}
- private Intent prepareProviderAPICommand() {
- mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
- status_message = (TextView) findViewById(R.id.status_message);
-
+ private Intent prepareProviderAPICommand() {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
@@ -319,12 +314,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
* Shows the log in dialog.
*/
public void logInDialog(Bundle resultData) {
- FragmentTransaction transaction = fragment_manager.removePreviousFragment(LogInDialog.TAG);
+ FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG);
- DialogFragment newFragment = LogInDialog.newInstance();
+ DialogFragment newFragment = SessionDialog.newInstance();
if(resultData != null && !resultData.isEmpty())
newFragment.setArguments(resultData);
- newFragment.show(transaction, LogInDialog.TAG);
+ newFragment.show(transaction, SessionDialog.TAG);
}
@Override
@@ -334,12 +329,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if(parameters == null)
parameters = new Bundle();
- parameters.putString(SessionDialogInterface.USERNAME, username);
- parameters.putString(SessionDialogInterface.PASSWORD, password);
-
- mProgressBar.setVisibility(ProgressBar.VISIBLE);
- status_message.setText(R.string.authenticating_message);
+ parameters.putString(SessionDialog.USERNAME, username);
+ parameters.putString(SessionDialog.PASSWORD, password);
+ if(eip_fragment != null) {
+ eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE);
+ eip_fragment.status_message.setText(R.string.authenticating_message);
+ }
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.setAction(ProviderAPI.SRP_AUTH);
startService(provider_API_command);
@@ -354,12 +350,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
*/
public void logOut() {
Intent provider_API_command = prepareProviderAPICommand();
-
- if(mProgressBar == null) mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
- mProgressBar.setVisibility(ProgressBar.VISIBLE);
- if(status_message == null) status_message = (TextView) findViewById(R.id.status_message);
- status_message.setText(R.string.logout_message);
-
+ if(eip_fragment != null) {
+
+ eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE);
+ eip_fragment.status_message.setText(R.string.logout_message);
+ }
provider_API_command.setAction(ProviderAPI.LOG_OUT);
startService(provider_API_command);
}
@@ -368,13 +363,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
* Shows the sign up dialog.
*/
public void signUpDialog(Bundle resultData) {
- FragmentTransaction transaction = fragment_manager.removePreviousFragment(SignUpDialog.TAG);
+ FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG);
- DialogFragment newFragment = SignUpDialog.newInstance();
+ DialogFragment newFragment = SessionDialog.newInstance();
if(resultData != null && !resultData.isEmpty()) {
newFragment.setArguments(resultData);
}
- newFragment.show(transaction, SignUpDialog.TAG);
+ newFragment.show(transaction, SessionDialog.TAG);
}
@Override
@@ -384,12 +379,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if(parameters == null)
parameters = new Bundle();
- parameters.putString(SessionDialogInterface.USERNAME, username);
- parameters.putString(SessionDialogInterface.PASSWORD, password);
-
- mProgressBar.setVisibility(ProgressBar.VISIBLE);
- status_message.setText(R.string.signingup_message);
-
+ parameters.putString(SessionDialog.USERNAME, username);
+ parameters.putString(SessionDialog.PASSWORD, password);
+ if(eip_fragment != null) {
+ eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE);
+ eip_fragment.status_message.setText(R.string.signingup_message);
+ }
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.setAction(ProviderAPI.SRP_REGISTER);
startService(provider_API_command);
@@ -418,8 +413,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
public void onReceiveResult(int resultCode, Bundle resultData) {
Log.d(TAG, "onReceiveResult");
if(resultCode == ProviderAPI.SRP_REGISTRATION_SUCCESSFUL) {
- String username = resultData.getString(SessionDialogInterface.USERNAME);
- String password = resultData.getString(SessionDialogInterface.PASSWORD);
+ String username = resultData.getString(SessionDialog.USERNAME);
+ String password = resultData.getString(SessionDialog.PASSWORD);
logIn(username, password);
} else if(resultCode == ProviderAPI.SRP_REGISTRATION_FAILED) {
changeStatusMessage(resultCode);
@@ -477,8 +472,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
String request = resultData.getString(Constants.REQUEST_TAG);
if(request.equalsIgnoreCase(Constants.ACTION_UPDATE_EIP_SERVICE)) {
if(resultCode == Activity.RESULT_OK) {
- if(authed_eip)
- eipStart();
+ if(authed_eip && eip_fragment != null) eip_fragment.startEipFromScratch();
}
}
}
@@ -493,17 +487,16 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
protected void onReceiveResult(int resultCode, Bundle resultData){
super.onReceiveResult(resultCode, resultData);
String request = resultData.getString(Constants.REQUEST_TAG);
- if(status_message == null) status_message = (TextView) findViewById(R.id.status_message);
- if (request.equalsIgnoreCase(Constants.ACTION_IS_EIP_RUNNING)){
+ if (request.equalsIgnoreCase(Constants.ACTION_IS_EIP_RUNNING)){
if (resultCode == Activity.RESULT_OK){
switch(previous_result_code){
- case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: status_message.setText(R.string.succesful_authentication_message); break;
- case ProviderAPI.SRP_AUTHENTICATION_FAILED: status_message.setText(R.string.authentication_failed_message); break;
- case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: status_message.setText(R.string.authed_secured_status); break;
- case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
- case ProviderAPI.LOGOUT_SUCCESSFUL: status_message.setText(R.string.logged_out_message); break;
- case ProviderAPI.LOGOUT_FAILED: status_message.setText(R.string.log_out_failed_message); break;
+ case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.SRP_AUTHENTICATION_FAILED: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
+ case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.authed_secured_status); break;
+ case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
+ case ProviderAPI.LOGOUT_SUCCESSFUL: eip_fragment.status_message.setText(R.string.logged_out_message); break;
+ case ProviderAPI.LOGOUT_FAILED: eip_fragment.status_message.setText(R.string.log_out_failed_message); break;
}
}
@@ -511,13 +504,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
switch(previous_result_code){
- case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: status_message.setText(R.string.succesful_authentication_message); break;
- case ProviderAPI.SRP_AUTHENTICATION_FAILED: status_message.setText(R.string.authentication_failed_message); break;
- case ProviderAPI.SRP_REGISTRATION_FAILED: status_message.setText(R.string.registration_failed_message); break;
+ case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.SRP_AUTHENTICATION_FAILED: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
+ case ProviderAPI.SRP_REGISTRATION_FAILED: eip_fragment.status_message.setText(R.string.registration_failed_message); break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: break;
- case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
- case ProviderAPI.LOGOUT_SUCCESSFUL: status_message.setText(R.string.logged_out_message); break;
- case ProviderAPI.LOGOUT_FAILED: status_message.setText(R.string.log_out_failed_message); break;
+ case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
+ case ProviderAPI.LOGOUT_SUCCESSFUL: eip_fragment.status_message.setText(R.string.logged_out_message); break;
+ case ProviderAPI.LOGOUT_FAILED: eip_fragment.status_message.setText(R.string.log_out_failed_message); break;
}
}
}
@@ -528,11 +521,10 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
}
private void hideProgressBar() {
- if(mProgressBar == null)
- mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
-
- mProgressBar.setProgress(0);
- mProgressBar.setVisibility(ProgressBar.GONE);
+ if(eip_fragment != null) {
+ eip_fragment.progress_bar.setProgress(0);
+ eip_fragment.progress_bar.setVisibility(ProgressBar.GONE);
+ }
}
/**
@@ -559,20 +551,4 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
eip_intent.putExtra(Constants.RECEIVER_TAG, eip_receiver);
startService(eip_intent);
}
-
- private void eipStop(){
- EipServiceFragment eipFragment = (EipServiceFragment) getFragmentManager().findFragmentByTag(EipServiceFragment.TAG);
- eipFragment.stopEIP();
- }
-
- private void eipStart() {
- EipServiceFragment eipFragment = (EipServiceFragment) getFragmentManager().findFragmentByTag(EipServiceFragment.TAG);
- eipFragment.startEipFromScratch();
- }
-
- protected void showProgressBar() {
- if(mProgressBar == null)
- mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
- mProgressBar.setVisibility(ProgressBar.VISIBLE);
- }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
index 592a9552..a8ffda72 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
@@ -12,19 +12,22 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.CompoundButton;
+import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import java.util.Observable;
import java.util.Observer;
+import butterknife.ButterKnife;
+import butterknife.InjectView;
+import butterknife.OnCheckedChanged;
import de.blinkt.openvpn.activities.DisconnectVPN;
import se.leap.bitmaskclient.eip.Constants;
import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
-public class EipServiceFragment extends Fragment implements Observer, CompoundButton.OnCheckedChangeListener {
+public class EipServiceFragment extends Fragment implements Observer {
public static String TAG = "se.leap.bitmask.EipServiceFragment";
@@ -33,9 +36,13 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
protected static final String STATUS_MESSAGE = TAG + ".status_message";
public static final String START_ON_BOOT = "start on boot";
- private View eipFragment;
- private static Switch eipSwitch;
- private TextView status_message;
+ private View view;
+ @InjectView(R.id.eipSwitch)
+ Switch eip_switch;
+ @InjectView(R.id.status_message)
+ TextView status_message;
+ @InjectView(R.id.eipProgress)
+ ProgressBar progress_bar;
private static Activity parent_activity;
private static EIPReceiver mEIPReceiver;
@@ -57,35 +64,27 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-
- eipFragment = inflater.inflate(R.layout.eip_service_fragment, container, false);
- View eipDetail = eipFragment.findViewById(R.id.eipDetail);
- eipDetail.setVisibility(View.VISIBLE);
-
- View eipSettings = eipFragment.findViewById(R.id.eipSettings);
- eipSettings.setVisibility(View.GONE); // FIXME too!
+ view = inflater.inflate(R.layout.eip_service_fragment, container, false);
+ ButterKnife.inject(this, view);
if (eip_status.isConnecting())
- eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE);
-
- status_message = (TextView) eipFragment.findViewById(R.id.status_message);
+ eip_switch.setVisibility(View.VISIBLE);
- eipSwitch = (Switch) eipFragment.findViewById(R.id.eipSwitch);
- Log.d(TAG, "onCreateView, eipSwitch is checked? " + eipSwitch.isChecked());
- eipSwitch.setOnCheckedChangeListener(this);
-
- if(getArguments() != null && getArguments().containsKey(START_ON_BOOT) && getArguments().getBoolean(START_ON_BOOT))
+ Log.d(TAG, "onCreateView, eip_switch is checked? " + eip_switch.isChecked());
+
+ Bundle arguments = getArguments();
+ if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT))
startEipFromScratch();
if (savedInstanceState != null) {
- setStatusMessage(savedInstanceState.getString(STATUS_MESSAGE));
+ status_message.setText(savedInstanceState.getString(STATUS_MESSAGE));
if(savedInstanceState.getBoolean(IS_PENDING))
eip_status.setConnecting();
else if(savedInstanceState.getBoolean(IS_CONNECTED)) {
eip_status.setConnectedOrDisconnected();
}
}
- return eipFragment;
+ return view;
}
@Override
@@ -106,22 +105,16 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
protected void saveEipStatus() {
boolean eip_is_on = false;
Log.d(TAG, "saveEipStatus");
- if(eipSwitch.isChecked()) {
+ if(eip_switch.isChecked()) {
eip_is_on = true;
}
if(parent_activity != null)
Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, eip_is_on).commit();
}
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (buttonView.equals(eipSwitch)){
- handleSwitch(isChecked);
- }
- }
-
- private void handleSwitch(boolean isChecked) {
+
+ @OnCheckedChanged(R.id.eipSwitch)
+ void handleSwitch(boolean isChecked) {
if(isChecked)
handleSwitchOn();
else
@@ -175,31 +168,30 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
.setNegativeButton(parent_activity.getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- eipSwitch.setChecked(true);
+ eip_switch.setChecked(true);
}
})
.show();
}
public void startEipFromScratch() {
- eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE);
+ progress_bar.setVisibility(View.VISIBLE);
+ eip_switch.setVisibility(View.VISIBLE);
String status = parent_activity.getString(R.string.eip_status_start_pending);
- setStatusMessage(status);
+ status_message.setText(status);
- if(!eipSwitch.isChecked()) {
- eipSwitch.setChecked(true);
+ if(!eip_switch.isChecked()) {
+ eip_switch.setChecked(true);
saveEipStatus();
}
eipCommand(Constants.ACTION_START_EIP);
}
protected void stopEIP() {
- View eipProgressBar = parent_activity.findViewById(R.id.eipProgress);
- if(eipProgressBar != null)
- eipProgressBar.setVisibility(View.GONE);
-
+ hideProgressBar();
+
String status = parent_activity.getString(R.string.eip_state_not_connected);
- setStatusMessage(status);
+ status_message.setText(status);
eipCommand(Constants.ACTION_STOP_EIP);
}
@@ -247,26 +239,26 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
hideProgressBar();
Log.d(TAG, "setConnectedUi? " + eip_status.isConnected());
adjustSwitch();
- setStatusMessage(parent_activity.getString(R.string.eip_state_connected));
+ status_message.setText(parent_activity.getString(R.string.eip_state_connected));
}
private void setDisconnectedUI(){
hideProgressBar();
adjustSwitch();
- setStatusMessage(parent_activity.getString(R.string.eip_state_not_connected));
+ status_message.setText(parent_activity.getString(R.string.eip_state_not_connected));
}
private void adjustSwitch() {
if(eip_status.isConnected() || eip_status.isConnecting()) {
- Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked? " + eipSwitch.isChecked());
- if(!eipSwitch.isChecked()) {
- eipSwitch.setChecked(true);
+ Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked? " + eip_switch.isChecked());
+ if(!eip_switch.isChecked()) {
+ eip_switch.setChecked(true);
}
} else {
Log.d(TAG, "adjustSwitch, !isConnected && !isConnecting? " + eip_status.toString());
- if(eipSwitch.isChecked()) {
- eipSwitch.setChecked(false);
+ if(eip_switch.isChecked()) {
+ eip_switch.setChecked(false);
}
}
}
@@ -275,8 +267,8 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
int localizedResId = eip_status.getLocalizedResId();
String logmessage = eip_status.getLogMessage();
String prefix = parent_activity.getString(localizedResId);
-
- setStatusMessage(prefix + " " + logmessage);
+
+ status_message.setText(prefix + " " + logmessage);
adjustSwitch();
}
@@ -287,8 +279,8 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
}
private void hideProgressBar() {
- if(parent_activity != null && parent_activity.findViewById(R.id.eipProgress) != null)
- parent_activity.findViewById(R.id.eipProgress).setVisibility(View.GONE);
+ if(progress_bar != null)
+ progress_bar.setVisibility(View.GONE);
}
protected class EIPReceiver extends ResultReceiver {
@@ -307,10 +299,10 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
switch (resultCode){
case Activity.RESULT_OK:
Log.d(TAG, "Action start eip = Result OK");
- eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE);
+ progress_bar.setVisibility(View.VISIBLE);
break;
case Activity.RESULT_CANCELED:
- eipFragment.findViewById(R.id.eipProgress).setVisibility(View.GONE);
+ progress_bar.setVisibility(View.GONE);
break;
}
} else if (request.equals(Constants.ACTION_STOP_EIP)) {
@@ -337,9 +329,8 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
case Activity.RESULT_CANCELED:
Dashboard dashboard = (Dashboard) parent_activity;
- dashboard.showProgressBar();
- String status = parent_activity.getString(R.string.updating_certificate_message);
- setStatusMessage(status);
+ progress_bar.setVisibility(View.VISIBLE);
+ status_message.setText(getString(R.string.updating_certificate_message));
if(LeapSRPSession.getToken().isEmpty() && !Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false)) {
dashboard.logInDialog(Bundle.EMPTY);
} else {
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java
deleted file mode 100644
index 875b76d7..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListFragment.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * Copyright (c) 2013 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package se.leap.bitmaskclient;
-
-import android.app.Activity;
-import android.app.ListFragment;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ListView;
-
-import butterknife.ButterKnife;
-import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-
-/**
- * A list fragment representing a list of Providers. This fragment
- * also supports tablet devices by allowing list items to be given an
- * 'activated' state upon selection.
- * <p>
- * Activities containing this fragment MUST implement the {@link Callbacks}
- * interface.
- */
-public class ProviderListFragment extends ListFragment {
-
- public static String TAG = "provider_list_fragment";
- public static String SHOW_ALL_PROVIDERS = "show_all_providers";
- public static String TOP_PADDING = "top padding from providerlistfragment";
- private ProviderListAdapter content_adapter;
-
- /**
- * The serialization (saved instance state) Bundle key representing the
- * activated item position. Only used on tablets.
- */
- private static final String STATE_ACTIVATED_POSITION = "activated_position";
-
- /**
- * The fragment's current callback object, which is notified of list item
- * clicks.
- */
- private Callbacks mCallbacks = sDummyCallbacks;
-
- /**
- * The current activated item position. Only used on tablets.
- */
- private int mActivatedPosition = ListView.INVALID_POSITION;
-
- /**
- * A callback interface that all activities containing this fragment must
- * implement. This mechanism allows activities to be notified of item
- * selections.
- */
- public interface Callbacks {
- /**
- * Callback for when an item has been selected.
- */
- public void onItemSelected(String id);
- }
-
- /**
- * A dummy implementation of the {@link Callbacks} interface that does
- * nothing. Used only when this fragment is not attached to an activity.
- */
- private static Callbacks sDummyCallbacks = new Callbacks() {
- @Override
- public void onItemSelected(String id) {
- }
- };
-
- /**
- * Mandatory empty constructor for the fragment manager to instantiate the
- * fragment (e.g. upon screen orientation changes).
- */
- public ProviderListFragment() {
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
- View view = inflater.inflate(R.layout.provider_list_fragment, container, false);
- ButterKnife.inject(this, view);
- return view;
- }
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
- // Restore the previously serialized activated item position.
- if (savedInstanceState != null
- && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
- setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
- }
- if(getArguments() != null && getArguments().containsKey(TOP_PADDING)) {
- int topPadding = getArguments().getInt(TOP_PADDING);
- View current_view = getView();
- current_view.setPadding(current_view.getPaddingLeft(), topPadding, current_view.getPaddingRight(), current_view.getPaddingBottom());
- }
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
-
- // Activities containing this fragment must implement its callbacks.
- if (!(activity instanceof Callbacks)) {
- throw new IllegalStateException("Activity must implement fragment's callbacks.");
- }
-
- mCallbacks = (Callbacks) activity;
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
-
- // Reset the active callbacks interface to the dummy implementation.
- mCallbacks = sDummyCallbacks;
- }
-
- @Override
- public void onListItemClick(ListView listView, View view, int position, long id) {
- super.onListItemClick(listView, view, position, id);
-
- // Notify the active callbacks interface (the activity, if the
- // fragment is attached to one) that an item has been selected.
- mCallbacks.onItemSelected(ProviderListContent.ITEMS.get(position).name());
-
- for(int item_position = 0; item_position < listView.getCount(); item_position++) {
- if(item_position != position)
- content_adapter.hide(item_position);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- if (mActivatedPosition != ListView.INVALID_POSITION) {
- // Serialize and persist the activated item position.
- outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
- }
- }
-
- public void notifyAdapter() {
- content_adapter.notifyDataSetChanged();
- }
- /**
- * Turns on activate-on-click mode. When this mode is on, list items will be
- * given the 'activated' state when touched.
- */
- public void setActivateOnItemClick(boolean activateOnItemClick) {
- // When setting CHOICE_MODE_SINGLE, ListView will automatically
- // give items the 'activated' state when touched.
- getListView().setChoiceMode(activateOnItemClick
- ? ListView.CHOICE_MODE_SINGLE
- : ListView.CHOICE_MODE_NONE);
- }
-
- private void setActivatedPosition(int position) {
- if (position == ListView.INVALID_POSITION) {
- getListView().setItemChecked(mActivatedPosition, false);
- } else {
- getListView().setItemChecked(position, true);
- }
-
- mActivatedPosition = position;
- }
-
- public void removeLastItem() {
- content_adapter.remove(content_adapter.getItem(content_adapter.getCount()-1));
- content_adapter.notifyDataSetChanged();
- }
-
- public void addItem(Provider provider) {
- content_adapter.add(provider);
- content_adapter.notifyDataSetChanged();
- }
-
- public void hideAllBut(int position) {
- int real_count = content_adapter.getCount();
- for(int i = 0; i < real_count;)
- if(i != position) {
- content_adapter.hide(i);
- position--;
- real_count--;
- } else {
- i++;
- }
- }
-
- /**
- * @return a new instance of this ListFragment.
- */
- public static ProviderListFragment newInstance() {
- return new ProviderListFragment();
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/LogInDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
index 5263392e..9676faa8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/LogInDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
@@ -26,6 +26,9 @@ import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
+import butterknife.ButterKnife;
+import butterknife.InjectView;
+
/**
* Implements the log in dialog, currently without progress dialog.
*
@@ -36,45 +39,56 @@ import android.widget.TextView;
* @author parmegv
*
*/
-public class LogInDialog extends SessionDialogInterface {
+public class SessionDialog extends DialogFragment{
- final public static String TAG = LogInDialog.class.getSimpleName();
+ final public static String TAG = SessionDialog.class.getSimpleName();
+
+ final public static String USERNAME = "username";
+ final public static String PASSWORD = "password";
+ final public static String USERNAME_MISSING = "username missing";
+ final public static String PASSWORD_INVALID_LENGTH = "password_invalid_length";
+
+ @InjectView(R.id.user_message)
+ TextView user_message;
+ @InjectView(R.id.username_entered)
+ EditText username_field;
+ @InjectView(R.id.password_entered)
+ EditText password_field;
- private static LogInDialog dialog;
+ private static SessionDialog dialog;
private static boolean is_eip_pending = false;
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
- View log_in_dialog_view = inflater.inflate(R.layout.log_in_dialog, null);
-
- final TextView user_message = (TextView)log_in_dialog_view.findViewById(R.id.user_message);
- final EditText username_field = (EditText)log_in_dialog_view.findViewById(R.id.username_entered);
- final EditText password_field = (EditText)log_in_dialog_view.findViewById(R.id.password_entered);
+ View view = inflater.inflate(R.layout.session_dialog, null);
+ ButterKnife.inject(this, view);
if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) {
password_field.requestFocus();
}
- if (getArguments() != null) {
- is_eip_pending = getArguments().getBoolean(EipServiceFragment.IS_PENDING, false);
- if (getArguments().containsKey(PASSWORD_INVALID_LENGTH))
- password_field.setError(getResources().getString(R.string.error_not_valid_password_user_message));
- if (getArguments().containsKey(USERNAME)) {
- String username = getArguments().getString(USERNAME);
+
+ Bundle arguments = getArguments();
+ if (arguments != null) {
+ is_eip_pending = arguments.getBoolean(EipServiceFragment.IS_PENDING, false);
+ if (arguments.containsKey(PASSWORD_INVALID_LENGTH))
+ password_field.setError(getString(R.string.error_not_valid_password_user_message));
+ if (arguments.containsKey(USERNAME)) {
+ String username = arguments.getString(USERNAME);
username_field.setText(username);
}
- if (getArguments().containsKey(USERNAME_MISSING)) {
- username_field.setError(getResources().getString(R.string.username_ask));
+ if (arguments.containsKey(USERNAME_MISSING)) {
+ username_field.setError(getString(R.string.username_ask));
}
- if(getArguments().containsKey(getResources().getString(R.string.user_message)))
- user_message.setText(getArguments().getString(getResources().getString(R.string.user_message)));
+ if(arguments.containsKey(getString(R.string.user_message)))
+ user_message.setText(arguments.getString(getString(R.string.user_message)));
else
user_message.setVisibility(View.GONE);
}
- builder.setView(log_in_dialog_view)
+ builder.setView(view)
.setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String username = username_field.getText().toString();
@@ -99,9 +113,10 @@ public class LogInDialog extends SessionDialogInterface {
return builder.create();
}
+
/**
- * Interface used to communicate LogInDialog with Dashboard.
+ * Interface used to communicate SessionDialog with Dashboard.
*
* @author parmegv
*
@@ -119,7 +134,7 @@ public class LogInDialog extends SessionDialogInterface {
*/
public static DialogFragment newInstance() {
if(dialog == null)
- dialog = new LogInDialog();
+ dialog = new SessionDialog();
return dialog;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialogInterface.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialogInterface.java
deleted file mode 100644
index 66b86ccd..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/SessionDialogInterface.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (c) 2013 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient;
-
-import android.app.Activity;
-import android.app.DialogFragment;
-import android.content.DialogInterface;
-
-/**
- * @author parmegv
- */
-public abstract class SessionDialogInterface extends DialogFragment {
- final public static String USERNAME = "username";
- final public static String PASSWORD = "password";
- final public static String USERNAME_MISSING = "username missing";
- final public static String PASSWORD_INVALID_LENGTH = "password_invalid_length";
-
- @Override
- public void onAttach(Activity activity) { super.onAttach(activity); }
-
- @Override
- public void onCancel(DialogInterface dialog) { super.onCancel(dialog); }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java b/app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java
deleted file mode 100644
index f6d6cc3f..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * Copyright (c) 2013 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package se.leap.bitmaskclient;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.DialogFragment;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.EditText;
-import android.widget.TextView;
-
-/**
- * Implements the sign up dialog, currently without progress dialog.
- *
- * It returns to the previous fragment when finished, and sends username and password to the registration method.
- *
- * It also notifies the user if the password is not valid.
- *
- * @author parmegv
- *
- */
-public class SignUpDialog extends SessionDialogInterface {
-
- final public static String TAG = SignUpDialog.class.getSimpleName();
-
- private static SignUpDialog dialog;
- private static boolean is_eip_pending = false;
-
- public AlertDialog onCreateDialog(Bundle savedInstanceState) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- LayoutInflater inflater = getActivity().getLayoutInflater();
- View log_in_dialog_view = inflater.inflate(R.layout.log_in_dialog, null);
-
- final TextView user_message = (TextView)log_in_dialog_view.findViewById(R.id.user_message);
- final EditText username_field = (EditText)log_in_dialog_view.findViewById(R.id.username_entered);
- final EditText password_field = (EditText)log_in_dialog_view.findViewById(R.id.password_entered);
-
- if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) {
- password_field.requestFocus();
- }
- if (getArguments() != null) {
- is_eip_pending = getArguments().getBoolean(EipServiceFragment.IS_PENDING, false);
- if (getArguments().containsKey(PASSWORD_INVALID_LENGTH))
- password_field.setError(getResources().getString(R.string.error_not_valid_password_user_message));
- if(getArguments().containsKey(USERNAME_MISSING))
- username_field.setError(getResources().getString(R.string.username_ask));
- if(getArguments().containsKey(USERNAME)) {
- String username = getArguments().getString(USERNAME);
- username_field.setText(username);
- }
- if(getArguments().containsKey(getResources().getString(R.string.user_message)))
- user_message.setText(getArguments().getString(getResources().getString(R.string.user_message)));
- else
- user_message.setVisibility(View.GONE);
- }
-
- builder.setView(log_in_dialog_view)
- .setPositiveButton(R.string.signup_button, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- String username = username_field.getText().toString();
- String password = password_field.getText().toString();
- dialog.dismiss();
- interface_with_Dashboard.signUp(username, password);
- }
- })
- .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- interface_with_Dashboard.cancelLoginOrSignup();
- }
- });
-
- return builder.create();
- }
-
- /**
- * Interface used to communicate SignUpDialog with Dashboard.
- *
- * @author parmegv
- *
- */
- public interface SignUpDialogInterface {
- public void signUp(String username, String password);
- public void cancelLoginOrSignup();
- }
-
- SignUpDialogInterface interface_with_Dashboard;
-
- /**
- * @return a new instance of this DialogFragment.
- */
- public static DialogFragment newInstance() {
- if(dialog == null)
- dialog = new SignUpDialog();
- return dialog;
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- try {
- interface_with_Dashboard = (SignUpDialogInterface) activity;
- } catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
- + " must implement SignUpDialogListener");
- }
- }
-
- @Override
- public void onCancel(DialogInterface dialog) {
- if(is_eip_pending)
- interface_with_Dashboard.cancelLoginOrSignup();
- super.onCancel(dialog);
- }
-}