summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-04-30 13:51:43 +0200
committerParménides GV <parmegv@sdf.org>2015-04-30 13:52:04 +0200
commit237e51e09ea7ae13c4cdf7fd9247447f6d75fb9a (patch)
tree955df579d3589ca6a74a7b86fea1ade0e10b2781 /app/src/main/java/se/leap
parent9a54c425f6d96e1872899eabf78fb60082a8d234 (diff)
Works smoothly, correct texts.
Next step: beautify.
Diffstat (limited to 'app/src/main/java/se/leap')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java26
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/User.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java (renamed from app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java)20
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java (renamed from app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java)111
5 files changed, 71 insertions, 93 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index f87c9f94..bf35d6c3 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -63,7 +63,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
TextView provider_name;
EipFragment eip_fragment;
- UserSessionFragment user_session_fragment;
+ UserStatusFragment user_status_fragment;
private static Provider provider = new Provider();
public ProviderAPIResultReceiver providerAPI_result_receiver;
private boolean switching_provider;
@@ -79,7 +79,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
- User.init();
+ User.init(getString(R.string.default_username));
ProviderAPICommand.initialize(this);
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this);
@@ -89,7 +89,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
startActivityForResult(new Intent(this, ConfigurationWizard.class), CONFIGURE_LEAP);
else {
buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false));
- user_session_fragment.restoreSessionStatus(savedInstanceState);
+ user_status_fragment.restoreSessionStatus(savedInstanceState);
}
}
@@ -199,11 +199,11 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
provider_name.setText(provider.getDomain());
- user_session_fragment = new UserSessionFragment();
+ user_status_fragment = new UserStatusFragment();
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);
+ user_status_fragment.setArguments(bundle);
+ fragment_manager.replace(R.id.user_status_fragment, user_status_fragment, UserStatusFragment.TAG);
if (provider.hasEIP()) {
fragment_manager.removePreviousFragment(EipFragment.TAG);
@@ -227,10 +227,6 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
public boolean onPrepareOptionsMenu(Menu menu) {
if (provider.allowsRegistration()) {
menu.findItem(R.id.signup_button).setVisible(true);
-
- boolean logged_in = User.loggedIn();
- menu.findItem(R.id.login_button).setVisible(!logged_in);
- menu.findItem(R.id.logout_button).setVisible(logged_in);
}
return true;
}
@@ -252,15 +248,9 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
return true;
case R.id.switch_provider:
switching_provider = true;
- if (User.loggedIn()) user_session_fragment.logOut();
+ if (User.loggedIn()) user_status_fragment.logOut();
else switchProvider();
return true;
- case R.id.login_button:
- sessionDialog(Bundle.EMPTY);
- return true;
- case R.id.logout_button:
- user_session_fragment.logOut();
- return true;
case R.id.signup_button:
sessionDialog(Bundle.EMPTY);
return true;
@@ -306,7 +296,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) {
String username = resultData.getString(SessionDialog.USERNAME);
String password = resultData.getString(SessionDialog.PASSWORD);
- user_session_fragment.logIn(username, password);
+ user_status_fragment.logIn(username, password);
} else if (resultCode == ProviderAPI.FAILED_SIGNUP) {
sessionDialog(resultData);
} else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) {
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java
index 18f16301..f89418ba 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java
@@ -167,7 +167,7 @@ public class SessionDialog extends DialogFragment {
super.onAttach(activity);
try {
- interface_with_Dashboard = (SessionDialogInterface) activity.getFragmentManager().findFragmentById(R.id.user_session_fragment);;
+ interface_with_Dashboard = (SessionDialogInterface) activity.getFragmentManager().findFragmentById(R.id.user_status_fragment);;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement LogInDialogListener");
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java
index 716e2ed6..64ce0629 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java
@@ -19,12 +19,13 @@ package se.leap.bitmaskclient.userstatus;
import se.leap.bitmaskclient.LeapSRPSession;
public class User {
- private static String user_name = "";
+ private static String user_name;
private static User user;
- public static User init() {
+ public static User init(String default_username) {
if (user == null) {
user = new User();
+ user.setUserName(default_username);
}
return user;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java
index dec0e719..edfed8d6 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java
@@ -22,9 +22,9 @@ import java.util.*;
import se.leap.bitmaskclient.R;
-public class UserSessionStatus extends Observable {
- public static String TAG = UserSessionStatus.class.getSimpleName();
- private static UserSessionStatus current_status;
+public class UserStatus extends Observable {
+ public static String TAG = UserStatus.class.getSimpleName();
+ private static UserStatus current_status;
private static Resources resources;
public enum SessionStatus {
@@ -58,17 +58,17 @@ public class UserSessionStatus extends Observable {
}
}
- private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN;
+ private static SessionStatus session_status = SessionStatus.LOGGED_OUT;
- public static UserSessionStatus getInstance(Resources resources) {
+ public static UserStatus getInstance(Resources resources) {
if (current_status == null) {
- current_status = new UserSessionStatus(resources);
+ current_status = new UserStatus(resources);
}
return current_status;
}
- private UserSessionStatus(Resources resources) {
- UserSessionStatus.resources = resources;
+ private UserStatus(Resources resources) {
+ UserStatus.resources = resources;
}
private void sessionStatus(SessionStatus session_status) {
@@ -85,7 +85,7 @@ public class UserSessionStatus extends Observable {
}
public boolean isLoggedIn() {
- return session_status == SessionStatus.LOGGING_IN;
+ return session_status == SessionStatus.LOGGED_IN;
}
public boolean isLoggedOut() {
@@ -103,7 +103,7 @@ public class UserSessionStatus extends Observable {
public String toString() {
String user_session_status = User.userName();
- String default_username = resources.getString(R.string.default_user, "");
+ String default_username = resources.getString(R.string.default_username, "");
if(user_session_status.isEmpty() && !default_username.equalsIgnoreCase("null")) user_session_status = default_username;
user_session_status += " " + session_status.toString();
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
index dc334c3d..0766dbd5 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
@@ -10,37 +10,38 @@ import org.jetbrains.annotations.NotNull;
import java.util.*;
import butterknife.*;
+import mbanje.kurt.fabbutton.FabButton;
import se.leap.bitmaskclient.*;
import se.leap.bitmaskclient.eip.EipStatus;
-public class UserSessionFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface {
+public class UserStatusFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface {
- public static String TAG = UserSessionFragment.class.getSimpleName();
+ public static String TAG = UserStatusFragment.class.getSimpleName();
private static Dashboard dashboard;
private ProviderAPIResultReceiver providerAPI_result_receiver;
- @InjectView(R.id.user_session_status)
- TextView user_session_status_text_view;
- @InjectView(R.id.user_session_status_progress)
- ProgressBar user_session_status_progress_bar;
- @InjectView(R.id.user_session_button)
- Button main_button;
+ @InjectView(R.id.user_status_username)
+ TextView username;
+ @InjectView(R.id.user_status_icon)
+ FabButton icon;
+ @InjectView(R.id.user_status_button)
+ Button button;
- private UserSessionStatus user_session_status;
+ private UserStatus status;
private boolean allows_registration = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- user_session_status = UserSessionStatus.getInstance(getResources());
- user_session_status.addObserver(this);
+ status = UserStatus.getInstance(getResources());
+ status.addObserver(this);
}
@Override
public void onSaveInstanceState(@NotNull Bundle outState) {
- if (user_session_status_text_view != null && user_session_status_text_view.getVisibility() == TextView.VISIBLE)
- outState.putSerializable(UserSessionStatus.TAG, user_session_status.sessionStatus());
+ if (username != null && username.getVisibility() == TextView.VISIBLE)
+ outState.putSerializable(UserStatus.TAG, status.sessionStatus());
super.onSaveInstanceState(outState);
}
@@ -54,7 +55,7 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi
Bundle arguments = getArguments();
allows_registration = arguments.getBoolean(Provider.ALLOW_REGISTRATION);
- handleNewUserSessionStatus(user_session_status);
+ handleNewStatus(status);
return view;
}
@@ -62,7 +63,7 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi
@Override
public void onDestroyView() {
super.onDestroyView();
- Fragment fragment = (getFragmentManager().findFragmentById(R.id.user_session_fragment));
+ Fragment fragment = (getFragmentManager().findFragmentById(R.id.user_status_fragment));
FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
@@ -78,34 +79,40 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi
public void restoreSessionStatus(Bundle savedInstanceState) {
if (savedInstanceState != null)
- if (savedInstanceState.containsKey(UserSessionStatus.TAG)) {
- UserSessionStatus.SessionStatus status = (UserSessionStatus.SessionStatus) savedInstanceState.getSerializable(UserSessionStatus.TAG);
- user_session_status.updateStatus(status, getResources());
+ if (savedInstanceState.containsKey(UserStatus.TAG)) {
+ UserStatus.SessionStatus status = (UserStatus.SessionStatus) savedInstanceState.getSerializable(UserStatus.TAG);
+ this.status.updateStatus(status, getResources());
}
}
- @OnClick(R.id.user_session_button)
- public void handleMainButton() {
- if(user_session_status.isLoggedIn())
+ @OnClick(R.id.user_status_button)
+ public void handleButton() {
+ android.util.Log.d(TAG, status.toString());
+ if(status.isLoggedIn())
logOut();
- else if(user_session_status.isLoggedOut())
+ else if(status.isLoggedOut())
dashboard.sessionDialog(Bundle.EMPTY);
- else if(user_session_status.inProgress())
+ else if(status.inProgress())
cancelLoginOrSignup();
}
@Override
public void update(Observable observable, Object data) {
- if (observable instanceof UserSessionStatus) {
- UserSessionStatus status = (UserSessionStatus) observable;
- handleNewUserSessionStatus(status);
+ if (observable instanceof UserStatus) {
+ final UserStatus status = (UserStatus) observable;
+ dashboard.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ handleNewStatus(status);
+ }
+ });
}
}
- private void handleNewUserSessionStatus(UserSessionStatus status) {
- user_session_status = status;
+ private void handleNewStatus(UserStatus status) {
+ this.status = status;
if (allows_registration) {
- if (user_session_status.inProgress())
+ if (this.status.inProgress())
showUserSessionProgressBar();
else
hideUserSessionProgressBar();
@@ -115,48 +122,27 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi
}
private void showUserSessionProgressBar() {
- dashboard.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- user_session_status_progress_bar.setVisibility(ProgressBar.VISIBLE);
- }
- });
+ icon.showProgress(true);
}
private void hideUserSessionProgressBar() {
- dashboard.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- user_session_status_progress_bar.setVisibility(ProgressBar.GONE);
- }
- });
+ icon.showProgress(false);
}
private void changeMessage() {
- final String message = user_session_status.toString();
- dashboard.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- user_session_status_text_view.setText(message);
- }
- });
+ final String message = User.userName();
+ username.setText(message);
}
private void updateButton() {
- if(User.loggedIn())
- dashboard.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- main_button.setText(dashboard.getString(R.string.logout_button));
- }
- });
- else if(allows_registration)
- dashboard.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- main_button.setText(dashboard.getString(R.string.login_button));
- }
- });
+ if(status.isLoggedIn())
+ button.setText(dashboard.getString(R.string.logout_button));
+ else if(allows_registration) {
+ if (status.isLoggedOut())
+ button.setText(dashboard.getString(R.string.login_button));
+ else if (status.inProgress())
+ button.setText(dashboard.getString(android.R.string.cancel));
+ }
}
@@ -175,6 +161,7 @@ public class UserSessionFragment extends Fragment implements Observer, SessionDi
}
public void logOut() {
+ android.util.Log.d(TAG, "Log out");
ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.LOG_OUT, providerAPI_result_receiver);
}