-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
143 additions
and
38 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
app/src/main/java/ksnd/hiraganaconverter/view/MainActivityUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package ksnd.hiraganaconverter.view | ||
|
||
import ksnd.hiraganaconverter.core.data.inappupdate.InAppUpdateState | ||
import ksnd.hiraganaconverter.core.model.ReviewInfo | ||
import ksnd.hiraganaconverter.core.model.ui.FontType | ||
import ksnd.hiraganaconverter.core.model.ui.Theme | ||
|
||
data class MainActivityUiState( | ||
val theme: Theme = Theme.AUTO, | ||
val fontType: FontType = FontType.YUSEI_MAGIC, | ||
val inAppUpdateState: InAppUpdateState = InAppUpdateState.Requesting, | ||
val reviewInfo: ReviewInfo = ReviewInfo(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/data/src/main/java/ksnd/hiraganaconverter/core/data/di/ReviewInfoRepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ksnd.hiraganaconverter.core.data.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import ksnd.hiraganaconverter.core.domain.repository.ConvertHistoryRepository | ||
import ksnd.hiraganaconverter.core.data.repository.ConvertHistoryRepositoryImpl | ||
import ksnd.hiraganaconverter.core.data.repository.ReviewInfoRepositoryImpl | ||
import ksnd.hiraganaconverter.core.domain.repository.ReviewInfoRepository | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class ReviewInfoRepositoryModule { | ||
@Binds | ||
@Singleton | ||
abstract fun bindConvertHistoryRepository(impl: ReviewInfoRepositoryImpl): ReviewInfoRepository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ata/src/main/java/ksnd/hiraganaconverter/core/data/repository/ReviewInfoRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ksnd.hiraganaconverter.core.data.repository | ||
|
||
import androidx.datastore.core.DataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import ksnd.hiraganaconverter.core.domain.repository.ReviewInfoRepository | ||
import ksnd.hiraganaconverter.core.model.ReviewInfo | ||
import javax.inject.Inject | ||
|
||
class ReviewInfoRepositoryImpl @Inject constructor( | ||
private val dataStore: DataStore<ReviewInfo>, | ||
) : ReviewInfoRepository { | ||
override val reviewInfo: Flow<ReviewInfo> = dataStore.data | ||
|
||
override suspend fun countUpTotalConvertCount(): Int { | ||
val newCount = (reviewInfo.firstOrNull()?.totalConvertCount ?: 0) + 1 | ||
dataStore.updateData { it.copy(totalConvertCount = newCount) } | ||
return newCount | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...src/test/java/ksnd/hiraganaconverter/core/data/repository/ReviewInfoRepositoryImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ksnd.hiraganaconverter.core.data.repository | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStoreFactory | ||
import androidx.datastore.preferences.preferencesDataStoreFile | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.test.runTest | ||
import ksnd.hiraganaconverter.core.data.di.ReviewInfoSerializer | ||
import ksnd.hiraganaconverter.core.testing.MainDispatcherRule | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class ReviewInfoRepositoryImplTest { | ||
@get: Rule | ||
val mainDispatcherRule = MainDispatcherRule() | ||
|
||
private val context = ApplicationProvider.getApplicationContext<Context>() | ||
private val dataStore = DataStoreFactory.create( | ||
serializer = ReviewInfoSerializer, | ||
produceFile = { context.preferencesDataStoreFile("TestReviewInfoDataStore") }, | ||
) | ||
private val repository = ReviewInfoRepositoryImpl(dataStore = dataStore) | ||
|
||
@Test | ||
|
||
fun countUpTotalConvertCount_first_is1() = runTest { | ||
assertThat(repository.countUpTotalConvertCount()).isEqualTo(1) | ||
} | ||
|
||
@Test | ||
fun countUpTotalConvertCount_countUp_isCountUp() = runTest { | ||
repeat(5) { assertThat(repository.countUpTotalConvertCount()).isEqualTo(it + 1) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...omain/src/main/java/ksnd/hiraganaconverter/core/domain/repository/ReviewInfoRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ksnd.hiraganaconverter.core.domain.repository | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import ksnd.hiraganaconverter.core.model.ReviewInfo | ||
|
||
interface ReviewInfoRepository { | ||
val reviewInfo: Flow<ReviewInfo> | ||
suspend fun countUpTotalConvertCount(): Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
core/model/src/main/java/ksnd/hiraganaconverter/core/model/ReviewInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ksnd.hiraganaconverter.core.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ReviewInfo( | ||
val isAlreadyReviewed: Boolean = false, | ||
val totalConvertCount: Int = 0, | ||
val lastRequestReviewLocalDateStr: String? = null, | ||
) |