Quellcode durchsuchen

Merge branch 'developer' of https://gitlab.com/Arisono/SkWeiChat-Baidu into gitlab_developer

Arison vor 9 Jahren
Ursprung
Commit
67f4eb85a0

+ 11 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/activity/oa/AlarmReceiver.java

@@ -201,7 +201,18 @@ public class AlarmReceiver extends BroadcastReceiver {
         }
     }
 
+    //清空提醒
+    private void unArmmanager(Context ct) {
+        Intent intent = new Intent(ct, AlarmReceiver.class);
+        intent.setAction("ALARMA_ACTION");
+        PendingIntent pi = PendingIntent.getBroadcast(ct, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+        AlarmManager alarm = (AlarmManager) ct.getSystemService(ct.ALARM_SERVICE);
+        alarm.cancel(pi);
+    }
+
+    //TODO 在这里提醒时候会延迟6分钟不知道为什么
     private void setArmmanager(Context ct, long time) {
+        unArmmanager(ct);
         Log.i("gongpengming", TimeUtils.f_long_2_str(time));
         //操作:发送一个广播,广播接收后Toast提示定时操作完成
         Intent intent = new Intent(ct, AlarmReceiver.class);

+ 24 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/fragment/SigninFragment.java

@@ -35,8 +35,10 @@ import com.xzjmyk.pm.activity.ui.erp.util.FlexJsonUtil;
 import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
 import com.xzjmyk.pm.activity.ui.erp.util.ViewUtil;
 import com.xzjmyk.pm.activity.util.BaiduMapUtil;
+import com.xzjmyk.pm.activity.util.CalendarUtils;
 import com.xzjmyk.pm.activity.util.TimeUtils;
 import com.xzjmyk.pm.activity.view.crouton.Crouton;
+import com.xzjmyk.pm.activity.view.wheel.OASigninPicker;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
@@ -158,6 +160,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
 
         }
     };
+
     //生命周期
     @Override
     public void onAttach(Context ct) {
@@ -203,7 +206,8 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
                 }
                 break;
             case R.id.title:
-                showPopMenu();
+                showDateDialog();
+//                showPopMenu();
                 break;
             case R.id.unoffice_mm:
                 intent = new Intent(ct, LocationMapActivity.class);
@@ -275,6 +279,24 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
         loadNetData(System.currentTimeMillis());//获取打卡班次信息
     }
 
+    private void showDateDialog() {
+        OASigninPicker picker = new OASigninPicker(ct);
+        picker.setRange(CalendarUtils.getCurrentYear(), CalendarUtils.getCurrentMonth(), CalendarUtils.getCurrentDate());
+        picker.setSelectedItem(CalendarUtils.getCurrentYear(), CalendarUtils.getCurrentMonth(), CalendarUtils.getCurrentDate());
+        picker.setOnDateTimePickListener(new OASigninPicker.OnDateTimePickListener() {
+            @Override
+            public void setTime(String year, String month, String day) {
+                String time = year + "-" + month + "-" + day;
+                isToday = time.equals(TimeUtils.s_long_2_str(System.currentTimeMillis())) ? true : false;
+                title.setText(year + "年" + month + "月" + day + "日  " + TimeUtils.getWeek(TimeUtils.s_str_2_long(time)));
+                if (adapter != null && adapter.getBeans() != null && adapter.getBeans().size() > 0)
+                    adapter.getBeans().clear();
+                loadNetData(TimeUtils.s_str_2_long(time));
+            }
+        });
+        picker.show();
+    }
+
     private void showPopMenu() {
         //显示选择日期窗口
         for (int i = 0; i < timeList.length; i++)
@@ -456,6 +478,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
         //TODO 待优化算法处理
         for (int i = 0; i < beans.size(); i++) {
             b = beans.get(i);
+            beans.get(i).signinList.clear();
             for (String e : logTime) {
                 if (!StringUtils.isEmpty(b.startSignin) && !StringUtils.isEmpty(b.endSignnin) && e.compareTo(b.startSignin) > 0 && e.compareTo(b.endSignnin) < 0) {
                     beans.get(i).signinList.add(e);

+ 23 - 15
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/net/ViewUtil.java

@@ -62,8 +62,10 @@ public class ViewUtil {
     private static MaterialDialog loginERPDialog;
     private static List<LoginEntity> erpEntities;
     private static boolean hasErp = true;//是否有erp
+
     /**
      * 获取Listview的高度,然后设置ViewPager的高度
+     *
      * @param listView
      * @return
      */
@@ -88,19 +90,20 @@ public class ViewUtil {
 
     /**
      * 弹出Toast消息
+     *
      * @param msg
      */
     public static void ToastMessage(Context cont, String msg) {
-        if (cont instanceof Activity){
-            Crouton.makeText((Activity)cont,msg,cont.getResources().getColor(R.color.light_green),2000).show();
-        }else{
+        if (cont instanceof Activity) {
+            Crouton.makeText((Activity) cont, msg, cont.getResources().getColor(R.color.light_green), 2000).show();
+        } else {
             Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
         }
-        
+
     }
-    
+
     public static void ShowMessageTitle(Context ct, String msg) {
-         new MaterialDialog.Builder(ct).title("系統提示").content(msg)
+        new MaterialDialog.Builder(ct).title("系統提示").content(msg)
                 .positiveText("关闭").autoDismiss(false)
                 .callback(new ButtonCallback() {
                     @Override
@@ -109,7 +112,7 @@ public class ViewUtil {
                     }
                 }).show();
     }
-    
+
     public static void ShowMessageTitleAutoDismiss(Context ct, String msg, long time) {
         final MaterialDialog messageDialog = new MaterialDialog.Builder(ct).title("系統提示").content(msg)
                 .positiveText("关闭").autoDismiss(false)
@@ -278,7 +281,6 @@ public class ViewUtil {
     }
 
 
-   
     public static Handler handler = new Handler() {
         public void handleMessage(Message msg) {
             switch (msg.what) {
@@ -443,7 +445,7 @@ public class ViewUtil {
                                             }
                                         }
                                     }
-                                    return true; 
+                                    return true;
                                 }
                             }).positiveText("确定").show();
         }
@@ -507,7 +509,6 @@ public class ViewUtil {
 
     ;
 
-  
 
     /**
      * @author LiuJie
@@ -540,8 +541,6 @@ public class ViewUtil {
         startNetThread(url, param, handler, what, null, null, "get");
     }
 
-   
-
 
     /**
      * @author Administrator
@@ -562,9 +561,12 @@ public class ViewUtil {
             public void run() {
                 boolean isNetHas = CommonUtil.isNetWorkConnected(ct);
                 if (isNetHas) {
+                    if (!params.containsKey("sessionId")) {
+                        params.put("sessionId", CommonUtil.getSharedPreferences(ct, "sessionId"));
+                    }
                     if (!StringUtils.isEmpty(CommonUtil.getSharedPreferences(ct, "erp_username"))
-                            &&headers!=null) {
-                         headers.put("sessionUser", CommonUtil.getSharedPreferences(ct, "erp_username"));
+                            && headers != null) {
+                        headers.put("sessionUser", CommonUtil.getSharedPreferences(ct, "erp_username"));
                     }
                     HttpUtil.Response result = httpSendTask(url, params, headers, request);
                     if (result != null) {
@@ -576,6 +578,12 @@ public class ViewUtil {
                         LogUtil.prinlnLongMsg("result", result.getResponseText());
                         Log.i("result", "http 接收响应-----------------------------------------");
                         if (result.getStatusCode() == 200) {
+                            JsonValidator jsonValidator = new JsonValidator();
+                            if (jsonValidator.validate(result.getResponseText())) {
+                                if (JSON.parseObject(result.getResponseText()).containsKey("sessionId")) {
+                                    CommonUtil.setSharedPreferences(ct, "sessionId", JSON.parseObject(result.getResponseText()).getString("sessionId"));
+                                }
+                            }
                             if (bundle == null || message == null) {
                                 Bundle bundle = new Bundle();
                                 Message message = new Message();
@@ -664,7 +672,7 @@ public class ViewUtil {
         return response;
     }
 
-    
+
     /**
      * @注释:ERP自动登录
      */

+ 11 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/util/ViewUtil.java

@@ -31,6 +31,7 @@ public class ViewUtil {
     private static Message message;
     private static Bundle bundle;
     private static String request;
+
     public static HttpUtil.Response httpSendTask(
             String url,
             Map<String, Object> params,
@@ -50,7 +51,7 @@ public class ViewUtil {
         return response;
     }
 
-    private   Handler handler = new Handler() {
+    private Handler handler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             if (msg.what == 500) {//重登陆
@@ -105,11 +106,20 @@ public class ViewUtil {
             public void run() {
                 boolean isNetHas = Constants.isNetworkConnected(ct);
                 if (isNetHas) {
+                    if (!params.containsKey("sessionId")) {
+                        params.put("sessionId", CommonUtil.getSharedPreferences(ct, "sessionId"));
+                    }
                     Log.i("result:", "url=" + url);
                     HttpUtil.Response result = httpSendTask(url, params, headers, request);
                     if (result != null) {
                         prinltResponseInfo(result, url, params);
                         if (result.getStatusCode() == 200) {
+                            JsonValidator jsonValidator = new JsonValidator();
+                            if (jsonValidator.validate(result.getResponseText())) {
+                                if (JSON.parseObject(result.getResponseText()).containsKey("sessionId")) {
+                                    CommonUtil.setSharedPreferences(ct, "sessionId", JSON.parseObject(result.getResponseText()).getString("sessionId"));
+                                }
+                            }
                             if (bundle == null || message == null) {
                                 Bundle bundle = new Bundle();
                                 Message message = new Message();

+ 295 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/view/wheel/OASigninPicker.java

@@ -0,0 +1,295 @@
+package com.xzjmyk.pm.activity.view.wheel;
+
+import android.app.Activity;
+import android.support.annotation.IntDef;
+import android.support.annotation.NonNull;
+import android.text.TextUtils;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+/**
+ * Created by Dong on 2016/5/13.
+ * 年月日 时分秒
+ */
+public class OASigninPicker extends WheelPicker {
+
+    /**
+     * 年月日
+     */
+    public static final int YEAR_MONTH_DAY = 0;
+    private ArrayList<String> years = new ArrayList<String>();
+    private ArrayList<String> months = new ArrayList<String>();
+    private ArrayList<String> days = new ArrayList<String>();
+    private String yearLabel = "年", monthLabel = "月", dayLabel = "日";
+    private int selectedYearIndex = 0, selectedMonthIndex = 0, selectedDayIndex = 0;
+    private String hourLabel = "时", minuteLabel = "分";
+    private OnDateTimePickListener onDateTimePickListener;
+    private int year, month, day = 0;
+
+    @IntDef(flag = false, value = {YEAR_MONTH_DAY})
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface Mode {
+    }
+
+    public OASigninPicker(Activity activity) {
+        super(activity);
+        textSize = 16;//年月日时分,比较宽,设置字体小一点才能显示完整
+        for (int i = 2010; i <= 2016; i++) {
+            years.add(String.valueOf(i));
+        }
+        for (int i = 1; i <= 12; i++) {
+            months.add(DateUtils.fillZero(i));
+        }
+        for (int i = 1; i <= 31; i++) {
+            days.add(DateUtils.fillZero(i));
+        }
+    }
+
+    @NonNull
+    @Override
+    protected View makeCenterView() {
+        LinearLayout layout = new LinearLayout(activity);
+        layout.setOrientation(LinearLayout.HORIZONTAL);
+        layout.setGravity(Gravity.CENTER);
+        WheelView yearView = new WheelView(activity.getBaseContext());
+        yearView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
+        yearView.setTextSize(textSize);
+        yearView.setTextColor(textColorNormal, textColorFocus);
+        yearView.setLineVisible(lineVisible);
+        yearView.setLineColor(lineColor);
+        yearView.setOffset(offset);
+        layout.addView(yearView);
+        TextView yearTextView = new TextView(activity);
+        yearTextView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
+        yearTextView.setTextSize(textSize);
+        yearTextView.setTextColor(textColorFocus);
+        if (!TextUtils.isEmpty(yearLabel)) {
+            yearTextView.setText(yearLabel);
+        }
+        layout.addView(yearTextView);
+
+        final WheelView monthView = new WheelView(activity.getBaseContext());
+        monthView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
+        monthView.setTextSize(textSize);
+        monthView.setTextColor(textColorNormal, textColorFocus);
+        monthView.setLineVisible(lineVisible);
+        monthView.setLineColor(lineColor);
+        monthView.setOffset(offset);
+        layout.addView(monthView);
+        TextView monthTextView = new TextView(activity);
+        monthTextView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
+        monthTextView.setTextSize(textSize);
+        monthTextView.setTextColor(textColorFocus);
+        if (!TextUtils.isEmpty(monthLabel)) {
+            monthTextView.setText(monthLabel);
+        }
+        layout.addView(monthTextView);
+
+        final WheelView dayView = new WheelView(activity.getBaseContext());
+        dayView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
+        dayView.setTextSize(textSize);
+        dayView.setTextColor(textColorNormal, textColorFocus);
+        dayView.setLineVisible(lineVisible);
+        dayView.setLineColor(lineColor);
+        dayView.setOffset(offset);
+        layout.addView(dayView);
+        TextView dayTextView = new TextView(activity);
+        dayTextView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
+        dayTextView.setTextSize(textSize);
+        dayTextView.setTextColor(textColorFocus);
+        if (!TextUtils.isEmpty(dayLabel)) {
+            dayTextView.setText(dayLabel);
+        }
+        layout.addView(dayTextView);
+        yearView.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
+            @Override
+            public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
+                selectedYearIndex = selectedIndex;
+                int maxDays = 0, maxMonth = 0;
+                if (isRange() && item.equals(getIntMonth(year))) {
+                    maxMonth = month;
+                    if (getSelectedMonth().equals(getIntMonth(month))) {
+                        maxDays = day;
+                    } else {
+                        maxDays = DateUtils.calculateDaysInMonth(stringToYearMonthDay(item), stringToYearMonthDay(months.get(selectedMonthIndex)));
+                    }
+                } else {
+                    maxMonth = 12;
+                    maxDays = DateUtils.calculateDaysInMonth(stringToYearMonthDay(item), stringToYearMonthDay(months.get(selectedMonthIndex)));
+                }
+
+                days.clear();
+                for (int i = 1; i <= maxDays; i++) {
+                    days.add(DateUtils.fillZero(i));
+                }
+                if (selectedDayIndex >= maxDays) {
+                    //年或月变动时,保持之前选择的日不动:如果之前选择的日是之前年月的最大日,则日自动为该年月的最大日
+                    selectedDayIndex = days.size() - 1;
+                }
+                dayView.setItems(days, selectedDayIndex);
+                months.clear();
+                for (int i = 1; i <= maxMonth; i++) {
+                    months.add(DateUtils.fillZero(i));
+                }
+                if (selectedMonthIndex >= maxMonth) {
+                    //年或月变动时,保持之前选择的日不动:如果之前选择的日是之前年月的最大日,则日自动为该年月的最大日
+                    selectedMonthIndex = months.size() - 1;
+                }
+                monthView.setItems(months, selectedMonthIndex);
+            }
+        });
+
+        monthView.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
+            @Override
+            public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
+                selectedMonthIndex = selectedIndex;
+                int maxDays = 0;
+                if (isRange() && getSelectedYear().equals(String.valueOf(year)) && months.get(selectedIndex).equals(getIntMonth(month))) {
+                    maxDays = day;
+                } else
+                    maxDays = DateUtils.calculateDaysInMonth(stringToYearMonthDay(years.get(selectedYearIndex)), stringToYearMonthDay(item));
+                days.clear();
+                for (int i = 1; i <= maxDays; i++) {
+                    days.add(DateUtils.fillZero(i));
+                }
+                if (selectedDayIndex >= maxDays) {
+                    //年或月变动时,保持之前选择的日不动:如果之前选择的日是之前年月的最大日,则日自动为该年月的最大日
+                    selectedDayIndex = days.size() - 1;
+                }
+                dayView.setItems(days, selectedDayIndex);
+            }
+        });
+        dayView.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
+            @Override
+            public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
+                selectedDayIndex = selectedIndex;
+            }
+        });
+        yearView.setItems(years, selectedYearIndex);
+        monthView.setItems(months, selectedMonthIndex);
+        dayView.setItems(days, selectedDayIndex);
+        return layout;
+    }
+
+    private boolean isRange() {
+        if (year != 0 && month != 0 && day != 0)
+            return true;
+        else return false;
+    }
+
+    @Override
+    protected void onSubmit() {
+        if (onDateTimePickListener != null) {
+            String year = getSelectedYear();
+            String month = getSelectedMonth();
+            String day = getSelectedDay();
+            onDateTimePickListener.setTime(year, month, day);
+        }
+    }
+
+    /**
+     * Gets selected year.
+     *
+     * @return the selected year
+     */
+    public String getSelectedYear() {
+        return years.get(selectedYearIndex);
+    }
+
+    private String getIntMonth(int t) {
+        return (t < 10 ? "0" : "") + String.valueOf(t);
+    }
+
+    /**
+     * Gets selected month.
+     *
+     * @return the selected month
+     */
+    public String getSelectedMonth() {
+        return months.get(selectedMonthIndex);
+    }
+
+    /**
+     * Gets selected day.
+     *
+     * @return the selected day
+     */
+    public String getSelectedDay() {
+        return days.get(selectedDayIndex);
+    }
+
+    private int stringToYearMonthDay(String text) {
+        if (text.startsWith("0")) {
+            //截取掉前缀0以便转换为整数
+            text = text.substring(1);
+        }
+        return Integer.parseInt(text);
+    }
+
+    /**
+     * Sets label.
+     *
+     * @param yearLabel  the year label
+     * @param monthLabel the month label
+     * @param dayLabel   the day label
+     */
+    public void setLabel(String yearLabel, String monthLabel, String dayLabel, String hourLabel, String minuteLabel) {
+        this.yearLabel = yearLabel;
+        this.monthLabel = monthLabel;
+        this.dayLabel = dayLabel;
+        this.hourLabel = hourLabel;
+        this.minuteLabel = minuteLabel;
+    }
+
+
+    public void setRange(int year, int month, int day) {
+        this.year = year;
+        this.month = month;
+        this.day = day;
+
+    }
+
+    private int findItemIndex(ArrayList<String> items, int item) {
+        //折半查找有序元素的索引
+        int index = Collections.binarySearch(items, item, new Comparator<Object>() {
+            @Override
+            public int compare(Object lhs, Object rhs) {
+                String lhsStr = lhs.toString();
+                String rhsStr = rhs.toString();
+                lhsStr = lhsStr.startsWith("0") ? lhsStr.substring(1) : lhsStr;
+                rhsStr = rhsStr.startsWith("0") ? rhsStr.substring(1) : rhsStr;
+                return Integer.parseInt(lhsStr) - Integer.parseInt(rhsStr);
+            }
+        });
+        if (index < 0) {
+            index = 0;
+        }
+        return index;
+    }
+
+    public void setSelectedItem(int yeas, int month, int day) {
+        selectedMonthIndex = findItemIndex(months, month);
+        selectedDayIndex = findItemIndex(days, day);
+        selectedYearIndex = findItemIndex(years, yeas);
+    }
+
+    /**
+     * The interface On DateTime pick listener.
+     */
+    public interface OnDateTimePickListener {
+        void setTime(String year, String month, String day);
+    }
+
+    public void setOnDateTimePickListener(OnDateTimePickListener listener) {
+        this.onDateTimePickListener = listener;
+    }
+
+}

+ 9 - 2
WeiChat/src/main/res/layout/oa_mylistview_item.xml

@@ -7,18 +7,23 @@
 
     <TextView
         android:id="@+id/item_name_tv"
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_toLeftOf="@+id/item_remak"
+        android:ellipsize="end"
+        android:lines="1"
         android:text="万达广场"
         android:textColor="@color/text_main"
         android:textSize="@dimen/text_main" />
 
     <TextView
         android:id="@+id/item_remak"
+        android:ellipsize="end"
+        android:lines="1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="10dp"
-        android:layout_toRightOf="@id/item_name_tv"
+        android:layout_toLeftOf="@+id/item_status_tv"
         android:text="签订合同"
         android:textColor="@color/text_main"
         android:textSize="@dimen/text_main" />
@@ -57,6 +62,8 @@
         android:layout_marginTop="5dp"
         android:layout_toLeftOf="@+id/item_doit_tv"
         android:text="市场>李四"
+        android:ellipsize="end"
+        android:lines="1"
         android:textColor="@color/text_hine"
         android:textSize="@dimen/text_hine" />