parent
616724a762
commit
ac9f9eb6b8
@ -1,12 +0,0 @@ |
||||
package com.arialyy.aria.core.provider |
||||
|
||||
import androidx.room.RoomDatabase |
||||
|
||||
/** |
||||
* @Author laoyuyu |
||||
* @Description |
||||
* @Date 19:32 PM 2023/1/13 |
||||
**/ |
||||
interface IdbProvider { |
||||
fun initDb() |
||||
} |
@ -0,0 +1,35 @@ |
||||
/* |
||||
* 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.core |
||||
|
||||
import android.annotation.SuppressLint |
||||
import com.arialyy.aria.core.service.ServiceManager |
||||
|
||||
/** |
||||
* @Author laoyuyu |
||||
* @Description |
||||
* @Date 10:40 AM 2023/1/16 |
||||
**/ |
||||
@SuppressLint("StaticFieldLeak") |
||||
internal object DuaContext { |
||||
const val DB_SERVICE = "DB_SERVICE" |
||||
|
||||
private val serviceArray = arrayOf(DB_SERVICE) |
||||
|
||||
fun isService(serviceName: String) = serviceName in serviceArray |
||||
|
||||
fun getServiceManager() = ServiceManager |
||||
} |
@ -0,0 +1,43 @@ |
||||
/* |
||||
* 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.core.provider |
||||
|
||||
import android.content.Context |
||||
import androidx.startup.Initializer |
||||
import com.arialyy.aria.core.DuaContext |
||||
import com.arialyy.aria.core.service.DbService |
||||
import timber.log.Timber |
||||
import timber.log.Timber.DebugTree |
||||
|
||||
class DuaStartupProvider : Initializer<Unit> { |
||||
|
||||
override fun create(context: Context) { |
||||
DuaContext.getServiceManager().let { |
||||
it.registerService(DuaContext.DB_SERVICE, context, DbService::class.java) |
||||
} |
||||
initLog() |
||||
} |
||||
|
||||
private fun initLog() { |
||||
if (Timber.treeCount == 0) { |
||||
Timber.plant(DebugTree()) |
||||
} |
||||
} |
||||
|
||||
override fun dependencies(): MutableList<Class<out Initializer<*>>> { |
||||
return mutableListOf() |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
/* |
||||
* 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.core.service |
||||
|
||||
import android.content.Context |
||||
|
||||
/** |
||||
* @Author laoyuyu |
||||
* @Description |
||||
* @Date 19:34 AM 2023/1/16 |
||||
**/ |
||||
internal interface IService { |
||||
|
||||
fun init(context: Context) |
||||
} |
@ -0,0 +1,56 @@ |
||||
/* |
||||
* 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.core.service |
||||
|
||||
import android.content.Context |
||||
import com.arialyy.aria.core.DuaContext |
||||
import com.arialyy.aria.exception.AriaException |
||||
import timber.log.Timber |
||||
|
||||
object ServiceManager { |
||||
private val serviceCache = hashMapOf<String, IService>() |
||||
|
||||
private fun getServiceName(clazz: Class<*>) = clazz.name |
||||
|
||||
/** |
||||
* register a service |
||||
* @param serviceName [DuaContext.DB_SERVICE] |
||||
*/ |
||||
fun <T : IService> registerService(serviceName: String, context: Context, clazz: Class<T>) { |
||||
if (!DuaContext.isService(serviceName)) { |
||||
throw AriaException("$serviceName Not a service.") |
||||
} |
||||
val sn = getServiceName(clazz) |
||||
val service = serviceCache[sn] |
||||
if (service == null) { |
||||
Timber.d("start register service: $sn") |
||||
val s = clazz.newInstance() |
||||
s.init(context) |
||||
serviceCache[serviceName] = s |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 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.") |
||||
} |
||||
return (serviceCache[serviceName] |
||||
?: throw AriaException("service not found: $serviceName")) as DbService |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
/* |
||||
* 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 |
||||
|
||||
import androidx.room.ProvidedTypeConverter |
||||
import androidx.room.TypeConverter |
||||
import com.google.gson.Gson |
||||
import com.google.gson.reflect.TypeToken |
||||
|
||||
/** |
||||
* @Author laoyuyu |
||||
* @Description |
||||
* @Date 7:24 PM 2023/1/16 |
||||
**/ |
||||
@ProvidedTypeConverter |
||||
class DGUrlConverter { |
||||
private val gson by lazy { |
||||
Gson() |
||||
} |
||||
|
||||
@TypeConverter |
||||
fun stringToList(string: String?): List<String> { |
||||
if (string.isNullOrEmpty()) return emptyList() |
||||
return gson.fromJson(string, object : TypeToken<List<String>>() {}.type) |
||||
} |
||||
|
||||
@TypeConverter |
||||
fun listToString(strList: List<String>): String { |
||||
return gson.toJson(strList) |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
/* |
||||
* 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.entiry.DEntity |
||||
|
||||
/** |
||||
* @Author laoyuyu |
||||
* @Description |
||||
* @Date 19:23 AM 2023/1/16 |
||||
**/ |
||||
@Dao |
||||
interface DEntityDao { |
||||
@Query("SELECT * FROM DEntity WHERE :dId=dId") |
||||
suspend fun queryDEntityById(dId: String): DEntity |
||||
|
||||
@Query("SELECT * FROM DEntity WHERE :sourceUrl=sourceUrl") |
||||
suspend fun queryDEntityBySource(sourceUrl: String): DEntity |
||||
|
||||
@Insert |
||||
suspend fun insert(dEntity: DEntity) |
||||
|
||||
@Update |
||||
suspend fun update(dEntity: DEntity) |
||||
|
||||
@Delete |
||||
suspend fun delete(dEntity: DEntity) |
||||
} |
@ -0,0 +1,46 @@ |
||||
/* |
||||
* 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.entiry.UEntity |
||||
|
||||
/** |
||||
* @Author laoyuyu |
||||
* @Description |
||||
* @Date 19:23 AM 2023/1/16 |
||||
**/ |
||||
@Dao |
||||
interface UEntityDao { |
||||
@Query("SELECT * FROM DEntity WHERE :uId=uId") |
||||
suspend fun queryUEntityById(uId: String): UEntity |
||||
|
||||
@Query("SELECT * FROM UEntity WHERE :filePath=filePath") |
||||
suspend fun queryUEntityBySource(filePath: String): UEntity |
||||
|
||||
@Insert |
||||
suspend fun insert(uEntity: UEntity) |
||||
|
||||
@Update |
||||
suspend fun update(uEntity: UEntity) |
||||
|
||||
@Delete |
||||
suspend fun delete(uEntity: UEntity) |
||||
} |
@ -0,0 +1,62 @@ |
||||
/* |
||||
* 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.entiry |
||||
|
||||
import androidx.room.Entity |
||||
import androidx.room.PrimaryKey |
||||
import androidx.room.TypeConverters |
||||
import com.arialyy.aria.orm.DGUrlConverter |
||||
|
||||
/** |
||||
* @Author laoyuyu |
||||
* @Description |
||||
* @Date 4:32 PM 2023/1/16 |
||||
**/ |
||||
@Entity |
||||
@TypeConverters(DGUrlConverter::class) |
||||
data class DGEntity( |
||||
@PrimaryKey(autoGenerate = true) val dgId: Int = 0, |
||||
|
||||
/** |
||||
* 组合任务等hash为: 为子任务地址相加的url的Md5 |
||||
* ftpdir为:ftpdir下载地址 |
||||
*/ |
||||
val groupHash: String, |
||||
|
||||
/** |
||||
* 任务组别名 |
||||
*/ |
||||
val alias: String? = null, |
||||
|
||||
/** |
||||
* 保存路径 |
||||
*/ |
||||
val savePath: String, |
||||
|
||||
/** |
||||
* 子任务url地址 |
||||
*/ |
||||
val urls: List<String>, |
||||
|
||||
/** |
||||
* extended Information |
||||
*/ |
||||
var ext: String? = null, |
||||
|
||||
val createTime: Long, |
||||
|
||||
val updateTime: Long |
||||
) |
@ -0,0 +1,28 @@ |
||||
/* |
||||
* 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.entiry |
||||
|
||||
import androidx.room.Embedded |
||||
import androidx.room.Relation |
||||
|
||||
data class DGSubList( |
||||
@Embedded val dgEntity: DGEntity, |
||||
@Relation( |
||||
parentColumn = "dgId", |
||||
entityColumn = "dId" |
||||
) |
||||
val subEntity: List<DEntity> |
||||
) |
Loading…
Reference in new issue