mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 02:46:54 -04:00
add base room implementation
This commit is contained in:
@@ -45,4 +45,5 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation project(":base")
|
||||
implementation project(":userlist")
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".home.HomeActivity"
|
||||
android:name=".view.HomeActivity"
|
||||
android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -1,7 +1,32 @@
|
||||
package com.hako.friendlists
|
||||
|
||||
import android.app.Application
|
||||
import com.hako.base.di.baseModule
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.core.context.startKoin
|
||||
import timber.log.Timber
|
||||
|
||||
@Suppress("unused")
|
||||
class MainApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
setupLogger()
|
||||
setupDi()
|
||||
}
|
||||
|
||||
private fun setupLogger() {
|
||||
Timber.plant(Timber.DebugTree())
|
||||
}
|
||||
|
||||
private fun setupDi() {
|
||||
startKoin {
|
||||
androidContext(this@MainApplication)
|
||||
|
||||
modules(
|
||||
listOf(
|
||||
baseModule
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hako.friendlists.home
|
||||
package com.hako.friendlists.view
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ android {
|
||||
minSdkVersion build_versions.min_sdk
|
||||
targetSdkVersion build_versions.target_sdk
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
buildConfigField "String", "DB_NAME", '"friendlists.db"'
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
|
||||
16
base/src/main/java/com/hako/base/di/BaseModules.kt
Normal file
16
base/src/main/java/com/hako/base/di/BaseModules.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.hako.base.di
|
||||
|
||||
import androidx.room.Room
|
||||
import com.hako.base.BuildConfig
|
||||
import com.hako.base.room.BaseDatabase
|
||||
import org.koin.dsl.module
|
||||
|
||||
val baseModule = module {
|
||||
|
||||
// Room database
|
||||
single { Room.databaseBuilder(get(), BaseDatabase::class.java, BuildConfig.DB_NAME).build() }
|
||||
factory { get<BaseDatabase>().userDao() }
|
||||
factory { get<BaseDatabase>().albumDao() }
|
||||
factory { get<BaseDatabase>().photoDao() }
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.hako.base.room.entities.PhotoEntity
|
||||
import com.hako.base.room.entities.UserEntity
|
||||
|
||||
@Database(entities = [UserEntity::class, AlbumEntity::class, PhotoEntity::class], version = 1, exportSchema = false)
|
||||
abstract class Database : RoomDatabase() {
|
||||
abstract class BaseDatabase : RoomDatabase() {
|
||||
abstract fun userDao(): UserDao
|
||||
abstract fun albumDao(): AlbumDao
|
||||
abstract fun photoDao(): PhotoDao
|
||||
@@ -19,7 +19,7 @@ interface AlbumDao {
|
||||
val all: List<AlbumEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${AlbumEntity.TABLE_NAME}")
|
||||
fun count(page: Int): Int
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${AlbumEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
@@ -19,7 +19,7 @@ interface PhotoDao {
|
||||
val all: List<PhotoEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${PhotoEntity.TABLE_NAME}")
|
||||
fun count(page: Int): Int
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${PhotoEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
@@ -19,7 +19,7 @@ interface UserDao {
|
||||
val all: List<UserEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${UserEntity.TABLE_NAME}")
|
||||
fun count(page: Int): Int
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${UserEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
Reference in New Issue
Block a user