From c6178e504fc8a10e08d0979ba7cc5071fd7771b4 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 1 Sep 2020 11:01:32 +0200 Subject: [PATCH] Clean files and update CHANGES --- CHANGES.md | 2 +- tools/check/forbidden_strings_in_code.txt | 2 +- .../app/core/date/DateFormatterProvider.kt | 1 - .../app/core/date/VectorDateFormatter.kt | 6 ++--- .../vector/app/core/resources/DateProvider.kt | 1 - .../crypto/keysrequest/KeyRequestHandler.kt | 24 +++++++------------ .../timeline/TimelineEventController.kt | 1 - .../timeline/action/MessageActionState.kt | 4 ---- .../media/DataAttachmentRoomProvider.kt | 1 - .../app/features/settings/VectorLocale.kt | 3 ++- .../features/settings/devices/DeviceItem.kt | 4 ---- 11 files changed, 15 insertions(+), 34 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b1a93209bc..19104b3ed8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features ✨: - Improvements 🙌: - - + - Handle date formatting properly (show time am/pm if needed, display year when needed) Bugfix 🐛: - diff --git a/tools/check/forbidden_strings_in_code.txt b/tools/check/forbidden_strings_in_code.txt index b5438a0c5b..0a58175731 100644 --- a/tools/check/forbidden_strings_in_code.txt +++ b/tools/check/forbidden_strings_in_code.txt @@ -164,7 +164,7 @@ Formatter\.formatShortFileSize===1 # android\.text\.TextUtils ### This is not a rule, but a warning: the number of "enum class" has changed. For Json classes, it is mandatory that they have `@JsonClass(generateAdapter = false)`. If it is ok, change the value in file forbidden_strings_in_code.txt -enum class===76 +enum class===77 ### Do not import temporary legacy classes import org.matrix.android.sdk.internal.legacy.riot===3 diff --git a/vector/src/main/java/im/vector/app/core/date/DateFormatterProvider.kt b/vector/src/main/java/im/vector/app/core/date/DateFormatterProvider.kt index 0ca2eed2a6..ed1c2d828a 100644 --- a/vector/src/main/java/im/vector/app/core/date/DateFormatterProvider.kt +++ b/vector/src/main/java/im/vector/app/core/date/DateFormatterProvider.kt @@ -24,4 +24,3 @@ interface DateFormatterProvider { val dateWithYearFormatter: DateTimeFormatter } - diff --git a/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt b/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt index ecc1d7fe12..eb6f6a94f7 100644 --- a/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt +++ b/vector/src/main/java/im/vector/app/core/date/VectorDateFormatter.kt @@ -34,7 +34,7 @@ class VectorDateFormatter @Inject constructor(private val context: Context, private val hourFormatter by lazy { if (DateFormat.is24HourFormat(context)) { - DateTimeFormatter.ofPattern("H:mm", localeProvider.current()) + DateTimeFormatter.ofPattern("HH:mm", localeProvider.current()) } else { DateTimeFormatter.ofPattern("h:mm a", localeProvider.current()) } @@ -42,7 +42,7 @@ class VectorDateFormatter @Inject constructor(private val context: Context, private val fullDateFormatter by lazy { val pattern = if (DateFormat.is24HourFormat(context)) { - DateFormat.getBestDateTimePattern(localeProvider.current(), "EEE, d MMM yyyy H:mm") + DateFormat.getBestDateTimePattern(localeProvider.current(), "EEE, d MMM yyyy HH:mm") } else { DateFormat.getBestDateTimePattern(localeProvider.current(), "EEE, d MMM yyyy h:mm a") } @@ -58,7 +58,7 @@ class VectorDateFormatter @Inject constructor(private val context: Context, * @return the formatted date as string. */ fun format(ts: Long?, dateFormatKind: DateFormatKind): String { - if (ts == null) return "" + if (ts == null) return "-" val localDateTime = DateProvider.toLocalDateTime(ts) return when (dateFormatKind) { DateFormatKind.DEFAULT_DATE_AND_TIME -> formatDateAndTime(ts) diff --git a/vector/src/main/java/im/vector/app/core/resources/DateProvider.kt b/vector/src/main/java/im/vector/app/core/resources/DateProvider.kt index 2fce3e974a..30cb1dcae4 100644 --- a/vector/src/main/java/im/vector/app/core/resources/DateProvider.kt +++ b/vector/src/main/java/im/vector/app/core/resources/DateProvider.kt @@ -44,4 +44,3 @@ object DateProvider { } fun LocalDateTime.toTimestamp(): Long = DateProvider.toTimestamp(this) - diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysrequest/KeyRequestHandler.kt b/vector/src/main/java/im/vector/app/features/crypto/keysrequest/KeyRequestHandler.kt index 961cca4b70..4ed0e037d4 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysrequest/KeyRequestHandler.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysrequest/KeyRequestHandler.kt @@ -21,6 +21,8 @@ package im.vector.app.features.crypto.keysrequest import android.content.Context import im.vector.app.R +import im.vector.app.core.date.DateFormatKind +import im.vector.app.core.date.VectorDateFormatter import im.vector.app.features.popup.DefaultVectorAlert import im.vector.app.features.popup.PopupAlertManager import org.matrix.android.sdk.api.MatrixCallback @@ -38,10 +40,6 @@ import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo import timber.log.Timber -import java.text.DateFormat -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale import javax.inject.Inject import javax.inject.Singleton @@ -54,8 +52,11 @@ import javax.inject.Singleton */ @Singleton -class KeyRequestHandler @Inject constructor(private val context: Context, private val popupAlertManager: PopupAlertManager) - : GossipingRequestListener, +class KeyRequestHandler @Inject constructor( + private val context: Context, + private val popupAlertManager: PopupAlertManager, + private val dateFormatter: VectorDateFormatter +) : GossipingRequestListener, VerificationService.Listener { private val alertsToRequests = HashMap>() @@ -156,16 +157,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context, privat moreInfo.lastSeenIp } - val lastSeenTime = moreInfo.lastSeenTs?.let { ts -> - val dateFormatTime = SimpleDateFormat("HH:mm:ss", Locale.getDefault()) - val date = Date(ts) - - val time = dateFormatTime.format(date) - val dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()) - - dateFormat.format(date) + ", " + time - } ?: "-" - + val lastSeenTime = dateFormatter.format(moreInfo.lastSeenTs, DateFormatKind.DEFAULT_DATE_AND_TIME) val lastSeenInfo = context.getString(R.string.devices_details_last_seen_format, lastSeenIp, lastSeenTime) dialogText = if (wasNewDevice) { context.getString(R.string.you_added_a_new_device_with_info, deviceName, lastSeenInfo) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt index f9635d4b85..be59128c26 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt @@ -30,7 +30,6 @@ import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.epoxy.LoadingItem_ import im.vector.app.core.extensions.localDateTime import im.vector.app.core.extensions.nextOrNull -import im.vector.app.core.resources.DateProvider import im.vector.app.features.home.room.detail.RoomDetailAction import im.vector.app.features.home.room.detail.RoomDetailViewState import im.vector.app.features.home.room.detail.UnreadState diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionState.kt index 587400700d..83d56a65c9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionState.kt @@ -22,10 +22,6 @@ import com.airbnb.mvrx.Uninitialized import im.vector.app.core.extensions.canReact import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent -import java.text.SimpleDateFormat -import java.time.LocalDateTime -import java.util.Date -import java.util.Locale /** * Quick reactions state diff --git a/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt b/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt index 6209179961..085153a721 100644 --- a/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt +++ b/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt @@ -21,7 +21,6 @@ import android.view.View import androidx.core.view.isVisible import im.vector.app.core.date.DateFormatKind import im.vector.app.core.date.VectorDateFormatter -import im.vector.app.core.extensions.localDateTime import im.vector.lib.attachmentviewer.AttachmentInfo import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.session.events.model.isVideoMessage diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorLocale.kt b/vector/src/main/java/im/vector/app/features/settings/VectorLocale.kt index b9d81ab005..d0e4af4b97 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorLocale.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorLocale.kt @@ -22,6 +22,7 @@ import androidx.core.content.edit import androidx.preference.PreferenceManager import im.vector.app.BuildConfig import im.vector.app.R +import im.vector.app.core.resources.LocaleProvider import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import timber.log.Timber @@ -57,7 +58,7 @@ object VectorLocale { /** * Init this object */ - fun init(context: Context) { + fun init(context: Context, localeProvider: LocaleProvider) { this.context = context val preferences = PreferenceManager.getDefaultSharedPreferences(context) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/DeviceItem.kt b/vector/src/main/java/im/vector/app/features/settings/devices/DeviceItem.kt index 0b18b65314..7affdbf25b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/DeviceItem.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/DeviceItem.kt @@ -31,10 +31,6 @@ import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.resources.ColorProvider import im.vector.app.core.utils.DimensionConverter import me.gujun.android.span.span -import java.text.DateFormat -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale /** * A list item for Device.