blonsky95 / DigiCoachAndroid

0 stars 0 forks source link

TASK 3 & 7 - add premade blocks #34

Closed blonsky95 closed 4 years ago

blonsky95 commented 4 years ago

Add a couple premade blocks which are installed on the first time the application is run https://stackoverflow.com/questions/44697418/how-to-populate-android-room-database-table-on-first-run

blonsky95 commented 4 years ago

ADD TO THIS: Fix this warning: 2019-11-19 23:06:59.402 18386-18395/com.tatoe.mydigicoach W/SQLiteConnectionPool: A SQLiteConnection object for database -/data/user/0/com.tatoe.mydigicoach/databases/digital_coach.db- was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

blonsky95 commented 4 years ago

Also read this and UNDERSTAND: https://www.baeldung.com/kotlin-threads-coroutines

blonsky95 commented 4 years ago

So it seems to work, but I left a TODO in Library for an issue, which as described in that block of comment: when data viewmodel is first initialized it loads the intiial blocks, but the observers don't seem to pick it up, perhaps because it is done from another thread maybe coroutines fixes this. but basically dataviewmodel needs to be initialized once before the intial blocks are seen in Library app blocks list.

blonsky95 commented 4 years ago

ADD TO THIS: Fix this warning: 2019-11-19 23:06:59.402 18386-18395/com.tatoe.mydigicoach W/SQLiteConnectionPool: A SQLiteConnection object for database -/data/user/0/com.tatoe.mydigicoach/databases/digital_coach.db- was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

To solve this dataview model now calls getInstance instead of buildDatabase directly. See if the warning continue happening with this approach.

blonsky95 commented 4 years ago

I added the import button functionality to the adapter

blonsky95 commented 4 years ago

todo:

blonsky95 commented 4 years ago

Also read this and UNDERSTAND: https://www.baeldung.com/kotlin-threads-coroutines

AppRoomDatabase is now created with a coroutine instead of a thread in Executors but for some reason using Dispatchers.IOThread wasn't working and it has to be called from GlobalScope. Not sure why.

When we want to run a job and want a response, we can create a deferred job: val deferred = async { return@async "${Thread.currentThread()} has run." } and then do something with the result with: runBlocking { val result = deferred.await() println(result) }

This might be used when we await for operation

blonsky95 commented 4 years ago

Ok dialog is there but ran into a little problem, as exercises in exercisecreator were empty. They had no fieldsHashMap.

It's because when I use the Exercise constrcutor (name, description) no fields map is created. So in initial block the exercises have to use the other constructor < Exercise(LinkedHashMap(mutableMapOf("Name" to "pull ups", "Description" to "Change grip to use different muscles")))> like that.

Do that with the rest, and perhaps change in Exercise creator the creation of exercises with the linkedhashmap constructor as well

then check if the deleting is working + add it to deleting block in Blocks

blonsky95 commented 4 years ago

Deleting isn't working because:

When the exercises are initialised they dont have an id, it is autogenerated when they are inserted into the db. So the block has as components exercises without id, so they can't be deleted.

The solution will be to import the exercises separately and one by one, and then fetch them from the database and create the block and import it. However problems:

blonsky95 commented 4 years ago

Ok its done its working lets get this bread When importing block from premade or wherever, it first inserts all the exercises, and when they have been inserted in db, they are used (now they have ID) to insert the block. notes