Browse Source

<修改病房人数统计显示,增加登录界面>

weizhengliang 5 years ago
parent
commit
9e50e308f2

+ 3 - 1
app/src/main/AndroidManifest.xml

@@ -14,13 +14,15 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:supportsRtl="true"
         android:theme="@style/Theme.AppCompat.Light.NoActionBar">
         android:theme="@style/Theme.AppCompat.Light.NoActionBar">
-        <activity android:name=".MainActivity">
+        <activity android:name=".InitActivity"
+            android:windowSoftInputMode="adjustUnspecified|stateHidden">
             <intent-filter>
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <action android:name="android.intent.action.MAIN" />
 
 
                 <category android:name="android.intent.category.LAUNCHER" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
             </intent-filter>
         </activity>
         </activity>
+        <activity android:name="com.wdkl.infoboardclassic.MainActivity"></activity>
     </application>
     </application>
 
 
 </manifest>
 </manifest>

+ 6 - 1
app/src/main/java/com/wdkl/infoboardclassic/BaseApp.java

@@ -3,7 +3,9 @@ package com.wdkl.infoboardclassic;
 import android.app.Application;
 import android.app.Application;
 import android.content.Context;
 import android.content.Context;
 
 
+import com.wdkl.infoboardclassic.constant.Constants;
 import com.wdkl.infoboardclassic.manager.PatientInfoManager;
 import com.wdkl.infoboardclassic.manager.PatientInfoManager;
+import com.wdkl.infoboardclassic.utils.SharedPreferencesUtil;
 
 
 public class BaseApp extends Application {
 public class BaseApp extends Application {
     private static Context mContext;//全局上下文对象
     private static Context mContext;//全局上下文对象
@@ -16,7 +18,10 @@ public class BaseApp extends Application {
         app = this;
         app = this;
         mContext = getApplicationContext();
         mContext = getApplicationContext();
 
 
-        PatientInfoManager.getInstance().getPatientInfo();
+        //默认记住IP
+        if (SharedPreferencesUtil.getIntSp(mContext, Constants.MSG_SP, SharedPreferencesUtil.KEEP_IP) == -1) {
+            SharedPreferencesUtil.putIntSp(mContext, Constants.MSG_SP, SharedPreferencesUtil.KEEP_IP, 1);
+        }
     }
     }
 
 
     public static Context getContext() {
     public static Context getContext() {

+ 113 - 0
app/src/main/java/com/wdkl/infoboardclassic/InitActivity.java

@@ -0,0 +1,113 @@
+package com.wdkl.infoboardclassic;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.EditText;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.alibaba.fastjson.JSONObject;
+import com.wdkl.infoboardclassic.constant.Constants;
+import com.wdkl.infoboardclassic.data.PatientInfoBean;
+import com.wdkl.infoboardclassic.manager.PatientInfoManager;
+import com.wdkl.infoboardclassic.utils.SharedPreferencesUtil;
+import com.wdkl.infoboardclassic.utils.ToastUtil;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+public class InitActivity extends AppCompatActivity {
+
+    EditText et_ipAddr;
+    Button btn_login;
+    CheckBox cb_keepIp;
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_init);
+
+        et_ipAddr = findViewById(R.id.host_ip);
+        cb_keepIp = findViewById(R.id.cb_keep_ip);
+        int isKeepIp = SharedPreferencesUtil.getIntSp(getApplicationContext(), Constants.MSG_SP, SharedPreferencesUtil.KEEP_IP);
+        String hostIp = SharedPreferencesUtil.getStringSp(getApplicationContext(), Constants.MSG_SP, SharedPreferencesUtil.HOST_ADDR);
+        if (isKeepIp == 1) {
+            et_ipAddr.setText(hostIp);
+            cb_keepIp.setChecked(true);
+        } else {
+            cb_keepIp.setChecked(false);
+        }
+
+        btn_login = findViewById(R.id.login_button);
+        btn_login.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                String ipAddr = et_ipAddr.getText().toString().trim();
+                Log.d("wzl", "ip: " + ipAddr);
+                if (ipAddr.length() < 7 || ipAddr.length() > 15) {
+                    ToastUtil.showShortToast(R.string.tips_invalid_ip);
+                } else {
+                    getHostData(ipAddr);
+                }
+                if (cb_keepIp.isChecked()) {
+                    SharedPreferencesUtil.putStringSp(getApplicationContext(), Constants.MSG_SP, SharedPreferencesUtil.HOST_ADDR, ipAddr);
+                } else {
+                    SharedPreferencesUtil.putStringSp(getApplicationContext(), Constants.MSG_SP, SharedPreferencesUtil.HOST_ADDR, "");
+                }
+            }
+        });
+    }
+
+    private void showMainActivity() {
+        Intent intent = new Intent(this, MainActivity.class);
+        startActivity(intent);
+        finish();
+    }
+
+    private void getHostData(String addr) {
+        Constants.HOST_IP = addr;
+        OkHttpClient.Builder builder = new OkHttpClient.Builder()
+                .connectTimeout(30, TimeUnit.SECONDS)
+                .writeTimeout(60, TimeUnit.SECONDS)
+                .readTimeout(60, TimeUnit.SECONDS);
+
+        String hostUrl = Constants.HOST_ADDR_PRE + Constants.HOST_IP + Constants.PORT + "/" + Constants.PATH;
+        Log.d("wzl", "host ip: " + Constants.HOST_IP + ", hostUrl: " + hostUrl);
+        OkHttpClient httpClient = builder.build();
+        Request request = new Request.Builder()
+                .url(hostUrl)
+                .get()
+                .build();
+
+        httpClient.newCall(request).enqueue(new Callback() {
+            @Override
+            public void onFailure(Call call, IOException e) {
+                ToastUtil.showLongToast(R.string.tips_get_data_err);
+            }
+
+            @Override
+            public void onResponse(Call call, Response response) throws IOException {
+                if (response.isSuccessful()) {
+                    String responseStr = response.body().string();
+                    List<PatientInfoBean> patientList = JSONObject.parseArray(responseStr, PatientInfoBean.class);
+                    PatientInfoManager.getInstance().setPatientInfoBeanList(patientList);
+                    showMainActivity();
+                } else {
+                    ToastUtil.showShortToast(R.string.tips_get_data_err);
+                }
+            }
+        });
+    }
+}

+ 60 - 0
app/src/main/java/com/wdkl/infoboardclassic/MainActivity.java

@@ -4,18 +4,35 @@ import androidx.appcompat.app.AppCompatActivity;
 import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentManager;
 
 
 import android.os.Bundle;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
 import android.view.Window;
 import android.view.Window;
 import android.view.WindowManager;
 import android.view.WindowManager;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
 import com.wdkl.infoboardclassic.fragment.RoomInfoFragment;
 import com.wdkl.infoboardclassic.fragment.RoomInfoFragment;
 import com.wdkl.infoboardclassic.manager.PatientInfoManager;
 import com.wdkl.infoboardclassic.manager.PatientInfoManager;
+import com.wdkl.infoboardclassic.utils.DateUtil;
+
+import java.lang.ref.WeakReference;
+import java.text.SimpleDateFormat;
 
 
 public class MainActivity extends AppCompatActivity {
 public class MainActivity extends AppCompatActivity {
     FragmentManager fragmentManager;
     FragmentManager fragmentManager;
 
 
     RoomInfoFragment roomInfoFragment;
     RoomInfoFragment roomInfoFragment;
 
 
+    private UpdateHandler mHandler;
+
+    public static String curDate;
+    public static String nextDate;
+    public static final String DATE_FORMAT = "yyyy-MM-dd";
+
+    private static final int MSG_GET_DATE = 101;
+    private static final int MSG_UPDATE_ROOM_INFO = 102;
+
+    TextView tvDate;
+
     @Override
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
@@ -29,10 +46,53 @@ public class MainActivity extends AppCompatActivity {
         TextView tvTitle = findViewById(R.id.view_title_center_tv);
         TextView tvTitle = findViewById(R.id.view_title_center_tv);
         tvTitle.setText(title);
         tvTitle.setText(title);
 
 
+        tvDate = findViewById(R.id.view_title_right_tv);
+        updateDate();
+
+        mHandler = new UpdateHandler(this);
+        mHandler.sendEmptyMessageDelayed(MSG_GET_DATE, 20*1000);
+
         fragmentManager = getSupportFragmentManager();
         fragmentManager = getSupportFragmentManager();
         roomInfoFragment = RoomInfoFragment.newInstance("RoomInfoFragment");
         roomInfoFragment = RoomInfoFragment.newInstance("RoomInfoFragment");
         fragmentManager.beginTransaction()
         fragmentManager.beginTransaction()
                 .add(R.id.info_content, roomInfoFragment, "RoomInfoFragment")
                 .add(R.id.info_content, roomInfoFragment, "RoomInfoFragment")
                 .commit();
                 .commit();
     }
     }
+
+    private void updateDate() {
+        long curTime = System.currentTimeMillis();
+        curDate = new SimpleDateFormat(DATE_FORMAT).format(curTime);
+        nextDate = new SimpleDateFormat(DATE_FORMAT).format(curTime + 24*60*60*1000);
+        tvDate.setText(curDate);
+    }
+
+    public static class UpdateHandler extends Handler {
+
+        private WeakReference<MainActivity> weakReference;
+
+        public UpdateHandler(MainActivity mainActivity) {
+            weakReference = new WeakReference<>(mainActivity);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            super.handleMessage(msg);
+            MainActivity activity = weakReference.get();
+            if (activity != null) {
+                switch (msg.what) {
+                    case MSG_GET_DATE:
+                        activity.updateDate();
+                        PatientInfoManager.getInstance().getPatientInfo();
+                        activity.mHandler.sendEmptyMessageDelayed(MSG_UPDATE_ROOM_INFO, 10*1000);
+                        break;
+                    case MSG_UPDATE_ROOM_INFO:
+                        if (activity.roomInfoFragment != null) {
+                            activity.roomInfoFragment.updateData();
+                        }
+                        activity.mHandler.sendEmptyMessageDelayed(MSG_GET_DATE, 30*1000);
+                        break;
+                }
+            }
+        }
+    }
 }
 }

+ 5 - 1
app/src/main/java/com/wdkl/infoboardclassic/adapter/PatientAdapter.java

@@ -25,7 +25,6 @@ public class PatientAdapter extends RecyclerView.Adapter<PatientAdapter.PatientV
     public PatientAdapter(Context context, int resId) {
     public PatientAdapter(Context context, int resId) {
         mContext = context;
         mContext = context;
         layoutId = resId;
         layoutId = resId;
-        allPatientInfoItems = PatientInfoManager.getInstance().getAllPatientInfoItemList();
     }
     }
 
 
     @NonNull
     @NonNull
@@ -52,6 +51,11 @@ public class PatientAdapter extends RecyclerView.Adapter<PatientAdapter.PatientV
         return allPatientInfoItems.size();
         return allPatientInfoItems.size();
     }
     }
 
 
+    public void refreshData() {
+        allPatientInfoItems = PatientInfoManager.getInstance().getAllPatientInfoItemList();
+        notifyDataSetChanged();
+    }
+
 
 
     class PatientViewHolder extends RecyclerView.ViewHolder {
     class PatientViewHolder extends RecyclerView.ViewHolder {
         TextView tvItemTitle;
         TextView tvItemTitle;

+ 6 - 2
app/src/main/java/com/wdkl/infoboardclassic/constant/Constants.java

@@ -5,7 +5,11 @@ import android.os.Environment;
 public class Constants {
 public class Constants {
     public static final String MSG_SP = "msg_sp";
     public static final String MSG_SP = "msg_sp";
 
 
-    public static final String HOST_ADDR = "http://192.168.3.23:8080";  //test ip
+    public static String HOST_ADDR_PRE = "http://";
 
 
-    public static final String PATH = "home/patient_info";
+    public static String HOST_IP = "192.168.3.23";  //test
+
+    public static String PORT = ":8080";
+
+    public static String PATH = "home/patient_info";
 }
 }

+ 61 - 15
app/src/main/java/com/wdkl/infoboardclassic/data/PatientInfoBean.java

@@ -1,6 +1,8 @@
 package com.wdkl.infoboardclassic.data;
 package com.wdkl.infoboardclassic.data;
 
 
 
 
+import com.alibaba.fastjson.annotation.JSONField;
+
 /**
 /**
  * 病人信息
  * 病人信息
  *
  *
@@ -8,81 +10,117 @@ package com.wdkl.infoboardclassic.data;
  */
  */
 public class PatientInfoBean {
 public class PatientInfoBean {
 
 
+    @JSONField(name = "his_phoc_id")
     private String hisPhocId;
     private String hisPhocId;
 
 
+    @JSONField(name = "his_id")
     private String hisId;
     private String hisId;
 
 
+    @JSONField(name = "frame_id")
     private Integer frameId;
     private Integer frameId;
 
 
+    @JSONField(name = "device_id")
     private Integer deviceId;
     private Integer deviceId;
 
 
+    @JSONField(name = "card_id")
     private String cardId;
     private String cardId;
 
 
+    @JSONField(name = "name")
     private String name;
     private String name;
 
 
+    @JSONField(name = "name_py")
     private String namePy;
     private String namePy;
 
 
+    @JSONField(name = "sex")
     private Integer sex;
     private Integer sex;
 
 
+    @JSONField(name = "age")
     private Integer age;
     private Integer age;
 
 
+    @JSONField(name = "age_unit")
     private Integer ageUnit;
     private Integer ageUnit;
 
 
+    @JSONField(name = "birthday")
     private Long birthday;
     private Long birthday;
 
 
+    @JSONField(name = "idcard")
     private String idcard;
     private String idcard;
 
 
+    @JSONField(name = "address")
     private String address;
     private String address;
 
 
+    @JSONField(name = "mobile")
     private String mobile;
     private String mobile;
 
 
-    private Long indate;
+    @JSONField(name = "in_date")
+    private Long inDate;
+
+    @JSONField(name = "out_date")
+    private Long outDate;
 
 
+    @JSONField(name = "doctor_id")
     private Integer doctorId;
     private Integer doctorId;
 
 
+    @JSONField(name = "nurse_id")
     private Integer nurseId;
     private Integer nurseId;
 
 
+    @JSONField(name = "aide_id")
     private Integer aideId;
     private Integer aideId;
 
 
+    @JSONField(name = "grade_level")
     private Integer gradeLevel;
     private Integer gradeLevel;
 
 
+    @JSONField(name = "dosage_level")
     private Integer dosageLevel;
     private Integer dosageLevel;
 
 
+    @JSONField(name = "diet_level")
     private Integer dietLevel;
     private Integer dietLevel;
 
 
+    @JSONField(name = "insulate_level")
     private Integer insulateLevel;
     private Integer insulateLevel;
 
 
+    @JSONField(name = "alleray_level")
     private Integer allerayLevel;
     private Integer allerayLevel;
 
 
+    @JSONField(name = "intimes")
     private Integer intimes;
     private Integer intimes;
 
 
+    @JSONField(name = "status")
     private Integer status;
     private Integer status;
 
 
+    @JSONField(name = "illness_description")
     private String illnessDescription;
     private String illnessDescription;
 
 
     private Long id;
     private Long id;
 
 
+    @JSONField(name = "create_time")
     private Long createTime;
     private Long createTime;
 
 
+    @JSONField(name = "archived")
     private Boolean archived;
     private Boolean archived;
 
 
+    @JSONField(name = "update_time")
     private Long updateTime;
     private Long updateTime;
 
 
+    @JSONField(name = "sync_time")
     private Long syncTime;
     private Long syncTime;
 
 
+    @JSONField(name = "server_id")
     private Integer serverId;
     private Integer serverId;
 
 
+    @JSONField(name = "client_id")
     private Long clientId;
     private Long clientId;
 
 
+    @JSONField(name = "part_id")
     private Integer partId;
     private Integer partId;
 
 
     public PatientInfoBean(String hisPhocId, String hisId, Integer frameId, Integer deviceId,
     public PatientInfoBean(String hisPhocId, String hisId, Integer frameId, Integer deviceId,
                            String cardId, String name, String namePy, Integer sex, Integer age, Integer ageUnit,
                            String cardId, String name, String namePy, Integer sex, Integer age, Integer ageUnit,
-                           Long birthday, String idcard, String address, String mobile, Long indate, Integer doctorId,
-                           Integer nurseId, Integer aideId, Integer gradeLevel, Integer dosageLevel, Integer dietLevel,
-                           Integer insulateLevel, Integer allerayLevel, Integer intimes, Integer status,
-                           String illnessDescription, Long id, Long createTime, Boolean archived, Long updateTime,
-                           Long syncTime, Integer serverId, Long clientId, Integer partId) {
+                           Long birthday, String idcard, String address, String mobile, Long inDate, Long outDate,
+                           Integer doctorId, Integer nurseId, Integer aideId, Integer gradeLevel, Integer dosageLevel,
+                           Integer dietLevel, Integer insulateLevel, Integer allerayLevel, Integer intimes,
+                           Integer status, String illnessDescription, Long id, Long createTime, Boolean archived,
+                           Long updateTime, Long syncTime, Integer serverId, Long clientId, Integer partId) {
         this.hisPhocId = hisPhocId;
         this.hisPhocId = hisPhocId;
         this.hisId = hisId;
         this.hisId = hisId;
         this.frameId = frameId;
         this.frameId = frameId;
@@ -97,7 +135,8 @@ public class PatientInfoBean {
         this.idcard = idcard;
         this.idcard = idcard;
         this.address = address;
         this.address = address;
         this.mobile = mobile;
         this.mobile = mobile;
-        this.indate = indate;
+        this.inDate = inDate;
+        this.outDate = outDate;
         this.doctorId = doctorId;
         this.doctorId = doctorId;
         this.nurseId = nurseId;
         this.nurseId = nurseId;
         this.aideId = aideId;
         this.aideId = aideId;
@@ -299,14 +338,6 @@ public class PatientInfoBean {
         this.mobile = mobile;
         this.mobile = mobile;
     }
     }
 
 
-    public Long getIndate() {
-        return this.indate;
-    }
-
-    public void setIndate(Long indate) {
-        this.indate = indate;
-    }
-
     public Integer getDoctorId() {
     public Integer getDoctorId() {
         return this.doctorId;
         return this.doctorId;
     }
     }
@@ -395,4 +426,19 @@ public class PatientInfoBean {
         this.illnessDescription = illnessDescription;
         this.illnessDescription = illnessDescription;
     }
     }
 
 
+    public Long getInDate() {
+        return this.inDate;
+    }
+
+    public void setInDate(Long inDate) {
+        this.inDate = inDate;
+    }
+
+    public Long getOutDate() {
+        return this.outDate;
+    }
+
+    public void setOutDate(Long outDate) {
+        this.outDate = outDate;
+    }
 }
 }

+ 8 - 2
app/src/main/java/com/wdkl/infoboardclassic/fragment/RoomInfoFragment.java

@@ -14,6 +14,7 @@ import com.wdkl.infoboardclassic.R;
 import com.wdkl.infoboardclassic.adapter.NurseConfigAdapter;
 import com.wdkl.infoboardclassic.adapter.NurseConfigAdapter;
 import com.wdkl.infoboardclassic.adapter.PatientAdapter;
 import com.wdkl.infoboardclassic.adapter.PatientAdapter;
 import com.wdkl.infoboardclassic.base.BaseFragment;
 import com.wdkl.infoboardclassic.base.BaseFragment;
+import com.wdkl.infoboardclassic.manager.MyLinearLayoutManager;
 
 
 import butterknife.Bind;
 import butterknife.Bind;
 
 
@@ -48,20 +49,25 @@ public class RoomInfoFragment extends BaseFragment {
         mContext = getActivity();
         mContext = getActivity();
         //左侧住院人数
         //左侧住院人数
         patientAdapter = new PatientAdapter(mContext, R.layout.patient_count_item);
         patientAdapter = new PatientAdapter(mContext, R.layout.patient_count_item);
-        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
+        LinearLayoutManager layoutManager = new MyLinearLayoutManager(mContext);
         layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
         layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
         rvInfoCount.setLayoutManager(layoutManager);
         rvInfoCount.setLayoutManager(layoutManager);
         rvInfoCount.setAdapter(patientAdapter);
         rvInfoCount.setAdapter(patientAdapter);
         DividerItemDecoration itemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
         DividerItemDecoration itemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
         itemDecoration.setDrawable(getResources().getDrawable(R.drawable.white_line, null));
         itemDecoration.setDrawable(getResources().getDrawable(R.drawable.white_line, null));
         rvInfoCount.addItemDecoration(itemDecoration);
         rvInfoCount.addItemDecoration(itemDecoration);
+        patientAdapter.refreshData();
 
 
         //右侧护理信息
         //右侧护理信息
         nurseConfigAdapter = new NurseConfigAdapter(mContext, R.layout.nurse_config_item);
         nurseConfigAdapter = new NurseConfigAdapter(mContext, R.layout.nurse_config_item);
-        LinearLayoutManager layoutManager2 = new LinearLayoutManager(mContext);
+        LinearLayoutManager layoutManager2 = new MyLinearLayoutManager(mContext);
         layoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
         layoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
         rvNurseConfig.setLayoutManager(layoutManager2);
         rvNurseConfig.setLayoutManager(layoutManager2);
         rvNurseConfig.setAdapter(nurseConfigAdapter);
         rvNurseConfig.setAdapter(nurseConfigAdapter);
         rvNurseConfig.addItemDecoration(itemDecoration);
         rvNurseConfig.addItemDecoration(itemDecoration);
     }
     }
+
+    public void updateData() {
+        patientAdapter.refreshData();
+    }
 }
 }

+ 32 - 0
app/src/main/java/com/wdkl/infoboardclassic/manager/MyLinearLayoutManager.java

@@ -0,0 +1,32 @@
+package com.wdkl.infoboardclassic.manager;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+public class MyLinearLayoutManager extends LinearLayoutManager {
+    public MyLinearLayoutManager(Context context) {
+        super(context);
+    }
+
+    public MyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
+        super(context, orientation, reverseLayout);
+    }
+
+    public MyLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+        super( context, attrs, defStyleAttr, defStyleRes );
+    }
+
+    @Override
+    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
+        try {
+            //try catch一下
+            super.onLayoutChildren( recycler, state );
+        } catch (IndexOutOfBoundsException e) {
+            e.printStackTrace();
+        }
+
+    }
+}

+ 45 - 18
app/src/main/java/com/wdkl/infoboardclassic/manager/PatientInfoManager.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.wdkl.infoboardclassic.BaseApp;
 import com.wdkl.infoboardclassic.BaseApp;
+import com.wdkl.infoboardclassic.MainActivity;
 import com.wdkl.infoboardclassic.R;
 import com.wdkl.infoboardclassic.R;
 import com.wdkl.infoboardclassic.constant.Constants;
 import com.wdkl.infoboardclassic.constant.Constants;
 import com.wdkl.infoboardclassic.data.AllPatientInfoItem;
 import com.wdkl.infoboardclassic.data.AllPatientInfoItem;
@@ -14,10 +15,10 @@ import com.wdkl.infoboardclassic.data.PatientInfoBean;
 import com.wdkl.infoboardclassic.utils.ToastUtil;
 import com.wdkl.infoboardclassic.utils.ToastUtil;
 
 
 import java.io.IOException;
 import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Date;
 import java.util.List;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 
 
 import okhttp3.Call;
 import okhttp3.Call;
@@ -34,8 +35,9 @@ public class PatientInfoManager {
     private List<String> nurseConfigTitleList = new ArrayList<>();
     private List<String> nurseConfigTitleList = new ArrayList<>();
     private List<NurseConfigItem> nurseConfigItemList = new ArrayList<>();
     private List<NurseConfigItem> nurseConfigItemList = new ArrayList<>();
 
 
+    private List<PatientInfoBean> patientInfoBeanList;
+
     private int[] titleId = new int[] {R.string.patient_count_title, R.string.discharged_today_title, R.string.discharged_tomorrow_title, R.string.admission_today};
     private int[] titleId = new int[] {R.string.patient_count_title, R.string.discharged_today_title, R.string.discharged_tomorrow_title, R.string.admission_today};
-    private int[] contents = new int[]{0, 0, 0, 0};
 
 
     private PatientInfoManager(){
     private PatientInfoManager(){
     }
     }
@@ -58,9 +60,10 @@ public class PatientInfoManager {
                 .writeTimeout(60, TimeUnit.SECONDS)
                 .writeTimeout(60, TimeUnit.SECONDS)
                 .readTimeout(60, TimeUnit.SECONDS);
                 .readTimeout(60, TimeUnit.SECONDS);
 
 
+        String hostUrl = Constants.HOST_ADDR_PRE + Constants.HOST_IP + Constants.PORT + "/" + Constants.PATH;
         OkHttpClient httpClient = builder.build();
         OkHttpClient httpClient = builder.build();
         Request request = new Request.Builder()
         Request request = new Request.Builder()
-                .url(Constants.HOST_ADDR + "/" + Constants.PATH)
+                .url(hostUrl)
                 .get()
                 .get()
                 .build();
                 .build();
 
 
@@ -74,14 +77,8 @@ public class PatientInfoManager {
             public void onResponse(Call call, Response response) throws IOException {
             public void onResponse(Call call, Response response) throws IOException {
                 if (response.isSuccessful()) {
                 if (response.isSuccessful()) {
                     String responseStr = response.body().string();
                     String responseStr = response.body().string();
-                    Log.d(TAG, "get response:" + responseStr);
-
-                    List<PatientInfoBean> patientList = JSONObject.parseArray(responseStr, PatientInfoBean.class);
-                    parsePatientInfo(patientList);
-
-                    for (PatientInfoBean model : patientList) {
-                        Log.d(TAG, model.getName());
-                    }
+                    //Log.d(TAG, "get response:" + responseStr);
+                    patientInfoBeanList = JSONObject.parseArray(responseStr, PatientInfoBean.class);
                 } else {
                 } else {
                     Log.e(TAG, response.body().string());
                     Log.e(TAG, response.body().string());
                     ToastUtil.showShortToast("获取数据错误");
                     ToastUtil.showShortToast("获取数据错误");
@@ -90,12 +87,38 @@ public class PatientInfoManager {
         });
         });
     }
     }
 
 
-    private void parsePatientInfo(List<PatientInfoBean> patients) {
-        allPatientInfoItemList.clear();
-        if (patients != null) {
-            contents[0] = patients.size();
+    public void setPatientInfoBeanList(List<PatientInfoBean> patients) {
+        patientInfoBeanList = patients;
+    }
+
+    private void parsePatientInfo() {
+        int[] contents = new int[] {0, 0, 0, 0};
+        if (patientInfoBeanList != null) {
+            contents[0] = patientInfoBeanList.size();  //现有住院总人数
+            for (PatientInfoBean bean: patientInfoBeanList) {
+                Long outTime = bean.getOutDate();
+                if (outTime != null && outTime > 0) {
+                    Date outDate = new Date(outTime);
+                    String outDay = new SimpleDateFormat(MainActivity.DATE_FORMAT).format(outDate);
+                    if (MainActivity.curDate.equals(outDay)) {
+                        contents[1]++;  //今日出院
+                    } else if (MainActivity.nextDate.equals(outDay)) {
+                        contents[2]++;  //明日出院
+                    }
+                }
+
+                Long inTime = bean.getInDate();
+                if (inTime != null && inTime > 0) {
+                    Date inDate = new Date(inTime);
+                    String inDay = new SimpleDateFormat(MainActivity.DATE_FORMAT).format(inDate);
+                    if (MainActivity.curDate.equals(inDay)) {
+                        contents[3]++;  //今日入院
+                    }
+                }
+            }
+
             for (int i = 0; i < titleId.length; i++) {
             for (int i = 0; i < titleId.length; i++) {
-                //住院信息
+                //住院人数信息
                 AllPatientInfoItem allPatientInfoItem = new AllPatientInfoItem();
                 AllPatientInfoItem allPatientInfoItem = new AllPatientInfoItem();
                 allPatientInfoItem.setInfoTitle(getString(titleId[i]));
                 allPatientInfoItem.setInfoTitle(getString(titleId[i]));
                 allPatientInfoItem.setInfoContent(Integer.toString(contents[i]));
                 allPatientInfoItem.setInfoContent(Integer.toString(contents[i]));
@@ -105,12 +128,13 @@ public class PatientInfoManager {
     }
     }
 
 
     public List<AllPatientInfoItem> getAllPatientInfoItemList() {
     public List<AllPatientInfoItem> getAllPatientInfoItemList() {
+        parsePatientInfo();
         if (allPatientInfoItemList.size() == 0) {
         if (allPatientInfoItemList.size() == 0) {
             //默认值
             //默认值
             for (int i = 0; i < titleId.length; i++) {
             for (int i = 0; i < titleId.length; i++) {
                 AllPatientInfoItem allPatientInfoItem = new AllPatientInfoItem();
                 AllPatientInfoItem allPatientInfoItem = new AllPatientInfoItem();
                 allPatientInfoItem.setInfoTitle(getString(titleId[i]));
                 allPatientInfoItem.setInfoTitle(getString(titleId[i]));
-                allPatientInfoItem.setInfoContent(Integer.toString(contents[i]));
+                allPatientInfoItem.setInfoContent("0");
                 allPatientInfoItemList.add(allPatientInfoItem);
                 allPatientInfoItemList.add(allPatientInfoItem);
             }
             }
         }
         }
@@ -142,5 +166,8 @@ public class PatientInfoManager {
         allPatientInfoItemList.clear();
         allPatientInfoItemList.clear();
         nurseConfigTitleList.clear();
         nurseConfigTitleList.clear();
         nurseConfigItemList.clear();
         nurseConfigItemList.clear();
+        if (patientInfoBeanList != null) {
+            patientInfoBeanList.clear();
+        }
     }
     }
 }
 }

+ 21 - 0
app/src/main/java/com/wdkl/infoboardclassic/utils/DateUtil.java

@@ -0,0 +1,21 @@
+package com.wdkl.infoboardclassic.utils;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DateUtil {
+
+    public static String longToString(Long currentTime, String formatType) {
+        try {
+            Date date = new Date(currentTime);
+            return dateToString(date, formatType);
+        } catch (Exception e) {
+            //
+        }
+        return "0";
+    }
+
+    public static String dateToString(Date date, String dateType) {
+        return new SimpleDateFormat(dateType).format(date);
+    }
+}

+ 14 - 0
app/src/main/java/com/wdkl/infoboardclassic/utils/SharedPreferencesUtil.java

@@ -4,6 +4,9 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences;
 
 
 public class SharedPreferencesUtil {
 public class SharedPreferencesUtil {
+
+    public static final String KEEP_IP = "keep_ip";
+
     public static final String HOST_ADDR="host_addr";
     public static final String HOST_ADDR="host_addr";
 
 
     public static void putStringSp(Context context, String spname, String vname, String vdata) {
     public static void putStringSp(Context context, String spname, String vname, String vdata) {
@@ -16,4 +19,15 @@ public class SharedPreferencesUtil {
         String name = sp.getString(vname, "");
         String name = sp.getString(vname, "");
         return name;
         return name;
     }
     }
+
+    public static void putIntSp(Context context, String spname,String vname,int vdata) {
+        SharedPreferences sp = context.getSharedPreferences(spname, Context.MODE_PRIVATE);
+        sp.edit().putInt(vname, vdata).commit();
+    }
+
+    public static int getIntSp(Context context, String spname, String vname) {
+        SharedPreferences sp = context.getSharedPreferences(spname, Context.MODE_PRIVATE);
+        int name = sp.getInt(vname, -1);
+        return name;
+    }
 }
 }

+ 5 - 0
app/src/main/res/drawable/selector_login_botton.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:drawable="@drawable/selector_login_button_item_true" android:state_pressed="true"/>
+    <item android:drawable="@drawable/selector_login_button_item_false"/>
+</selector>

+ 5 - 0
app/src/main/res/drawable/selector_login_button_item_false.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android" >
+    <solid android:color="#F57401" />
+    <corners android:radius="20dp"></corners>
+</shape>

+ 5 - 0
app/src/main/res/drawable/selector_login_button_item_true.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android" >
+    <solid android:color="#F0D85A" />
+    <corners android:radius="20dp"></corners>
+</shape>

+ 63 - 0
app/src/main/res/layout/activity_init.xml

@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <include
+        android:id="@+id/activity_layout_title"
+        layout="@layout/view_title_layout">
+    </include>
+
+    <RelativeLayout
+        android:id="@+id/activity_layout_main"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_below="@+id/activity_layout_title">
+
+        <EditText
+            android:id="@+id/host_ip"
+            android:layout_width="match_parent"
+            android:layout_marginLeft="25dp"
+            android:layout_marginTop="25dp"
+            android:layout_marginRight="25dp"
+            android:layout_height="50dp"
+            android:hint="@string/hint_enter_ip_addr"
+            android:inputType="number"
+            android:digits="0123456789."/>
+
+        <LinearLayout
+            android:id="@+id/ll_keep_ip"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:layout_marginStart="25dp"
+            android:layout_below="@id/host_ip"
+            android:orientation="horizontal">
+            <CheckBox
+                android:id="@+id/cb_keep_ip"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center"/>
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center"
+                android:textSize="18sp"
+                android:text="@string/title_keep_ip"/>
+        </LinearLayout>
+
+        <Button
+            android:id="@+id/login_button"
+            android:layout_width="match_parent"
+            android:layout_height="55dp"
+            android:layout_gravity="center_horizontal"
+            android:layout_marginLeft="25dp"
+            android:layout_marginRight="25dp"
+            android:layout_marginTop="20dp"
+            android:layout_below="@+id/ll_keep_ip"
+            android:background="@drawable/selector_login_botton"
+            android:text="@string/login"
+            android:textColor="@color/white"
+            android:textSize="22sp" />
+    </RelativeLayout>
+</RelativeLayout>

+ 11 - 0
app/src/main/res/layout/view_title_layout.xml

@@ -22,4 +22,15 @@
         android:text=""
         android:text=""
         android:textColor="@color/white"
         android:textColor="@color/white"
         android:textSize="36sp" />
         android:textSize="36sp" />
+
+    <TextView
+        android:id="@+id/view_title_right_tv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentEnd="true"
+        android:layout_centerVertical="true"
+        android:layout_marginEnd="10dp"
+        android:gravity="center"
+        android:textColor="@color/white"
+        android:textSize="20sp" />
 </RelativeLayout>
 </RelativeLayout>

+ 6 - 0
app/src/main/res/values/strings.xml

@@ -3,8 +3,14 @@
     
     
     <string name="info_title">工作信息看板</string>
     <string name="info_title">工作信息看板</string>
     <string name="room_info">病房动态</string>
     <string name="room_info">病房动态</string>
+    <string name="login">登  录</string>
+    <string name="title_keep_ip">记住当前IP</string>
+    <string name="hint_enter_ip_addr">请输入需要连接的主机IP地址</string>
+    <string name="tips_invalid_ip">请输入正确的IP地址</string>
+    <string name="tips_get_data_err">获取数据出错,请检查网络或IP地址!</string>
     <string name="patient_count_title">现有人数</string>
     <string name="patient_count_title">现有人数</string>
     <string name="discharged_today_title">今日出院</string>
     <string name="discharged_today_title">今日出院</string>
     <string name="discharged_tomorrow_title">明日出院</string>
     <string name="discharged_tomorrow_title">明日出院</string>
     <string name="admission_today">今日入院</string>
     <string name="admission_today">今日入院</string>
+    <string name="date_format">yyyy-MM-dd</string>
 </resources>
 </resources>