Transferred notification message parts into strings.xml

This commit is contained in:
Pierre 2018-04-11 08:50:16 +02:00
parent 5798df62bf
commit 711afa46e2
3 changed files with 37 additions and 12 deletions

View File

@ -3,10 +3,12 @@ package org.communiquons.android.comunic.client.data.utils;
import android.content.Context;
import android.util.ArrayMap;
import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.data.enums.NotifElemType;
import org.communiquons.android.comunic.client.data.enums.NotificationTypes;
import org.communiquons.android.comunic.client.data.models.Notif;
import org.communiquons.android.comunic.client.data.models.UserInfo;
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
/**
* Notifications utilities
@ -34,24 +36,24 @@ public class NotifsUtils {
//For friendship request
if(notif.getType() == NotificationTypes.SENT_FRIEND_REQUEST)
message += "sent you a friendship request.";
message += UiUtils.getString(context, R.string.notif_sent_friend_request);
if(notif.getType() == NotificationTypes.ACCEPTED_FRIEND_REQUEST)
message += "accepted your friendship request.";
message += UiUtils.getString(context, R.string.notif_accepted_friend_request);
if(notif.getType() == NotificationTypes.REJECTED_FRIEND_REQUEST)
message += "rejected your friendship request.";
message += UiUtils.getString(context, R.string.notif_rejected_friend_request);
//In case of creation of an element
if(notif.getType() == NotificationTypes.ELEM_CREATED){
//For the posts
if(notif.getOn_elem_type() == NotifElemType.POST)
message += "created a new post";
message += UiUtils.getString(context, R.string.notif_created_post);
}
//For comments creation
if(notif.getType() == NotificationTypes.COMMENT_CREATED){
message += "posted a comment";
message += UiUtils.getString(context, R.string.notif_posted_comment);
}
//Add a separator
@ -62,10 +64,10 @@ public class NotifsUtils {
if(notif.getFrom_container_type() == NotifElemType.USER_PAGE){
if(notif.getFrom_user_id() == notif.getFrom_container_id())
message += "on his / her page";
message += UiUtils.getString(context, R.string.notif_on_creator_page);
else
message += "on " + userInfos.get(notif.getFrom_container_id()).getDisplayFullName()
+ "'s page";
message += UiUtils.getString(context, R.string.notif_on_user_page,
userInfos.get(notif.getFrom_container_id()).getDisplayFullName());
}

View File

@ -17,10 +17,10 @@ import org.communiquons.android.comunic.client.R;
public class UiUtils {
/**
* Get a color from ressources
* Get a color from resources
*
* @param context The context of the application
* @param color_id The ID of the ressource
* @param color_id The ID of the resource
* @return The ID of the color
*/
public static int getColor(Context context, int color_id){
@ -34,7 +34,7 @@ public class UiUtils {
}
/**
* Get a drawable from ressources
* Get a drawable from resources
*
* @param context The context of the application
* @param drawable_id The ID of the drawable to get
@ -44,12 +44,28 @@ public class UiUtils {
}
/**
* Get a string from ressources
* Get a string from resources
*
* @param context The context of the application
* @param res_id The ID of the resource
* @return The string
*/
public static String getString(Context context, int res_id){
return context.getResources().getString(res_id);
}
/**
* Get a string from resources with parameters
*
* @param context The context of the application
* @param res_id Resource ID
* @param formatsArgs Additional arguments
* @return The string
*/
public static String getString(Context context, int res_id, Object... formatsArgs){
return context.getResources().getString(res_id, formatsArgs);
}
/**
* Create and display a loading dialog
*

View File

@ -157,4 +157,11 @@
<string name="err_delete_all_notifs">An error occurred while trying to delete the entire list of notifications!</string>
<string name="success_delete_all_notifs">All the notifications have been deleted!</string>
<string name="err_get_list_notifs">An error occurred while trying to get the list of notifications !</string>
<string name="notif_sent_friend_request">sent you a friendship request.</string>
<string name="notif_accepted_friend_request">accepted your friendship request.</string>
<string name="notif_rejected_friend_request">rejected your friendship request.</string>
<string name="notif_created_post">created a new post</string>
<string name="notif_posted_comment">posted a comment</string>
<string name="notif_on_creator_page">on his / her page</string>
<string name="notif_on_user_page">on %1$s\'s page</string>
</resources>