summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SessionDialog.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/User.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java60
5 files changed, 51 insertions, 28 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index ee64a1b3..4207872d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -78,7 +78,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
super.onCreate(savedInstanceState);
app = this;
- user_session_status = UserSessionStatus.getInstance();
+ user_session_status = UserSessionStatus.getInstance(getResources());
user_session_status.addObserver(this);
PRNGFixes.apply();
@@ -86,6 +86,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
+ User.init();
restoreProvider(savedInstanceState);
if (provider == null || provider.getName().isEmpty())
@@ -109,7 +110,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
if (savedInstanceState != null)
if (savedInstanceState.containsKey(UserSessionStatus.TAG)) {
UserSessionStatus.SessionStatus status = (UserSessionStatus.SessionStatus) savedInstanceState.getSerializable(UserSessionStatus.TAG);
- user_session_status.updateStatus(status);
+ user_session_status.updateStatus(status, getResources());
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java
index b961350e..1ced6d60 100644
--- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java
+++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java
@@ -42,7 +42,6 @@ public class LeapSRPSession {
final public static String AUTHORIZATION_HEADER = "Authorization";
final public static String TAG = "Leap SRP session class tag";
- private User user;
private SRPParameters params;
private String username;
private String password;
diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
index e92c6b7b..30344ff2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
@@ -114,9 +114,10 @@ public class SessionDialog extends DialogFragment {
if (arguments.containsKey(ERRORS.USERNAME_MISSING.toString())) {
username_field.setError(getString(R.string.username_ask));
}
- if (arguments.containsKey(getString(R.string.user_message)))
+ if (arguments.containsKey(getString(R.string.user_message))) {
user_message.setText(arguments.getString(getString(R.string.user_message)));
- else if (user_message.getVisibility() != TextView.VISIBLE)
+ 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())
diff --git a/app/src/main/java/se/leap/bitmaskclient/User.java b/app/src/main/java/se/leap/bitmaskclient/User.java
index 4bbd9a91..f3d3b8b1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/User.java
+++ b/app/src/main/java/se/leap/bitmaskclient/User.java
@@ -17,10 +17,11 @@
package se.leap.bitmaskclient;
public class User {
- private static String user_name = "You";
+ private static String user_name = "";
private static User user;
+ public static int DEFAULT_CONJUGATION_PERSON = 1;
- public static User getInstance() {
+ public static User init() {
if (user == null) {
user = new User();
}
@@ -31,8 +32,7 @@ public class User {
User.user_name = user_name;
}
- private User() {
- }
+ private User() { }
public static String userName() {
return user_name;
diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java
index e43c8a25..28c7ecc7 100644
--- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java
@@ -16,13 +16,14 @@
*/
package se.leap.bitmaskclient;
-import android.os.*;
+import android.content.res.*;
import java.util.*;
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,
@@ -31,19 +32,41 @@ public class UserSessionStatus extends Observable {
DIDNT_LOG_OUT,
LOGGING_IN,
LOGGING_OUT,
- SIGNING_UP
+ 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() {
+ public static UserSessionStatus getInstance(Resources resources) {
if (current_status == null) {
- current_status = new UserSessionStatus();
+ current_status = new UserSessionStatus(resources);
}
return current_status;
}
- private UserSessionStatus() {
+ private UserSessionStatus(Resources resources) {
+ UserSessionStatus.resources = resources;
}
private void sessionStatus(SessionStatus session_status) {
@@ -59,8 +82,8 @@ public class UserSessionStatus extends Observable {
|| session_status == SessionStatus.LOGGING_OUT;
}
- public static void updateStatus(SessionStatus session_status) {
- current_status = getInstance();
+ public static void updateStatus(SessionStatus session_status, Resources resources) {
+ current_status = getInstance(resources);
current_status.sessionStatus(session_status);
current_status.setChanged();
current_status.notifyObservers();
@@ -68,20 +91,19 @@ public class UserSessionStatus extends Observable {
@Override
public String toString() {
- String username = User.userName();
+ String user_session_status = User.userName();
- return username + " " + conjugateToBe(username) + " "
- + session_status.toString().toLowerCase().replaceAll("_", " ");
- }
+ 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();
- private String conjugateToBe(String subject) {
- String conjugation = "";
- if(subject.equalsIgnoreCase("I"))
- conjugation = "am";
- else if(subject.equalsIgnoreCase("you") || subject.equalsIgnoreCase("we")|| subject.equalsIgnoreCase("they"))
- conjugation = "are";
- else conjugation = "is";
+ user_session_status = user_session_status.trim();
+ if(User.userName().isEmpty())
+ user_session_status = capitalize(user_session_status);
+ return user_session_status;
+ }
- return conjugation;
+ private String capitalize(String to_be_capitalized) {
+ return to_be_capitalized.substring(0,1).toUpperCase() + to_be_capitalized.substring(1);
}
}