Skip to content

Conversation

@gurnoorpannu
Copy link
Contributor

Fixed #70
Changes Made:

  • Created DurationFormatter utility to format durations in human-readable format
  • Updated MainScreen to use formatted durations instead of raw minutes
  • Added support for displaying time in minutes, hours, days format
  • Updated string resources for English, French, and German
  • Fixed issue where large minute values (e.g. 259450 minutes) are now displayed as readable format like '180 days and 2 hours'

Fixes the main screen duration display issue.

- Created DurationFormatter utility to format durations in human-readable format
- Updated MainScreen to use formatted durations instead of raw minutes
- Added support for displaying time in minutes, hours, days format
- Updated string resources for English, French, and German
- Fixed issue where large minute values (e.g. 259450 minutes) are now displayed as readable format like '180 days and 2 hours'

Fixes the main screen duration display issue.
@ioit-aaa
Copy link
Contributor

The problem has been assigned to someone else, but that person just didn't fix it, thanks for the pr

@ioit-aaa
Copy link
Contributor

Please fix the lint problem

Copy link
Owner

@msbelaid msbelaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, I've left a few comments for you to review.
There are also a few lint issues to fix.


object DurationFormatter {

fun formatDuration(context: Context, duration: Duration): String {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s generally not recommended to pass Context as a function argument. It’s better to rely on dependency injection, or for this simple case, use an extension function on Context for this kind of logic.

val totalMinutes = duration.inWholeMinutes

return when {
totalMinutes < 60 -> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using constants

    private const val MINUTES_IN_HOUR = 60
    private const val MINUTES_IN_DAY = 1440

// Less than 1 hour - show in minutes
context.resources.getQuantityString(R.plurals.duration_minutes, totalMinutes.toInt(), totalMinutes)
}
totalMinutes < 1440 -> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

    private const val MINUTES_IN_HOUR = 60
    private const val MINUTES_IN_DAY = 1440

Text(stringResource(R.string.stats_last_usage_time, usageDurationMinutes, state.blockInterval))
val formattedLastUsage = state.lastUsageDuration?.let {
DurationFormatter.formatDuration(LocalContext.current, it)
} ?: "0 minutes"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid hardcoded strings

- Replaced hardcoded strings with proper string resources
- Added constants for MINUTES_IN_HOUR and MINUTES_IN_DAY to avoid magic numbers
- Converted DurationFormatter to extension function to avoid passing Context as parameter
- Added missing translations for duration strings in all supported languages:
  - Arabic (ar) with proper plural forms
  - Hindi (hi)
  - Japanese (ja)
  - Russian (ru) with proper plural forms
  - Chinese (zh-rCN)
- Added 'many' quantity for French plurals to fix lint warnings
- Fixed XML encoding issues in French strings

All lint issues related to our changes have been resolved.
@gurnoorpannu
Copy link
Contributor Author

@msbelaid can you review these changes?

@gurnoorpannu
Copy link
Contributor Author

can you check now @msbelaid
doesnt show any lint issue now to me

Comment on lines 84 to 86
lint {
baseline = file("lint-baseline.xml")
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not add any baseline file to the repo, remove these lines and the lint-baseline.xml than run gradlew ktlintFormat to fix the lint errors.

@@ -0,0 +1,906 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire file needs to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay I'll remove this then

Comment on lines +26 to +45
<string name="usage_free_duration_message">太棒了!你已经远离令人分心的应用超过 %1$s,继续保持!</string>
<string name="apps_usage_duration_message">你在过去的 %2$s 中,使用了令人分心的应用超过 %1$s。</string>

<!-- Duration formatting strings -->
<string name="duration_hours_minutes">%1$s 和 %2$s</string>
<string name="duration_days_hours">%1$s 和 %2$s</string>

<plurals name="duration_minutes">
<item quantity="other">%d分钟</item>
</plurals>

<plurals name="duration_hours">
<item quantity="other">%d小时</item>
</plurals>

<plurals name="duration_days">
<item quantity="other">%d天</item>
</plurals>

<string name="duration_zero_minutes">0分钟</string>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ioit-aaa , please take a look on this translation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ioit-aaa , please take a look on this translation

It looks good

Copy link
Contributor

@ioit-aaa ioit-aaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translation looks fine

@gurnoorpannu
Copy link
Contributor Author

@msbelaid I have made the requested changes

@gurnoorpannu
Copy link
Contributor Author

@ioit-aaa can you review this?

@gurnoorpannu
Copy link
Contributor Author

@msbelaid you need any more changes?

@msbelaid msbelaid merged commit 201f982 into msbelaid:master Oct 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display time in a human-readable format

3 participants