Skip to content

Commit

Permalink
Removed language detection from PersonalizationViewModel, removed isS…
Browse files Browse the repository at this point in the history
…ameLanguage
  • Loading branch information
nbradbury committed Dec 19, 2024
1 parent 98febe2 commit 826d227
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.ui.mysite.SelectedSiteRepository
import org.wordpress.android.util.LocaleManagerWrapper
import org.wordpress.android.viewmodel.ScopedViewModel
import javax.inject.Inject
import javax.inject.Named
Expand All @@ -20,7 +19,6 @@ class PersonalizationViewModel @Inject constructor(
private val selectedSiteRepository: SelectedSiteRepository,
private val shortcutsPersonalizationViewModelSlice: ShortcutsPersonalizationViewModelSlice,
private val dashboardCardPersonalizationViewModelSlice: DashboardCardPersonalizationViewModelSlice,
private val localeManagerWrapper: LocaleManagerWrapper
) : ScopedViewModel(bgDispatcher) {
val uiState = dashboardCardPersonalizationViewModelSlice.uiState
val shortcutsState = shortcutsPersonalizationViewModelSlice.uiState
Expand All @@ -32,7 +30,6 @@ class PersonalizationViewModel @Inject constructor(
val appLanguage = _appLanguage as LiveData<String>

init {
emitLanguageRefreshIfNeeded(localeManagerWrapper.getLanguage())
shortcutsPersonalizationViewModelSlice.initialize(viewModelScope)
dashboardCardPersonalizationViewModelSlice.initialize(viewModelScope)
}
Expand Down Expand Up @@ -67,13 +64,4 @@ class PersonalizationViewModel @Inject constructor(
val siteId = selectedSiteRepository.getSelectedSite()!!.siteId
shortcutsPersonalizationViewModelSlice.addShortcut(shortcutState,siteId)
}

private fun emitLanguageRefreshIfNeeded(languageCode: String) {
if (languageCode.isNotEmpty()) {
val shouldEmitLanguageRefresh = !localeManagerWrapper.isSameLanguage(languageCode)
if (shouldEmitLanguageRefresh) {
_appLanguage.value = languageCode
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ object LocaleManager {
private const val MIN_LANGUAGE_CODE_LENGTH = 2
private const val MAX_LANGUAGE_CODE_LENGTH = 6

/**
* Compare the language for the current context with another language.
*
* @param language The language to compare
* @return True if the languages are the same, else false
*/
fun isSameLanguage(language: String): Boolean {
val newLocale = languageLocale(language)
return Locale.getDefault().toString() == newLocale.toString()
}

@Suppress("ForbiddenComment")
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ class LocaleManagerWrapper
fun getTimeZone(): TimeZone = TimeZone.getDefault()
fun getCurrentCalendar(): Calendar = Calendar.getInstance(getLocale())
fun getLanguage(): String = LocaleManager.getLanguage()
fun isSameLanguage(language: String): Boolean = LocaleManager.isSameLanguage(language)
}

0 comments on commit 826d227

Please sign in to comment.