From 32757d3f355104970c7f6c41f7db8aae648f34b4 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 11 Dec 2017 17:46:14 +0100 Subject: [PATCH] Conversation list displayed correctly. --- .idea/misc.xml | 2 +- .../comunic/client/data/Utilities.java | 46 ++++++++++++++++++- .../ConversationsListAdapter.java | 12 +++++ .../fragment_conversationslist_item.xml | 1 + app/src/main/res/values/strings.xml | 6 +++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 503aca7..33952c6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -55,7 +55,7 @@ - + diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/Utilities.java b/app/src/main/java/org/communiquons/android/comunic/client/data/Utilities.java index 1550901..799b791 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/Utilities.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/Utilities.java @@ -1,12 +1,15 @@ package org.communiquons.android.comunic.client.data; import android.content.Context; +import android.content.res.Resources; import android.os.Build; import android.text.Html; import android.text.TextUtils; import android.util.Log; import android.util.Patterns; +import org.communiquons.android.comunic.client.R; + import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -219,8 +222,47 @@ public class Utilities { * @return Generated string */ public String timeToString(int time){ - //TODO : implement seconds to string function - return null; + + Resources res = mContext.getResources(); + + //Check if the time is inferior to 1 => now + if(time < 1) + return res.getString(R.string.date_now); + + //Less than one minute + else if (time < 60){ + return time + res.getString(R.string.date_s); + } + + //Less than one hour + else if (time < 3600){ + int secs = (int) Math.floor(time / 60); + return secs + res.getString(R.string.date_m); + } + + //Less than a day + else if (time < 86400){ + int hours = (int) Math.floor(time / 3600); + return hours + res.getString(R.string.date_h); + } + + //Less than a month + else if (time < 2678400){ + int days = (int) Math.floor(time / 86400); + return days + res.getString(days > 1 ? R.string.date_days : R.string.date_day); + } + + //Less than a year + else if (time < 31536000){ + int months = (int) Math.floor(time / 2678400); + return months + res.getString(months > 1 ? R.string.date_months : R.string.date_month); + } + + //A several amount of years + else { + int years = (int) Math.floor(31536000); + return years + res.getString(years > 1 ? R.string.date_years : R.string.date_year); + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/conversations/ConversationsListAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/data/conversations/ConversationsListAdapter.java index 3e4b842..8d63062 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/conversations/ConversationsListAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/conversations/ConversationsListAdapter.java @@ -12,6 +12,7 @@ import android.widget.ArrayAdapter; import android.widget.TextView; import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.Utilities; import java.util.ArrayList; import java.util.zip.Inflater; @@ -29,6 +30,8 @@ import static android.R.id.list; public class ConversationsListAdapter extends ArrayAdapter { + private Utilities utils; + /** * Class constructor * @@ -37,6 +40,8 @@ public class ConversationsListAdapter extends ArrayAdapter { */ public ConversationsListAdapter(Context context, ArrayList list){ super(context, 0, list); + + utils = new Utilities(context); } @@ -89,6 +94,13 @@ public class ConversationsListAdapter extends ArrayAdapter { .getString(R.string.conversations_members_number), infos.countMembers()); number_members.setText(members_text); + + + //Update the last activity time of the conversation + TextView last_activity = convertView. + findViewById(R.id.fragment_conversationslist_item_lastactive); + last_activity.setText(utils.timeToString(Utilities.time() - infos.getLast_active())); + return convertView; } diff --git a/app/src/main/res/layout/fragment_conversationslist_item.xml b/app/src/main/res/layout/fragment_conversationslist_item.xml index 1716213..639bdd2 100644 --- a/app/src/main/res/layout/fragment_conversationslist_item.xml +++ b/app/src/main/res/layout/fragment_conversationslist_item.xml @@ -56,6 +56,7 @@ android:src="@android:drawable/ic_menu_my_calendar"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c4fd8e6..2ca6a4a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,6 +40,12 @@ minutes min sec + day + days + month + months + year + years h m s