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
package safeluck.drive.evaluation.DB.rtktb;
 
import android.content.Context;
import android.util.Log;
 
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.List;
 
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.DB.Student;
import safeluck.drive.evaluation.DB.WorkRoomDataBase;
import safeluck.drive.evaluation.util.FileUtil;
 
public class RTKConfigWork extends Worker {
    private Context context;
    public RTKConfigWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
        this.context = context;
    }
 
    @NonNull
    @Override
    public Result doWork() {
 
        try {
            InputStream inputStream = getApplicationContext().getAssets().open(Constant.RTK_CONFIG_JSON);
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            JsonReader jsonReader = new JsonReader(inputStreamReader);
 
            Gson gson = new Gson();
            Type type = new TypeToken<RTKConfig>(){}.getType();
 
            RTKConfig mstus=gson.fromJson(jsonReader,   type);
            WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getRTKConfigDao().insert(mstus);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.failure();
        }
        return Result.success();
    }
}