Ver código fonte

1.完成Android Apex Drivers Message。

Pen Li 7 anos atrás
pai
commit
3f2f54e40a

+ 15 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/ApexDriverApplication.java

@@ -166,6 +166,21 @@ public class ApexDriverApplication extends Application {
         editor.commit();
     }
 
+    public void updatePassword(String password) {
+        this.password = password;
+        SharedPreferences pref = ApexDriverApplication.sharedApplication().getSharedPreferences(ApexDriverApplication.preferencesKey, 0);
+        SharedPreferences.Editor editor = pref.edit();
+        try {
+
+            editor.putString("password", encryptString(password));
+
+        } catch (Exception e) {
+            editor.putString("password", null);
+            e.printStackTrace();
+        }
+        editor.commit();
+    }
+
     public String savedUser() {
         SharedPreferences pref = getSharedPreferences(ApexDriverApplication.preferencesKey, 0);
         String user = pref.getString("user", null);

+ 37 - 23
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/base/BasicObject.java

@@ -3,6 +3,7 @@ package com.usai.redant.apexdrivers.base;
 import org.json.JSONObject;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 public class BasicObject {
@@ -33,45 +34,38 @@ public class BasicObject {
                     if (type == value.getClass() || ((type == int.class || type == long.class) && value.getClass() == Integer.class) || ((type == float.class || type == double.class) && (value.getClass() == Double.class || value.getClass() == Float.class))) {
 
 
-                        String setter = "set" + toUpperCaseFirstOne(key);
-                       try {
-                           Method method = cls.getMethod(setter,type);
-                           if (method != null) {
-                               method.invoke(this,value);
-                           } else {
-                               f.set(this,value);
-                           }
-                       } catch (NoSuchMethodException e) {
-
-                           e.printStackTrace();
-
-                           f.set(this,value);
-                       } catch (SecurityException e) {
-                           e.printStackTrace();
-
-                           f.set(this,value);
-                       }
+                        boolean success = invokeSetter(cls,f,type,key,value);
+                        if (!success) {
+                            f.set(this,value);
+                        }
 
                     } else {
+
                         if (value.getClass() == String.class) {
+
                             String string = (String)value;
-                            if (type == Integer.class) {
+
+                            if (type == Integer.class || type == int.class || type == long.class) {
 
                                 value = Integer.valueOf(string);
-                                f.set(this,value);
 
-                            } else if (type == Double.class) {
+
+                            } else if (type == Double.class || type == double.class || type == float.class) {
 
                                 value = Double.valueOf(string);
-                                f.set(this,value);
 
-                            } else if (type == Boolean.class) {
+                            } else if (type == Boolean.class || type == boolean.class) {
 
                                 value = Boolean.valueOf(string);
+                            }
+
+                            boolean success = invokeSetter(cls,f,type,key,value);
+                            if (!success) {
                                 f.set(this,value);
                             }
 
                         }
+
                     }
 
                 }
@@ -82,6 +76,26 @@ public class BasicObject {
         }
     }
 
+
+    public boolean invokeSetter(Class cls, Field f, Class type,String key,Object value) {
+
+        String setter = "set" + toUpperCaseFirstOne(key);
+        try {
+            Method method = cls.getMethod(setter,type);
+            if (method != null) {
+
+                method.invoke(this,value);
+
+                return true;
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return false;
+    }
+
     public static String toUpperCaseFirstOne(String s){
         if(Character.isUpperCase(s.charAt(0)))
             return s;

+ 4 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/home/HomeMoreActivity.java

@@ -286,6 +286,10 @@ public class HomeMoreActivity extends AppCompatActivity implements AbsListView.O
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 
+                if (position >= mOrders.size()) {
+                    return;
+                }
+
 
                 HomeOrderModel orderModel = mOrders.get(position);
 

+ 5 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/message/MessageActivity.java

@@ -178,6 +178,10 @@ public class MessageActivity extends AppCompatActivity implements AbsListView.On
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 
+                if (position >= self.messages.size()) {
+                    return;
+                }
+
                 MessageModel model = self.messages.get(position);
                 if (model.isNew) {
                     model.setIsNew(false);
@@ -304,6 +308,7 @@ public class MessageActivity extends AppCompatActivity implements AbsListView.On
                     showWarningMsg("Sorry,something is wrong");
                 }
 
+                footer.setVisibility(View.INVISIBLE);
                 isLoading = false;
             }
         }, new OperationQueue.OperationCancelCallBack() {

+ 1 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/setting/changepassword/ChangePasswordDialog.java

@@ -128,6 +128,7 @@ public class ChangePasswordDialog extends Dialog {
                     if (result == com.usai.redant.rautils.utils.Network.RESULT_TRUE) {
 
                         showWarningMsg("change password success");
+                        ApexDriverApplication.sharedApplication().updatePassword(newPass);
 
                     } else {
                         String msg = json.optString("err_msg");

+ 1 - 2
ApexDrivers/app/src/main/res/layout/message_item_cell.xml

@@ -55,8 +55,7 @@
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
                     android:textColor="#000000"
-                    android:textSize="17sp"
-                    android:textStyle="bold"
+                    android:textSize="18sp"
                     android:text="New Order"
                     />