| | |
| | | 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 com.google.gson.Gson; |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.bean.RTKConfig; |
| | | import safeluck.drive.evaluation.DB.rtktb.RTKConfig; |
| | | |
| | | /**FTP配置UI |
| | | * MyApplication2 |
| | |
| | | private static final String TAG = "RTKConfigFragment"; |
| | | |
| | | private EditText et_ip,et_port,et_city_id,et_city_province,et_phone; |
| | | private RTKConfigViewModel rtkConfigViewModel; |
| | | private RTKConfig mRtkConfig; |
| | | |
| | | public static SupportFragment newInstance(){ |
| | | return new RTKConfigFragment(); |
| | |
| | | |
| | | 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) { |
| | | 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()); |
| | | } |
| | | }); |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | switch (v.getId()){ |
| | | case R.id.btn_save_rtk: |
| | | Gson gson = new Gson(); |
| | | String rtkConfigjson = gson.toJson(RTKConfig.class); |
| | | 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; |
| | | } |
| | | } |