android-room

Updating a RecyclerView by a new LiveData<List> return from Room dynamically

試著忘記壹切 提交于 2021-01-07 06:11:57
问题 I have a conventional Room->DAO->Livedata->Repositiry->ViewModel->RecyclerView app. Different buttons of UI must pass different lists of data to RecyclerView. By button click I want: Make new @Query in DAO and get new LiveData<`List> object in return. Put this new data into the RecyclerViewAdapter and call notifyDataSetChanged () to make new List visuals. The Dao @Query: @Query("SELECT * FROM entry_table WHERE path LIKE :path ORDER BY priority DESC") LiveData<List<Entry>> getNotesOfFolder

Updating a RecyclerView by a new LiveData<List> return from Room dynamically

偶尔善良 提交于 2021-01-07 06:11:27
问题 I have a conventional Room->DAO->Livedata->Repositiry->ViewModel->RecyclerView app. Different buttons of UI must pass different lists of data to RecyclerView. By button click I want: Make new @Query in DAO and get new LiveData<`List> object in return. Put this new data into the RecyclerViewAdapter and call notifyDataSetChanged () to make new List visuals. The Dao @Query: @Query("SELECT * FROM entry_table WHERE path LIKE :path ORDER BY priority DESC") LiveData<List<Entry>> getNotesOfFolder

How do I replace Asynctask with RxJava Observer?

你。 提交于 2021-01-07 02:29:46
问题 I have a test project with Room database. Using Asynctask I can successfully insert an object with some test data into the database. I'm trying to learn RxJava and replace Asynctask with RxJava's observer , but it doesn't work. I have read alot of documentation and watched tutorials, but I don't think I quite get it. Here's the relevant code: Here I set my Room object with the data from my List : for(ObjectForArray item: listToDatabase) { myRoomEntity.setName( item.getName() ); Log.d( "TAG",

Android instrumented test freezes when it tests a suspend function that uses RoomDatabase.withTransaction

大兔子大兔子 提交于 2021-01-05 06:16:17
问题 I'm trying to test the following LocalDataSource function, NameLocalData.methodThatFreezes function, but it freezes. How can I solve this? Or How can I test it in another way? Class to be tested class NameLocalData(private val roomDatabase: RoomDatabase) : NameLocalDataSource { override suspend fun methodThatFreezes(someParameter: Something): Something { roomDatabase.withTransaction { try { // calling room DAO methods here } catch(e: SQLiteConstraintException) { // ... } return something } }

Android LiveData in androidTest returns null

做~自己de王妃 提交于 2021-01-04 03:23:28
问题 I'm running an androidTest instrumentation test and I have a method that returns LiveData from a DAO object using Room. I'm calling the method like so: val animal = roomDatabase.animalsDao().getAnimal(1) animal.observeForever(mMockObserver) assertNotNull(animal.value) I used Mockito to mock the observer: @Mock private lateinit var mMockObserver = Observer<Animal> This should return an instance of LiveData containing the Animal at id 1, but it's null. It's my understanding that in order for

Android Room ORM: Support custom build of SQLite

为君一笑 提交于 2021-01-03 10:32:32
问题 I need to use a custom build of SQLite (based on sqlite.org version https://sqlite.org/android/doc/trunk/www/index.wiki) so that I can use custom FTS Tokenizers and to use SEE to encrypt my databases. I'm using the following code to create a Room database: val mainDb = Room.databaseBuilder(context, MainDatabase::class.java, "main") .openHelperFactory(SqliteOrgSQLiteOpenHelperFactory()) .build() I tried to implement my own "SupportSQLiteOpenHelper.Factory" (SqliteOrgSQLiteOpenHelperFactory)

Pre-packaged database has an invalid schema error

烈酒焚心 提交于 2020-12-31 04:30:55
问题 I'm building an Android application based on an old Android project. In my new application I'm using Room. I have to use the same database that is used in the first project. Furthermore, I've extracted the database from the first project using com.amitshekhar.android:debug-db library. After obtaining the database file I would like to open it with the Room. I am building database like this: Room.databaseBuilder( androidContext(), Database::class.java, "database.db" ).createFromAsset("database

Pre-packaged database has an invalid schema error

断了今生、忘了曾经 提交于 2020-12-31 04:30:20
问题 I'm building an Android application based on an old Android project. In my new application I'm using Room. I have to use the same database that is used in the first project. Furthermore, I've extracted the database from the first project using com.amitshekhar.android:debug-db library. After obtaining the database file I would like to open it with the Room. I am building database like this: Room.databaseBuilder( androidContext(), Database::class.java, "database.db" ).createFromAsset("database

Room TypeConverter with constructer

北战南征 提交于 2020-12-29 06:35:48
问题 I have Room TypeConverter and I need to inject parameter to it's constructor class RoomConverters(moshi Moshi) { @TypeConverter fun fromUserActionLog(data: UserActionLogModel): String { return moshi.adapter(UserActionLogModel::class.java).toJson(data) } @TypeConverter fun toUserActionLog(json: String): UserActionLogModel { return moshi.adapter(UserActionLogModel::class.java).fromJson(json)} } } But when I can not annotate TypeConverter to database object with contructor; @Database(entities =

Room TypeConverter with constructer

南楼画角 提交于 2020-12-29 06:33:50
问题 I have Room TypeConverter and I need to inject parameter to it's constructor class RoomConverters(moshi Moshi) { @TypeConverter fun fromUserActionLog(data: UserActionLogModel): String { return moshi.adapter(UserActionLogModel::class.java).toJson(data) } @TypeConverter fun toUserActionLog(json: String): UserActionLogModel { return moshi.adapter(UserActionLogModel::class.java).fromJson(json)} } } But when I can not annotate TypeConverter to database object with contructor; @Database(entities =