ToDoDatabase singleton updated/fixed.

navHostFragment's layout width and height are now 0dp (match constraint)
This commit is contained in:
Stefan 2020-08-15 22:03:13 +02:00
parent 56dfa4209b
commit ddfb1fc373
3 changed files with 42 additions and 24 deletions

View File

@ -5,13 +5,13 @@ apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"
android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.example.todoapp"
minSdkVersion 26
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
@ -42,8 +42,8 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13'
@ -67,12 +67,12 @@ dependencies {
// Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7"
// DataBinding
kapt "com.android.databinding:compiler:3.2.0-alpha10"
kapt "androidx.databinding:databinding-common:4.0.0"
kapt "androidx.databinding:databinding-common:4.0.1"
// RecyclerView Animator
implementation 'jp.wasabeef:recyclerview-animators:3.0.0'

View File

@ -9,29 +9,47 @@ import com.example.todoapp.data.models.ToDoData
@Database(entities = [ToDoData::class], version = 1, exportSchema = false)
@TypeConverters(Converter::class)
abstract class ToDoDatabase: RoomDatabase() {
abstract class ToDoDatabase : RoomDatabase() {
abstract fun toDoDao(): ToDoDao
// companion object {
// @Volatile
// private var INSTANCE: ToDoDatabase? = null
//
// fun getDatabase(context: Context): ToDoDatabase {
// val tempInstance = INSTANCE
// if (tempInstance != null) {
// return tempInstance
// }
// synchronized(this) {
// val instance = Room.databaseBuilder(
// context.applicationContext,
// ToDoDatabase::class.java,
// "todo_database"
// ).build()
// INSTANCE = instance
// return instance
// }
// }
// }
companion object {
@Volatile
private var INSTANCE: ToDoDatabase? = null
fun getDatabase(context: Context): ToDoDatabase {
val tempInstance = INSTANCE
if(tempInstance != null){
return tempInstance
fun getDatabase(context: Context): ToDoDatabase =
INSTANCE ?: synchronized(this) {
INSTANCE
?: buildDatabase(context).also { INSTANCE = it }
}
synchronized(this){
val instance = Room.databaseBuilder(
private fun buildDatabase(context: Context) =
Room.databaseBuilder(
context.applicationContext,
ToDoDatabase::class.java,
"todo_database"
).build()
INSTANCE = instance
return instance
}
}
ToDoDatabase::class.java, "todo_database"
)
.build()
}
}

View File

@ -9,8 +9,8 @@
<fragment
android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"