Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
5AbhishekSaxena committed Mar 26, 2023
2 parents 304deac + 5c5c8da commit 02ad797
Show file tree
Hide file tree
Showing 54 changed files with 211 additions and 188 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ android {
}
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class GPDApplication : Application() {

}
class GPDApplication : Application()
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fun AgreementContent(
onDialogDismissButtonClick: () -> Unit,
onTermsAcceptedCheckedChange: (Boolean) -> Unit,
) {

if (viewState is AgreementViewState.Loading) {
LoadingContent()
} else if (viewState is AgreementViewState.Error) {
Expand All @@ -46,7 +45,7 @@ fun AgreementContent(
onShowAgreementButtonClick = onShowAgreementButtonClick,
onDialogConfirmButtonClick = onDialogConfirmButtonClick,
onDialogDismissButtonClick = onDialogDismissButtonClick,
onTermsAcceptedCheckedChange = onTermsAcceptedCheckedChange
onTermsAcceptedCheckedChange = onTermsAcceptedCheckedChange,
)
}
}
Expand All @@ -56,9 +55,8 @@ private fun LoadingContent() {
CircularProgressIndicator(
modifier = Modifier
.fillMaxSize()
.wrapContentSize(Alignment.Center)
.wrapContentSize(Alignment.Center),
)

}

@Composable
Expand All @@ -72,15 +70,15 @@ private fun LoadedContent(
onShowAgreementButtonClick: () -> Unit,
onDialogConfirmButtonClick: () -> Unit,
onDialogDismissButtonClick: () -> Unit,
onTermsAcceptedCheckedChange: (Boolean) -> Unit
onTermsAcceptedCheckedChange: (Boolean) -> Unit,
) {
if (!viewState.status && !viewState.showDialog) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
.padding(16.dp),
) {
Text(
text = "Please accept the terms and conditions of the application.",
Expand Down Expand Up @@ -108,7 +106,7 @@ private fun LoadedContent(
viewState = viewState,
onDialogConfirmButtonClick = onDialogConfirmButtonClick,
onDialogDismissButtonClick = onDialogDismissButtonClick,
onTermsAcceptedCheckedChange = onTermsAcceptedCheckedChange
onTermsAcceptedCheckedChange = onTermsAcceptedCheckedChange,
)
}
}
Expand All @@ -118,9 +116,10 @@ private fun AgreementDialog(
viewState: AgreementViewState.Loaded,
onDialogConfirmButtonClick: () -> Unit,
onDialogDismissButtonClick: () -> Unit,
onTermsAcceptedCheckedChange: (Boolean) -> Unit
onTermsAcceptedCheckedChange: (Boolean) -> Unit,
) {
AlertDialog(onDismissRequest = { },
AlertDialog(
onDismissRequest = { },
title = { Text(text = stringResource(id = R.string.agreement_title)) },
confirmButton = {
TextButton(
Expand All @@ -141,13 +140,13 @@ private fun AgreementDialog(
text = {
Column(
modifier = Modifier
.fillMaxSize()
.fillMaxSize(),
) {
Column(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.verticalScroll(rememberScrollState())
.verticalScroll(rememberScrollState()),
) {
Text(text = viewState.agreement)
}
Expand All @@ -170,9 +169,10 @@ private fun AgreementDialog(

Text(
text = stringResource(id = R.string.declaration),
modifier = Modifier.weight(1f)
modifier = Modifier.weight(1f),
)
}
}
})
}
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ fun AgreementScreen(
onShowAgreementButtonClick = viewModel::onShowAgreementButtonClick,
onDialogConfirmButtonClick = viewModel::onDialogConfirmButtonClick,
onDialogDismissButtonClick = viewModel::onDialogDismissButtonClick,
onTermsAcceptedCheckedChange = viewModel::onTermsAcceptedCheckedChange
onTermsAcceptedCheckedChange = viewModel::onTermsAcceptedCheckedChange,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.asStateFlow

@HiltViewModel
class AgreementViewModel @Inject constructor(
private val agreementRepository: AgreementRepository
private val agreementRepository: AgreementRepository,
) : ViewModel() {

private val _viewState = MutableStateFlow<AgreementViewState>(AgreementViewState.Initial)
Expand All @@ -36,8 +36,9 @@ class AgreementViewModel @Inject constructor(

fun onShowAgreementButtonClick() {
val currentViewState = _viewState.value
if (currentViewState is AgreementViewState.Loaded.Active)
if (currentViewState is AgreementViewState.Loaded.Active) {
_viewState.value = currentViewState.copy(showDialog = true)
}
}

fun onDialogConfirmButtonClick() {
Expand Down Expand Up @@ -68,7 +69,7 @@ class AgreementViewModel @Inject constructor(

private fun onAgreementAcceptanceStatusUpdate(
currentViewState: AgreementViewState.Loaded.Active,
status: Boolean
status: Boolean,
) {
if (!currentViewState.termsAccepted) return

Expand All @@ -78,7 +79,6 @@ class AgreementViewModel @Inject constructor(
)

updateAgreementAcceptanceStatus(status)

}

private fun updateAgreementAcceptanceStatus(status: Boolean) {
Expand All @@ -93,4 +93,4 @@ class AgreementViewModel @Inject constructor(

_viewState.value = currentViewState.copy(termsAccepted = checked)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sealed class AgreementViewState {
open val status: Boolean,
open val agreement: String,
open val termsAccepted: Boolean = false,
val inputEnabled: Boolean = false
val inputEnabled: Boolean = false,
) : AgreementViewState() {

data class Active(
Expand All @@ -35,21 +35,20 @@ sealed class AgreementViewState {
status = status,
agreement = agreement,
termsAccepted = true,
inputEnabled = false
inputEnabled = false,
)

data class Accepted(
override val status: Boolean,
override val agreement: String
override val agreement: String,
) : Loaded(
showDialog = false,
status = status,
agreement = agreement,
termsAccepted = true,
inputEnabled = true
inputEnabled = true,
)
}

data class Error(val error: Exception) : AgreementViewState()

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ interface AgreementRepository {
fun getAgreement(): String
fun updateAgreementAcceptanceStatus(status: Boolean)
fun getAgreementAcceptanceStatus(): Boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.inject.Inject

class AgreementRepositoryImpl @Inject constructor(
private val agreementLoader: AgreementLoader,
private val agreementPreferenceManager: AgreementPreferenceManager
private val agreementPreferenceManager: AgreementPreferenceManager,
) : AgreementRepository {

private var agreement: String? = null
Expand All @@ -24,4 +24,4 @@ class AgreementRepositoryImpl @Inject constructor(
override fun getAgreementAcceptanceStatus(): Boolean {
return agreementPreferenceManager.getAgreementAcceptanceStatus()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.abhishek.germanPocketDictionary.agreement.utils

interface AgreementLoader {
fun loadAgreement(): String
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.abhishek.germanPocketDictionary.agreement.utils
interface AgreementPreferenceManager {
fun updateAgreementAcceptanceStatus(status: Boolean)
fun getAgreementAcceptanceStatus(): Boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class AgreementPreferenceManagerImpl @Inject constructor(
override fun getAgreementAcceptanceStatus(): Boolean {
return sharedPreferenceManager.getBoolean(Constants.API_KEYS.PREF_AGREEMENT_KEY)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class RawResourceAgreementLoader @Inject constructor(
}
return agreement.toString()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ interface AgreementModule {
@Binds
@Singleton
fun bindAgreementLoader(
agreementLoader: RawResourceAgreementLoader
agreementLoader: RawResourceAgreementLoader,
): AgreementLoader

@Binds
@Singleton
fun bindAgreementRepository(
agreementRepository: AgreementRepositoryImpl
agreementRepository: AgreementRepositoryImpl,
): AgreementRepository

@Binds
@Singleton
fun bindAgreementSharedPreferenceManager(
agreementPreferenceManager: AgreementPreferenceManagerImpl
agreementPreferenceManager: AgreementPreferenceManagerImpl,
): AgreementPreferenceManager
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ abstract class RepositoryModule {

@Binds
abstract fun bindWordsDataSource(
localDataSource: LocalDataSource
localDataSource: LocalDataSource,
): WordsDataSource

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext


class LocalDataSource @Inject constructor(
@ApplicationContext private val context: Context
@ApplicationContext private val context: Context,
) : WordsDataSource {

private val words: MutableList<Word> = mutableListOf()
Expand Down Expand Up @@ -69,11 +68,12 @@ class LocalDataSource @Inject constructor(

val filteredWords = words.filter { it.category == category }

/*return*/ if (category == Constants.API_KEYS.CATEGORY_NUMBERS)
/*return*/ if (category == Constants.API_KEYS.CATEGORY_NUMBERS) {
filteredWords.sortedBy { it.numberValue }
else
} else {
filteredWords.sortedBy { it.germanTranslationWithoutArticle }
}
}
}

private fun getOpposites(): List<Word> {
val filteredWords = mutableListOf<Word>()
Expand All @@ -92,4 +92,4 @@ class LocalDataSource @Inject constructor(
companion object {
private const val DELAY_TIME = 800L
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.util.regex.Pattern
import javax.inject.Inject

class WordsRepository @Inject constructor(
private val wordsDataSource: WordsDataSource
private val wordsDataSource: WordsDataSource,
) {

private val words = mutableListOf<Word>()
Expand Down Expand Up @@ -35,4 +35,4 @@ class WordsRepository @Inject constructor(
matcher.find()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class MainActivity : ComponentActivity() {
enterTransition = { slideInHorizontally(initialOffsetX = { it }) },
exitTransition = { slideOutHorizontally(targetOffsetX = { -it }) },
popEnterTransition = { slideInHorizontally(initialOffsetX = { -it }) },
popExitTransition = { slideOutHorizontally(targetOffsetX = { it }) }
)
popExitTransition = { slideOutHorizontally(targetOffsetX = { it }) },
),
)

GPDTheme {
ConfigureSystemBars()
Surface {
DestinationsNavHost(
navGraph = NavGraphs.root,
engine = navHostEngine
engine = navHostEngine,
)
}
}
Expand All @@ -59,8 +59,8 @@ class MainActivity : ComponentActivity() {
SideEffect {
systemUiController.setSystemBarsColor(
color = backgroundColor,
darkIcons = useDarkIcons
darkIcons = useDarkIcons,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ fun UiText.getString(context: Context): String {
@Composable
fun UiText.getString(): String {
return this.getString(LocalContext.current)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ fun ErrorText(
.wrapContentSize(Alignment.Center),
color = MaterialTheme.colorScheme.error,
)
}
}
Loading

0 comments on commit 02ad797

Please sign in to comment.