| | |
| | | package com.example.firstapp.database.repository |
| | | |
| | | import androidx.annotation.WorkerThread |
| | | import com.example.firstapp.database.dao.KeywordDao |
| | | import com.example.firstapp.database.entity.KeywordConfig |
| | | import com.example.firstapp.database.entity.KeywordEntity |
| | |
| | | return try { |
| | | // 从网络获取配置 |
| | | val response = apiService.getKeywords() |
| | | if (response.status == 1) { |
| | | if (response.code == "0") { |
| | | // 保存到本地数据库作为缓存 |
| | | saveToLocal(response.data) |
| | | keywordDao.getAllKeywords() |
| | |
| | | keywordDao.insertAll(keywordEntities) |
| | | } |
| | | |
| | | @WorkerThread |
| | | fun deleteAll() = keywordDao.deleteAll() |
| | | |
| | | |
| | | } |
| | | |