localized date. rounded minutes, hours and dates in last seen

This commit is contained in:
iNPUTmice 2014-06-07 13:57:03 +02:00
parent ea8f3a2675
commit 71886ed2ab
4 changed files with 24 additions and 14 deletions

View File

@ -15,6 +15,7 @@
<string name="action_delete_contact">Aus Kontaktliste entfernen</string> <string name="action_delete_contact">Aus Kontaktliste entfernen</string>
<string name="title_activity_contacts">Kontakte</string> <string name="title_activity_contacts">Kontakte</string>
<string name="just_now">gerade</string> <string name="just_now">gerade</string>
<string name="minutes_ago">vor %d Minuten</string>
<string name="sending">senden&#8230;</string> <string name="sending">senden&#8230;</string>
<string name="announce_pgp">PGP Ankündigung erneuern</string> <string name="announce_pgp">PGP Ankündigung erneuern</string>
<string name="encrypted_message">Entschlüssle Nachricht. Bitte warten&#8230;</string> <string name="encrypted_message">Entschlüssle Nachricht. Bitte warten&#8230;</string>

View File

@ -22,7 +22,7 @@
<string name="title_activity_conversations">Conversations</string> <string name="title_activity_conversations">Conversations</string>
<string name="title_activity_sharewith">Compartir con Conversación</string> <string name="title_activity_sharewith">Compartir con Conversación</string>
<string name="just_now">ahora</string> <string name="just_now">ahora</string>
<string name="minutes_ago">min</string> <string name="minutes_ago">%d min</string>
<string name="unread_conversations">conversaciones por leer</string> <string name="unread_conversations">conversaciones por leer</string>
<string name="sending">enviando&#8230;</string> <string name="sending">enviando&#8230;</string>
<string name="announce_pgp">Renovar anuncio PGP</string> <string name="announce_pgp">Renovar anuncio PGP</string>

View File

@ -22,7 +22,7 @@
<string name="title_activity_conversations">Conversations</string> <string name="title_activity_conversations">Conversations</string>
<string name="title_activity_sharewith">Share with Conversation</string> <string name="title_activity_sharewith">Share with Conversation</string>
<string name="just_now">just now</string> <string name="just_now">just now</string>
<string name="minutes_ago">min ago</string> <string name="minutes_ago">%d mins ago</string>
<string name="unread_conversations">unread Conversations</string> <string name="unread_conversations">unread Conversations</string>
<string name="sending">sending&#8230;</string> <string name="sending">sending&#8230;</string>
<string name="announce_pgp">Renew PGP announcement</string> <string name="announce_pgp">Renew PGP announcement</string>

View File

@ -1,8 +1,8 @@
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -39,6 +39,7 @@ import android.preference.PreferenceManager;
import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Contacts;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder; import android.support.v4.app.TaskStackBuilder;
import android.text.format.DateFormat;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.text.Html; import android.text.Html;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -60,31 +61,40 @@ public class UIHelper {
} }
Date date = new Date(time); Date date = new Date(time);
long difference = (System.currentTimeMillis() - time) / 1000; long difference = (System.currentTimeMillis() - time) / 1000;
if (difference < 60) { if (difference < 90) {
return context.getString(R.string.just_now); return context.getString(R.string.just_now);
} else if (difference < 60 * 10) { } else if (difference < 60 * 15) {
return difference / 60 + " " + context.getString(R.string.minutes_ago); return context.getString(R.string.minutes_ago,Math.round(difference/60.0));
} else if (difference < 60 * 60 * 24) { } else if (today(date)) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm",Locale.US); java.text.DateFormat df = DateFormat.getTimeFormat(context);
return sdf.format(date); return df.format(date);
} else { } else {
return DateUtils.formatDateTime(context, date.getTime(), DATE_NO_YEAR_FLAGS); return DateUtils.formatDateTime(context, date.getTime(), DATE_NO_YEAR_FLAGS);
} }
} }
private static boolean today(Date date) {
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date);
cal2.setTimeInMillis(System.currentTimeMillis());
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
}
public static String lastseen(Context context, long time) { public static String lastseen(Context context, long time) {
if (time==0) { if (time==0) {
return context.getString(R.string.never_seen); return context.getString(R.string.never_seen);
} }
long difference = (System.currentTimeMillis() - time) / 1000; long difference = (System.currentTimeMillis() - time) / 1000;
if (difference < 60) { if (difference < 90) {
return context.getString(R.string.last_seen_now); return context.getString(R.string.last_seen_now);
} else if (difference < 60 * 90) { } else if (difference < 60 * 90) {
return context.getString(R.string.last_seen_mins,difference/60); return context.getString(R.string.last_seen_mins,Math.round(difference/60.0));
} else if (difference < 60 * 60 * 36) { } else if (difference < 60 * 60 * 36) {
return context.getString(R.string.last_seen_hours,difference/(60*60)); return context.getString(R.string.last_seen_hours,Math.round(difference/(60.0*60.0)));
} else { } else {
return context.getString(R.string.last_seen_days,difference/(60*60*24)); return context.getString(R.string.last_seen_days,Math.round(difference/(60.0*60.0*24.0)));
} }
} }
@ -101,7 +111,6 @@ public class UIHelper {
} }
private static void drawTile(Canvas canvas, String letter, int tileColor, int textColor, int left, int top, int right, int bottom) { private static void drawTile(Canvas canvas, String letter, int tileColor, int textColor, int left, int top, int right, int bottom) {
int size = canvas.getWidth();
Paint tilePaint = new Paint(), textPaint = new Paint(); Paint tilePaint = new Paint(), textPaint = new Paint();
tilePaint.setColor(tileColor); tilePaint.setColor(tileColor);
textPaint.setColor(textColor); textPaint.setColor(textColor);