mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Friend status displayed in friends list.
This commit is contained in:
parent
5ded2cd7b4
commit
5c8d8a8f52
@ -1,6 +1,8 @@
|
||||
package org.communiquons.android.comunic.client.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
@ -13,6 +15,7 @@ import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
import java.util.Formatter;
|
||||
|
||||
/**
|
||||
@ -184,4 +187,28 @@ public class Utilities {
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a string sent through the API to be shown in a TextView element
|
||||
*
|
||||
* @param input The string to prepare
|
||||
* @return The string ready to be shown
|
||||
*/
|
||||
public static String prepareStringTextView(String input){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return Html.fromHtml(input, Html.FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH).toString();
|
||||
}
|
||||
else
|
||||
return Html.fromHtml(input).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current timestamp
|
||||
*
|
||||
* @return The current timestamp
|
||||
*/
|
||||
public static int time(){
|
||||
Date date = new Date();
|
||||
return (int) Math.ceil(date.getTime()/1000);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.communiquons.android.comunic.client.data.friendsList;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.Utilities;
|
||||
|
||||
/**
|
||||
* Friend object
|
||||
*
|
||||
@ -9,6 +11,11 @@ package org.communiquons.android.comunic.client.data.friendsList;
|
||||
|
||||
public class Friend {
|
||||
|
||||
/**
|
||||
* The minimal time of activity required to consider a user as signed in
|
||||
*/
|
||||
private static final int USER_INACTIVE_AFTER = 35;
|
||||
|
||||
/**
|
||||
* The ID of the friend
|
||||
*/
|
||||
@ -105,4 +112,13 @@ public class Friend {
|
||||
public int getLast_activity() {
|
||||
return last_activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether user is signed in or not
|
||||
*
|
||||
* @return True if user is signed in / false else
|
||||
*/
|
||||
public boolean signed_in(){
|
||||
return (Utilities.time()-USER_INACTIVE_AFTER) < last_activity;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.communiquons.android.comunic.client.data.friendsList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
@ -11,9 +10,10 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.communiquons.android.comunic.client.BuildConfig;
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadManager;
|
||||
import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadTask;
|
||||
import org.communiquons.android.comunic.client.data.Utilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -58,7 +58,27 @@ public class FriendsAdapter extends ArrayAdapter<FriendUser> {
|
||||
|
||||
//Update user name
|
||||
TextView user_name = listItemView.findViewById(R.id.fragment_friendslist_item_fullname);
|
||||
user_name.setText(friendUser.getUserInfo().getFullName());
|
||||
user_name.setText(Utilities.prepareStringTextView(friendUser.getUserInfo().getFullName()));
|
||||
|
||||
//Update user status
|
||||
boolean signed_in = friendUser.getFriend().signed_in();
|
||||
TextView statusView = listItemView.findViewById(R.id.fragment_friendslist_item_status);
|
||||
|
||||
//Set the text
|
||||
statusView.setText(signed_in ?
|
||||
getContext().getText(R.string.user_status_online) :
|
||||
getContext().getText(R.string.user_status_offline)
|
||||
);
|
||||
|
||||
//Set the color
|
||||
int status_color = 0;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
status_color = getContext().getResources().getColor(signed_in ? R.color.holo_green_dark : R.color.darker_gray, null);
|
||||
}
|
||||
else {
|
||||
status_color = getContext().getResources().getColor(signed_in ? R.color.holo_green_dark : R.color.darker_gray);
|
||||
}
|
||||
statusView.setTextColor(status_color);
|
||||
|
||||
return listItemView;
|
||||
}
|
||||
|
@ -32,8 +32,10 @@
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_friendslist_item_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/user_status_offline"
|
||||
tools:text="Online"
|
||||
android:textColor="@android:color/holo_green_dark"/>
|
||||
|
||||
|
@ -3,4 +3,7 @@
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
|
||||
<color name="holo_green_dark">#ff669900</color>
|
||||
<color name="darker_gray">#aaa</color>
|
||||
</resources>
|
||||
|
@ -18,4 +18,6 @@
|
||||
<string name="navigation_bottom_me_item">Me</string>
|
||||
<string name="fragment_friendslist_err_refresh">Couldn\'t refresh friends list !</string>
|
||||
<string name="fragment_friendslist_err_get_userinfos">Couldn\'t get information about your friends!</string>
|
||||
<string name="user_status_online">Online</string>
|
||||
<string name="user_status_offline">Offline</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user