重构m3u8实体

v4
lyy 2 years ago
parent b1abda97d6
commit 126b88d67f
  1. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt
  2. 8
      PublicComponent/src/main/java/com/arialyy/aria/core/service/DbService.kt
  3. 10
      PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt
  4. 9
      PublicComponent/src/main/java/com/arialyy/aria/orm/DuaDb.kt
  5. 2
      PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt
  6. 48
      PublicComponent/src/main/java/com/arialyy/aria/orm/dao/MEntityDao.kt
  7. 17
      PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MEntity.kt
  8. 15
      PublicComponent/src/main/java/com/arialyy/aria/orm/entity/MKeyInfo.kt

@ -17,6 +17,7 @@ package com.arialyy.aria.core
import android.annotation.SuppressLint import android.annotation.SuppressLint
import com.arialyy.aria.core.service.ServiceManager import com.arialyy.aria.core.service.ServiceManager
import kotlinx.coroutines.MainScope
/** /**
* @Author laoyuyu * @Author laoyuyu
@ -28,6 +29,7 @@ internal object DuaContext {
const val DB_SERVICE = "DB_SERVICE" const val DB_SERVICE = "DB_SERVICE"
private val serviceArray = arrayOf(DB_SERVICE) private val serviceArray = arrayOf(DB_SERVICE)
val duaScope = MainScope()
fun isService(serviceName: String) = serviceName in serviceArray fun isService(serviceName: String) = serviceName in serviceArray

@ -27,7 +27,7 @@ import com.arialyy.aria.util.ReflectionUtil
* @Description * @Description
* @Date 19:36 AM 2023/1/16 * @Date 19:36 AM 2023/1/16
**/ **/
internal class DbService : IService { class DbService : IService {
private var duaDb: DuaDb? = null private var duaDb: DuaDb? = null
/** /**
@ -48,11 +48,7 @@ internal class DbService : IService {
} }
} }
// fun findDEntity(dId: Int): DEntity? { fun getDuaDb() = duaDb
// if (duaDb == null) {
// return null
// }
// }
override fun init(context: Context) { override fun init(context: Context) {
var customDb = findCustomDatabase(context) var customDb = findCustomDatabase(context)

@ -46,11 +46,11 @@ object ServiceManager {
/** /**
* get datebase service, if already [registerService] custom service, return custom service * get datebase service, if already [registerService] custom service, return custom service
*/ */
fun getDbService(serviceName: String): DbService { fun getDbService(): DbService {
if (!DuaContext.isService(serviceName)) { if (!DuaContext.isService(DuaContext.DB_SERVICE)) {
throw AriaException("$serviceName Not a service.") throw AriaException("${DuaContext.DB_SERVICE} Not a service.")
} }
return (serviceCache[serviceName] return (serviceCache[DuaContext.DB_SERVICE]
?: throw AriaException("service not found: $serviceName")) as DbService ?: throw AriaException("service not found: ${DuaContext.DB_SERVICE}")) as DbService
} }
} }

@ -18,19 +18,26 @@ package com.arialyy.aria.orm
import androidx.room.Database import androidx.room.Database
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import com.arialyy.aria.orm.dao.DEntityDao 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.dao.UEntityDao
import com.arialyy.aria.orm.entity.BlockRecord import com.arialyy.aria.orm.entity.BlockRecord
import com.arialyy.aria.orm.entity.DGEntity import com.arialyy.aria.orm.entity.DGEntity
import com.arialyy.aria.orm.entity.MEntity 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.TaskRecord
import com.arialyy.aria.orm.entity.UEntity import com.arialyy.aria.orm.entity.UEntity
@Database( @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 version = 1
) )
abstract class DuaDb : RoomDatabase() { abstract class DuaDb : RoomDatabase() {
abstract fun getDEntityDao(): DEntityDao abstract fun getDEntityDao(): DEntityDao
abstract fun getUEntityDao(): UEntityDao abstract fun getUEntityDao(): UEntityDao
abstract fun getDGEntityDao(): DGEntityDao
abstract fun getMEntityDao(): MEntityDao
} }

@ -26,7 +26,7 @@ import com.arialyy.aria.orm.entity.DEntity
/** /**
* @Author laoyuyu * @Author laoyuyu
* @Description * @Description
* @Date 19:23 AM 2023/1/16 * @Date 7:23 AM 2023/1/16
**/ **/
@Dao @Dao
interface DEntityDao { interface DEntityDao {

@ -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
}

@ -18,6 +18,10 @@ package com.arialyy.aria.orm.entity
import androidx.room.Entity import androidx.room.Entity
import androidx.room.Index import androidx.room.Index
import androidx.room.PrimaryKey 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"])]) @Entity(indices = [Index(value = ["sourceUrl", "savePath"])])
data class MEntity( data class MEntity(
@ -58,4 +62,15 @@ data class MEntity(
*/ */
val cacheDir: String? = null 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)
}
}

@ -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 package com.arialyy.aria.orm.entity
import androidx.room.Entity import androidx.room.Entity

Loading…
Cancel
Save