From 493b1ee642ab07b8893a1784f4099a9331e1353e Mon Sep 17 00:00:00 2001 From: MyungHyun Ryu Date: Mon, 4 Dec 2023 00:00:42 +0900 Subject: [PATCH 1/3] :bugs: Fix coroutine cancellation --- .../repository/WeightTableRepository.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt index bb939c0d..1686bbb2 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt @@ -51,13 +51,15 @@ class WeightTableRepository @Inject constructor( } } - suspend fun replaceWeightTable(weightRowList: List) { - - val weightRowEntityList = mutableListOf() - for (weightRow in weightRowList) { - weightRowEntityList.add(weightRowMapper.mapFromDomainModel(weightRow)) + fun replaceWeightTable(weightRowList: List) { + CoroutineScope(Dispatchers.IO).launch { + val weightRowEntityList = mutableListOf() + for (weightRow in weightRowList) { + weightRowEntityList.add(weightRowMapper.mapFromDomainModel(weightRow)) + } + weightRowDao.upsertAll(weightRowEntityList) } - weightRowDao.upsertAll(weightRowEntityList) + } suspend fun getBackupWeightTableRequest(): BackupWeightTableRequest { From 028f0d097e54b237bff66cb4e65f0a974f5ade65 Mon Sep 17 00:00:00 2001 From: MyungHyun Ryu Date: Mon, 4 Dec 2023 00:04:37 +0900 Subject: [PATCH 2/3] :bugs: Update db initialization logic to take account guest --- .../java/com/example/speechbuddy/HomeActivity.kt | 15 +++++++++++---- .../speechbuddy/worker/SeedDatabaseWorker.kt | 8 ++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/HomeActivity.kt b/frontend/app/src/main/java/com/example/speechbuddy/HomeActivity.kt index ddb01224..0ce505d7 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/HomeActivity.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/HomeActivity.kt @@ -3,6 +3,7 @@ package com.example.speechbuddy import android.content.Intent import android.os.Build import android.os.Bundle +import android.util.Log import android.view.MotionEvent import android.view.inputmethod.InputMethodManager import androidx.activity.compose.setContent @@ -15,6 +16,7 @@ import com.example.speechbuddy.ui.SpeechBuddyTheme import com.example.speechbuddy.worker.SeedDatabaseWorker import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch +import com.example.speechbuddy.utils.Constants.Companion.GUEST_ID @AndroidEntryPoint class HomeActivity : BaseActivity() { @@ -23,10 +25,15 @@ class HomeActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - // force the database worker to build a new db - // in order to check if the weight-db is empty or not and fill it - val request = OneTimeWorkRequestBuilder().build() - WorkManager.getInstance(this).enqueue(request) + if(sessionManager.userId.value==GUEST_ID) { + // only activates if it is in guest mode. + // does not activate when logged in since db is overwritten on login + // force the database worker to build a new db + // in order to check if the weight-db is empty or not and fill it + Log.d("test", "home acrivity starting initialization of db") + val request = OneTimeWorkRequestBuilder().build() + WorkManager.getInstance(this).enqueue(request) + } setContent { SpeechBuddyTheme( settingsRepository = settingsRepository, diff --git a/frontend/app/src/main/java/com/example/speechbuddy/worker/SeedDatabaseWorker.kt b/frontend/app/src/main/java/com/example/speechbuddy/worker/SeedDatabaseWorker.kt index 2675ea56..d324e565 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/worker/SeedDatabaseWorker.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/worker/SeedDatabaseWorker.kt @@ -27,21 +27,25 @@ class SeedDatabaseWorker( val database = AppDatabase.getInstance(applicationContext) - if (!applicationContext.getDatabasePath("speechbuddy-db").exists()) { + Log.d("create-db", "no db->initializing db") createWeightTable(database) } else{ // check if the weight table is filled with 0 val currentDb = database.weightRowDao().getAllWeightRows().first() - var cnt = 1 + var cnt = 0 for (currentWeightRowEntity in currentDb) { if (currentWeightRowEntity.weights.all{it == 0}){ cnt+=1 // count the rows with 0 weights } } if (cnt == currentDb.size){ // if weight table is filled with 0 + Log.d("create-db", "empty db->initializing db") createWeightTable(database) } + else{ + Log.d("create-db", "db exists") + } } From 054bfcd28781873c10518bd2f3b6ec02dd268991 Mon Sep 17 00:00:00 2001 From: MyungHyun Ryu Date: Mon, 4 Dec 2023 00:05:37 +0900 Subject: [PATCH 3/3] :bugs: Fetch image when opening MySymbolSettings --- .../example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt index 43f49740..b24b1bc5 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt @@ -43,6 +43,7 @@ class MySymbolSettingsViewModel @Inject internal constructor( private var getSymbolsJob: Job? = null init { + symbolRepository.checkImages() getSymbols() }