Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
RznNike committed Jan 26, 2024
2 parents 4f6b43e + 37e2ca8 commit 3065afe
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 166 deletions.
7 changes: 2 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {
targetSdk = rootProject.extra["TARGET_SDK"] as Int
versionCode = rootProject.extra["VERSION_CODE"] as Int
versionName = rootProject.extra["VERSION_NAME"] as String
resourceConfigurations += setOf("en", "ru")
}

buildTypes {
Expand Down Expand Up @@ -148,7 +149,7 @@ dependencies {
implementation("com.google.android.material:material:1.11.0")

// Firebase
implementation("com.google.firebase:firebase-crashlytics-ktx:18.6.0")
implementation("com.google.firebase:firebase-crashlytics-ktx:18.6.1")
implementation("com.google.firebase:firebase-messaging:23.4.0")

// Koin
Expand Down Expand Up @@ -182,10 +183,6 @@ dependencies {
// https://github.com/coil-kt/coil
implementation("io.coil-kt:coil:2.5.0")

// Language
// https://github.com/YarikSOffice/lingver
implementation("com.github.YarikSOffice:lingver:1.3.0")

// MPAndroidChart
// https://github.com/PhilJay/MPAndroidChart
implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
android:localeConfig="@xml/locales_config"
tools:ignore="DataExtractionRules,UnusedAttribute">

<activity
Expand Down Expand Up @@ -45,6 +46,15 @@
</intent-filter>
</service>

<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false"
android:exported="false">
<meta-data
android:name="autoStoreLocales"
android:value="true" />
</service>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.file_provider"
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/ru/rznnike/eyehealthmanager/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ru.rznnike.eyehealthmanager.app
import android.app.Application
import androidx.lifecycle.ProcessLifecycleOwner
import com.google.firebase.FirebaseApp
import com.yariksoffice.lingver.Lingver
import io.objectbox.BoxStore
import io.objectbox.android.Admin
import org.koin.android.ext.android.inject
Expand All @@ -28,7 +27,6 @@ class App : Application() {
initFirebase()
initKoin()
initLifecycleObserver()
initLanguage()
initObjectBoxBrowser()
}

Expand All @@ -52,10 +50,6 @@ class App : Application() {
.addObserver(appLifecycleObserver)
}

private fun initLanguage() {
Lingver.init(this, preferences.language.get())
}

private fun initObjectBoxBrowser() {
if (BuildConfig.DEBUG) {
Admin(boxStore).start(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import ru.rznnike.eyehealthmanager.domain.interactor.test.*
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetAcuityTestingSettingsUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetAppThemeUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetApplyDynamicCorrectionsUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.SetUserLanguageUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetDisplayedChangelogVersionUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetTestingSettingsUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetUserLanguageUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetWelcomeDialogShowedUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.SetAcuityTestingSettingsUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.SetAppThemeUseCase
Expand All @@ -27,8 +25,6 @@ val interactorModule = module {
single { SetWelcomeDialogShowedUseCase(get(), get()) }
single { GetDisplayedChangelogVersionUseCase(get(), get()) }
single { SetDisplayedChangelogVersionUseCase(get(), get()) }
single { GetUserLanguageUseCase(get(), get()) }
single { SetUserLanguageUseCase(get(), get()) }
single { GetTestingSettingsUseCase(get(), get()) }
single { SetTestingSettingsUseCase(get(), get()) }
single { GetAcuityTestingSettingsUseCase(get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package ru.rznnike.eyehealthmanager.app.global.ui.activity

import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import androidx.activity.addCallback
import androidx.annotation.LayoutRes
import com.yariksoffice.lingver.Lingver
import moxy.MvpAppCompatActivity
import org.koin.android.ext.android.inject
import ru.rznnike.eyehealthmanager.R
Expand All @@ -14,7 +12,6 @@ import ru.rznnike.eyehealthmanager.app.global.ui.fragment.BaseFragment
import ru.rznnike.eyehealthmanager.app.utils.extensions.applyTheme
import ru.rznnike.eyehealthmanager.data.preference.PreferencesWrapper
import ru.rznnike.eyehealthmanager.domain.model.enums.AppTheme
import ru.rznnike.eyehealthmanager.domain.model.enums.Language

abstract class BaseActivity(@LayoutRes layoutRes: Int) : MvpAppCompatActivity(layoutRes) {
private val preferences: PreferencesWrapper by inject()
Expand All @@ -24,24 +21,13 @@ abstract class BaseActivity(@LayoutRes layoutRes: Int) : MvpAppCompatActivity(la
get() = supportFragmentManager.findFragmentById(R.id.container) as? BaseFragment

override fun onCreate(savedInstanceState: Bundle?) {
setLanguage()
applyTheme(AppTheme[preferences.appTheme.get()])
onBackPressedDispatcher.addCallback(this) {
currentFragment?.onBackPressed()
}
super.onCreate(savedInstanceState)
}

private fun setLanguage() {
if (!preferences.language.isSet()) {
val defaultLanguage = Resources.getSystem().configuration.locales[0].language
preferences.language.set(Language[defaultLanguage].tag)
}

Lingver.getInstance().setLocale(application, preferences.language.get())
errorHandler.resources = baseContext.resources
}

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
errorHandler.resources = baseContext.resources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.rznnike.eyehealthmanager.app.presentation.main.settings

import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import moxy.InjectViewState
import moxy.presenterScope
Expand All @@ -12,11 +11,11 @@ import ru.rznnike.eyehealthmanager.app.dispatcher.notifier.Notifier
import ru.rznnike.eyehealthmanager.app.global.presentation.BasePresenter
import ru.rznnike.eyehealthmanager.app.global.presentation.ErrorHandler
import ru.rznnike.eyehealthmanager.app.utils.extensions.applyTheme
import ru.rznnike.eyehealthmanager.app.utils.extensions.getSelectedLanguage
import ru.rznnike.eyehealthmanager.app.utils.extensions.setSelectedLanguage
import ru.rznnike.eyehealthmanager.domain.interactor.dev.GenerateDataUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetAppThemeUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.GetUserLanguageUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.SetAppThemeUseCase
import ru.rznnike.eyehealthmanager.domain.interactor.user.SetUserLanguageUseCase
import ru.rznnike.eyehealthmanager.domain.model.enums.AppTheme
import ru.rznnike.eyehealthmanager.domain.model.enums.DataGenerationType
import ru.rznnike.eyehealthmanager.domain.model.enums.Language
Expand All @@ -26,26 +25,24 @@ class SettingsPresenter : BasePresenter<SettingsView>() {
private val errorHandler: ErrorHandler by inject()
private val notifier: Notifier by inject()
private val eventDispatcher: EventDispatcher by inject()
private val getUserLanguageUseCase: GetUserLanguageUseCase by inject()
private val setUserLanguageUseCase: SetUserLanguageUseCase by inject()
private val getAppThemeUseCase: GetAppThemeUseCase by inject()
private val setAppThemeUseCase: SetAppThemeUseCase by inject()
private val generateDataUseCase: GenerateDataUseCase by inject()

private var language = Language.EN
private var language = getSelectedLanguage()
private var theme = AppTheme.SYSTEM

override fun onFirstViewAttach() {
initData()
}

fun onResume() {
language = getSelectedLanguage()
populateData()
}

private fun initData() {
presenterScope.launch {
getUserLanguageUseCase().process(
{ result ->
language = result
}, ::onError
)
getAppThemeUseCase().process(
{ result ->
theme = result
Expand All @@ -61,17 +58,7 @@ class SettingsPresenter : BasePresenter<SettingsView>() {
theme = theme
)

fun changeLanguage(language: Language) {
presenterScope.launch {
viewState.setProgress(true)
setUserLanguageUseCase(language).process(
{
delay(500)
viewState.updateUiLanguage()
}, ::onError
)
}
}
fun changeLanguage(language: Language) = setSelectedLanguage(language)

fun changeTheme(newTheme: AppTheme) {
presenterScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ interface SettingsView : NavigationMvpView {

@AddToEndSingle
fun populateData(language: Language, theme: AppTheme)

@OneExecution
fun updateUiLanguage()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ru.rznnike.eyehealthmanager.app.global.ui.fragment.BaseFragment
import ru.rznnike.eyehealthmanager.app.presentation.main.settings.SettingsPresenter
import ru.rznnike.eyehealthmanager.app.presentation.main.settings.SettingsView
import ru.rznnike.eyehealthmanager.app.utils.extensions.addSystemWindowInsetToPadding
import ru.rznnike.eyehealthmanager.app.utils.extensions.restartApp
import ru.rznnike.eyehealthmanager.app.utils.extensions.setScaleOnTouch
import ru.rznnike.eyehealthmanager.app.utils.extensions.setVisible
import ru.rznnike.eyehealthmanager.databinding.DialogAboutAppBinding
Expand Down Expand Up @@ -50,6 +49,11 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings), SettingsView
initOnClickListeners()
}

override fun onResume() {
super.onResume()
presenter.onResume()
}

private fun initViews() = binding.apply {
listOf(
buttonTestingSettings,
Expand Down Expand Up @@ -128,8 +132,6 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings), SettingsView
)
}

override fun updateUiLanguage() = requireActivity().restartApp()

private fun showThemeSelectionBottomDialog(currentTheme: AppTheme) {
showBottomDialog(
header = getString(R.string.choose_theme),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package ru.rznnike.eyehealthmanager.app.utils.extensions
import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import ru.rznnike.eyehealthmanager.domain.model.enums.AppTheme
import ru.rznnike.eyehealthmanager.domain.model.enums.Language
import java.util.Locale
import kotlin.system.exitProcess

fun Activity.restartApp() {
Expand All @@ -21,3 +24,11 @@ fun applyTheme(theme: AppTheme) {
}
AppCompatDelegate.setDefaultNightMode(flag)
}

fun getSelectedLanguage() = Language[
(AppCompatDelegate.getApplicationLocales()[0] ?: Locale.getDefault()).language
]

fun setSelectedLanguage(language: Language) = AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(language.tag)
)
Loading

0 comments on commit 3065afe

Please sign in to comment.