| | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.DB.Student; |
| | | import safeluck.drive.evaluation.DB.WokViewModel; |
| | | import safeluck.drive.evaluation.DB.criterias.CriteriaForI; |
| | | import safeluck.drive.evaluation.DB.criterias.viewmodel.CriteriaIViewModel; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.tcp.ConnectThread; |
| | | |
| | |
| | | public class TcpFragment extends SupportFragment implements View.OnClickListener { |
| | | |
| | | |
| | | private static final String TAG = TcpFragment.class.getSimpleName(); |
| | | private TextInputEditText ip; |
| | | private TextInputEditText port; |
| | | private Button btn_connect; |
| | | private Button btn_send; |
| | | private ConnectThread connectThread; |
| | | private AppCompatEditText sendEditText; |
| | | private WokViewModel workViewModel; |
| | | private CriteriaIViewModel workViewModel; |
| | | private int item_id=0; |
| | | |
| | | public static TcpFragment newInstance() { |
| | | return new TcpFragment(); |
| | |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | View view = inflater.inflate(R.layout.layout_tcpclient, container, false); |
| | | initView(view); |
| | | workViewModel =ViewModelProviders.of(this).get(WokViewModel.class); |
| | | workViewModel =ViewModelProviders.of(this).get(CriteriaIViewModel.class); |
| | | |
| | | workViewModel.getStudents().observe((LifecycleOwner) this, new Observer<List<Student>>() { |
| | | @Override |
| | | public void onChanged(List<Student> students) { |
| | | for (Student student:students){ |
| | | Log.i("Students", "onChanged: "+student.toString()); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | return view; |
| | | } |
| | | |
| | |
| | | //// connectThread.sendMessage(sendEditText.getText().toString().trim()); |
| | | //// sendEditText.getText().clear(); |
| | | //// } |
| | | workViewModel.insertStudent(new Student(1002,"王五","500107198910124566",1)); |
| | | checkCriteria(++item_id); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void checkCriteria(int item_id) { |
| | | workViewModel.queryCriteriaI(item_id).observe(TcpFragment.this, new Observer<CriteriaForI>() { |
| | | @Override |
| | | public void onChanged(CriteriaForI criteriaForI) { |
| | | Log.i(TAG, "onChanged: "+criteriaForI.toString()); |
| | | } |
| | | }); |
| | | } |
| | | } |