endian11
2020-10-26 a5c2e37286dd29b02fff10247e6f3201ad5f58cd
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
package safeluck.drive.evaluation.fragment.rulefragments;
 
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
 
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
 
import com.anyun.exam.lib.AYSdk;
import com.google.gson.Gson;
 
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.bean.CommonSetting;
import safeluck.drive.evaluation.bean.StationSetting;
import safeluck.drive.evaluation.fragment.rulefragments.cview.TextEditText;
import safeluck.drive.evaluation.util.Utils;
import safeluck.drive.evaluation.viewmodels.CommonSettingViewModel;
import safeluck.drive.evaluation.viewmodels.StationSettingViewModel;
 
/**
 * DriveJudge
 *
 * 通过站点设置
 * Created by lzw on 2020/9/14. 10:16:39
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class FragmentSetting5 extends SupportFragment {
    private static final String ARG_NUMBER = "arg_number";
    private static final String TAG = FragmentSetting5.class.getSimpleName();
    private Gson gson = new Gson();
    private StationSetting mStationSetting;
    private StationSettingViewModel mStationSettingViewModel;
 
    private TextEditText te_cross_school_max_speed;
    private TextEditText te_crossing_break_valid_distance;
    private TextEditText te_crossing_stop_valid_distance;
 
    private int mNumber;
 
    public static FragmentSetting5 newInstance(String number) {
        FragmentSetting5 fragment = new FragmentSetting5();
        Bundle args = new Bundle();
        args.putInt(ARG_NUMBER, Integer.parseInt(number));
        fragment.setArguments(args);
        return fragment;
    }
 
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            mNumber =args.getInt(ARG_NUMBER) ;
            Log.i(TAG,"mNumber="+mNumber);
        }
    }
 
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_fragment_stationsettin, container, false);
        initView(view);
        mStationSettingViewModel = ViewModelProviders.of(this).get(StationSettingViewModel.class);
        mStationSettingViewModel.getStationSetting().observe(this, new Observer<StationSetting>() {
            @Override
            public void onChanged(StationSetting commonSetting) {
                if (commonSetting != null){
                    mStationSetting = commonSetting;
                    setDatas();
                }
            }
        });
        return view;
    }
 
    private void initView(View view) {
        te_cross_school_max_speed = view.findViewById(R.id.cross_school_max_speed);
        te_crossing_break_valid_distance = view.findViewById(R.id.crossing_break_valid_distance);
        te_crossing_stop_valid_distance = view.findViewById(R.id.crossing_stop_valid_distance);
 
        view.findViewById(R.id.btn_setting_save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String teCrossSchoolMaxSpeedInput = te_cross_school_max_speed.getInput();
                String teCrossingBreakValidDistanceInput = te_crossing_break_valid_distance.getInput();
                String teCrossingStopValidDistanceInput = te_crossing_stop_valid_distance.getInput();
                if (mStationSetting != null){
                    if (Utils.isDigital(teCrossingBreakValidDistanceInput)){
                        mStationSetting.setCrossing_break_valid_distance(Integer.parseInt(teCrossingBreakValidDistanceInput));
                    }  if (Utils.isDigital(teCrossSchoolMaxSpeedInput)){
                        mStationSetting.setCross_school_max_speed(Integer.parseInt(teCrossSchoolMaxSpeedInput));
                    }  if (Utils.isNumber(teCrossingStopValidDistanceInput)){
                        mStationSetting.setCrossing_stop_valid_distance(Double.parseDouble(teCrossingStopValidDistanceInput));
                    }
                    mStationSettingViewModel.saveCommonSetting(mStationSetting);
                    Toast.makeText(_mActivity, "通过站点设置成功", Toast.LENGTH_SHORT).show();
                    AYSdk.getInstance().sendCmd(Constant.ID_judge_args,gson.toJson(mStationSetting));
                }
            }
        });
 
    }
 
    private void setDatas() {
        te_cross_school_max_speed.setInput(String.valueOf(mStationSetting.getCross_school_max_speed()));
        te_crossing_break_valid_distance.setInput(String.valueOf(mStationSetting.getCrossing_break_valid_distance()));
        te_crossing_stop_valid_distance.setInput(String.valueOf(mStationSetting.getCrossing_stop_valid_distance()));
    }
}