From 126b88d67f9a23ca5b7c6466d73b5046fa49e125 Mon Sep 17 00:00:00 2001 From: lyy <511455842@QQ.com> Date: Fri, 20 Jan 2023 10:38:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84m3u8=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/arialyy/aria/core/DuaContext.kt | 2 + .../arialyy/aria/core/service/DbService.kt | 8 +--- .../aria/core/service/ServiceManager.kt | 10 ++-- .../main/java/com/arialyy/aria/orm/DuaDb.kt | 9 +++- .../com/arialyy/aria/orm/dao/DEntityDao.kt | 2 +- .../com/arialyy/aria/orm/dao/MEntityDao.kt | 48 +++++++++++++++++++ .../com/arialyy/aria/orm/entity/MEntity.kt | 17 ++++++- .../com/arialyy/aria/orm/entity/MKeyInfo.kt | 15 ++++++ 8 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 PublicComponent/src/main/java/com/arialyy/aria/orm/dao/MEntityDao.kt diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt index f00a923f..c6a650db 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt @@ -17,6 +17,7 @@ package com.arialyy.aria.core import android.annotation.SuppressLint import com.arialyy.aria.core.service.ServiceManager +import kotlinx.coroutines.MainScope /** * @Author laoyuyu @@ -28,6 +29,7 @@ internal object DuaContext { const val DB_SERVICE = "DB_SERVICE" private val serviceArray = arrayOf(DB_SERVICE) + val duaScope = MainScope() fun isService(serviceName: String) = serviceName in serviceArray diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/service/DbService.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/service/DbService.kt index 3046f481..ed431f17 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/service/DbService.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/service/DbService.kt @@ -27,7 +27,7 @@ import com.arialyy.aria.util.ReflectionUtil * @Description * @Date 19:36 AM 2023/1/16 **/ -internal class DbService : IService { +class DbService : IService { private var duaDb: DuaDb? = null /** @@ -48,11 +48,7 @@ internal class DbService : IService { } } - // fun findDEntity(dId: Int): DEntity? { - // if (duaDb == null) { - // return null - // } - // } + fun getDuaDb() = duaDb override fun init(context: Context) { var customDb = findCustomDatabase(context) diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt index 243545a0..85d7dd8e 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt @@ -46,11 +46,11 @@ object ServiceManager { /** * get datebase service, if already [registerService] custom service, return custom service */ - fun getDbService(serviceName: String): DbService { - if (!DuaContext.isService(serviceName)) { - throw AriaException("$serviceName Not a service.") + fun getDbService(): DbService { + if (!DuaContext.isService(DuaContext.DB_SERVICE)) { + throw AriaException("${DuaContext.DB_SERVICE} Not a service.") } - return (serviceCache[serviceName] - ?: throw AriaException("service not found: $serviceName")) as DbService + return (serviceCache[DuaContext.DB_SERVICE] + ?: throw AriaException("service not found: ${DuaContext.DB_SERVICE}")) as DbService } } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DuaDb.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/DuaDb.kt index 0c3dfcb7..1647dc11 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DuaDb.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DuaDb.kt @@ -18,19 +18,26 @@ package com.arialyy.aria.orm import androidx.room.Database import androidx.room.RoomDatabase import com.arialyy.aria.orm.dao.DEntityDao +import com.arialyy.aria.orm.dao.DGEntityDao +import com.arialyy.aria.orm.dao.MEntityDao import com.arialyy.aria.orm.dao.UEntityDao import com.arialyy.aria.orm.entity.BlockRecord import com.arialyy.aria.orm.entity.DGEntity import com.arialyy.aria.orm.entity.MEntity +import com.arialyy.aria.orm.entity.MKeyInfo import com.arialyy.aria.orm.entity.TaskRecord import com.arialyy.aria.orm.entity.UEntity @Database( - entities = [DbEntity::class, UEntity::class, DGEntity::class, MEntity::class, TaskRecord::class, BlockRecord::class], + entities = [DbEntity::class, UEntity::class, DGEntity::class, MEntity::class, MKeyInfo::class, TaskRecord::class, BlockRecord::class], version = 1 ) abstract class DuaDb : RoomDatabase() { abstract fun getDEntityDao(): DEntityDao abstract fun getUEntityDao(): UEntityDao + + abstract fun getDGEntityDao(): DGEntityDao + + abstract fun getMEntityDao(): MEntityDao } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt index ab0c5494..d9e5ab1c 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt @@ -26,7 +26,7 @@ import com.arialyy.aria.orm.entity.DEntity /** * @Author laoyuyu * @Description - * @Date 19:23 AM 2023/1/16 + * @Date 7:23 AM 2023/1/16 **/ @Dao interface DEntityDao { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/MEntityDao.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/MEntityDao.kt new file mode 100644 index 00000000..bb29b31a --- /dev/null +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/MEntityDao.kt @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.orm.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query +import androidx.room.Update +import com.arialyy.aria.orm.entity.MEntity +import com.arialyy.aria.orm.entity.MKeyInfo + +/** + * @Author laoyuyu + * @Description + * @Date 10:23 AM 2023/1/120 + **/ +@Dao +interface MEntityDao { + + @Query("SELECT * FROM MEntity WHERE :savePath=savePath") + suspend fun getMEntityByPath(savePath: String): MEntity + + @Update + suspend fun update(entity: MEntity) + + @Insert + suspend fun insert(entity: MEntity) + + @Delete + suspend fun delete(entity: MEntity) + + @Query("SELECT * FROM MKeyInfo WHERE :kId=kId") + suspend fun getKeyInfoByKId(kId: Int): MKeyInfo +} \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MEntity.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MEntity.kt index cf0c18ba..2b869b2d 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MEntity.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MEntity.kt @@ -18,6 +18,10 @@ package com.arialyy.aria.orm.entity import androidx.room.Entity import androidx.room.Index import androidx.room.PrimaryKey +import com.arialyy.aria.core.DuaContext +import com.arialyy.aria.orm.DuaDb +import timber.log.Timber +import java.util.TimeZone @Entity(indices = [Index(value = ["sourceUrl", "savePath"])]) data class MEntity( @@ -58,4 +62,15 @@ data class MEntity( */ val cacheDir: String? = null -) +) { + fun hasKey() = keyId != -1 + + suspend fun getKeyInfo(): MKeyInfo? { + if (!hasKey()) { + Timber.w("no key info") + return null + } + return DuaContext.getServiceManager().getDbService().getDuaDb()?.getMEntityDao() + ?.getKeyInfoByKId(keyId) + } +} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MKeyInfo.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MKeyInfo.kt index 481773fa..b98cf4fa 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MKeyInfo.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MKeyInfo.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.arialyy.aria.orm.entity import androidx.room.Entity