diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListScreen.kt b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListScreen.kt index 3a3719d1c..6947e0383 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListScreen.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListScreen.kt @@ -49,7 +49,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.toSize import androidx.lifecycle.viewmodel.compose.viewModel import com.programmersbox.favoritesdatabase.ListDao -import com.programmersbox.favoritesdatabase.SecurityItem import com.programmersbox.uiviews.utils.LocalCustomListDao import com.programmersbox.uiviews.utils.LocalSettingsHandling import com.programmersbox.uiviews.utils.biometricPrompting @@ -66,7 +65,6 @@ fun OtakuListScreen( ) { val context = LocalContext.current val scope = rememberCoroutineScope() - val securityItems = viewModel.securityItems val showListDetail by LocalSettingsHandling.current.rememberShowListDetail() val windowSize = with(LocalDensity.current) { @@ -110,12 +108,12 @@ fun OtakuListScreen( state.navigateBack() }, addSecurityItem = { - scope.launch { listDao.addSecurityItem(SecurityItem(it)) } + scope.launch { listDao.updateBiometric(it, true) } }, removeSecurityItem = { - scope.launch { listDao.removeSecurityItem(SecurityItem(it)) } + scope.launch { listDao.updateBiometric(it, false) } }, - hasAuthentication = securityItems.any { s -> s.uuid == targetState.item.uuid } + hasAuthentication = targetState.item.useBiometric ) BackHandler { viewModel.customItem = null @@ -150,7 +148,7 @@ fun OtakuListScreen( customLists = viewModel.customLists, navigateDetail = { viewModel.customItem = it - if (securityItems.any { s -> s.uuid == it.item.uuid }) { + if (it.item.useBiometric) { biometricPrompting( context.findActivity(), biometricPrompt diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListViewModel.kt b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListViewModel.kt index c85f05589..abde0c950 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListViewModel.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/lists/OtakuListViewModel.kt @@ -12,7 +12,6 @@ import androidx.lifecycle.viewModelScope import com.programmersbox.favoritesdatabase.CustomList import com.programmersbox.favoritesdatabase.CustomListInfo import com.programmersbox.favoritesdatabase.ListDao -import com.programmersbox.favoritesdatabase.SecurityItem import com.programmersbox.gsonutils.toJson import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -53,8 +52,6 @@ class OtakuListViewModel( .toList() } - val securityItems = mutableStateListOf() - init { listDao.getAllLists() .onEach { @@ -62,14 +59,6 @@ class OtakuListViewModel( customLists.addAll(it) } .launchIn(viewModelScope) - - listDao.getSecurityItems() - .onEach { - println(it) - securityItems.clear() - securityItems.addAll(it) - } - .launchIn(viewModelScope) } fun removeItem(item: CustomListInfo) { diff --git a/favoritesdatabase/src/main/java/com/programmersbox/favoritesdatabase/CustomList.kt b/favoritesdatabase/src/main/java/com/programmersbox/favoritesdatabase/CustomList.kt index 1108e01b2..2be4019f2 100644 --- a/favoritesdatabase/src/main/java/com/programmersbox/favoritesdatabase/CustomList.kt +++ b/favoritesdatabase/src/main/java/com/programmersbox/favoritesdatabase/CustomList.kt @@ -22,11 +22,11 @@ import kotlinx.coroutines.flow.Flow import java.util.UUID @Database( - entities = [CustomListItem::class, CustomListInfo::class, SecurityItem::class], - version = 3, + entities = [CustomListItem::class, CustomListInfo::class], + version = 7, autoMigrations = [ AutoMigration(from = 1, to = 2), - AutoMigration(from = 2, to = 3) + AutoMigration(from = 2, to = 7), ] ) abstract class ListDatabase : RoomDatabase() { @@ -111,14 +111,8 @@ interface ListDao { } } - @Insert(onConflict = OnConflictStrategy.REPLACE) - suspend fun addSecurityItem(item: SecurityItem) - - @Delete - suspend fun removeSecurityItem(item: SecurityItem) - - @Query("SELECT * FROM SecurityItem") - fun getSecurityItems(): Flow> + @Query("UPDATE CustomListItem SET useBiometric = :useBiometric WHERE uuid = :uuid") + suspend fun updateBiometric(uuid: UUID, useBiometric: Boolean) } data class CustomList( @@ -128,7 +122,7 @@ data class CustomList( parentColumn = "uuid", entityColumn = "uuid" ) - val list: List + val list: List, ) @Entity(tableName = "CustomListItem") @@ -140,6 +134,8 @@ data class CustomListItem( val name: String, @ColumnInfo(name = "time") val time: Long = System.currentTimeMillis(), + @ColumnInfo(defaultValue = "0") + val useBiometric: Boolean = false, ) @Entity(tableName = "CustomListInfo") @@ -160,9 +156,3 @@ data class CustomListInfo( @ColumnInfo(name = "sources") val source: String, ) - -@Entity(tableName = "SecurityItem") -data class SecurityItem( - @PrimaryKey - val uuid: UUID, -) \ No newline at end of file