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 {
|
dependencies {
|
||||||
implementation project(":base")
|
implementation project(":base")
|
||||||
|
implementation project(":userlist")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".home.HomeActivity"
|
android:name=".view.HomeActivity"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -1,7 +1,32 @@
|
|||||||
package com.hako.friendlists
|
package com.hako.friendlists
|
||||||
|
|
||||||
import android.app.Application
|
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() {
|
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
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ android {
|
|||||||
minSdkVersion build_versions.min_sdk
|
minSdkVersion build_versions.min_sdk
|
||||||
targetSdkVersion build_versions.target_sdk
|
targetSdkVersion build_versions.target_sdk
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
buildConfigField "String", "DB_NAME", '"friendlists.db"'
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
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
|
import com.hako.base.room.entities.UserEntity
|
||||||
|
|
||||||
@Database(entities = [UserEntity::class, AlbumEntity::class, PhotoEntity::class], version = 1, exportSchema = false)
|
@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 userDao(): UserDao
|
||||||
abstract fun albumDao(): AlbumDao
|
abstract fun albumDao(): AlbumDao
|
||||||
abstract fun photoDao(): PhotoDao
|
abstract fun photoDao(): PhotoDao
|
||||||
@@ -19,7 +19,7 @@ interface AlbumDao {
|
|||||||
val all: List<AlbumEntity>
|
val all: List<AlbumEntity>
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM ${AlbumEntity.TABLE_NAME}")
|
@Query("SELECT COUNT(*) FROM ${AlbumEntity.TABLE_NAME}")
|
||||||
fun count(page: Int): Int
|
fun count(): Int
|
||||||
|
|
||||||
@Query("DELETE FROM ${AlbumEntity.TABLE_NAME}")
|
@Query("DELETE FROM ${AlbumEntity.TABLE_NAME}")
|
||||||
fun nukeDatabase()
|
fun nukeDatabase()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ interface PhotoDao {
|
|||||||
val all: List<PhotoEntity>
|
val all: List<PhotoEntity>
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM ${PhotoEntity.TABLE_NAME}")
|
@Query("SELECT COUNT(*) FROM ${PhotoEntity.TABLE_NAME}")
|
||||||
fun count(page: Int): Int
|
fun count(): Int
|
||||||
|
|
||||||
@Query("DELETE FROM ${PhotoEntity.TABLE_NAME}")
|
@Query("DELETE FROM ${PhotoEntity.TABLE_NAME}")
|
||||||
fun nukeDatabase()
|
fun nukeDatabase()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ interface UserDao {
|
|||||||
val all: List<UserEntity>
|
val all: List<UserEntity>
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM ${UserEntity.TABLE_NAME}")
|
@Query("SELECT COUNT(*) FROM ${UserEntity.TABLE_NAME}")
|
||||||
fun count(page: Int): Int
|
fun count(): Int
|
||||||
|
|
||||||
@Query("DELETE FROM ${UserEntity.TABLE_NAME}")
|
@Query("DELETE FROM ${UserEntity.TABLE_NAME}")
|
||||||
fun nukeDatabase()
|
fun nukeDatabase()
|
||||||
|
|||||||
Reference in New Issue
Block a user