lizhanwei
2020-02-11 e0e6f7cf7ebf2a6fbfea13eb0743f5e95b1dc60c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package safeluck.drive.evaluation.fragment;
 
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
 
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
 
import com.anyun.exam.lib.MyLog;
import com.google.gson.Gson;
 
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatus;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatusViewModel;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.DB.rtktb.RTKConfig;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.viewmodels.RTKConnAndLogin;
import safeluck.drive.evaluation.viewmodels.RTKConnAndLoginViewModel;
 
/**FTP配置UI
 * MyApplication2
 * Created by lzw on 2019/3/20. 11:22:39
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class RTKConfigFragment extends SupportFragment implements View.OnClickListener {
 
    private static final String TAG = "RTKConfigFragment";
 
    private EditText et_ip,et_port,et_city_id,et_city_province,et_phone;
    //              RTK注册状态、RTK连接状态、
    private TextView tv_reg,tv_connect,tv_model,tv_sn,tv_imei,tv_login;
    private RTKConfigViewModel rtkConfigViewModel;
    private RTKConfig mRtkConfig;
    private AppStatusViewModel appStatusViewModel;
 
    public static SupportFragment newInstance(){
        return new RTKConfigFragment();
    }
 
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 
 
        View view = inflater.inflate(R.layout.layout_rtk_setting,container,false);
        initView(view);
        rtkConfigViewModel= ViewModelProviders.of(this).get(RTKConfigViewModel.class);
        rtkConfigViewModel.getRTKConfig().observe(this, new Observer<RTKConfig>() {
            @Override
            public void onChanged(RTKConfig rtkConfig) {
                if (rtkConfig != null){
                    Log.i(TAG, "RTKConfig Changed: "+rtkConfig.toString());
                    mRtkConfig = rtkConfig;
                    et_ip.setText(rtkConfig.getIp());
                    et_city_id.setText(String.valueOf(rtkConfig.getCity()));
                    et_city_province.setText(String.valueOf(rtkConfig.getProvince()));
                    et_port.setText(String.valueOf(rtkConfig.getPort()));
                    et_phone.setText(rtkConfig.getPhone());
                    tv_sn.setText(getResources().getString(R.string.rtk_config_sn,rtkConfig.getSn()));
                    tv_model.setText(getResources().getString(R.string.rtk_config_model,rtkConfig.getModel()));
                    tv_imei.setText(getResources().getString(R.string.rtk_config_imei,rtkConfig.getImei()));
                    tv_reg.setText(getResources().getString(R.string.rtk_register_status,rtkConfig.getRegistered()));
                }
 
 
            }
        });
 
        appStatusViewModel = ViewModelProviders.of(this).get(AppStatusViewModel.class);
        appStatusViewModel.getAppStatus().observe(this, new Observer<AppStatus>() {
            @Override
            public void onChanged(AppStatus appStatus) {
                if (appStatus != null){
                    tv_login.setText(getResources().getString(R.string.rtk_config_login,appStatus.getRtk_login_code()));
                    tv_connect.setText(getResources().getString(R.string.rtk_connect_status,appStatus.getRtk_connect_status()));
                }
            }
        });
 
 
        return view;
    }
 
    private void initView(View view) {
        view.findViewById(R.id.btn_save_rtk).setOnClickListener(this);
        et_ip = view.findViewById(R.id.rtk_addr_ip);
        et_city_id = view.findViewById(R.id.et_city_id);
        et_city_province = view.findViewById(R.id.et_provice_id);
        et_phone = view.findViewById(R.id.et_phone);
        et_port = view.findViewById(R.id.rtk_addr_port);
 
        tv_connect = view.findViewById(R.id.tv_rtk_connect);//RTK平台连接状态
        tv_imei = view.findViewById(R.id.tv_rtk_imei);
        tv_login = view.findViewById(R.id.tv_rtk_login);//RTK平台登录结果
        tv_model = view.findViewById(R.id.tv_rtk_model);
        tv_reg = view.findViewById(R.id.tv_rtk_reg);//RTK平台注册状态
        tv_sn = view.findViewById(R.id.tv_rtk_sn);
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_save_rtk:
                if (mRtkConfig != null){
                    mRtkConfig.setPort(Integer.parseInt(et_port.getText().toString().trim()));
                    mRtkConfig.setCity(Integer.parseInt(et_city_id.getText().toString().trim()));
                    mRtkConfig.setProvince(Integer.parseInt(et_city_province.getText().toString().trim()));
                    mRtkConfig.setIp(et_ip.getText().toString().trim());
                    mRtkConfig.setPhone(et_phone.getText().toString().trim());
                    rtkConfigViewModel.insertRTKConfig(mRtkConfig);
                }
                break;
        }
    }
 
 
 
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
 
    }
 
    @Override
    public void onDetach() {
        super.onDetach();
    }
}