Skip to content

Commit

Permalink
Fixed a bug where questions are not shuffled
Browse files Browse the repository at this point in the history
  • Loading branch information
JackEblan committed Aug 18, 2024
1 parent b0ae884 commit c90976b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ package com.android.socialworkreviewer.core.data.repository
import com.android.socialworkreviewer.core.model.Announcement
import com.android.socialworkreviewer.core.network.firestore.AnnouncementDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import javax.inject.Inject

internal class DefaultAnnouncementRepository @Inject constructor(private val announcementDataSource: AnnouncementDataSource) :
AnnouncementRepository {
override fun getAnnouncements(): Flow<List<Announcement>> {
return announcementDataSource.getAnnouncementDocuments().distinctUntilChanged()
return announcementDataSource.getAnnouncementDocuments()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.android.socialworkreviewer.core.database.model.AverageEntity
import com.android.socialworkreviewer.core.model.Average
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import javax.inject.Inject
Expand All @@ -36,7 +37,7 @@ internal class DefaultAverageRepository @Inject constructor(
return averageDao.getAverageEntitiesByCategory(categoryId = categoryId)
.map { averageEntities ->
averageEntities.map { averageEntity -> averageEntity.toAverage() }
}
}.distinctUntilChanged()
}

override suspend fun upsertAverage(average: Average) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ package com.android.socialworkreviewer.core.data.repository
import com.android.socialworkreviewer.core.model.Category
import com.android.socialworkreviewer.core.network.firestore.CategoryDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import javax.inject.Inject

internal class DefaultCategoryRepository @Inject constructor(private val categoryDataSource: CategoryDataSource) :
CategoryRepository {
override fun getCategories(): Flow<List<Category>> {
return categoryDataSource.getCategoryDocuments().distinctUntilChanged()
return categoryDataSource.getCategoryDocuments()
}

override suspend fun getCategory(categoryId: String): Category? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class GetQuestionsUseCase @Inject constructor(
numberOfQuestions: Int? = null,
): List<Question> {
return if (numberOfQuestions != null) {
questionRepository.getQuestions(id = id).take(numberOfQuestions)
questionRepository.getQuestions(id = id).shuffled().take(numberOfQuestions)
} else {
questionRepository.getQuestions(id = id)
questionRepository.getQuestions(id = id).shuffled()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.google.firebase.firestore.Query
import com.google.firebase.firestore.snapshots
import com.google.firebase.firestore.toObject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull
import javax.inject.Inject

Expand All @@ -43,6 +44,6 @@ internal class DefaultAnnouncementDataSource @Inject constructor(
null
}
}
}
}.distinctUntilChanged()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.google.firebase.firestore.snapshots
import com.google.firebase.firestore.toObject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
Expand All @@ -49,7 +50,7 @@ internal class DefaultCategoryDataSource @Inject constructor(
null
}
}
}
}.distinctUntilChanged()
}

override suspend fun getCategoryDocument(categoryDocumentId: String): Category? {
Expand Down

0 comments on commit c90976b

Please sign in to comment.