Fixed shared prefs login and MyAccount buttons
authordrizea <danielrizea27@gmail.com>
Sat, 9 Mar 2013 15:30:14 +0000 (17:30 +0200)
committerdrizea <danielrizea27@gmail.com>
Sat, 9 Mar 2013 15:30:14 +0000 (17:30 +0200)
Open-ILS/src/Android/AndroidManifest.xml
Open-ILS/src/Android/res/layout/activity_splash.xml
Open-ILS/src/Android/res/layout/dashbord_account.xml
Open-ILS/src/Android/src/org/evergreen/android/globals/Utils.java
Open-ILS/src/Android/src/org/evergreen/android/views/AccountScreenDashboard.java
Open-ILS/src/Android/src/org/evergreen/android/views/ConfigureApplicationActivity.java
Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/SplashActivity.java

index 987119c..c1dde69 100644 (file)
@@ -43,8 +43,7 @@
         <activity
             android:name=".views.splashscreen.SplashActivity"
             android:label="@string/app_name"
-            android:theme="@android:style/Theme.Light.NoTitleBar"
-            >
+            android:theme="@android:style/Theme.Light.NoTitleBar">
                <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
         <activity
             android:name=".views.MainScreenDashboard"
             android:label="@string/app_name"
-            android:theme="@android:style/Theme.Light.NoTitleBar"
-             >
+            android:theme="@android:style/Theme.Light.NoTitleBar">
         </activity>
         
         <activity android:name=".views.AccountScreenDashboard"
-                       android:theme="@android:style/Theme.Light.NoTitleBar"
-            ></activity>
+                       android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
         
         <activity android:name="org.evergreen.android.views.ApplicationPreferences"></activity>
         
         <!-- First launch configuration activity -->
         <activity
-            android:name="org.evergreen.android.views.ConfigureApplicationActivity"
-            ></activity>
+            android:name="org.evergreen.android.views.ConfigureApplicationActivity"></activity>
             
         <!-- Search -->    
             
         <activity android:name=".searchCatalog.SampleUnderlinesNoFade"
-            android:label="Underlines/No Fade"
-            >
+            android:label="Underlines/No Fade">
         </activity>
                <activity android:name=".searchCatalog.MoreCopyInformation">
                </activity>
                <activity
             android:name=".searchCatalog.SearchCatalogListView"
-            android:label="@string/app_name"
-            >
+            android:label="@string/app_name">
         </activity>
         <activity 
             android:name=".searchCatalog.AdvancedSearchActivity">
index 46f20a4..b5d3088 100644 (file)
@@ -30,6 +30,7 @@
         <TextView 
         android:id="@+id/action_in_progress"
         android:layout_width="fill_parent"
+        android:gravity="center"
         android:layout_height="wrap_content"
         android:layout_below="@id/logo"
         android:paddingTop="10dip"
index 5d58de1..97ae3e8 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
-    android:layout_height="match_parent"
+    android:layout_height="fill_parent"
     android:orientation="vertical"
     android:background="@drawable/background_grey_image"
      >
@@ -66,7 +66,7 @@
     <LinearLayout
         android:orientation="horizontal"
         android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="fill_parent"
         android:gravity="center"
         android:layout_weight="1">
         <Button android:id="@+id/account_btn_fines"
index 76e25ad..07c7efa 100644 (file)
@@ -161,6 +161,9 @@ public class Utils {
 
         System.out.println("Network access " + networkAccessEnabled);
 
+        if (!networkAccessEnabled)
+            throw new NoNetworkAccessException();
+        
         if (networkAccessEnabled) {
             // check to see if httpAddress is avaialble using the network
             // connection
@@ -169,10 +172,6 @@ public class Utils {
             if (httpAddressAccessReachable == false)
                 throw new NoAccessToServer();
         }
-
-        if (!networkAccessEnabled)
-            throw new NoNetworkAccessException();
-
         return networkAccessEnabled;
 
     }
index 9cf7f2a..6fdf48d 100644 (file)
@@ -55,7 +55,6 @@ public class AccountScreenDashboard extends Activity {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.dashbord_account);
-
         myAccountButton = (Button) findViewById(R.id.my_account_button);
 
         myAccountButton.setOnClickListener(new OnClickListener() {
index 58885a6..1392e2c 100644 (file)
@@ -66,6 +66,13 @@ public class ConfigureApplicationActivity extends Activity {
         username = (EditText) findViewById(R.id.username);
         password = (EditText) findViewById(R.id.password);
 
+        
+        SharedPreferences preferences = PreferenceManager
+                .getDefaultSharedPreferences(context);
+        username.setText(preferences.getString("username", ""));
+        server_http.setText(preferences.getString("library_url", ""));  
+        password.setText(preferences.getString("password", ""));
+        
         Button connect = (Button) findViewById(R.id.connect_button);
 
         connect.setOnClickListener(new OnClickListener() {
@@ -89,7 +96,7 @@ public class ConfigureApplicationActivity extends Activity {
                         }
 
                         if (server_address == true) {
-
+                            
                             SharedPreferences preferences = PreferenceManager
                                     .getDefaultSharedPreferences(context);
                             SharedPreferences.Editor editor = preferences
@@ -97,7 +104,7 @@ public class ConfigureApplicationActivity extends Activity {
                             // store into preference
                             editor.putString("library_url", server_http
                                     .getText().toString());
-
+                            
                             editor.putString("username", username.getText()
                                     .toString());
                             editor.putString("password", password.getText()
index 006bce7..7b6a293 100644 (file)
@@ -30,8 +30,10 @@ import org.evergreen.android.views.ConfigureApplicationActivity;
 import org.evergreen.android.views.splashscreen.LoadingTask.LoadingTaskFinishedListener;
 
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.Service;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.net.ConnectivityManager;
@@ -50,7 +52,15 @@ public class SplashActivity extends Activity implements
     private ProgressBar progressBar;
 
     private String TAG = "SplashActivity";
-
+    
+    private AlertDialog alertDialog;
+    
+    
+    private static final int ABORT = 1;
+    private static final int ABORT_SERVER_PROBLEM = 2;
+    private static final int ABORT_NETWORK_CONN_PROLEM = 3;
+    private static final int OK = 0;
+    
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -63,39 +73,125 @@ public class SplashActivity extends Activity implements
         // Find the progress bar
         progressBar = (ProgressBar) findViewById(R.id.activity_splash_progress_bar);
 
-        boolean abort = false;
-
+        int abort = OK;
         SharedPreferences prefs = PreferenceManager
                 .getDefaultSharedPreferences(context);
         GlobalConfigs.httpAddress = prefs.getString("library_url", "");
         String username = prefs.getString("username", "username");
         String password = prefs.getString("password", "pas");
         AccountAccess.setAccountInfo(username, password);
-        try {
 
+        try {
             Utils.checkNetworkStatus((ConnectivityManager) getSystemService(Service.CONNECTIVITY_SERVICE));
         } catch (NoNetworkAccessException e) {
-            abort = true;
+            abort = ABORT_NETWORK_CONN_PROLEM;
             e.printStackTrace();
         } catch (NoAccessToServer e) {
-            abort = true;
-
-            // dialog.show();
+            // you have no access to server or server down
+            abort = ABORT_SERVER_PROBLEM;
+            e.printStackTrace();
+        }
+        
+        if(!prefs.contains("library_url")) {
             Intent configureIntent = new Intent(this,
                     ConfigureApplicationActivity.class);
             startActivityForResult(configureIntent, 0);
-
         }
-
-        if (abort != true) {
+        
+        if (abort == OK) {
             // Start your loading
             new LoadingTask(progressBar, this, this, progressText, this)
                     .execute("download"); // Pass in whatever you need a url is
                                           // just an example we don't use it
                                           // in this tutorial
         }
+        else
+        {
+            
+            
+            switch(abort) {
+            
+            case ABORT_NETWORK_CONN_PROLEM : {
+                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
+                        context);
+         
+                    // set title
+                    alertDialogBuilder.setTitle("Network problem");
+         
+                    // set dialog message
+                    alertDialogBuilder
+                        .setMessage("You do not have your network activated. Please activate it.")
+                        .setCancelable(false)
+                        .setNegativeButton("exit",new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog,int id) {
+                                // if this button is clicked, just close
+                                // the dialog box and do nothing
+                                dialog.cancel();
+                                finish();
+                            }
+                        });
+         
+                        // create alert dialog
+                        alertDialog = alertDialogBuilder.create();
+         
+                        // show it
+                        alertDialog.show();
+                
+            } break;
+            
+            case ABORT_SERVER_PROBLEM : {
+                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
+                        context);
+         
+                    // set title
+                    alertDialogBuilder.setTitle("Evergreen server problem");
+         
+                    // set dialog message
+                    alertDialogBuilder
+                        .setMessage("Seams the server can't be found. Please configure the server address")
+                        .setCancelable(false)
+                        .setPositiveButton("Configure",new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog,int id) {
+                                // if this button is clicked, close
+                                // current activity
+                                
+                                Intent configureIntent = new Intent(context, 
+                                        ConfigureApplicationActivity.class);
+                                startActivityForResult(configureIntent, 0);
+                                
+                            }
+                          })
+                        .setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog,int id) {
+                                // if this button is clicked, just close
+                                // the dialog box and do nothing
+                                dialog.cancel();
+                                finish();
+                            }
+                        });
+         
+                        // create alert dialog
+                        alertDialog = alertDialogBuilder.create();
+         
+                        // show it
+                        alertDialog.show();
+            } break;
+            
+            }
+
+        }
     }
 
+    
+    @Override
+    protected void onStop() {
+        // TODO Auto-generated method stub
+        super.onStop();
+        if(alertDialog != null) {
+            alertDialog.dismiss();
+        }
+    }
+    
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         switch (resultCode) {