From 0fac8e999da164422a31abb72043593bdbb8549c Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Mon, 11 Feb 2013 14:46:28 +0100 Subject: [PATCH] Clean up date handling. Remove home-grown date formatting, and replace it by usage of the DateUtils class which is present since API level 3. --- res/values-ca/strings.xml | 9 +- res/values-cs/strings.xml | 9 +- res/values-da/strings.xml | 9 +- res/values-de/strings.xml | 9 +- res/values-el/strings.xml | 9 +- res/values-es/strings.xml | 11 +-- res/values-fi/strings.xml | 9 +- res/values-fr/strings.xml | 9 +- res/values-gl/strings.xml | 9 +- res/values-hu/strings.xml | 9 +- res/values-it/strings.xml | 11 +-- res/values-iw/strings.xml | 9 +- res/values-ja/strings.xml | 9 +- res/values-ko/strings.xml | 9 +- res/values-nl/strings.xml | 9 +- res/values-pl/strings.xml | 9 +- res/values-pt-rBR/strings.xml | 9 +- res/values-ru/strings.xml | 9 +- res/values-sv/strings.xml | 9 +- res/values-tr/strings.xml | 8 +- res/values-uk/strings.xml | 9 +- res/values-zh-rCN/strings.xml | 7 -- res/values-zh-rTW/strings.xml | 9 +- res/values/arrays.xml | 7 -- res/values/strings.xml | 9 +- res/xml/global_preferences.xml | 8 -- src/com/fsck/k9/activity/Accounts.java | 3 +- .../fsck/k9/activity/ActivityListener.java | 16 +--- src/com/fsck/k9/activity/FolderList.java | 23 +++-- src/com/fsck/k9/activity/K9ListActivity.java | 21 ----- .../fsck/k9/activity/MessageInfoHolder.java | 8 -- src/com/fsck/k9/activity/setup/Prefs.java | 15 --- .../fsck/k9/fragment/MessageListFragment.java | 26 +----- src/com/fsck/k9/helper/DateFormatter.java | 93 ------------------- src/com/fsck/k9/helper/MessageHelper.java | 25 ----- .../fsck/k9/preferences/GlobalSettings.java | 31 ------- .../fsck/k9/preferences/SettingsImporter.java | 2 - src/com/fsck/k9/view/MessageHeader.java | 22 ++--- tests/src/com/fsck/k9/TranslationTest.java | 41 -------- 39 files changed, 56 insertions(+), 502 deletions(-) delete mode 100644 src/com/fsck/k9/helper/DateFormatter.java delete mode 100644 tests/src/com/fsck/k9/TranslationTest.java diff --git a/res/values-ca/strings.xml b/res/values-ca/strings.xml index dbebbf5ea..a22cb7b3d 100644 --- a/res/values-ca/strings.xml +++ b/res/values-ca/strings.xml @@ -109,7 +109,7 @@ Si us plau, envia’ns els errors, contribueix a millorar-lo a Proc %s:%s%s \u0020%s/%s - Propera comprovació @ %s + Propera comprovació %s Comprovació acabada @@ -814,13 +814,6 @@ Si us plau, envia’ns els errors, contribueix a millorar-lo a Quan s’està comprovant \'Dades en segon pla\' i \'Auto sincronització\' - Format de la data - - dd-MMM-yyyy - Selecciona-ho tot Carpetes màximes a comprovar diff --git a/res/values-cs/strings.xml b/res/values-cs/strings.xml index 1ea6cd7be..2e2c67190 100644 --- a/res/values-cs/strings.xml +++ b/res/values-cs/strings.xml @@ -115,7 +115,7 @@ Posílejte prosím chybová hlášení, přispívejte novými funkcemi a ptejte Zpracování %s:%s%s \u0020%s/%s - Příští dotaz @ %s + Příští dotaz %s @@ -819,13 +819,6 @@ Posílejte prosím chybová hlášení, přispívejte novými funkcemi a ptejte Jsou-li \'Data na pozadí\' a \'Aut. synchronizace\' zaškrtnuty - Formát data - - dd. MMMM yyyy - Vybrat vše Max. počet složek řízených PUSH diff --git a/res/values-da/strings.xml b/res/values-da/strings.xml index 5092d88d0..2d09aa4ed 100644 --- a/res/values-da/strings.xml +++ b/res/values-da/strings.xml @@ -110,7 +110,7 @@ Vær venlig at sende fejlrapporter, anmodning om nye funktioner, og spørgsmål Behandler %s:%s%s \u0020%s/%s - Næste synkronisering @ %s + Næste synkronisering %s synkronisering deaktiveret @@ -813,13 +813,6 @@ Vær venlig at sende fejlrapporter, anmodning om nye funktioner, og spørgsmål Når \"Baggrundsdata\" & \"Auto-sync\" er aktiveret - Datoformat - - dd-MMM-yyyy - Vælg alle Max antal mapper som skal kontrolleres ved push diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index f5aa226b7..68f9cbeb4 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -109,7 +109,7 @@ Um Fehler zu melden, neue Funktionen vorzuschlagen oder Fragen zu stellen, besuc Verarbeite %s:%s%s \u0020%s/%s - Nächster Abruf @ %s + Nächster Abruf %s Synchronisation abgeschaltet @@ -844,13 +844,6 @@ Um Fehler zu melden, neue Funktionen vorzuschlagen oder Fragen zu stellen, besuc Wenn \'Hintergrunddaten\' & \'Automatische Synchronisation\' aktiviert sind Wenn \'Automatische Synchronisation\' aktiviert ist - Datumsformat - - dd.MMM yyyy - Alle auswählen Maximale Push-Ordner-Anzahl diff --git a/res/values-el/strings.xml b/res/values-el/strings.xml index a8e20e186..0017c00d1 100644 --- a/res/values-el/strings.xml +++ b/res/values-el/strings.xml @@ -810,13 +810,6 @@ Όταν ελέγχονται \'Δεδομένα παρασκηνίου\' & \'Αυτόματο συγχρονισμός\' Όταν έχει επιλεγεί \'Auto-sync\' - Γραφή ημερομηνίας - - dd-MMM-yyyy - Επιλογή όλων Μέγιστο φακέλων για σπρώξιμο @@ -1096,4 +1089,4 @@ Προβολή συζήτησης Σύντμηση μηνυμάτων που ανήκουν στον ίδιο νήμα - \ No newline at end of file + diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml index 617998a9a..8c2983a2e 100644 --- a/res/values-es/strings.xml +++ b/res/values-es/strings.xml @@ -110,7 +110,7 @@ Por favor, envía los errores detectados, contribuye con nuevas funcionalidades Proc %s:%s%s \u0020%s/%s - Próxima sincronización a las %s + Próxima sincronización %s Sincronización deshabilitada @@ -811,13 +811,6 @@ Por favor, envía los errores detectados, contribuye con nuevas funcionalidades Cuando \'Sincronización en segundo plano\' y \'Sincronización automática\' esten activos - Formato de fecha - - dd-MM-yyyy - Seleccionar todos Max. carpetas Push @@ -1086,4 +1079,4 @@ Por favor, envía los errores detectados, contribuye con nuevas funcionalidades Vista agrupada por conversación Contraer mensajes de la misma conversación - \ No newline at end of file + diff --git a/res/values-fi/strings.xml b/res/values-fi/strings.xml index 92c116a44..8801f1485 100755 --- a/res/values-fi/strings.xml +++ b/res/values-fi/strings.xml @@ -118,7 +118,7 @@ Virheraportit, osallistuminen projektiin ja kysymykset: Mene osoitteeseen Käsitellään %s:%s%s \u0020%s/%s - Seuraava tarkistus @ %s + Seuraava tarkistus %s Synkronointi pois päältä %d valittu @@ -842,13 +842,6 @@ Virheraportit, osallistuminen projektiin ja kysymykset: Mene osoitteeseen Kun \'Taustadata\' ja \'Automaattinen synkronointi\' on valittu Kun Automaattinen synkronointi on valittu - Päivämäärän muoto - - dd-MMM-yyyy - Valitse kaikki Push-tilassa tarkistettavien kansioiden enimmäismäärä diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index 6d250e889..ee9689381 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -142,7 +142,7 @@ Si vous avez des suggestions, découvert des bugs ou simplement une idée de fon Prép %s:%s%s \u0020%s/%s - Prochaine récup. à %s + Prochaine récup. %s synchronisation désactivée %d sélectionné(s) @@ -866,13 +866,6 @@ de plus Lorsque «\u00A0Données en arrière-plan\u00A0» et «\u00A0Synchronisation auto\u00A0» sont activés Lorsque «\u00A0Synchronisation auto\u00A0» est activée - Format de date - - dd-MMM-yyyy - Sélectionner tout Maximum de dossiers Push à vérifier diff --git a/res/values-gl/strings.xml b/res/values-gl/strings.xml index 8b394344a..74c9e8c8e 100644 --- a/res/values-gl/strings.xml +++ b/res/values-gl/strings.xml @@ -109,7 +109,7 @@ Por favor, envía os erros detectados, contribúe con novas funcionalidas e preg Proc %s:%s%s \u0020%s/%s - Próxima comprobación @ %s + Próxima comprobación %s Comprobación rematada @@ -810,13 +810,6 @@ Por favor, envía os erros detectados, contribúe con novas funcionalidas e preg Cando \'Sincronización en segundo plano\' e \'Sincronización automática\' estén activos - Formato de data - - dd-MMM-yyyy - Seleccionar todos Max. subscripcións diff --git a/res/values-hu/strings.xml b/res/values-hu/strings.xml index e030d36ad..cf83785ab 100644 --- a/res/values-hu/strings.xml +++ b/res/values-hu/strings.xml @@ -111,7 +111,7 @@ Hibajelentéseivel hozzájárul az újabb verziók tökéletesítéséhez, kérd Feldolgozás %s:%s%s \u0020%s/%s - Frissítés @ %s + Frissítés %s Nincs frissítve @@ -810,13 +810,6 @@ Hibajelentéseivel hozzájárul az újabb verziók tökéletesítéséhez, kérd "Ha a 'Háttéradatok' és 'Auto-szink' bekapcsolva" AMikor az \'Automatikus szinkronizáció\' be van kapcsolva - Dátum formátuma - - dd-MMM-yyyy - Mindent kijelöl Ellenőrízhető mappák száma diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index e840c2748..d6100cc5d 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -110,7 +110,7 @@ Invia le tue segnalazioni, suggerisci nuove funzionalità e chiedi informazioni Elab %s:%s%s \u0020%s/%s - Prossima verifica alle %s + Prossima verifica %s Sincronizzazione disabilitata @@ -814,13 +814,6 @@ Invia le tue segnalazioni, suggerisci nuove funzionalità e chiedi informazioni Quando \'Dati in background\' e \'Sincronizzazione automatica\' sono selezionati Quando \'Sincronizzazione automatica\' è selezionato - Formato data - - dd-MMM-yyyy - Seleziona tutti Max cartelle Push @@ -1100,4 +1093,4 @@ Invia le tue segnalazioni, suggerisci nuove funzionalità e chiedi informazioni - \ No newline at end of file + diff --git a/res/values-iw/strings.xml b/res/values-iw/strings.xml index a95767a7c..cd12930dc 100644 --- a/res/values-iw/strings.xml +++ b/res/values-iw/strings.xml @@ -110,7 +110,7 @@ \u0020%s/%s - + הסנכרון מושבת @@ -810,13 +810,6 @@ "מתי ש\'נתונים ברקע\' ו\'סינכרון אוטומטי\' מסומנים " - פורמט תאריך - - dd-MMM-yyyy - בחר הכל מקסימום תיקיות כדי לבדוק עם דחיפה diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml index d9c1e10ee..36daffcba 100644 --- a/res/values-ja/strings.xml +++ b/res/values-ja/strings.xml @@ -110,7 +110,7 @@ K-9 は大多数のメールクライアントと同様に、ほとんどのフ 処理 %s:%s%s \u0020%s/%s - 次回受信 @ %s + 次回受信 %s 同期停止 %d件選択しました @@ -809,13 +809,6 @@ K-9 は大多数のメールクライアントと同様に、ほとんどのフ バックグランドデータと自動同期がチェックされた時 自動同期がチェックされた時 - 日付書式 - - dd-MMM-yyyy - 全選択 プッシュ受信の最大フォルダ数 diff --git a/res/values-ko/strings.xml b/res/values-ko/strings.xml index f960e3bd8..be6171910 100644 --- a/res/values-ko/strings.xml +++ b/res/values-ko/strings.xml @@ -109,7 +109,7 @@ K-9 메일은 다른 메일 클라이언트와 마찬가지로 대부분의 무 Proc %s:%s%s \u0020%s/%s - 다음 수신 @ %s + 다음 수신 %s 동기화 실패 @@ -810,13 +810,6 @@ K-9 메일은 다른 메일 클라이언트와 마찬가지로 대부분의 무 \'백그라운드 데이타\'와 \'Auto-sync\'가 선택된 경우 - 날짜 형식 - - dd-MMM-yyyy - 모두 선택 Push 체크할 최대 폴더 수 diff --git a/res/values-nl/strings.xml b/res/values-nl/strings.xml index f887b82d0..558e9d3f7 100644 --- a/res/values-nl/strings.xml +++ b/res/values-nl/strings.xml @@ -110,7 +110,7 @@ Graag foutrapporten, bijdrage nieuwe functies en vragen stellen op Proc %s:%s%s \u0020%s/%s - Volgende poll @ %s + Volgende poll %s Synchroniseren uitgeschakeld @@ -810,13 +810,6 @@ Graag foutrapporten, bijdrage nieuwe functies en vragen stellen op Wanneer \'Achtergrond data\' & \'Auto-sync\' zijn aangevinkt - Datum formaat - - dd-MMM-yyyy - Selecteer alle Max mappen om te controleren met push diff --git a/res/values-pl/strings.xml b/res/values-pl/strings.xml index 832ef485c..a67785985 100644 --- a/res/values-pl/strings.xml +++ b/res/values-pl/strings.xml @@ -124,7 +124,7 @@ Wszelkie zgłoszenia usterek, zapytania oraz nowe pomysły prosimy przesyłać z Przetwarzam: %s:%s%s \u0020%s/%s - Sprawdzę o %s + Sprawdzę %s Synchronizacja wyłączona @@ -822,13 +822,6 @@ Wszelkie zgłoszenia usterek, zapytania oraz nowe pomysły prosimy przesyłać z Gdy systemowe opcje \'Dane w tle\' oraz \'Autosynchronizacja\' są włączone - Format daty - - dd-MMM-yyyy - Zaznacz wszystko Sprawdzanie przez Push diff --git a/res/values-pt-rBR/strings.xml b/res/values-pt-rBR/strings.xml index 58cf50f5b..55875a3e5 100644 --- a/res/values-pt-rBR/strings.xml +++ b/res/values-pt-rBR/strings.xml @@ -110,7 +110,7 @@ Por favor, nos envie relatórios de bugs, contribua para novas melhorias e faça Proc %s:%s%s \u0020%s/%s - Nova verif. às @ %s + Nova verif. %s Sincronização desabilitada @@ -809,13 +809,6 @@ Por favor, nos envie relatórios de bugs, contribua para novas melhorias e faça Quando \'Dados de segundo plano\' e \'Auto-sinc\' estiverem checados Quando a \'Auto-sinc\' estiver ligada - Formato de data - - dd-MMM-yyyy - Selecione todos Máximo de pastas para checar com push diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml index 39aefa01f..9d5d5f2e7 100644 --- a/res/values-ru/strings.xml +++ b/res/values-ru/strings.xml @@ -110,7 +110,7 @@ K-9 Mail это программа электронной почты для Andr Обработка %s:%s%s \u0020%s/%s - Следующий запрос @ %s + Следующий запрос %s Синхронизация запрещена @@ -806,13 +806,6 @@ K-9 Mail это программа электронной почты для Andr Когда \'Фоновые данные\' и \'Автосинхронизация\' включены Когда выбрана \'Автосинхронизация\' - Формат даты - - dd-MMM-yyyy - Выбрать все Максимальное число папок для проверки с \"Push\" diff --git a/res/values-sv/strings.xml b/res/values-sv/strings.xml index e5d9c0c08..0c03482f1 100644 --- a/res/values-sv/strings.xml +++ b/res/values-sv/strings.xml @@ -110,7 +110,7 @@ Vänligen skicka felrapporter, hjälp till med nya funktioner och ställ frågor Behandlar %s:%s%s \u0020%s/%s - Nästa kontroll @ %s + Nästa kontroll %s Synk avaktiverat @@ -813,13 +813,6 @@ Vänligen skicka felrapporter, hjälp till med nya funktioner och ställ frågor När \'Bakgrundsdata\' & \'Auto-sync\' är aktiverade - Datumformat - - dd MMM yyyy - Markera alla Max antal mappar att kontrollera med push diff --git a/res/values-tr/strings.xml b/res/values-tr/strings.xml index 6b1f306a0..8fd0d827a 100644 --- a/res/values-tr/strings.xml +++ b/res/values-tr/strings.xml @@ -110,7 +110,7 @@ Lütfen hata raporlarınızı, istediğiniz yeni özellikleri ve sorularınızı İşlem %s%s%s \u0020%s/%s - Sonraki alım @ %s + Sonraki alım %s Senk. kapalı @@ -813,12 +813,6 @@ Lütfen hata raporlarınızı, istediğiniz yeni özellikleri ve sorularınızı \'Arkaplan verisi\' & \'Oto. Senk.\' işaretli olduğu zaman - Tarih Biçimi - - Hepsini Seç Push ile en fazla kontrol edilecek klasör sayısı diff --git a/res/values-uk/strings.xml b/res/values-uk/strings.xml index 454a9cb04..77833cc4d 100644 --- a/res/values-uk/strings.xml +++ b/res/values-uk/strings.xml @@ -110,7 +110,7 @@ K-9 Mail це поштовий клієнт з відкритим вихідни Опрацювання %s:%s%s \u0020%s/%s - Наступний запит @ %s + Наступний запит %s Синхронізація заборонена @@ -812,13 +812,6 @@ K-9 Mail це поштовий клієнт з відкритим вихідни Коли \'Фонові дані\' та \'Автосинхронізація\' включено - Формат дати - - dd-MMM-yyyy - Вибрати усе Найбільша кількість папок для перевірки з push diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index d1e4ceeb7..34a6eb0ef 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -803,13 +803,6 @@ K-9改进的功能包括: 当“后台数据”&“自动同步”被选中 - 日期格式 - - dd-MMM-yyyy - 选择全部 推送时最多检查文件夹数量 diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml index 02398d078..5c5002d71 100644 --- a/res/values-zh-rTW/strings.xml +++ b/res/values-zh-rTW/strings.xml @@ -109,7 +109,7 @@ K-9改良的功能包括: 正在處理%s:%s%s \u0020%s/%s - 下次接收時間 @ %s + 下次接收時間 %s 同步已停用 %d 已選擇 @@ -804,13 +804,6 @@ K-9改良的功能包括: 當「背景資料」&「自動同步」被勾選 "當「自動同步」被勾選" - 日期格式 - - dd-MMM-yyyy - 選擇全部 推送時檢查信件匣上限數量 diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 483e656fc..eb7c2634a 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -529,13 +529,6 @@ NEVER - - SHORT - MEDIUM - @string/date_format_common - yyyy-MM-dd - - @string/font_size_default @string/font_size_tiniest diff --git a/res/values/strings.xml b/res/values/strings.xml index ba70b6c13..16e5ca5a9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -118,7 +118,7 @@ Please submit bug reports, contribute new features and ask questions at Proc %s:%s%s \u0020%s/%s - Next poll @ %s + Next poll %s Syncing disabled %d selected @@ -851,13 +851,6 @@ Please submit bug reports, contribute new features and ask questions at When \'Background data\' & \'Auto-sync\' are checked When \'Auto-sync\' is checked - Date format - - dd-MMM-yyyy - Select all Max folders to check with push diff --git a/res/xml/global_preferences.xml b/res/xml/global_preferences.xml index f44fc2c0a..232f387bf 100644 --- a/res/xml/global_preferences.xml +++ b/res/xml/global_preferences.xml @@ -80,14 +80,6 @@ android:title="@string/font_size_settings_title" android:summary="@string/font_size_settings_description" /> - - 0 ? context.getString(R.string.activity_unread_count, unreadMessageCount) : ""), - operation); - } - - public String getOperation(Context context, DateFormat timeFormat){ + public String getOperation(Context context) { String operation; String progress = null; if (mLoadingAccountDescription != null @@ -67,7 +59,9 @@ public class ActivityListener extends MessagingListener { } else { long nextPollTime = MailService.getNextPollTime(); if (nextPollTime != -1) { - operation = context.getString(R.string.status_next_poll, timeFormat.format(nextPollTime)); + operation = context.getString(R.string.status_next_poll, + DateUtils.getRelativeTimeSpanString(nextPollTime, System.currentTimeMillis(), + DateUtils.MINUTE_IN_MILLIS, 0)); } else if (MailService.isSyncDisabled()) { operation = context.getString(R.string.status_syncing_off); } else { diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index ff51ad51d..cf44d1be9 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -2,7 +2,6 @@ package com.fsck.k9.activity; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -13,6 +12,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.PowerManager; import android.text.TextUtils.TruncateAt; +import android.text.format.DateUtils; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -117,7 +117,7 @@ public class FolderList extends K9ListActivity implements OnNavigationListener { mActionBarUnread.setVisibility(View.VISIBLE); } - String operation = mAdapter.mListener.getOperation(FolderList.this, getTimeFormat()).trim(); + String operation = mAdapter.mListener.getOperation(FolderList.this); if (operation.length() < 1) { mActionBarSubTitle.setText(mAccount.getEmail()); } else { @@ -366,7 +366,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener { onOpenFolder(mAccount.getAutoExpandFolderName()); finish(); } else { - initializeActivityView(); } } @@ -377,9 +376,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener { setListAdapter(mAdapter); getListView().setTextFilterEnabled(mAdapter.getFilter() != null); // should never be false but better safe then sorry - - mHandler.refreshTitle(); - } @SuppressWarnings("unchecked") @@ -419,6 +415,8 @@ public class FolderList extends K9ListActivity implements OnNavigationListener { if (mAdapter == null) initializeActivityView(); + mHandler.refreshTitle(); + MessagingController.getInstance(getApplication()).addListener(mAdapter.mListener); //mAccount.refresh(Preferences.getPreferences(this)); MessagingController.getInstance(getApplication()).getAccountStats(this, mAccount, mAdapter.mListener); @@ -1045,17 +1043,22 @@ public class FolderList extends K9ListActivity implements OnNavigationListener { } holder.folderName.setText(folder.displayName); - String statusText = ""; + CharSequence statusText = ""; if (folder.loading) { statusText = getString(R.string.status_loading); } else if (folder.status != null) { statusText = folder.status; } else if (folder.lastChecked != 0) { - Date lastCheckedDate = new Date(folder.lastChecked); + long now = System.currentTimeMillis(); + int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; - statusText = getTimeFormat().format(lastCheckedDate) + " " + - getDateFormat().format(lastCheckedDate); + if (Math.abs(now - folder.lastChecked) > DateUtils.WEEK_IN_MILLIS) { + statusText = DateUtils.formatDateTime(context, folder.lastChecked, flags); + } else { + statusText = DateUtils.getRelativeTimeSpanString(folder.lastChecked, + now, DateUtils.SECOND_IN_MILLIS, flags); + } } if (folder.pushActive) { diff --git a/src/com/fsck/k9/activity/K9ListActivity.java b/src/com/fsck/k9/activity/K9ListActivity.java index 119b53be2..0d6aeebad 100644 --- a/src/com/fsck/k9/activity/K9ListActivity.java +++ b/src/com/fsck/k9/activity/K9ListActivity.java @@ -1,7 +1,5 @@ package com.fsck.k9.activity; -import java.text.DateFormat; - import android.view.KeyEvent; import android.view.MotionEvent; import android.widget.AdapterView; @@ -12,21 +10,16 @@ import com.actionbarsherlock.app.SherlockListActivity; import com.fsck.k9.K9; import com.fsck.k9.activity.K9ActivityCommon.K9ActivityMagic; import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener; -import com.fsck.k9.helper.DateFormatter; public class K9ListActivity extends SherlockListActivity implements K9ActivityMagic { private K9ActivityCommon mBase; - private DateFormat mDateFormat; - private DateFormat mTimeFormat; - @Override public void onCreate(Bundle savedInstanceState) { mBase = K9ActivityCommon.newInstance(this); super.onCreate(savedInstanceState); - setupFormats(); } @Override @@ -38,20 +31,6 @@ public class K9ListActivity extends SherlockListActivity implements K9ActivityMa @Override public void onResume() { super.onResume(); - setupFormats(); - } - - public DateFormat getDateFormat() { - return mDateFormat; - } - - public DateFormat getTimeFormat() { - return mTimeFormat; - } - - private void setupFormats() { - mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); - mDateFormat = DateFormatter.getDateFormat(this); } @Override diff --git a/src/com/fsck/k9/activity/MessageInfoHolder.java b/src/com/fsck/k9/activity/MessageInfoHolder.java index 4669daec6..eecf4f80d 100644 --- a/src/com/fsck/k9/activity/MessageInfoHolder.java +++ b/src/com/fsck/k9/activity/MessageInfoHolder.java @@ -1,7 +1,6 @@ package com.fsck.k9.activity; import java.util.Date; -import com.fsck.k9.helper.MessageHelper; import com.fsck.k9.mail.Message; public class MessageInfoHolder { @@ -43,11 +42,4 @@ public class MessageInfoHolder { public int hashCode() { return uid.hashCode(); } - - public String getDate(MessageHelper messageHelper) { - if (date == null) { - date = messageHelper.formatDate(message.getSentDate()); - } - return date; - } } diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index fedf9c158..169a7bd82 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -31,7 +31,6 @@ import com.fsck.k9.R; import com.fsck.k9.activity.ColorPickerDialog; import com.fsck.k9.activity.K9PreferenceActivity; import com.fsck.k9.controller.MessagingController; -import com.fsck.k9.helper.DateFormatter; import com.fsck.k9.helper.FileBrowserHelper; import com.fsck.k9.helper.FileBrowserHelper.FileBrowserFailOverCallback; import com.fsck.k9.preferences.CheckBoxListPreference; @@ -57,7 +56,6 @@ public class Prefs extends K9PreferenceActivity { private static final String PREFERENCE_FIXED_MESSAGE_THEME = "fixedMessageViewTheme"; private static final String PREFERENCE_COMPOSER_THEME = "messageComposeTheme"; private static final String PREFERENCE_FONT_SIZE = "font_size"; - private static final String PREFERENCE_DATE_FORMAT = "dateFormat"; private static final String PREFERENCE_ANIMATIONS = "animations"; private static final String PREFERENCE_GESTURES = "gestures"; private static final String PREFERENCE_VOLUME_NAVIGATION = "volumeNavigation"; @@ -109,7 +107,6 @@ public class Prefs extends K9PreferenceActivity { private CheckBoxPreference mFixedMessageTheme; private ListPreference mMessageTheme; private ListPreference mComposerTheme; - private ListPreference mDateFormat; private CheckBoxPreference mAnimations; private CheckBoxPreference mGestures; private CheckBoxListPreference mVolumeNavigation; @@ -195,17 +192,6 @@ public class Prefs extends K9PreferenceActivity { } }); - mDateFormat = (ListPreference) findPreference(PREFERENCE_DATE_FORMAT); - String[] formats = DateFormatter.getFormats(this); - CharSequence[] entries = new CharSequence[formats.length]; - CharSequence[] values = new CharSequence[formats.length]; - for (int i = 0 ; i < formats.length; i++) { - String format = formats[i]; - entries[i] = DateFormatter.getSampleDate(this, format); - values[i] = format; - } - initListPreference(mDateFormat, DateFormatter.getFormat(this), entries, values); - mAnimations = (CheckBoxPreference)findPreference(PREFERENCE_ANIMATIONS); mAnimations.setChecked(K9.showAnimations()); @@ -541,7 +527,6 @@ public class Prefs extends K9PreferenceActivity { Editor editor = preferences.edit(); K9.save(editor); - DateFormatter.setDateFormat(editor, mDateFormat.getValue()); editor.commit(); if (needsRefresh) { diff --git a/src/com/fsck/k9/fragment/MessageListFragment.java b/src/com/fsck/k9/fragment/MessageListFragment.java index 2236392a9..a76845423 100644 --- a/src/com/fsck/k9/fragment/MessageListFragment.java +++ b/src/com/fsck/k9/fragment/MessageListFragment.java @@ -1,10 +1,8 @@ package com.fsck.k9.fragment; -import java.text.DateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.Date; import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; @@ -37,6 +35,7 @@ import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.text.Spannable; import android.text.SpannableStringBuilder; +import android.text.format.DateUtils; import android.text.style.AbsoluteSizeSpan; import android.text.style.ForegroundColorSpan; import android.util.Log; @@ -408,9 +407,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick private MessageListFragmentListener mFragmentListener; - - private DateFormat mTimeFormat; - private boolean mThreadedList; private boolean mIsThreadDisplay; @@ -625,7 +621,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick mFragmentListener.setMessageListTitle(displayName); - String operation = mListener.getOperation(activity, getTimeFormat()).trim(); + String operation = mListener.getOperation(activity); if (operation.length() < 1) { mFragmentListener.setMessageListSubTitle(mAccount.getEmail()); } else { @@ -658,18 +654,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick } } - private void setupFormats() { - mTimeFormat = android.text.format.DateFormat.getTimeFormat(mContext); - } - - private DateFormat getTimeFormat() { - if (mTimeFormat == null) { - setupFormats(); - } - - return mTimeFormat; - } - private void progress(final boolean progress) { mFragmentListener.enableActionBarProgress(progress); if (mPullToRefreshView != null && !progress) { @@ -988,8 +972,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick public void onResume() { super.onResume(); - setupFormats(); - Context appContext = getActivity().getApplicationContext(); mSenderAboveSubject = K9.messageListSenderAboveSubject(); @@ -1791,6 +1773,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick boolean ccMe = mMessageHelper.toMe(account, ccAddrs); CharSequence displayName = mMessageHelper.getDisplayName(account, fromAddrs, toAddrs); + CharSequence displayDate = DateUtils.getRelativeTimeSpanString(context, cursor.getLong(DATE_COLUMN)); String counterpartyAddress = null; if (fromMe) { @@ -1803,9 +1786,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick counterpartyAddress = fromAddrs[0].getAddress(); } - Date sentDate = new Date(cursor.getLong(DATE_COLUMN)); - String displayDate = mMessageHelper.formatDate(sentDate); - int threadCount = (mThreadedList) ? cursor.getInt(THREAD_COUNT_COLUMN) : 0; String subject = cursor.getString(SUBJECT_COLUMN); diff --git a/src/com/fsck/k9/helper/DateFormatter.java b/src/com/fsck/k9/helper/DateFormatter.java deleted file mode 100644 index d3c9ab979..000000000 --- a/src/com/fsck/k9/helper/DateFormatter.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.fsck.k9.helper; - -import android.content.Context; -import android.content.SharedPreferences.Editor; -import android.util.Log; -import com.fsck.k9.K9; -import com.fsck.k9.Preferences; -import com.fsck.k9.R; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; - -public class DateFormatter { - private DateFormatter() { - } - private final static Calendar SAMPLE_DATE = Calendar.getInstance(); - static { - SAMPLE_DATE.set(SAMPLE_DATE.get(Calendar.YEAR), SAMPLE_DATE.getActualMaximum(Calendar.MONTH), SAMPLE_DATE.getActualMaximum(Calendar.DAY_OF_MONTH)); - } - - public static final String SHORT_FORMAT = "SHORT"; - public static final String MEDIUM_FORMAT = "MEDIUM"; - public static final String DEFAULT_FORMAT = SHORT_FORMAT; - - public static final String PREF_KEY = "dateFormat"; - - private static volatile String sChosenFormat = null; - - public static String getSampleDate(Context context, String formatString) { - java.text.DateFormat formatter = getDateFormat(context, formatString); - return formatter.format(SAMPLE_DATE.getTime()); - } - - public static String[] getFormats(Context context) { - return context.getResources().getStringArray(R.array.date_formats); - } - - private static ThreadLocal> storedFormats = new ThreadLocal>() { - @Override - public synchronized Map initialValue() { - return new HashMap(); - } - }; - - public static void clearChosenFormat() { - sChosenFormat = null; - } - - public static DateFormat getDateFormat(Context context, String formatString) { - java.text.DateFormat dateFormat; - - if (SHORT_FORMAT.equals(formatString)) { - dateFormat = android.text.format.DateFormat.getDateFormat(context); - } else if (MEDIUM_FORMAT.equals(formatString)) { - dateFormat = android.text.format.DateFormat.getMediumDateFormat(context); - } else { - Map formatMap = storedFormats.get(); - dateFormat = formatMap.get(formatString); - - if (dateFormat == null) { - dateFormat = new SimpleDateFormat(formatString); - formatMap.put(formatString, dateFormat); - } - } - return dateFormat; - } - - public static void setDateFormat(Editor editor, String formatString) { - sChosenFormat = formatString; - editor.putString(PREF_KEY, formatString); - } - - public static String getFormat(Context context) { - if (sChosenFormat == null) { - try { - Preferences prefs = Preferences.getPreferences(context); - sChosenFormat = prefs.getPreferences().getString(PREF_KEY, DEFAULT_FORMAT); - } catch (Exception e) { - Log.e(K9.LOG_TAG, "Couldn't load date format from preferences; using default.", e); - sChosenFormat = DEFAULT_FORMAT; - } - } - return sChosenFormat; - } - - public static DateFormat getDateFormat(Context context) { - String formatString = getFormat(context); - return getDateFormat(context, formatString); - } -} diff --git a/src/com/fsck/k9/helper/MessageHelper.java b/src/com/fsck/k9/helper/MessageHelper.java index 51ab08705..26430b9e8 100644 --- a/src/com/fsck/k9/helper/MessageHelper.java +++ b/src/com/fsck/k9/helper/MessageHelper.java @@ -1,8 +1,5 @@ package com.fsck.k9.helper; -import java.text.DateFormat; -import java.util.Date; - import android.content.Context; import android.text.SpannableStringBuilder; import android.util.Log; @@ -17,7 +14,6 @@ import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Message.RecipientType; -import com.fsck.k9.helper.DateFormatter; public class MessageHelper { @@ -32,14 +28,8 @@ public class MessageHelper { private Context mContext; - private DateFormat mTodayDateFormat; - - private DateFormat mDateFormat; - private MessageHelper(final Context context) { mContext = context; - mDateFormat = DateFormatter.getDateFormat(mContext); - mTodayDateFormat = android.text.format.DateFormat.getTimeFormat(mContext); } public void populate(final MessageInfoHolder target, final Message message, @@ -90,21 +80,6 @@ public class MessageHelper { Log.w(K9.LOG_TAG, "Unable to load message info", me); } } - public String formatDate(Date date) { - if (date == null) { - return ""; - } - if (Utility.isDateToday(date)) { - return mTodayDateFormat.format(date); - } else { - return mDateFormat.format(date); - } - } - - public void refresh() { - mDateFormat = DateFormatter.getDateFormat(mContext); - mTodayDateFormat = android.text.format.DateFormat.getTimeFormat(mContext); - } public CharSequence getDisplayName(Account account, Address[] fromAddrs, Address[] toAddrs) { final Contacts contactHelper = K9.showContactName() ? Contacts.getInstance(mContext) : null; diff --git a/src/com/fsck/k9/preferences/GlobalSettings.java b/src/com/fsck/k9/preferences/GlobalSettings.java index 6b4403414..e5b24a826 100644 --- a/src/com/fsck/k9/preferences/GlobalSettings.java +++ b/src/com/fsck/k9/preferences/GlobalSettings.java @@ -1,7 +1,6 @@ package com.fsck.k9.preferences; import java.io.File; -import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -22,7 +21,6 @@ import com.fsck.k9.K9.SplitViewMode; import com.fsck.k9.K9.Theme; import com.fsck.k9.R; import com.fsck.k9.Account.SortType; -import com.fsck.k9.helper.DateFormatter; import com.fsck.k9.preferences.Settings.*; public class GlobalSettings { @@ -63,9 +61,6 @@ public class GlobalSettings { s.put("countSearchMessages", Settings.versions( new V(1, new BooleanSetting(false)) )); - s.put("dateFormat", Settings.versions( - new V(1, new DateFormatSetting(DateFormatter.DEFAULT_FORMAT)) - )); s.put("enableDebugLogging", Settings.versions( new V(1, new BooleanSetting(false)) )); @@ -483,32 +478,6 @@ public class GlobalSettings { } } - /** - * A date format setting. - */ - public static class DateFormatSetting extends SettingsDescription { - public DateFormatSetting(String defaultValue) { - super(defaultValue); - } - - @Override - public Object fromString(String value) throws InvalidSettingValueException { - try { - // The placeholders "SHORT" and "MEDIUM" are fine. - if (DateFormatter.SHORT_FORMAT.equals(value) || - DateFormatter.MEDIUM_FORMAT.equals(value)) { - return value; - } - - // If the SimpleDateFormat constructor doesn't throw an exception, we're good. - new SimpleDateFormat(value); - return value; - } catch (Exception e) { - throw new InvalidSettingValueException(); - } - } - } - /** * A time setting. */ diff --git a/src/com/fsck/k9/preferences/SettingsImporter.java b/src/com/fsck/k9/preferences/SettingsImporter.java index aa55e4a34..8bcc5afab 100644 --- a/src/com/fsck/k9/preferences/SettingsImporter.java +++ b/src/com/fsck/k9/preferences/SettingsImporter.java @@ -22,7 +22,6 @@ import com.fsck.k9.Account; import com.fsck.k9.Identity; import com.fsck.k9.K9; import com.fsck.k9.Preferences; -import com.fsck.k9.helper.DateFormatter; import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings; @@ -293,7 +292,6 @@ public class SettingsImporter { } preferences.loadAccounts(); - DateFormatter.clearChosenFormat(); K9.loadPrefs(preferences); K9.setServicesEnabled(context); diff --git a/src/com/fsck/k9/view/MessageHeader.java b/src/com/fsck/k9/view/MessageHeader.java index 2631457db..d9e9f3124 100644 --- a/src/com/fsck/k9/view/MessageHeader.java +++ b/src/com/fsck/k9/view/MessageHeader.java @@ -7,6 +7,7 @@ import android.os.Parcelable; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.TextUtils; +import android.text.format.DateUtils; import android.text.style.StyleSpan; import android.util.Log; import android.util.AttributeSet; @@ -25,7 +26,6 @@ import com.fsck.k9.R; import com.fsck.k9.activity.misc.ContactPictureLoader; import com.fsck.k9.helper.Contacts; import com.fsck.k9.Account; -import com.fsck.k9.helper.DateFormatter; import com.fsck.k9.helper.MessageHelper; import com.fsck.k9.helper.StringUtils; import com.fsck.k9.mail.Address; @@ -38,7 +38,6 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; -import java.text.DateFormat; public class MessageHeader extends ScrollView implements OnClickListener { private Context mContext; @@ -49,8 +48,6 @@ public class MessageHeader extends ScrollView implements OnClickListener { private TextView mCcView; private TextView mCcLabel; private TextView mSubjectView; - private DateFormat mDateFormat; - private DateFormat mTimeFormat; private View mChip; private CheckBox mFlagged; @@ -87,8 +84,6 @@ public class MessageHeader extends ScrollView implements OnClickListener { public MessageHeader(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; - mDateFormat = DateFormatter.getDateFormat(mContext); - mTimeFormat = android.text.format.DateFormat.getTimeFormat(mContext); // 12/24 date format mContacts = Contacts.getInstance(mContext); } @@ -104,7 +99,6 @@ public class MessageHeader extends ScrollView implements OnClickListener { mContactBadge = (QuickContactBadge) findViewById(R.id.contact_badge); - mSubjectView = (TextView) findViewById(R.id.subject); mAdditionalHeadersView = (TextView) findViewById(R.id.additional_headers_view); mChip = findViewById(R.id.chip); @@ -224,8 +218,6 @@ public class MessageHeader extends ScrollView implements OnClickListener { public void populate(final Message message, final Account account) throws MessagingException { final Contacts contacts = K9.showContactName() ? mContacts : null; final CharSequence from = Address.toFriendly(message.getFrom(), contacts); - final String date = mDateFormat.format(message.getSentDate()); - final String time = mTimeFormat.format(message.getSentDate()); final CharSequence to = Address.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts); final CharSequence cc = Address.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts); @@ -274,11 +266,13 @@ public class MessageHeader extends ScrollView implements OnClickListener { } mSubjectView.setTextColor(0xff000000 | defaultSubjectColor); - if (date != null) { - mDateView.setText(time + " - " + date); - } else { - mDateView.setText(time); - } + String dateTime = DateUtils.formatDateTime(mContext, + message.getSentDate().getTime(), + DateUtils.FORMAT_SHOW_DATE + | DateUtils.FORMAT_ABBREV_ALL + | DateUtils.FORMAT_SHOW_TIME + | DateUtils.FORMAT_SHOW_YEAR); + mDateView.setText(dateTime); if (K9.showContactPicture()) { mContactBadge.assignContactFromEmail(counterpartyAddress, true); diff --git a/tests/src/com/fsck/k9/TranslationTest.java b/tests/src/com/fsck/k9/TranslationTest.java deleted file mode 100644 index 2bcf51d4f..000000000 --- a/tests/src/com/fsck/k9/TranslationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.fsck.k9; - -import com.fsck.k9.activity.K9ActivityCommon; -import com.fsck.k9.helper.DateFormatter; - -import android.content.Context; -import android.content.res.Resources; -import android.test.AndroidTestCase; - -public class TranslationTest extends AndroidTestCase { - public void testDateFormats() { - forAllLanguages(new LanguageSpecific() { - @Override - public void runWithLanguage(Context context, String language) { - Resources res = context.getResources(); - String dateFormatCommon = res.getString(R.string.date_format_common); - try { - DateFormatter.getDateFormat(mContext, dateFormatCommon); - } catch (Exception e) { - fail("Invalid date format string \"" + dateFormatCommon + - "\" for language \"" + language + "\""); - } - } - }); - } - - private void forAllLanguages(LanguageSpecific action) { - Resources res = mContext.getResources(); - String[] languages = res.getStringArray(R.array.supported_languages); - - for (String lang : languages) { - K9ActivityCommon.setLanguage(mContext, lang); - - action.runWithLanguage(mContext, lang); - } - } - - interface LanguageSpecific { - void runWithLanguage(Context context, String language); - } -}