| | |
| | | package safeluck.drive.evaluation.DB.route; |
| | | |
| | | import android.content.Context; |
| | | import android.os.Environment; |
| | | import android.util.Log; |
| | | |
| | | import androidx.annotation.NonNull; |
| | |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.google.gson.stream.JsonReader; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | |
| | | import java.util.List; |
| | | |
| | | import okhttp3.Route; |
| | | import safeluck.drive.evaluation.DB.Constant; |
| | | import safeluck.drive.evaluation.DB.Student; |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | import safeluck.drive.evaluation.bean.RouteCollect; |
| | |
| | | public Result doWork() { |
| | | Log.i(TAG, "doWork: "+Thread.currentThread().getId()); |
| | | try { |
| | | InputStream inputStream = getApplicationContext().getAssets().open("routeline.json"); |
| | | File file = new File(Environment.getExternalStorageDirectory()+File.separator+getApplicationContext().getPackageName()+ |
| | | File.separator+ Constant.ROUTELINE_JSON); |
| | | |
| | | if (!file.exists()){ |
| | | return Result.failure(); |
| | | } |
| | | InputStream inputStream = null; |
| | | try { |
| | | inputStream =new FileInputStream(file); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | InputStreamReader inputStreamReader = new InputStreamReader(inputStream); |
| | | JsonReader jsonReader = new JsonReader(inputStreamReader); |
| | | |
| | | |
| | | Gson gson = new Gson(); |
| | | Type type = new TypeToken<List<RouteCollect>>(){}.getType(); |
| | |
| | | routeCross.setActive(bean.getActive()); |
| | | routeCross.setIdx(bean.getIdx()); |
| | | routeCross.setRoad(bean.getRoad()); |
| | | routeCross.setRouteline_id(i+1); |
| | | routeCross.setRouteline_id(route.getId()); |
| | | WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getRouteCrooDao().insertRouteCross(routeCross); |
| | | } |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | } catch (IOException e) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.failure(); |
| | | } |