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();
|
}
|
}
|