Skip to content

Commit

Permalink
Add support for databases operated with coroutines.(#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dora4 committed Dec 13, 2024
1 parent 3076f2a commit 6d3a76f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.github.dora4"
artifactId = "dcache-android"
version = "3.1.3"
version = "3.1.4"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ abstract class BaseFlowRepository<M, F : CacheHolderFactory<M>>(val context: Con
return connectivityManager.activeNetworkInfo
}

protected open fun getModelType() : Class<M> {
return getGenericType(this) as Class<M>
}

private fun getGenericType(obj: Any): Class<*> {
return if (obj.javaClass.genericSuperclass is ParameterizedType &&
(obj.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments.isNotEmpty()) {
Expand All @@ -350,7 +354,7 @@ abstract class BaseFlowRepository<M, F : CacheHolderFactory<M>>(val context: Con
} else {
isLogPrint = repository.isLogPrint
}
MClass = getGenericType(this) as Class<M>
MClass = getModelType()
Log.d(TAG, "MClass:$MClass,isListMode:$isListMode")
cacheHolderFactory = createCacheHolderFactory()
// 二选一实现CacheHolder和DataFetcher并使用
Expand Down
6 changes: 5 additions & 1 deletion dcache/src/main/java/dora/cache/repository/BaseRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ abstract class BaseRepository<M, F : CacheHolderFactory<M>>(val context: Context
return connectivityManager.activeNetworkInfo
}

protected open fun getModelType() : Class<M> {
return getGenericType(this) as Class<M>
}

private fun getGenericType(obj: Any): Class<*> {
return if (obj.javaClass.genericSuperclass is ParameterizedType &&
(obj.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments.isNotEmpty()) {
Expand All @@ -346,7 +350,7 @@ abstract class BaseRepository<M, F : CacheHolderFactory<M>>(val context: Context
} else {
isLogPrint = repository.isLogPrint
}
MClass = getGenericType(this) as Class<M>
MClass = getModelType()
Log.d(TAG, "MClass:$MClass,isListMode:$isListMode")
cacheHolderFactory = createCacheHolderFactory()
// Implement either CacheHolder or DataFetcher and use it.
Expand Down

0 comments on commit 6d3a76f

Please sign in to comment.