| | |
| | | package cn.flightfeather.thirdapp.repository.dao |
| | | |
| | | import cn.flightfeather.thirdapp.bean.entity.MediaFileCache |
| | | import cn.flightfeather.thirdapp.bean.entity.Mediafile |
| | | import cn.flightfeather.thirdapp.common.database.DbFactory |
| | | import cn.flightfeather.thirdapp.common.database.FlatSaveInterface |
| | | import cn.flightfeather.thirdapp.common.database.flatMapDbSaveResult |
| | | import com.ping.greendao.gen.MediaFileCacheDao |
| | | import com.ping.greendao.gen.MediafileDao |
| | | import io.reactivex.Observable |
| | | import org.greenrobot.greendao.AbstractDao |
| | | |
| | | /** |
| | | * @author riku |
| | |
| | | true |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取缓存的文件 |
| | | */ |
| | | fun getFileCache(url: String?): Observable<String> { |
| | | return DbFactory.getGreenDaoObservable().map { |
| | | val resultList = it.mediaFileCacheDao.queryBuilder() |
| | | .where(MediaFileCacheDao.Properties.Url.eq(url)) |
| | | .list() |
| | | if (resultList.isNotEmpty()) { |
| | | resultList[0].path |
| | | } else { |
| | | "" |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存缓存的文件 |
| | | */ |
| | | fun saveFileCache(url: String, localPath: String, thumbnailPath: String? = null) { |
| | | flatMapDbSaveResult(DbFactory.getInstance().mediaFileCacheDao, |
| | | object : FlatSaveInterface<MediaFileCache, Long> { |
| | | override fun onQuery(dao: AbstractDao<MediaFileCache, Long>): List<MediaFileCache> { |
| | | return dao.queryBuilder() |
| | | .where(MediaFileCacheDao.Properties.Url.eq(url)) |
| | | .list() |
| | | } |
| | | |
| | | override fun onUpdate(list: List<MediaFileCache>) { |
| | | list[0].apply { |
| | | path = localPath |
| | | } |
| | | } |
| | | |
| | | override fun onInsert(): List<MediaFileCache> { |
| | | return listOf(MediaFileCache().apply { |
| | | this.url = url |
| | | this.path = localPath |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | } |