endian11
2020-01-10 09c6ca33263482d69fde9bff4b8221c36766c051
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
142
143
package safeluck.drive.evaluation.fragment;
 
import android.os.Bundle;
 
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
 
 
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
 
import com.anyun.exam.lib.AYSdk;
import com.anyun.exam.lib.MyLog;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.DB.failitems.FailedProjViewModel;
import safeluck.drive.evaluation.DB.failitems.FailedProj_select;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.adapter.ScoreAdapter;
import safeluck.drive.evaluation.bean.ScoreBean;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
 
/**
 * 联网训练UI
 * MyApplication2
 * Created by lzw on 2019/3/18. 13:33:14
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class NetWorkTrainFragment extends SupportFragment implements View.OnClickListener {
 
    private static final String TAG = NetWorkTrainFragment.class.getSimpleName();
    private ListView mListView ;
    private Button btn_start_exam;
    private ScoreAdapter mScoreAdapter;
 
    private int item_id;//扣分分数总和
 
    private List<ScoreBean> mArrayList = new ArrayList<>();
 
    public static SupportFragment newInstance() {
        return new NetWorkTrainFragment();
    }
 
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_train_fragment,container,false);
        initView(view);
 
        FailedProjViewModel failedProjViewModel = ViewModelProviders.of(this).get(FailedProjViewModel.class);
        failedProjViewModel.getFailedProjectsForI(Constant.TEST_STU_ID).observe(this, new Observer<List<FailedProj_select>>() {
            @Override
            public void onChanged(List<FailedProj_select> failedProj_selects) {
                item_id = 0;
                mArrayList.clear();
                for (FailedProj_select f :
                        failedProj_selects) {
                    item_id += f.getScore_deducting();
                    Log.i(TAG, "onChanged: "+f.toString());
                    mArrayList.add(new ScoreBean(f.getScore_deducting(),f.getItem_content(),f.getDeducting_reason()));
                    mScoreAdapter.addDatas(mArrayList);
                }
            }
        });
 
 
        return view;
    }
 
    private void initView(View view) {
        sendRTKConfig2RemoteService();
        mListView = view.findViewById(R.id.lv);
        mListView.setFocusable(false);
        view.findViewById(R.id.view_map).setOnClickListener(this);
        mScoreAdapter = new ScoreAdapter(_mActivity);
        mListView.setAdapter(mScoreAdapter);
        btn_start_exam = view.findViewById(R.id.btn_start);
        btn_start_exam.setOnClickListener(this);
        view.findViewById(R.id.tv_stop).setOnClickListener(this);
        mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item,null));
 
    }
    private void sendRTKConfig2RemoteService() {
        MyLog.d(TAG,"主动推送RTKConfig");
        CEventCenter.dispatchEvent(Constant.BIND_RTKCONFIG_TOPIC,Constant.FETCH_RTK_PLATFORM_INFO,0,"");
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_start:
                try {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("exam",1);
                    String examJson = jsonObject.toString();
                    Log.i(TAG, "onClick: "+examJson);
                    AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS,examJson);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.tv_stop:
                Toast.makeText(_mActivity, "结束考试", Toast.LENGTH_SHORT).show();
                try {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("exam",0);
                    String examJson = jsonObject.toString();
                    Log.i(TAG, "onClick: "+examJson);
                    AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS,examJson);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.view_map:
                MapFragment mapFragment = findFragment(MapFragment.class);
                if (mapFragment==null){
                    mapFragment = (MapFragment)MapFragment.newInstance();
                }
                start(mapFragment);
                break;
        }
    }
 
 
}