From f008b5ec8e1c74968e4a605d2de5423edf91b854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 29 Apr 2015 12:25:24 +0200 Subject: Creating a user session fragment. I've separated the user session management to it, and encapsulated ProviderAPICommand into its own class. Putting the fragment statically in dashboard.xml isn't working, Android complains about it being duplicated, so I'm going to add it dynamically. --- .../bitmaskclient/userstatus/SessionDialog.java | 182 +++++++++++++++++++++ .../se/leap/bitmaskclient/userstatus/User.java | 45 +++++ .../userstatus/UserSessionFragment.java | 178 ++++++++++++++++++++ .../userstatus/UserSessionStatus.java | 119 ++++++++++++++ 4 files changed, 524 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/User.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java new file mode 100644 index 00000000..f51a6779 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java @@ -0,0 +1,182 @@ +/** + * 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 . + */ +package se.leap.bitmaskclient.userstatus; + +import android.app.*; +import android.content.*; +import android.os.*; +import android.view.*; +import android.widget.*; + +import butterknife.*; +import se.leap.bitmaskclient.EipFragment; +import se.leap.bitmaskclient.Provider; +import se.leap.bitmaskclient.R; + +/** + * Implements the log in dialog, currently without progress dialog. + *

+ * It returns to the previous fragment when finished, and sends username and password to the authenticate method. + *

+ * It also notifies the user if the password is not valid. + * + * @author parmegv + */ +public class SessionDialog extends DialogFragment { + + + final public static String TAG = SessionDialog.class.getSimpleName(); + + final public static String USERNAME = "username"; + final public static String PASSWORD = "password"; + + public static enum ERRORS { + USERNAME_MISSING, + PASSWORD_INVALID_LENGTH, + RISEUP_WARNING + } + + @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 boolean is_eip_pending = false; + + public static SessionDialog getInstance(Provider provider, Bundle arguments) { + SessionDialog dialog = new SessionDialog(); + if (provider.getName().equalsIgnoreCase("riseup")) { + arguments = + arguments == Bundle.EMPTY ? + new Bundle() : arguments; + arguments.putBoolean(SessionDialog.ERRORS.RISEUP_WARNING.toString(), true); + } + if (arguments != null && !arguments.isEmpty()) { + dialog.setArguments(arguments); + } + return dialog; + } + + public AlertDialog onCreateDialog(Bundle savedInstanceState) { + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.session_dialog, null); + ButterKnife.inject(this, view); + + Bundle arguments = getArguments(); + if (arguments != Bundle.EMPTY) { + setUp(arguments); + } + + builder.setView(view) + .setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + String username = getEnteredUsername(); + String password = getEnteredPassword(); + dialog.dismiss(); + interface_with_Dashboard.logIn(username, password); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + interface_with_Dashboard.cancelLoginOrSignup(); + } + }) + .setNeutralButton(R.string.signup_button, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + String username = getEnteredUsername(); + String password = getEnteredPassword(); + dialog.dismiss(); + interface_with_Dashboard.signUp(username, password); + } + }); + + return builder.create(); + } + + private void setUp(Bundle arguments) { + is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); + if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) + password_field.setError(getString(R.string.error_not_valid_password_user_message)); + else if (arguments.containsKey(ERRORS.RISEUP_WARNING.toString())) { + user_message.setVisibility(TextView.VISIBLE); + user_message.setText(R.string.login_riseup_warning); + } + if (arguments.containsKey(USERNAME)) { + String username = arguments.getString(USERNAME); + username_field.setText(username); + } + if (arguments.containsKey(ERRORS.USERNAME_MISSING.toString())) { + username_field.setError(getString(R.string.username_ask)); + } + if (arguments.containsKey(getString(R.string.user_message))) { + user_message.setText(arguments.getString(getString(R.string.user_message))); + user_message.setVisibility(View.VISIBLE); + } else if (user_message.getVisibility() != TextView.VISIBLE) + user_message.setVisibility(View.GONE); + + if (!username_field.getText().toString().isEmpty() && password_field.isFocusable()) + password_field.requestFocus(); + + } + + private String getEnteredUsername() { + return username_field.getText().toString(); + } + + private String getEnteredPassword() { + return password_field.getText().toString(); + } + + + /** + * Interface used to communicate SessionDialog with Dashboard. + * + * @author parmegv + */ + public interface SessionDialogInterface { + public void logIn(String username, String password); + + public void signUp(String username, String password); + + public void cancelLoginOrSignup(); + } + + SessionDialogInterface interface_with_Dashboard; + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + interface_with_Dashboard = (SessionDialogInterface) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement LogInDialogListener"); + } + } + + @Override + public void onCancel(DialogInterface dialog) { + super.onCancel(dialog); + if (is_eip_pending) + interface_with_Dashboard.cancelLoginOrSignup(); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java new file mode 100644 index 00000000..716e2ed6 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java @@ -0,0 +1,45 @@ +/** + * 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 . + */ +package se.leap.bitmaskclient.userstatus; + +import se.leap.bitmaskclient.LeapSRPSession; + +public class User { + private static String user_name = ""; + private static User user; + + public static User init() { + if (user == null) { + user = new User(); + } + return user; + } + + public static void setUserName(String user_name) { + User.user_name = user_name; + } + + private User() { } + + public static String userName() { + return user_name; + } + + public static boolean loggedIn() { + return LeapSRPSession.loggedIn(); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java new file mode 100644 index 00000000..02b9fbeb --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java @@ -0,0 +1,178 @@ +package se.leap.bitmaskclient.userstatus; + +import android.app.*; +import android.os.*; +import android.view.*; +import android.widget.*; + +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +import butterknife.*; +import se.leap.bitmaskclient.*; +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; + + @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; + + private UserSessionStatus user_session_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); + + handleNewUserSessionStatus(user_session_status); + } + + @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()); + + super.onSaveInstanceState(outState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_user_session, container, false); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + Fragment fragment = (getFragmentManager().findFragmentById(R.id.user_session_fragment)); + FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction(); + ft.remove(fragment); + ft.commit(); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + dashboard = (Dashboard) activity; + + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); + providerAPI_result_receiver.setReceiver(dashboard); + } + + 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()); + } + } + + @OnClick(R.id.user_session_button) + public void handleMainButton() { + if(user_session_status.isLoggedIn()) + logOut(); + else if(user_session_status.isLoggedOut()) + dashboard.sessionDialog(Bundle.EMPTY); + else if(user_session_status.inProgress()) + cancelLoginOrSignup(); + } + + @Override + public void update(Observable observable, Object data) { + if (observable instanceof UserSessionStatus) { + UserSessionStatus status = (UserSessionStatus) observable; + handleNewUserSessionStatus(status); + } + } + + private void handleNewUserSessionStatus(UserSessionStatus status) { + user_session_status = status; + if (allows_registration) { + if (user_session_status.inProgress()) + showUserSessionProgressBar(); + else + hideUserSessionProgressBar(); + changeSessionStatusMessage(); + updateButton(); + } + } + + private void showUserSessionProgressBar() { + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + user_session_status_progress_bar.setVisibility(ProgressBar.VISIBLE); + } + }); + } + + private void hideUserSessionProgressBar() { + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + user_session_status_progress_bar.setVisibility(ProgressBar.GONE); + } + }); + } + + private void changeSessionStatusMessage() { + final String message = user_session_status.toString(); + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + user_session_status_text_view.setText(message); + } + }); + } + + private void updateButton() { + if(User.loggedIn()) + main_button.setText(getString(R.string.logout_button)); + else if(allows_registration) + main_button.setText(getString(R.string.login_button)); + } + + + @Override + public void signUp(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.SIGN_UP, providerAPI_result_receiver); + } + + @Override + public void logIn(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.LOG_IN, providerAPI_result_receiver); + } + + public void logOut() { + ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.LOG_OUT, providerAPI_result_receiver); + } + + public void cancelLoginOrSignup() { + EipStatus.getInstance().setConnectedOrDisconnected(); + } + + private Bundle bundlePassword(String password) { + Bundle parameters = new Bundle(); + if (!password.isEmpty()) + parameters.putString(SessionDialog.PASSWORD, password); + return parameters; + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java new file mode 100644 index 00000000..dec0e719 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java @@ -0,0 +1,119 @@ +/** + * 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 . + */ +package se.leap.bitmaskclient.userstatus; + +import android.content.res.*; + +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; + private static Resources resources; + + public enum SessionStatus { + LOGGED_IN, + LOGGED_OUT, + NOT_LOGGED_IN, + DIDNT_LOG_OUT, + LOGGING_IN, + LOGGING_OUT, + SIGNING_UP; + + @Override + public String toString() { + int id = 0; + if(this == SessionStatus.LOGGED_IN) + id = R.string.logged_in_user_status; + else if(this == SessionStatus.LOGGED_OUT) + id = R.string.logged_out_user_status; + else if(this == SessionStatus.NOT_LOGGED_IN) + id = R.string.not_logged_in_user_status; + else if(this == SessionStatus.DIDNT_LOG_OUT) + id = R.string.didnt_log_out_user_status; + else if(this == SessionStatus.LOGGING_IN) + id = R.string.logging_in_user_status; + else if(this == SessionStatus.LOGGING_OUT) + id = R.string.logging_out_user_status; + else if(this == SessionStatus.SIGNING_UP) + id = R.string.signingup_message; + + return resources.getString(id); + } + } + + private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN; + + public static UserSessionStatus getInstance(Resources resources) { + if (current_status == null) { + current_status = new UserSessionStatus(resources); + } + return current_status; + } + + private UserSessionStatus(Resources resources) { + UserSessionStatus.resources = resources; + } + + private void sessionStatus(SessionStatus session_status) { + this.session_status = session_status; + } + + public SessionStatus sessionStatus() { + return session_status; + } + + public boolean inProgress() { + return session_status == SessionStatus.LOGGING_IN + || session_status == SessionStatus.LOGGING_OUT; + } + + public boolean isLoggedIn() { + return session_status == SessionStatus.LOGGING_IN; + } + + public boolean isLoggedOut() { + return session_status == SessionStatus.LOGGED_OUT; + } + + public static void updateStatus(SessionStatus session_status, Resources resources) { + current_status = getInstance(resources); + current_status.sessionStatus(session_status); + current_status.setChanged(); + current_status.notifyObservers(); + } + + @Override + public String toString() { + String user_session_status = User.userName(); + + String default_username = resources.getString(R.string.default_user, ""); + if(user_session_status.isEmpty() && !default_username.equalsIgnoreCase("null")) user_session_status = default_username; + user_session_status += " " + session_status.toString(); + + user_session_status = user_session_status.trim(); + if(User.userName().isEmpty()) + user_session_status = capitalize(user_session_status); + return user_session_status; + } + + private String capitalize(String to_be_capitalized) { + return to_be_capitalized.substring(0,1).toUpperCase() + to_be_capitalized.substring(1); + } +} -- cgit v1.2.3 From 8833acbafe00eb2941cfa052cb679fc2684b5290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 29 Apr 2015 12:47:43 +0200 Subject: Dynamically load user session fragment. Tests click new button, instead of action bar's. Fixing more bugs... --- .../main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') 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 f51a6779..18f16301 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java @@ -81,7 +81,7 @@ public class SessionDialog extends DialogFragment { ButterKnife.inject(this, view); Bundle arguments = getArguments(); - if (arguments != Bundle.EMPTY) { + if (arguments != Bundle.EMPTY && arguments != null) { setUp(arguments); } @@ -165,8 +165,9 @@ public class SessionDialog extends DialogFragment { @Override public void onAttach(Activity activity) { super.onAttach(activity); + try { - interface_with_Dashboard = (SessionDialogInterface) activity; + interface_with_Dashboard = (SessionDialogInterface) activity.getFragmentManager().findFragmentById(R.id.user_session_fragment);; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement LogInDialogListener"); -- cgit v1.2.3 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. --- .../userstatus/UserSessionFragment.java | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') 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)); + } + }); } -- cgit v1.2.3 From 237e51e09ea7ae13c4cdf7fd9247447f6d75fb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 30 Apr 2015 13:51:43 +0200 Subject: Works smoothly, correct texts. Next step: beautify. --- .../bitmaskclient/userstatus/SessionDialog.java | 2 +- .../se/leap/bitmaskclient/userstatus/User.java | 5 +- .../userstatus/UserSessionFragment.java | 191 --------------------- .../userstatus/UserSessionStatus.java | 119 ------------- .../leap/bitmaskclient/userstatus/UserStatus.java | 119 +++++++++++++ .../userstatus/UserStatusFragment.java | 178 +++++++++++++++++++ 6 files changed, 301 insertions(+), 313 deletions(-) delete mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java delete mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') 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/UserSessionFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java deleted file mode 100644 index dc334c3d..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionFragment.java +++ /dev/null @@ -1,191 +0,0 @@ -package se.leap.bitmaskclient.userstatus; - -import android.app.*; -import android.os.*; -import android.view.*; -import android.widget.*; - -import org.jetbrains.annotations.NotNull; - -import java.util.*; - -import butterknife.*; -import se.leap.bitmaskclient.*; -import se.leap.bitmaskclient.eip.EipStatus; - -public class UserSessionFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface { - - public static String TAG = UserSessionFragment.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; - - private UserSessionStatus user_session_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); - } - - @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()); - - super.onSaveInstanceState(outState); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - 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 - public void onDestroyView() { - super.onDestroyView(); - Fragment fragment = (getFragmentManager().findFragmentById(R.id.user_session_fragment)); - FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction(); - ft.remove(fragment); - ft.commit(); - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - dashboard = (Dashboard) activity; - - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); - } - - 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()); - } - } - - @OnClick(R.id.user_session_button) - public void handleMainButton() { - if(user_session_status.isLoggedIn()) - logOut(); - else if(user_session_status.isLoggedOut()) - dashboard.sessionDialog(Bundle.EMPTY); - else if(user_session_status.inProgress()) - cancelLoginOrSignup(); - } - - @Override - public void update(Observable observable, Object data) { - if (observable instanceof UserSessionStatus) { - UserSessionStatus status = (UserSessionStatus) observable; - handleNewUserSessionStatus(status); - } - } - - private void handleNewUserSessionStatus(UserSessionStatus status) { - user_session_status = status; - if (allows_registration) { - if (user_session_status.inProgress()) - showUserSessionProgressBar(); - else - hideUserSessionProgressBar(); - changeMessage(); - updateButton(); - } - } - - private void showUserSessionProgressBar() { - dashboard.runOnUiThread(new Runnable() { - @Override - public void run() { - user_session_status_progress_bar.setVisibility(ProgressBar.VISIBLE); - } - }); - } - - private void hideUserSessionProgressBar() { - dashboard.runOnUiThread(new Runnable() { - @Override - public void run() { - user_session_status_progress_bar.setVisibility(ProgressBar.GONE); - } - }); - } - - 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); - } - }); - } - - 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)); - } - }); - } - - - @Override - public void signUp(String username, String password) { - User.setUserName(username); - Bundle parameters = bundlePassword(password); - ProviderAPICommand.execute(parameters, ProviderAPI.SIGN_UP, providerAPI_result_receiver); - } - - @Override - public void logIn(String username, String password) { - User.setUserName(username); - Bundle parameters = bundlePassword(password); - ProviderAPICommand.execute(parameters, ProviderAPI.LOG_IN, providerAPI_result_receiver); - } - - public void logOut() { - ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.LOG_OUT, providerAPI_result_receiver); - } - - public void cancelLoginOrSignup() { - EipStatus.getInstance().setConnectedOrDisconnected(); - } - - private Bundle bundlePassword(String password) { - Bundle parameters = new Bundle(); - if (!password.isEmpty()) - parameters.putString(SessionDialog.PASSWORD, password); - return parameters; - } -} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java deleted file mode 100644 index dec0e719..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserSessionStatus.java +++ /dev/null @@ -1,119 +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 . - */ -package se.leap.bitmaskclient.userstatus; - -import android.content.res.*; - -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; - private static Resources resources; - - public enum SessionStatus { - LOGGED_IN, - LOGGED_OUT, - NOT_LOGGED_IN, - DIDNT_LOG_OUT, - LOGGING_IN, - LOGGING_OUT, - SIGNING_UP; - - @Override - public String toString() { - int id = 0; - if(this == SessionStatus.LOGGED_IN) - id = R.string.logged_in_user_status; - else if(this == SessionStatus.LOGGED_OUT) - id = R.string.logged_out_user_status; - else if(this == SessionStatus.NOT_LOGGED_IN) - id = R.string.not_logged_in_user_status; - else if(this == SessionStatus.DIDNT_LOG_OUT) - id = R.string.didnt_log_out_user_status; - else if(this == SessionStatus.LOGGING_IN) - id = R.string.logging_in_user_status; - else if(this == SessionStatus.LOGGING_OUT) - id = R.string.logging_out_user_status; - else if(this == SessionStatus.SIGNING_UP) - id = R.string.signingup_message; - - return resources.getString(id); - } - } - - private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN; - - public static UserSessionStatus getInstance(Resources resources) { - if (current_status == null) { - current_status = new UserSessionStatus(resources); - } - return current_status; - } - - private UserSessionStatus(Resources resources) { - UserSessionStatus.resources = resources; - } - - private void sessionStatus(SessionStatus session_status) { - this.session_status = session_status; - } - - public SessionStatus sessionStatus() { - return session_status; - } - - public boolean inProgress() { - return session_status == SessionStatus.LOGGING_IN - || session_status == SessionStatus.LOGGING_OUT; - } - - public boolean isLoggedIn() { - return session_status == SessionStatus.LOGGING_IN; - } - - public boolean isLoggedOut() { - return session_status == SessionStatus.LOGGED_OUT; - } - - public static void updateStatus(SessionStatus session_status, Resources resources) { - current_status = getInstance(resources); - current_status.sessionStatus(session_status); - current_status.setChanged(); - current_status.notifyObservers(); - } - - @Override - public String toString() { - String user_session_status = User.userName(); - - String default_username = resources.getString(R.string.default_user, ""); - if(user_session_status.isEmpty() && !default_username.equalsIgnoreCase("null")) user_session_status = default_username; - user_session_status += " " + session_status.toString(); - - user_session_status = user_session_status.trim(); - if(User.userName().isEmpty()) - user_session_status = capitalize(user_session_status); - return user_session_status; - } - - private String capitalize(String to_be_capitalized) { - return to_be_capitalized.substring(0,1).toUpperCase() + to_be_capitalized.substring(1); - } -} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java new file mode 100644 index 00000000..edfed8d6 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java @@ -0,0 +1,119 @@ +/** + * 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 . + */ +package se.leap.bitmaskclient.userstatus; + +import android.content.res.*; + +import java.util.*; + +import se.leap.bitmaskclient.R; + +public class UserStatus extends Observable { + public static String TAG = UserStatus.class.getSimpleName(); + private static UserStatus current_status; + private static Resources resources; + + public enum SessionStatus { + LOGGED_IN, + LOGGED_OUT, + NOT_LOGGED_IN, + DIDNT_LOG_OUT, + LOGGING_IN, + LOGGING_OUT, + SIGNING_UP; + + @Override + public String toString() { + int id = 0; + if(this == SessionStatus.LOGGED_IN) + id = R.string.logged_in_user_status; + else if(this == SessionStatus.LOGGED_OUT) + id = R.string.logged_out_user_status; + else if(this == SessionStatus.NOT_LOGGED_IN) + id = R.string.not_logged_in_user_status; + else if(this == SessionStatus.DIDNT_LOG_OUT) + id = R.string.didnt_log_out_user_status; + else if(this == SessionStatus.LOGGING_IN) + id = R.string.logging_in_user_status; + else if(this == SessionStatus.LOGGING_OUT) + id = R.string.logging_out_user_status; + else if(this == SessionStatus.SIGNING_UP) + id = R.string.signingup_message; + + return resources.getString(id); + } + } + + private static SessionStatus session_status = SessionStatus.LOGGED_OUT; + + public static UserStatus getInstance(Resources resources) { + if (current_status == null) { + current_status = new UserStatus(resources); + } + return current_status; + } + + private UserStatus(Resources resources) { + UserStatus.resources = resources; + } + + private void sessionStatus(SessionStatus session_status) { + this.session_status = session_status; + } + + public SessionStatus sessionStatus() { + return session_status; + } + + public boolean inProgress() { + return session_status == SessionStatus.LOGGING_IN + || session_status == SessionStatus.LOGGING_OUT; + } + + public boolean isLoggedIn() { + return session_status == SessionStatus.LOGGED_IN; + } + + public boolean isLoggedOut() { + return session_status == SessionStatus.LOGGED_OUT; + } + + public static void updateStatus(SessionStatus session_status, Resources resources) { + current_status = getInstance(resources); + current_status.sessionStatus(session_status); + current_status.setChanged(); + current_status.notifyObservers(); + } + + @Override + public String toString() { + String user_session_status = User.userName(); + + 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(); + + user_session_status = user_session_status.trim(); + if(User.userName().isEmpty()) + user_session_status = capitalize(user_session_status); + return user_session_status; + } + + private String capitalize(String to_be_capitalized) { + return to_be_capitalized.substring(0,1).toUpperCase() + to_be_capitalized.substring(1); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java new file mode 100644 index 00000000..0766dbd5 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -0,0 +1,178 @@ +package se.leap.bitmaskclient.userstatus; + +import android.app.*; +import android.os.*; +import android.view.*; +import android.widget.*; + +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 UserStatusFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface { + + public static String TAG = UserStatusFragment.class.getSimpleName(); + private static Dashboard dashboard; + private ProviderAPIResultReceiver providerAPI_result_receiver; + + @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 UserStatus status; + private boolean allows_registration = false; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + status = UserStatus.getInstance(getResources()); + status.addObserver(this); + } + + @Override + public void onSaveInstanceState(@NotNull Bundle outState) { + if (username != null && username.getVisibility() == TextView.VISIBLE) + outState.putSerializable(UserStatus.TAG, status.sessionStatus()); + + super.onSaveInstanceState(outState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + 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); + handleNewStatus(status); + + return view; + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + Fragment fragment = (getFragmentManager().findFragmentById(R.id.user_status_fragment)); + FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction(); + ft.remove(fragment); + ft.commit(); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + dashboard = (Dashboard) activity; + + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); + } + + public void restoreSessionStatus(Bundle savedInstanceState) { + if (savedInstanceState != null) + if (savedInstanceState.containsKey(UserStatus.TAG)) { + UserStatus.SessionStatus status = (UserStatus.SessionStatus) savedInstanceState.getSerializable(UserStatus.TAG); + this.status.updateStatus(status, getResources()); + } + } + + @OnClick(R.id.user_status_button) + public void handleButton() { + android.util.Log.d(TAG, status.toString()); + if(status.isLoggedIn()) + logOut(); + else if(status.isLoggedOut()) + dashboard.sessionDialog(Bundle.EMPTY); + else if(status.inProgress()) + cancelLoginOrSignup(); + } + + @Override + public void update(Observable observable, Object data) { + if (observable instanceof UserStatus) { + final UserStatus status = (UserStatus) observable; + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + handleNewStatus(status); + } + }); + } + } + + private void handleNewStatus(UserStatus status) { + this.status = status; + if (allows_registration) { + if (this.status.inProgress()) + showUserSessionProgressBar(); + else + hideUserSessionProgressBar(); + changeMessage(); + updateButton(); + } + } + + private void showUserSessionProgressBar() { + icon.showProgress(true); + } + + private void hideUserSessionProgressBar() { + icon.showProgress(false); + } + + private void changeMessage() { + final String message = User.userName(); + username.setText(message); + } + + private void updateButton() { + 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)); + } + } + + + @Override + public void signUp(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.SIGN_UP, providerAPI_result_receiver); + } + + @Override + public void logIn(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.LOG_IN, providerAPI_result_receiver); + } + + public void logOut() { + android.util.Log.d(TAG, "Log out"); + ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.LOG_OUT, providerAPI_result_receiver); + } + + public void cancelLoginOrSignup() { + EipStatus.getInstance().setConnectedOrDisconnected(); + } + + private Bundle bundlePassword(String password) { + Bundle parameters = new Bundle(); + if (!password.isEmpty()) + parameters.putString(SessionDialog.PASSWORD, password); + return parameters; + } +} -- cgit v1.2.3 From 436de7afeea2cd234db8a4b70ace396101126e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 30 Apr 2015 19:09:31 +0200 Subject: Better layout, xlarge adaptation too. --- .../se/leap/bitmaskclient/userstatus/UserStatusFragment.java | 9 --------- 1 file changed, 9 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index 0766dbd5..f0f4a8fa 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -60,15 +60,6 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia return view; } - @Override - public void onDestroyView() { - super.onDestroyView(); - Fragment fragment = (getFragmentManager().findFragmentById(R.id.user_status_fragment)); - FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction(); - ft.remove(fragment); - ft.commit(); - } - @Override public void onAttach(Activity activity) { super.onAttach(activity); -- cgit v1.2.3 From 5cc63073c78f0792ea462f0c2119ce5d361e9c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 1 May 2015 11:25:40 +0200 Subject: Separated tests for VpnFragment. --- app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') 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 f89418ba..7dbbe059 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java @@ -23,7 +23,7 @@ import android.view.*; import android.widget.*; import butterknife.*; -import se.leap.bitmaskclient.EipFragment; +import se.leap.bitmaskclient.VpnFragment; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.R; @@ -113,7 +113,7 @@ public class SessionDialog extends DialogFragment { } private void setUp(Bundle arguments) { - is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); + is_eip_pending = arguments.getBoolean(VpnFragment.IS_PENDING, false); if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) password_field.setError(getString(R.string.error_not_valid_password_user_message)); else if (arguments.containsKey(ERRORS.RISEUP_WARNING.toString())) { -- cgit v1.2.3 From 6d2e86277cdf02d3c731d963656e2c4a0f8fea5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 5 May 2015 11:28:01 +0200 Subject: Rename user session fragment, add icon resource. The FabButton doesn't scale the icon as big as I want it to be, and it doesn't let me set the size to "wrap_content" because the library sets the sizes to match_parent. I'm going to try to modify my fork of FabButton to see if I can obtain what I want in its demo: just an icon and the progress indicator, the icon as big as possible. --- .../java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index f0f4a8fa..ed822116 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -50,9 +50,11 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_user_session, container, false); + View view = inflater.inflate(R.layout.user_session_fragment, container, false); ButterKnife.inject(this, view); + icon.setIcon(R.drawable.ic_account_circle, R.drawable.ic_account_circle); + Bundle arguments = getArguments(); allows_registration = arguments.getBoolean(Provider.ALLOW_REGISTRATION); handleNewStatus(status); -- cgit v1.2.3 From de63a99c74bb05c271b0c7a5903b6bfab9ec0a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 29 May 2015 10:33:51 +0200 Subject: Updated libraries, simplified user status fragment Updated butterknife, dagger, renderers, fabbuton and gson, as well as gradle plugin. --- .../leap/bitmaskclient/userstatus/FabButton.java | 34 ++++++++++++++++++++++ .../userstatus/UserStatusFragment.java | 32 +++++++++++++------- 2 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java new file mode 100644 index 00000000..1bf1847c --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java @@ -0,0 +1,34 @@ +package se.leap.bitmaskclient.userstatus; + + +import android.content.Context; +import android.util.AttributeSet; + +import mbanje.kurt.fabbutton.CircleImageView; +import se.leap.bitmaskclient.R; + +public class FabButton extends mbanje.kurt.fabbutton.FabButton { + + + public FabButton(Context context) { + super(context); + } + + public FabButton(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FabButton(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + protected void init(Context context, AttributeSet attrs, int defStyle) { + super.init(context, attrs, defStyle); + super.init(context, attrs, defStyle); + } + + private CircleImageView getImage() { + return (CircleImageView) findViewById(R.id.fabbutton_circle); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index ed822116..f670553f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -1,17 +1,29 @@ package se.leap.bitmaskclient.userstatus; -import android.app.*; -import android.os.*; -import android.view.*; -import android.widget.*; +import android.app.Activity; +import android.app.Fragment; +import android.os.Bundle; +import android.os.Handler; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; import org.jetbrains.annotations.NotNull; -import java.util.*; - -import butterknife.*; -import mbanje.kurt.fabbutton.FabButton; -import se.leap.bitmaskclient.*; +import java.util.Observable; +import java.util.Observer; + +import butterknife.ButterKnife; +import butterknife.InjectView; +import butterknife.OnClick; +import se.leap.bitmaskclient.Dashboard; +import se.leap.bitmaskclient.Provider; +import se.leap.bitmaskclient.ProviderAPI; +import se.leap.bitmaskclient.ProviderAPICommand; +import se.leap.bitmaskclient.ProviderAPIResultReceiver; +import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.eip.EipStatus; public class UserStatusFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface { @@ -53,8 +65,6 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia View view = inflater.inflate(R.layout.user_session_fragment, container, false); ButterKnife.inject(this, view); - icon.setIcon(R.drawable.ic_account_circle, R.drawable.ic_account_circle); - Bundle arguments = getArguments(); allows_registration = arguments.getBoolean(Provider.ALLOW_REGISTRATION); handleNewStatus(status); -- cgit v1.2.3 From 47e0180aaaaa5ba2cd921ebd28221ab27fd51b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 1 Jun 2015 11:15:40 +0200 Subject: Update user session button correctly on failure --- .../main/java/se/leap/bitmaskclient/userstatus/UserStatus.java | 8 ++++++++ .../java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java index edfed8d6..90ad0ffd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java @@ -92,6 +92,14 @@ public class UserStatus extends Observable { return session_status == SessionStatus.LOGGED_OUT; } + public boolean notLoggedIn() { + return session_status == SessionStatus.NOT_LOGGED_IN; + } + + public boolean didntLogOut() { + return session_status == SessionStatus.DIDNT_LOG_OUT; + } + public static void updateStatus(SessionStatus session_status, Resources resources) { current_status = getInstance(resources); current_status.sessionStatus(session_status); diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index f670553f..20189904 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -138,10 +138,10 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia } private void updateButton() { - if(status.isLoggedIn()) + if(status.isLoggedIn() || status.didntLogOut()) button.setText(dashboard.getString(R.string.logout_button)); else if(allows_registration) { - if (status.isLoggedOut()) + if (status.isLoggedOut() || status.notLoggedIn()) button.setText(dashboard.getString(R.string.login_button)); else if (status.inProgress()) button.setText(dashboard.getString(android.R.string.cancel)); -- cgit v1.2.3 From d1c6e3c1756cee8104a98718b70e2f3169d24a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 12 Jun 2015 17:01:35 +0200 Subject: Transparent background of the FabButton, yay! --- app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java | 6 ------ 1 file changed, 6 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/userstatus') diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java index 1bf1847c..d1c56dee 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/FabButton.java @@ -22,12 +22,6 @@ public class FabButton extends mbanje.kurt.fabbutton.FabButton { super(context, attrs, defStyle); } - @Override - protected void init(Context context, AttributeSet attrs, int defStyle) { - super.init(context, attrs, defStyle); - super.init(context, attrs, defStyle); - } - private CircleImageView getImage() { return (CircleImageView) findViewById(R.id.fabbutton_circle); } -- cgit v1.2.3