From 73c87d7b85afce79ed93253f7be58774624669e8 Mon Sep 17 00:00:00 2001 From: kenstir Date: Mon, 23 Nov 2015 21:38:47 -0500 Subject: [PATCH] Improved UX of brand new user. * In main menu, dynamically invalidate options menu when adding an account. * In auth activity, default to library of first existing account. If there are no existing accounts, then default to closest library by course GPS. --- Open-ILS/src/Android/core/AndroidManifest.xml | 3 +- .../evergreen_ils/accountAccess/AccountUtils.java | 8 +- .../evergreen_ils/auth/AuthenticatorActivity.java | 94 +++++++++++----- .../org/evergreen_ils/searchCatalog/Library.java | 12 +- .../src/org/evergreen_ils/views/MainActivity.java | 1 + .../views/splashscreen/LoadingTask.java | 4 +- .../src/Android/cwmars_app/AndroidManifest.xml | 2 +- Open-ILS/src/Android/cwmars_app/res/values/ou.xml | 2 +- Open-ILS/src/Android/demo_app/AndroidManifest.xml | 2 +- Open-ILS/src/Android/eg_app/AndroidManifest.xml | 3 +- .../src/Android/hemlock_app/.idea/uiDesigner.xml | 124 +++++++++++++++++++++ .../src/Android/hemlock_app/AndroidManifest.xml | 3 +- 12 files changed, 219 insertions(+), 39 deletions(-) create mode 100644 Open-ILS/src/Android/hemlock_app/.idea/uiDesigner.xml diff --git a/Open-ILS/src/Android/core/AndroidManifest.xml b/Open-ILS/src/Android/core/AndroidManifest.xml index a0d21ad188..333108579c 100644 --- a/Open-ILS/src/Android/core/AndroidManifest.xml +++ b/Open-ILS/src/Android/core/AndroidManifest.xml @@ -8,9 +8,10 @@ android:versionName="1.0" > + diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountUtils.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountUtils.java index 0bce6c07d8..8a3e88cd7f 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountUtils.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountUtils.java @@ -18,7 +18,7 @@ import java.io.IOException; */ public class AccountUtils { - public static Library getLibrary(Activity activity, String account_name, String account_type) { + public static Library getLibraryForAccount(Activity activity, String account_name, String account_type) { final AccountManager am = AccountManager.get(activity); Account account = new Account(account_name, account_type); String library_url = am.getUserData(account, Const.KEY_LIBRARY_URL); @@ -36,7 +36,11 @@ public class AccountUtils { library_name = activity.getString(R.string.ou_library_name); } - return new Library(library_url, library_name, null); + return new Library(library_url, library_name); + } + + public static Library getLibraryForAccount(Activity activity, Account account) { + return getLibraryForAccount(activity, account.name, account.type); } public static void invalidateAuthToken(Activity activity, String auth_token) { diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java index 0f391911d6..8b2d276287 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java @@ -2,6 +2,8 @@ package org.evergreen_ils.auth; import android.content.Context; import android.content.pm.ApplicationInfo; +import android.location.Location; +import android.location.LocationManager; import android.text.TextUtils; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -20,6 +22,7 @@ import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; +import org.evergreen_ils.accountAccess.AccountUtils; import org.evergreen_ils.globals.AppPrefs; import org.evergreen_ils.globals.Utils; import org.evergreen_ils.searchCatalog.Library; @@ -57,8 +60,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { String url = params[0]; String result = null; try { - Log.d(TAG, "fetching "+url); + Log.d(TAG, "fetching " + url); result = Utils.getNetPageContent(url); + //todo move json parsing to doInBackground } catch (Exception e) { Log.d(TAG, "error fetching", e); } @@ -66,14 +70,48 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { } protected void onPostExecute(String result) { - Log.d(TAG, "results available: "+result); + Log.d(TAG, "results available: " + result); + + // parse the response parseLibrariesJSON(result); + + // if the user has any existing accounts, then we can select a reasonable default library + Library default_library = null; + Location last_location = null; + Account[] existing_accounts = AccountUtils.getAccountsByType(AuthenticatorActivity.this); + Log.d(Const.AUTH_TAG, "there are " + existing_accounts.length + " existing accounts"); + if (existing_accounts.length > 0) { + default_library = AccountUtils.getLibraryForAccount(AuthenticatorActivity.this, existing_accounts[0]); + Log.d(Const.AUTH_TAG, "default_library=" + default_library); + } else { + LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + if (lm != null) last_location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + } + + // Build a List for use in the spinner adapter + // While we're at it choose a default library; first by prior account, second by proximity + Integer default_library_index = null; + float min_distance = Float.MAX_VALUE; ArrayList l = new ArrayList(libraries.size()); for (Library library : libraries) { + if (default_library != null && TextUtils.equals(default_library.url, library.url)) { + default_library_index = l.size(); + } else if (last_location != null && library.location != null) { + float distance = last_location.distanceTo(library.location); + if (distance < min_distance) { + default_library_index = l.size(); + min_distance = distance; + } + } l.add(library.directory_name); } ArrayAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, l); librarySpinner.setAdapter(adapter); + if (default_library_index != null) { + librarySpinner.setSelection(default_library_index); + } else { + librarySpinner.setSelected(false); + } } } @@ -95,11 +133,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { libraries_directory_json_url = getString(R.string.evergreen_libraries_url); String accountName = getIntent().getStringExtra(ARG_ACCOUNT_NAME); - Log.d(TAG, "onCreate> accountName="+accountName); + Log.d(TAG, "onCreate> accountName=" + accountName); authTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE); if (authTokenType == null) authTokenType = Const.AUTHTOKEN_TYPE; - Log.d(TAG, "onCreate> authTokenType="+authTokenType); + Log.d(TAG, "onCreate> authTokenType=" + authTokenType); if (isGenericApp()) { librarySpinner = (Spinner) findViewById(R.id.choose_library_spinner); @@ -115,8 +153,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { } }); } else { - selected_library = new Library(getString(R.string.ou_library_url), - getString(R.string.ou_library_name), null); + selected_library = new Library(getString(R.string.ou_library_url), getString(R.string.ou_library_name)); } TextView signInText = (TextView) findViewById(R.id.account_sign_in_text); @@ -135,7 +172,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { }); if (savedInstanceState != null) { - Log.d(TAG, "onCreate> savedInstanceState="+savedInstanceState); + Log.d(TAG, "onCreate> savedInstanceState=" + savedInstanceState); if (savedInstanceState.getString(STATE_ALERT_MESSAGE) != null) { showAlert(savedInstanceState.getString(STATE_ALERT_MESSAGE)); } @@ -170,7 +207,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - Log.d(TAG, "onActivityResult> requestCode="+requestCode+" resultCode="+resultCode); + Log.d(TAG, "onActivityResult> requestCode=" + requestCode + " resultCode=" + resultCode); // The sign up activity returned that the user has successfully created // an account if (requestCode == REQ_SIGNUP && resultCode == RESULT_OK) { @@ -199,20 +236,20 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { Bundle data = new Bundle(); try { authtoken = EvergreenAuthenticator.signIn(selected_library.url, username, password); - Log.d(TAG, "task> signIn returned "+authtoken); + Log.d(TAG, "task> signIn returned " + authtoken); data.putString(AccountManager.KEY_ACCOUNT_NAME, username); data.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType); data.putString(AccountManager.KEY_AUTHTOKEN, authtoken); data.putString(PARAM_USER_PASS, password); - data.putString(Const.KEY_LIBRARY_NAME, selected_library.short_name); + data.putString(Const.KEY_LIBRARY_NAME, selected_library.name); data.putString(Const.KEY_LIBRARY_URL, selected_library.url); } catch (AuthenticationException e) { if (e != null) errorMessage = e.getMessage(); - Log.d(TAG, "task> signIn caught auth exception "+errorMessage); + Log.d(TAG, "task> signIn caught auth exception " + errorMessage); } catch (Exception e2) { if (e2 != null) errorMessage = e2.getMessage(); - Log.d(TAG, "task> signIn caught other exception "+errorMessage); + Log.d(TAG, "task> signIn caught other exception " + errorMessage); } if (authtoken == null) data.putString(KEY_ERROR_MESSAGE, errorMessage); @@ -225,9 +262,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { @Override protected void onPostExecute(Intent intent) { task = null; - Log.d(TAG, "task.onPostExecute> intent="+intent); + Log.d(TAG, "task.onPostExecute> intent=" + intent); if (intent.hasExtra(KEY_ERROR_MESSAGE)) { - Log.d(TAG, "task.onPostExecute> error msg: "+intent.getStringExtra(KEY_ERROR_MESSAGE)); + Log.d(TAG, "task.onPostExecute> error msg: " + intent.getStringExtra(KEY_ERROR_MESSAGE)); onAuthFailure(intent.getStringExtra(KEY_ERROR_MESSAGE)); } else { Log.d(TAG, "task.onPostExecute> no error msg"); @@ -240,7 +277,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { protected void onAuthFailure(String errorMessage) { showAlert(errorMessage); } - + protected void showAlert(String errorMessage) { AlertDialog.Builder builder = new AlertDialog.Builder(this); alertMessage = errorMessage; @@ -264,10 +301,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { String library_name = intent.getStringExtra(Const.KEY_LIBRARY_NAME); String library_url = intent.getStringExtra(Const.KEY_LIBRARY_URL); final Account account = new Account(accountName, accountType); - Log.d(TAG, "onAuthSuccess> accountName="+accountName); + Log.d(TAG, "onAuthSuccess> accountName=" + accountName); //if (getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) - Log.d(TAG, "onAuthSuccess> addAccountExplicitly "+accountName); + Log.d(TAG, "onAuthSuccess> addAccountExplicitly " + accountName); String authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN); String authtokenType = authTokenType; @@ -279,7 +316,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { userdata.putString(Const.KEY_LIBRARY_URL, library_url); } if (accountManager.addAccountExplicitly(account, accountPassword, userdata)) { - Log.d(TAG, "onAuthSuccess> true, setAuthToken "+authtoken); + Log.d(TAG, "onAuthSuccess> true, setAuthToken " + authtoken); // Not setting the auth token will cause another call to the server // to authenticate the user accountManager.setAuthToken(account, authtokenType, authtoken); @@ -302,15 +339,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { libraries.clear(); if (isDebuggable()) { - Library library = new Library("https://demo.evergreencatalog.com", "evergreencatalog.com Demo", "0ut There, US (evergreencatalog.com Demo)"); - //Library library = new Library("http://mlnc4.mvlcstaff.org", "MVLC Demo", "0ut There, US (MVLC Demo)");// SSL not working + Library library = new Library("https://demo.evergreencatalog.com", "evergreencatalog.com Demo", "0ut There, US (evergreencatalog.com Demo)", null); + //Library library = new Library("http://mlnc4.mvlcstaff.org", "MVLC Demo", "0ut There, US (MVLC Demo)", null);// SSL not working libraries.add(library); } if (json != null) { - List> l; + List> l; try { - l = (List>) new JSONReader(json).readArray(); + l = (List>) new JSONReader(json).readArray(); } catch (JSONException e) { Log.d(TAG, "failed parsing libraries array", e); return; @@ -319,7 +356,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { String url = (String) map.get("url"); String directory_name = (String) map.get("directory_name"); String short_name = (String) map.get("short_name"); - Library library = new Library(url, short_name, directory_name); + Double latitude = (Double) map.get("latitude"); + Double longitude= (Double) map.get("longitude"); + Location location = new Location(""); + location.setLatitude(latitude); + location.setLongitude(longitude); + Library library = new Library(url, short_name, directory_name, location); libraries.add(library); } @@ -330,13 +372,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { } }); - for (int i = 0; i< libraries.size(); ++i) { - Log.d(TAG, "c["+i+"]: "+ libraries.get(i).directory_name); + for (int i = 0; i < libraries.size(); ++i) { + Log.d(TAG, "c[" + i + "]: " + libraries.get(i).directory_name); } } } public boolean isDebuggable() { - return ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) ); + return (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)); } } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/Library.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/Library.java index ef0f5a9cbe..648f0af21e 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/Library.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/Library.java @@ -1,5 +1,6 @@ package org.evergreen_ils.searchCatalog; +import android.location.Location; import android.text.TextUtils; /** value class @@ -7,11 +8,16 @@ import android.text.TextUtils; */ public class Library { public String url; // e.g. "https://catalog.cwmars.org" - public String short_name; // e.g. "C/W MARS" + public String name; // e.g. "C/W MARS" public String directory_name; // e.g. "Massachusetts, US (C/W MARS)" - public Library(String url, String short_name, String directory_name) { + public Location location; + public Library(String url, String name, String directory_name, Location location) { this.url = url; - this.short_name = short_name; + this.name = name; this.directory_name = directory_name; + this.location = location; + } + public Library(String url, String name) { + this(url, name, null, null); } } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/MainActivity.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/MainActivity.java index bc32116901..a7bf6cc248 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/MainActivity.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/MainActivity.java @@ -69,6 +69,7 @@ public class MainActivity extends ActionBarActivity { SplashActivity.restartApp(this); return true; } else if (id == R.id.action_add_account) { + invalidateOptionsMenu(); AccountUtils.addAccount(this, new Runnable() { @Override public void run() { diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java index 17e97ed95e..1e775095a1 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java @@ -100,8 +100,8 @@ public class LoadingTask { if (TextUtils.isEmpty(auth_token) || TextUtils.isEmpty(account_name)) return "no account"; - Library library = AccountUtils.getLibrary(mCallingActivity, account_name, accountType); - AppPrefs.setString(AppPrefs.LIBRARY_NAME, library.short_name); + Library library = AccountUtils.getLibraryForAccount(mCallingActivity, account_name, accountType); + AppPrefs.setString(AppPrefs.LIBRARY_NAME, library.name); AppPrefs.setString(AppPrefs.LIBRARY_URL, library.url); Log.d(TAG, tag+"Loading resources from "+library.url); diff --git a/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml b/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml index c6add355c5..248b32221e 100644 --- a/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml +++ b/Open-ILS/src/Android/cwmars_app/AndroidManifest.xml @@ -6,7 +6,7 @@ android:versionName="1.5"> diff --git a/Open-ILS/src/Android/cwmars_app/res/values/ou.xml b/Open-ILS/src/Android/cwmars_app/res/values/ou.xml index 8d28930acb..2d72fcf4d3 100644 --- a/Open-ILS/src/Android/cwmars_app/res/values/ou.xml +++ b/Open-ILS/src/Android/cwmars_app/res/values/ou.xml @@ -10,5 +10,5 @@ C/W MARS C/W MARS %2$s - https://bark.cwmars.org + https://catalog.cwmars.org diff --git a/Open-ILS/src/Android/demo_app/AndroidManifest.xml b/Open-ILS/src/Android/demo_app/AndroidManifest.xml index d497a19b87..54d58dec09 100644 --- a/Open-ILS/src/Android/demo_app/AndroidManifest.xml +++ b/Open-ILS/src/Android/demo_app/AndroidManifest.xml @@ -6,7 +6,7 @@ android:versionName="1.0"> diff --git a/Open-ILS/src/Android/eg_app/AndroidManifest.xml b/Open-ILS/src/Android/eg_app/AndroidManifest.xml index f5247e2c6d..8098bc6c8c 100644 --- a/Open-ILS/src/Android/eg_app/AndroidManifest.xml +++ b/Open-ILS/src/Android/eg_app/AndroidManifest.xml @@ -6,9 +6,10 @@ android:versionName="1.0"> + diff --git a/Open-ILS/src/Android/hemlock_app/.idea/uiDesigner.xml b/Open-ILS/src/Android/hemlock_app/.idea/uiDesigner.xml new file mode 100644 index 0000000000..e96534fb27 --- /dev/null +++ b/Open-ILS/src/Android/hemlock_app/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Open-ILS/src/Android/hemlock_app/AndroidManifest.xml b/Open-ILS/src/Android/hemlock_app/AndroidManifest.xml index 9b332cf868..6ee5a6e1e5 100644 --- a/Open-ILS/src/Android/hemlock_app/AndroidManifest.xml +++ b/Open-ILS/src/Android/hemlock_app/AndroidManifest.xml @@ -2,13 +2,14 @@ + -- 2.11.0