Skip to content

Commit

Permalink
Fix locale lint errors by passing correct Locale to necessary methods
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzkocer committed Oct 9, 2019
1 parent d2e5646 commit 41593d6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.wordpress.android.login.BuildConfig
import org.wordpress.android.ui.accounts.HelpActivity.Origin
import org.wordpress.android.ui.notifications.utils.NotificationsUtils
import org.wordpress.android.ui.prefs.AppPrefs
import org.wordpress.android.ui.utils.currentLocale
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T
import org.wordpress.android.util.DeviceUtils
Expand Down Expand Up @@ -457,7 +458,7 @@ private fun getNetworkInformation(context: Context): String {
return listOf(
"${ZendeskConstants.networkTypeLabel} $networkType",
"${ZendeskConstants.networkCarrierLabel} $carrierName",
"${ZendeskConstants.networkCountryCodeLabel} ${countryCodeLabel.toUpperCase()}"
"${ZendeskConstants.networkCountryCodeLabel} ${countryCodeLabel.toUpperCase(context.currentLocale)}"
).joinToString(separator = "\n")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wordpress.android.ui.news

import org.wordpress.android.util.analytics.AnalyticsUtils
import java.util.Locale
import javax.inject.Inject

import javax.inject.Singleton
Expand All @@ -12,14 +13,14 @@ class NewsTracker @Inject constructor() {
}

fun trackNewsCardShown(origin: NewsCardOrigin, version: Int) {
AnalyticsUtils.trackNewsCardShown(origin.name.toLowerCase(), version)
AnalyticsUtils.trackNewsCardShown(origin.name.toLowerCase(Locale.ROOT), version)
}

fun trackNewsCardDismissed(origin: NewsCardOrigin, version: Int) {
AnalyticsUtils.trackNewsCardDismissed(origin.name.toLowerCase(), version)
AnalyticsUtils.trackNewsCardDismissed(origin.name.toLowerCase(Locale.ROOT), version)
}

fun trackNewsCardExtendedInfoRequested(origin: NewsCardOrigin, version: Int) {
AnalyticsUtils.trackNewsCardExtendedInfoRequested(origin.name.toLowerCase(), version)
AnalyticsUtils.trackNewsCardExtendedInfoRequested(origin.name.toLowerCase(Locale.ROOT), version)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.wordpress.android.ui.pages.PageItem.Empty
import org.wordpress.android.ui.pages.PageItem.Page
import org.wordpress.android.ui.pages.PageItem.ParentPage
import org.wordpress.android.ui.reader.utils.ReaderUtils
import org.wordpress.android.ui.utils.currentLocale
import org.wordpress.android.util.DateTimeUtils
import org.wordpress.android.util.DisplayUtils
import org.wordpress.android.util.ImageUtils
Expand Down Expand Up @@ -54,6 +55,7 @@ sealed class PageItemViewHolder(internal val parent: ViewGroup, @LayoutRes layou
const val FEATURED_IMAGE_THUMBNAIL_SIZE_DP = 40
}

@ExperimentalStdlibApi
override fun onBind(pageItem: PageItem) {
(pageItem as Page).let { page ->
val indentWidth = DisplayUtils.dpToPx(parent.context, 16 * page.indent)
Expand All @@ -67,7 +69,8 @@ sealed class PageItemViewHolder(internal val parent: ViewGroup, @LayoutRes layou
page.title

val date = if (page.date == Date(0)) Date() else page.date
time.text = DateTimeUtils.javaDateToTimeSpan(date, parent.context).capitalize()
time.text = DateTimeUtils.javaDateToTimeSpan(date, parent.context)
.capitalize(parent.context.currentLocale)

if (page.labels.isNotEmpty()) {
labels.text = page.labels.map { parent.context.getString(it) }.sorted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.wordpress.android.ui.sitecreation.misc

import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import java.util.Locale
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -110,14 +111,14 @@ class SiteCreationTracker @Inject constructor(val tracker: AnalyticsTrackerWrapp
}

fun trackErrorShown(errorContext: String, errorType: SiteCreationErrorType, errorDescription: String? = null) {
trackErrorShown(errorContext, errorType.toString().toLowerCase(), errorDescription)
trackErrorShown(errorContext, errorType.toString().toLowerCase(Locale.ROOT), errorDescription)
}

fun trackErrorShown(errorContext: String, errorType: String, errorDescription: String? = null) {
tracker.track(
AnalyticsTracker.Stat.ENHANCED_SITE_CREATION_ERROR_SHOWN,
errorContext,
errorType.toLowerCase(),
errorType.toLowerCase(Locale.ROOT),
errorDescription ?: ""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.wordpress.android.ui.sitecreation.verticals.SiteCreationVerticalsView
import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.util.NetworkUtilsWrapper
import org.wordpress.android.viewmodel.SingleLiveEvent
import java.util.Locale
import javax.inject.Inject
import javax.inject.Named
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -263,7 +264,7 @@ class SiteCreationVerticalsViewModel @Inject constructor(
val onItemTapped = {
tracker.trackVerticalSelected(model.name, model.verticalId, model.isUserInputVertical)
_verticalSelected.value = if (model.isUserInputVertical) {
model.name.toLowerCase()
model.name.toLowerCase(Locale.ROOT)
} else {
model.verticalId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MostPopularInsightsUseCase
return listOf(buildTitle(), Empty())
}

@ExperimentalStdlibApi
override fun buildUiModel(domainModel: InsightsMostPopularModel): List<BlockListItem> {
val items = mutableListOf<BlockListItem>()
items.add(buildTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import org.wordpress.android.util.LocaleManagerWrapper
import org.wordpress.android.viewmodel.ContextProvider
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
import javax.inject.Inject

class DateUtils @Inject constructor(
private val contextProvider: ContextProvider,
private val localeManagerWrapper: LocaleManagerWrapper
) {
@ExperimentalStdlibApi
fun getWeekDay(dayOfTheWeek: Int): String {
val c = Calendar.getInstance()
c.firstDayOfWeek = Calendar.MONDAY
Expand All @@ -28,7 +30,7 @@ class DateUtils @Inject constructor(
}

val formatter = SimpleDateFormat("EEEE", localeManagerWrapper.getLocale())
return formatter.format(c.time).capitalize()
return formatter.format(c.time).capitalize(Locale.ROOT)
}

fun getHour(hour: Int): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.wordpress.android.ui.utils

import android.content.Context
import android.os.Build
import java.util.Locale

// https://developer.android.com/reference/android/content/res/Configuration.html#locale
val Context.currentLocale: Locale
get() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

This comment has been minimized.

Copy link
@malinajirka

malinajirka Oct 10, 2019

Contributor

We might want to consider simplifying this return ConfigurationCompat.getLocales(resources.configuration)[0]. Wdyt?

This comment has been minimized.

Copy link
@oguzkocer

oguzkocer Oct 10, 2019

Author Contributor

As always I am missing Android specific things, thanks for catching it. I also realized there is another extension file for Context, so I moved the currentLocale property there as well. eb8a8f7

return resources.configuration.locales.get(0)
} else {
@Suppress("DEPRECATION")
return resources.configuration.locale
}
}

0 comments on commit 41593d6

Please sign in to comment.