Skip to content

Commit b2166af

Browse files
committed
detekt
1 parent b8df41a commit b2166af

File tree

5 files changed

+43
-47
lines changed

5 files changed

+43
-47
lines changed

WordPress/src/main/java/org/wordpress/android/ui/newstats/mostviewed/MostViewedCard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import java.util.Locale
5858
private val CardCornerRadius = 10.dp
5959
private val CardPadding = 16.dp
6060
private val CardMargin = 16.dp
61-
private val HighlightedItemBackgroundAlpha = 0.08f
61+
private const val HIGHLIGHTED_ITEM_BACKGROUND_ALPHA = 0.08f
6262
private val ChangeBadgePositiveColor = Color(0xFF4CAF50)
6363
private val ChangeBadgeNegativeColor = Color(0xFFE91E63)
6464

@@ -321,7 +321,7 @@ private fun ColumnHeadersRow(
321321

322322
@Composable
323323
private fun MostViewedItemRow(item: MostViewedItem, percentage: Float) {
324-
val barColor = MaterialTheme.colorScheme.primary.copy(alpha = HighlightedItemBackgroundAlpha)
324+
val barColor = MaterialTheme.colorScheme.primary.copy(alpha = HIGHLIGHTED_ITEM_BACKGROUND_ALPHA)
325325

326326
Box(
327327
modifier = Modifier

WordPress/src/main/java/org/wordpress/android/ui/newstats/mostviewed/MostViewedCardUiState.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ sealed class MostViewedChange : Serializable {
5151
data class Negative(val value: Long, val percentage: Double) : MostViewedChange()
5252
data object NoChange : MostViewedChange()
5353
data object NotAvailable : MostViewedChange()
54+
55+
companion object {
56+
private const val serialVersionUID: Long = 1L
57+
}
5458
}
5559

5660
/**
@@ -62,4 +66,8 @@ data class MostViewedDetailItem(
6266
val title: String,
6367
val views: Long,
6468
val change: MostViewedChange
65-
) : Serializable
69+
) : Serializable {
70+
companion object {
71+
private const val serialVersionUID: Long = 1L
72+
}
73+
}

WordPress/src/main/java/org/wordpress/android/ui/newstats/mostviewed/MostViewedDetailActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class MostViewedDetailActivity : BaseAppCompatActivity() {
9090
}
9191

9292
companion object {
93+
@Suppress("LongParameterList")
9394
fun start(
9495
context: Context,
9596
dataSource: MostViewedDataSource,

WordPress/src/main/java/org/wordpress/android/ui/newstats/mostviewed/MostViewedViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import kotlin.math.abs
1818
import org.wordpress.android.viewmodel.ResourceProvider
1919
import javax.inject.Inject
2020

21+
private const val MONTH_ABBREVIATION_LENGTH = 3
22+
2123
@HiltViewModel
2224
class MostViewedViewModel @Inject constructor(
2325
private val selectedSiteRepository: SelectedSiteRepository,
@@ -184,7 +186,7 @@ private fun StatsPeriod.toDateRangeString(resourceProvider: ResourceProvider): S
184186
is StatsPeriod.Last6Months -> resourceProvider.getString(R.string.stats_period_last_6_months)
185187
is StatsPeriod.Last12Months -> resourceProvider.getString(R.string.stats_period_last_12_months)
186188
is StatsPeriod.Custom -> "${startDate.dayOfMonth}-${endDate.dayOfMonth} ${
187-
endDate.month.name.take(3).lowercase().replaceFirstChar { it.uppercase() }
189+
endDate.month.name.take(MONTH_ABBREVIATION_LENGTH).lowercase().replaceFirstChar { it.uppercase() }
188190
}"
189191
}
190192
}

WordPress/src/main/java/org/wordpress/android/ui/newstats/repository/StatsRepository.kt

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ private const val HOURLY_QUANTITY = 24
2626
private const val DAILY_QUANTITY = 1
2727
private const val WEEKLY_QUANTITY = 7
2828
private const val DAYS_BEFORE_END_DATE = -6
29-
private const val DAYS_IN_30_DAYS = 30
3029
private const val DAYS_IN_7_DAYS = 7
30+
private const val DAYS_IN_30_DAYS = 30
31+
private const val DAYS_IN_6_MONTHS = 182
32+
private const val DAYS_IN_12_MONTHS = 365
3133
private const val MONTHS_IN_6_MONTHS = 6
3234
private const val MONTHS_IN_12_MONTHS = 12
35+
private const val PERCENTAGE_MULTIPLIER = 100.0
36+
private const val PERCENTAGE_NO_CHANGE = 0.0
37+
private const val NUM_DAYS_TODAY = 1
3338

3439
/**
3540
* Repository for fetching stats data using the wordpress-rs API.
@@ -533,8 +538,8 @@ class StatsRepository @Inject constructor(
533538
val previousTotalViews = previousItemsMap.values.sumOf { it.views }
534539
val totalChange = totalViews - previousTotalViews
535540
val totalChangePercent = if (previousTotalViews > 0) {
536-
(totalChange.toDouble() / previousTotalViews.toDouble()) * 100.0
537-
} else if (totalViews > 0) 100.0 else 0.0
541+
(totalChange.toDouble() / previousTotalViews.toDouble()) * PERCENTAGE_MULTIPLIER
542+
} else if (totalViews > 0) PERCENTAGE_MULTIPLIER else PERCENTAGE_NO_CHANGE
538543

539544
MostViewedResult.Success(
540545
items = currentResult.items.mapIndexed { index, item ->
@@ -580,8 +585,8 @@ class StatsRepository @Inject constructor(
580585
val previousTotalViews = previousItemsMap.values.sumOf { it.views }
581586
val totalChange = totalViews - previousTotalViews
582587
val totalChangePercent = if (previousTotalViews > 0) {
583-
(totalChange.toDouble() / previousTotalViews.toDouble()) * 100.0
584-
} else if (totalViews > 0) 100.0 else 0.0
588+
(totalChange.toDouble() / previousTotalViews.toDouble()) * PERCENTAGE_MULTIPLIER
589+
} else if (totalViews > 0) PERCENTAGE_MULTIPLIER else PERCENTAGE_NO_CHANGE
585590

586591
MostViewedResult.Success(
587592
items = currentResult.items.mapIndexed { index, item ->
@@ -611,29 +616,29 @@ class StatsRepository @Inject constructor(
611616

612617
return when (period) {
613618
is StatsPeriod.Today -> {
614-
val yesterdayString = today.minusDays(1).format(dateFormatter)
615-
StatsDateRange.Preset(num = 1, date = todayString) to
616-
StatsDateRange.Preset(num = 1, date = yesterdayString)
619+
val yesterdayString = today.minusDays(NUM_DAYS_TODAY.toLong()).format(dateFormatter)
620+
StatsDateRange.Preset(num = NUM_DAYS_TODAY, date = todayString) to
621+
StatsDateRange.Preset(num = NUM_DAYS_TODAY, date = yesterdayString)
617622
}
618623
is StatsPeriod.Last7Days -> {
619-
val previousEndString = today.minusDays(7).format(dateFormatter)
620-
StatsDateRange.Preset(num = 7, date = todayString) to
621-
StatsDateRange.Preset(num = 7, date = previousEndString)
624+
val previousEndString = today.minusDays(DAYS_IN_7_DAYS.toLong()).format(dateFormatter)
625+
StatsDateRange.Preset(num = DAYS_IN_7_DAYS, date = todayString) to
626+
StatsDateRange.Preset(num = DAYS_IN_7_DAYS, date = previousEndString)
622627
}
623628
is StatsPeriod.Last30Days -> {
624-
val previousEndString = today.minusDays(30).format(dateFormatter)
625-
StatsDateRange.Preset(num = 30, date = todayString) to
626-
StatsDateRange.Preset(num = 30, date = previousEndString)
629+
val previousEndString = today.minusDays(DAYS_IN_30_DAYS.toLong()).format(dateFormatter)
630+
StatsDateRange.Preset(num = DAYS_IN_30_DAYS, date = todayString) to
631+
StatsDateRange.Preset(num = DAYS_IN_30_DAYS, date = previousEndString)
627632
}
628633
is StatsPeriod.Last6Months -> {
629-
val previousEndString = today.minusDays(182).format(dateFormatter)
630-
StatsDateRange.Preset(num = 182, date = todayString) to
631-
StatsDateRange.Preset(num = 182, date = previousEndString)
634+
val previousEndString = today.minusDays(DAYS_IN_6_MONTHS.toLong()).format(dateFormatter)
635+
StatsDateRange.Preset(num = DAYS_IN_6_MONTHS, date = todayString) to
636+
StatsDateRange.Preset(num = DAYS_IN_6_MONTHS, date = previousEndString)
632637
}
633638
is StatsPeriod.Last12Months -> {
634-
val previousEndString = today.minusDays(365).format(dateFormatter)
635-
StatsDateRange.Preset(num = 365, date = todayString) to
636-
StatsDateRange.Preset(num = 365, date = previousEndString)
639+
val previousEndString = today.minusDays(DAYS_IN_12_MONTHS.toLong()).format(dateFormatter)
640+
StatsDateRange.Preset(num = DAYS_IN_12_MONTHS, date = todayString) to
641+
StatsDateRange.Preset(num = DAYS_IN_12_MONTHS, date = previousEndString)
637642
}
638643
is StatsPeriod.Custom -> {
639644
val daysBetween = ChronoUnit.DAYS.between(period.startDate, period.endDate).toInt() + 1
@@ -649,26 +654,6 @@ class StatsRepository @Inject constructor(
649654
}
650655
}
651656
}
652-
653-
/**
654-
* Maps a StatsPeriod to the appropriate StatsDateRange for the API.
655-
*/
656-
private fun mapStatsPeriodToDateRange(period: StatsPeriod): StatsDateRange {
657-
val today = LocalDate.now()
658-
val todayString = today.format(dateFormatter)
659-
660-
return when (period) {
661-
is StatsPeriod.Today -> StatsDateRange.Preset(num = 1, date = todayString)
662-
is StatsPeriod.Last7Days -> StatsDateRange.Preset(num = 7, date = todayString)
663-
is StatsPeriod.Last30Days -> StatsDateRange.Preset(num = 30, date = todayString)
664-
is StatsPeriod.Last6Months -> StatsDateRange.Preset(num = 182, date = todayString)
665-
is StatsPeriod.Last12Months -> StatsDateRange.Preset(num = 365, date = todayString)
666-
is StatsPeriod.Custom -> StatsDateRange.Custom(
667-
startDate = period.startDate.format(dateFormatter),
668-
date = period.endDate.format(dateFormatter)
669-
)
670-
}
671-
}
672657
}
673658

674659
/**
@@ -793,10 +778,10 @@ data class MostViewedItemData(
793778
) {
794779
val viewsChange: Long get() = views - previousViews
795780
val viewsChangePercent: Double get() = if (previousViews > 0) {
796-
(viewsChange.toDouble() / previousViews.toDouble()) * 100.0
781+
(viewsChange.toDouble() / previousViews.toDouble()) * PERCENTAGE_MULTIPLIER
797782
} else if (views > 0) {
798-
100.0
783+
PERCENTAGE_MULTIPLIER
799784
} else {
800-
0.0
785+
PERCENTAGE_NO_CHANGE
801786
}
802787
}

0 commit comments

Comments
 (0)