This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseDao<T : BaseEntity>( | |
| private val tableName: String, | |
| private val roomDatabase: RoomDatabase) { | |
| ... the other abstract common methods ... | |
| fun getEntity(ids: Int): LiveData<T> { | |
| return object : ComputableLiveData<List<T>>() { | |
| private var observer: InvalidationTracker.Observer? = null | |
| override fun compute(): List<T>? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Dao | |
| abstract class CatDao : BaseDao<CatEntity>("cat_table") { | |
| ... the other abstract methods ... | |
| @Query("SELECT * from cat_table WHERE id = :id") | |
| abstract fun getEntity(id: Int): LiveData<CatEntity> | |
| @Query("SELECT * from cat_table WHERE id IN (:ids)") | |
| abstract fun getEntity(ids: List<Int>): LiveData<List<CatEntity>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseDao<T : BaseEntity>( | |
| private val tableName: String) { | |
| ... the other abstract common methods ... | |
| @RawQuery | |
| protected abstract fun getEntitySync(query: SupportSQLiteQuery): List<T>? | |
| fun getEntitySync(id: Int): T? { | |
| return getEntitySync(listOf(id))?.firstOrNull() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseEntity { | |
| abstract val id: Int | |
| } | |
| @Entity(tableName = "cat_table") | |
| data class CatEntity(@NonNull | |
| @PrimaryKey | |
| override | |
| val id: Int, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseDao<T>(private val tableName: String) { | |
| ... the other abstract common methods ... | |
| /** | |
| * This code snippet won't compile successfully | |
| * | |
| * @Query("DELETE from tableName") | |
| * abstract fun deleteAll(tableName : String) | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface BaseDao<T> { | |
| @Insert | |
| fun insert(entity: T) | |
| @Insert | |
| fun insert(entities: List<T>) | |
| @Update | |
| fun update(entity: T) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseDao<T : BaseEntity>( | |
| private val tableName: String, | |
| private val roomDatabase: RoomDatabase) { | |
| @Insert(onConflict = OnConflictStrategy.IGNORE) | |
| abstract fun insert(entity: T): Long | |
| @Insert(onConflict = OnConflictStrategy.IGNORE) | |
| abstract fun insert(entities: List<T>): LongArray |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity(tableName = "cat_table") | |
| data class CatEntity(@NonNull | |
| @PrimaryKey | |
| val id : Int, | |
| val name : String) | |
| @Entity(tableName = "dog_table") | |
| data class DogEntity(@NonNull | |
| @PrimaryKey | |
| val id : Int, | |
| val name : String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end | |
| import android.app.Activity; | |
| import android.app.Fragment; | |
| import android.app.FragmentManager; | |
| #parse("File Header.java") | |
| public class ${NAME} extends Fragment { | |
| private static final String FRAG_TAG = ${NAME}.class.getCanonicalName(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright (C) 2017 Mitchell Skaggs, Keturah Gadson, Ethan Holtgrieve, Nathan Skelton, Pattonville School District | |
| * | |
| * This program is free software: you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License as published by | |
| * the Free Software Foundation, either version 3 of the License, or | |
| * (at your option) any later version. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |