show "now" instead of "in 0s" timestamps (#2843)
* Add roundoff threshold for "now" (new string resource) output in getRelativeTimeSpanString * added tests * added string resource translation for `status_created_at_now` in DE, ES, JA * fixed ktlint issues * use resource file in test, linting passes * 501ms and 999ms now show "now" instead of "0s"
This commit is contained in:
parent
330401c7d0
commit
86e5c92a05
6 changed files with 37 additions and 1 deletions
|
@ -34,7 +34,10 @@ public class TimestampUtils {
|
|||
public static String getRelativeTimeSpanString(Context context, long then, long now) {
|
||||
long span = now - then;
|
||||
boolean future = false;
|
||||
if (span < 0) {
|
||||
if (Math.abs(span) < SECOND_IN_MILLIS) {
|
||||
return context.getString(R.string.status_created_at_now);
|
||||
}
|
||||
else if (span < 0) {
|
||||
future = true;
|
||||
span = -span;
|
||||
}
|
||||
|
|
|
@ -543,6 +543,7 @@
|
|||
<string name="tips_push_notification_migration">Melde alle Konten neu an, um die Unterstützung für Push-Benachrichtigungen zu aktivieren.</string>
|
||||
<string name="account_date_joined">%1$s beigetreten</string>
|
||||
<string name="status_count_one_plus">1+</string>
|
||||
<string name="status_created_at_now">Jetzt</string>
|
||||
<string name="error_loading_account_details">Fehler beim Laden der Kontodetails</string>
|
||||
<string name="action_edit_image">Bild bearbeiten</string>
|
||||
<string name="action_details">Details</string>
|
||||
|
|
|
@ -231,6 +231,7 @@
|
|||
<string name="post_media_video">Video</string>
|
||||
<string name="state_follow_requested">Solicitud enviada</string>
|
||||
<!--These are for timestamps on statuses. For example: "16s" or "2d"-->
|
||||
<string name="status_created_at_now">Ahora</string>
|
||||
<string name="abbreviated_in_years">en %dy</string>
|
||||
<string name="abbreviated_in_days">en %dd</string>
|
||||
<string name="abbreviated_in_hours">en %dh</string>
|
||||
|
|
|
@ -232,6 +232,7 @@
|
|||
<string name="post_media_video">動画</string>
|
||||
<string name="state_follow_requested">フォローリクエスト中</string>
|
||||
<!--These are for timestamps on statuses. For example: "16s" or "2d"-->
|
||||
<string name="status_created_at_now">現在</string>
|
||||
<string name="abbreviated_in_years">%d年後</string>
|
||||
<string name="abbreviated_in_days">%d日後</string>
|
||||
<string name="abbreviated_in_hours">%d時間後</string>
|
||||
|
|
|
@ -360,6 +360,7 @@
|
|||
<string name="post_media_audio">Audio</string>
|
||||
<string name="post_media_attachments">Attachments</string>
|
||||
<string name="status_count_one_plus">1+</string>
|
||||
<string name="status_created_at_now">now</string>
|
||||
|
||||
<string name="state_follow_requested">Follow requested</string>
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.keylesspalace.tusky.util
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.keylesspalace.tusky.R
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
private const val STATUS_CREATED_AT_NOW = "test"
|
||||
|
||||
@Config(sdk = [28])
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class TimestampUtilsTest {
|
||||
private val ctx: Context = mock {
|
||||
on { getString(R.string.status_created_at_now) } doReturn STATUS_CREATED_AT_NOW
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldShowNowForSmallTimeSpans() {
|
||||
assertEquals(STATUS_CREATED_AT_NOW, TimestampUtils.getRelativeTimeSpanString(ctx, 0, 300))
|
||||
assertEquals(STATUS_CREATED_AT_NOW, TimestampUtils.getRelativeTimeSpanString(ctx, 300, 0))
|
||||
assertEquals(STATUS_CREATED_AT_NOW, TimestampUtils.getRelativeTimeSpanString(ctx, 501, 0))
|
||||
assertEquals(STATUS_CREATED_AT_NOW, TimestampUtils.getRelativeTimeSpanString(ctx, 0, 999))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue