mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 15:59:29 +00:00
Can get and display information about groups in notification fragment.
This commit is contained in:
parent
2f4621c0e5
commit
9a2520efd5
@ -3,6 +3,7 @@ package org.communiquons.android.comunic.client.data.arrays;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||||
import org.communiquons.android.comunic.client.data.enums.NotifElemType;
|
import org.communiquons.android.comunic.client.data.enums.NotifElemType;
|
||||||
import org.communiquons.android.comunic.client.data.models.Notif;
|
import org.communiquons.android.comunic.client.data.models.Notif;
|
||||||
@ -23,6 +24,11 @@ public class NotifsList extends ArrayList<Notif> {
|
|||||||
*/
|
*/
|
||||||
private ArrayMap<Integer, UserInfo> mUsersInfo;
|
private ArrayMap<Integer, UserInfo> mUsersInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about the groups related to the notifications
|
||||||
|
*/
|
||||||
|
private ArrayMap<Integer, GroupInfo> mGroupsInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get and return the IDs of the users related to the notifications
|
* Get and return the IDs of the users related to the notifications
|
||||||
*
|
*
|
||||||
@ -62,6 +68,29 @@ public class NotifsList extends ArrayList<Notif> {
|
|||||||
return IDs;
|
return IDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get and return the IDs of the groups related to the notificatoin
|
||||||
|
*
|
||||||
|
* @return The ID of the groups related to the notification
|
||||||
|
*/
|
||||||
|
public ArrayList<Integer> getGroupsID(){
|
||||||
|
ArrayList<Integer> IDs = new ArrayList<>();
|
||||||
|
|
||||||
|
for(Notif notif : this){
|
||||||
|
|
||||||
|
if(notif.getOn_elem_type() == NotifElemType.GROUP_PAGE
|
||||||
|
&& !IDs.contains(notif.getOn_elem_id()))
|
||||||
|
IDs.add(notif.getOn_elem_id());
|
||||||
|
|
||||||
|
if(notif.getFrom_container_type() == NotifElemType.GROUP_PAGE
|
||||||
|
&& !IDs.contains(notif.getFrom_container_id()))
|
||||||
|
IDs.add(notif.getFrom_container_id());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return IDs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set information about the users related to the notifications
|
* Set information about the users related to the notifications
|
||||||
*
|
*
|
||||||
@ -80,4 +109,22 @@ public class NotifsList extends ArrayList<Notif> {
|
|||||||
public ArrayMap<Integer, UserInfo> getUsersInfo() {
|
public ArrayMap<Integer, UserInfo> getUsersInfo() {
|
||||||
return mUsersInfo;
|
return mUsersInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about the related groups
|
||||||
|
*
|
||||||
|
* @return Information about the related groups
|
||||||
|
*/
|
||||||
|
public ArrayMap<Integer, GroupInfo> getGroupsInfo() {
|
||||||
|
return mGroupsInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set information about the related groups
|
||||||
|
*
|
||||||
|
* @param mGroupsInfo Information about the groups
|
||||||
|
*/
|
||||||
|
public void setGroupsInfo(ArrayMap<Integer, GroupInfo> mGroupsInfo) {
|
||||||
|
this.mGroupsInfo = mGroupsInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package org.communiquons.android.comunic.client.data.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Posts creations levels
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public enum GroupPostsCreationLevel {
|
||||||
|
MODERATORS,
|
||||||
|
MEMBERS
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.communiquons.android.comunic.client.data.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group registration levels
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public enum GroupRegistrationLevel {
|
||||||
|
OPEN,
|
||||||
|
MODERATED,
|
||||||
|
CLOSED
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.communiquons.android.comunic.client.data.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups visibility levels
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public enum GroupVisibility {
|
||||||
|
OPEN,
|
||||||
|
PRIVATE,
|
||||||
|
SECRETE
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package org.communiquons.android.comunic.client.data.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups membership levels
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public enum GroupsMembershipLevels {
|
||||||
|
|
||||||
|
ADMINISTRATOR,
|
||||||
|
MODERATOR,
|
||||||
|
MEMBER,
|
||||||
|
INVITED,
|
||||||
|
PENDING,
|
||||||
|
VISITOR
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,220 @@
|
|||||||
|
package org.communiquons.android.comunic.client.data.helpers;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.ArrayMap;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupPostsCreationLevel;
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupRegistrationLevel;
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupVisibility;
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupsMembershipLevels;
|
||||||
|
import org.communiquons.android.comunic.client.data.models.APIRequest;
|
||||||
|
import org.communiquons.android.comunic.client.data.models.APIResponse;
|
||||||
|
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups helper
|
||||||
|
*/
|
||||||
|
public class GroupsHelper extends BaseHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups constructor
|
||||||
|
*
|
||||||
|
* @param context The context of the application
|
||||||
|
*/
|
||||||
|
public GroupsHelper(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about multiple groups
|
||||||
|
*
|
||||||
|
* @param IDs The ID of the target groups
|
||||||
|
* @return Information about the related groups
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public ArrayMap<Integer, GroupInfo> getInfoMultiple(ArrayList<Integer> IDs){
|
||||||
|
return downloadMultiple(IDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download information of multiple groups from the server
|
||||||
|
*
|
||||||
|
* @param IDs The IDs of the groups to get
|
||||||
|
* @return Information about the groups / null in case of failure
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private ArrayMap<Integer, GroupInfo> downloadMultiple(ArrayList<Integer> IDs){
|
||||||
|
|
||||||
|
//Make a request over the server
|
||||||
|
APIRequest request = new APIRequest(getContext(), "groups/get_multiple_info");
|
||||||
|
|
||||||
|
//Process the list of groups to get
|
||||||
|
StringBuilder reqList = new StringBuilder();
|
||||||
|
for(Integer id : IDs) {
|
||||||
|
reqList.append(id);
|
||||||
|
reqList.append(",");
|
||||||
|
}
|
||||||
|
request.addString("list", reqList.toString());
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
APIResponse response = new APIRequestHelper().exec(request);
|
||||||
|
JSONObject object = response.getJSONObject();
|
||||||
|
ArrayMap<Integer, GroupInfo> list = new ArrayMap<>();
|
||||||
|
|
||||||
|
if(object == null) return null;
|
||||||
|
|
||||||
|
//Parse the list of keys
|
||||||
|
for(Integer id : IDs){
|
||||||
|
|
||||||
|
//Get raw information about the group
|
||||||
|
JSONObject info = object.getJSONObject(id + "");
|
||||||
|
|
||||||
|
//Check if we did not get anything
|
||||||
|
if(info == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
list.put(id, parse_group_info(info));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse group information into GroupInfo object
|
||||||
|
*
|
||||||
|
* @param object The object to parse
|
||||||
|
* @return Generated group object
|
||||||
|
* @throws JSONException In case of failure
|
||||||
|
*/
|
||||||
|
private GroupInfo parse_group_info(@NonNull JSONObject object) throws JSONException {
|
||||||
|
|
||||||
|
GroupInfo info = new GroupInfo();
|
||||||
|
|
||||||
|
info.setId(object.getInt("id"));
|
||||||
|
info.setName(object.getString("name"));
|
||||||
|
info.setIcon_url(object.getString("icon_url"));
|
||||||
|
info.setNumber_members(object.getInt("number_members"));
|
||||||
|
info.setMembershipLevel(parse_membership_level(object.getString("membership")));
|
||||||
|
info.setVisibility(parse_group_visibility(object.getString("visibility")));
|
||||||
|
info.setRegistrationLevel(parse_group_registration_level(object.getString("registration_level")));
|
||||||
|
info.setPostCreationLevel(parse_post_creation_level(object.getString("posts_level")));
|
||||||
|
info.setVirtualDirectory(object.getString("virtual_directory"));
|
||||||
|
info.setFollowing(object.getBoolean("following"));
|
||||||
|
|
||||||
|
return info;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse membership level
|
||||||
|
*
|
||||||
|
* @param level Membership level to parse as string
|
||||||
|
* @return Equivalent membership level
|
||||||
|
*/
|
||||||
|
private GroupsMembershipLevels parse_membership_level(String level){
|
||||||
|
switch (level){
|
||||||
|
|
||||||
|
case "administrator":
|
||||||
|
return GroupsMembershipLevels.ADMINISTRATOR;
|
||||||
|
|
||||||
|
case "moderator":
|
||||||
|
return GroupsMembershipLevels.MODERATOR;
|
||||||
|
|
||||||
|
case "member":
|
||||||
|
return GroupsMembershipLevels.MEMBER;
|
||||||
|
|
||||||
|
case "invited":
|
||||||
|
return GroupsMembershipLevels.INVITED;
|
||||||
|
|
||||||
|
case "pending":
|
||||||
|
return GroupsMembershipLevels.PENDING;
|
||||||
|
|
||||||
|
case "visitor":
|
||||||
|
return GroupsMembershipLevels.VISITOR;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported membership level: " + level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse group visibility level
|
||||||
|
*
|
||||||
|
* @param level The level to parse
|
||||||
|
* @return Equivalent visibility level
|
||||||
|
*/
|
||||||
|
private GroupVisibility parse_group_visibility(String level){
|
||||||
|
switch (level){
|
||||||
|
|
||||||
|
case "open":
|
||||||
|
return GroupVisibility.OPEN;
|
||||||
|
|
||||||
|
case "private":
|
||||||
|
return GroupVisibility.PRIVATE;
|
||||||
|
|
||||||
|
case "secrete":
|
||||||
|
return GroupVisibility.SECRETE;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported group visibility level: " + level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse group registration level
|
||||||
|
*
|
||||||
|
* @param level The level to parse
|
||||||
|
* @return Equivalent registration level
|
||||||
|
*/
|
||||||
|
private GroupRegistrationLevel parse_group_registration_level(String level){
|
||||||
|
switch (level){
|
||||||
|
|
||||||
|
case "open":
|
||||||
|
return GroupRegistrationLevel.OPEN;
|
||||||
|
|
||||||
|
case "moderated":
|
||||||
|
return GroupRegistrationLevel.MODERATED;
|
||||||
|
|
||||||
|
case "closed":
|
||||||
|
return GroupRegistrationLevel.CLOSED;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported group registration level: " + level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse post creation level
|
||||||
|
*
|
||||||
|
* @param level The level to parse
|
||||||
|
* @return Equivalent post creation post level
|
||||||
|
*/
|
||||||
|
private GroupPostsCreationLevel parse_post_creation_level(String level){
|
||||||
|
switch (level){
|
||||||
|
|
||||||
|
case "moderators":
|
||||||
|
return GroupPostsCreationLevel.MODERATORS;
|
||||||
|
|
||||||
|
case "members":
|
||||||
|
return GroupPostsCreationLevel.MEMBERS;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported group post creation level: " + level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,119 @@
|
|||||||
|
package org.communiquons.android.comunic.client.data.models;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupRegistrationLevel;
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupVisibility;
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupsMembershipLevels;
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.GroupPostsCreationLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group information base model
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public class GroupInfo {
|
||||||
|
|
||||||
|
//Private fields
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String icon_url;
|
||||||
|
private int number_members;
|
||||||
|
private GroupsMembershipLevels membershipLevel;
|
||||||
|
private GroupVisibility visibility;
|
||||||
|
private GroupRegistrationLevel registrationLevel;
|
||||||
|
private GroupPostsCreationLevel postCreationLevel;
|
||||||
|
private String virtualDirectory;
|
||||||
|
private boolean following;
|
||||||
|
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIcon_url() {
|
||||||
|
return icon_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon_url(String icon_url) {
|
||||||
|
this.icon_url = icon_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumber_members() {
|
||||||
|
return number_members;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumber_members(int number_members) {
|
||||||
|
this.number_members = number_members;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupsMembershipLevels getMembershipLevel() {
|
||||||
|
return membershipLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMembershipLevel(GroupsMembershipLevels membershipLevel) {
|
||||||
|
this.membershipLevel = membershipLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupVisibility getVisibility() {
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisibility(GroupVisibility visibility) {
|
||||||
|
this.visibility = visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupRegistrationLevel getRegistrationLevel() {
|
||||||
|
return registrationLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegistrationLevel(GroupRegistrationLevel registrationLevel) {
|
||||||
|
this.registrationLevel = registrationLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupPostsCreationLevel getPostCreationLevel() {
|
||||||
|
return postCreationLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostCreationLevel(GroupPostsCreationLevel creationLevel) {
|
||||||
|
this.postCreationLevel = creationLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getVirtualDirectory() {
|
||||||
|
return virtualDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasVirtualDirectory(){
|
||||||
|
return virtualDirectory != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVirtualDirectory(@Nullable String virtualDirectory) {
|
||||||
|
this.virtualDirectory = virtualDirectory;
|
||||||
|
|
||||||
|
if(virtualDirectory != null){
|
||||||
|
if(virtualDirectory.equals("null"))
|
||||||
|
this.virtualDirectory = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFollowing() {
|
||||||
|
return following;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFollowing(boolean following) {
|
||||||
|
this.following = following;
|
||||||
|
}
|
||||||
|
}
|
@ -6,10 +6,13 @@ import android.util.ArrayMap;
|
|||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
import org.communiquons.android.comunic.client.data.enums.NotifElemType;
|
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.enums.NotificationTypes;
|
||||||
|
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||||
import org.communiquons.android.comunic.client.data.models.Notif;
|
import org.communiquons.android.comunic.client.data.models.Notif;
|
||||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
||||||
|
|
||||||
|
import java.security.acl.Group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifications utilities
|
* Notifications utilities
|
||||||
*
|
*
|
||||||
@ -25,10 +28,12 @@ public class NotifsUtils {
|
|||||||
* @param context The context of the application
|
* @param context The context of the application
|
||||||
* @param notif The target notification
|
* @param notif The target notification
|
||||||
* @param userInfos Information about the user of the notification
|
* @param userInfos Information about the user of the notification
|
||||||
|
* @param groupsInfo Information about related groups
|
||||||
* @return The message associated to the notification
|
* @return The message associated to the notification
|
||||||
*/
|
*/
|
||||||
public static String getNotificationMessage(Context context, Notif notif,
|
public static String getNotificationMessage(Context context, Notif notif,
|
||||||
ArrayMap<Integer, UserInfo> userInfos){
|
ArrayMap<Integer, UserInfo> userInfos,
|
||||||
|
ArrayMap<Integer, GroupInfo> groupsInfo){
|
||||||
|
|
||||||
//First, put the name of the user
|
//First, put the name of the user
|
||||||
String message = userInfos.get(notif.getFrom_user_id()).getDisplayFullName();
|
String message = userInfos.get(notif.getFrom_user_id()).getDisplayFullName();
|
||||||
@ -74,7 +79,8 @@ public class NotifsUtils {
|
|||||||
|
|
||||||
//Group page
|
//Group page
|
||||||
else if(notif.getFrom_container_type() == NotifElemType.GROUP_PAGE){
|
else if(notif.getFrom_container_type() == NotifElemType.GROUP_PAGE){
|
||||||
message += UiUtils.getString(context, R.string.notif_on_group_page);
|
message += UiUtils.getString(context, R.string.notif_on_group_page,
|
||||||
|
groupsInfo.get(notif.getFrom_container_id()).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return the message
|
//Return the message
|
||||||
|
@ -13,12 +13,15 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper;
|
import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper;
|
||||||
|
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||||
import org.communiquons.android.comunic.client.data.models.Notif;
|
import org.communiquons.android.comunic.client.data.models.Notif;
|
||||||
import org.communiquons.android.comunic.client.data.arrays.NotifsList;
|
import org.communiquons.android.comunic.client.data.arrays.NotifsList;
|
||||||
import org.communiquons.android.comunic.client.data.utils.NotifsUtils;
|
import org.communiquons.android.comunic.client.data.utils.NotifsUtils;
|
||||||
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifications list adapter
|
* Notifications list adapter
|
||||||
*
|
*
|
||||||
@ -38,6 +41,11 @@ public class NotificationsAdapter extends ArrayAdapter<Notif>{
|
|||||||
*/
|
*/
|
||||||
private ArrayMap<Integer, UserInfo> mUsersInfo;
|
private ArrayMap<Integer, UserInfo> mUsersInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about the groups related to the notifications
|
||||||
|
*/
|
||||||
|
private ArrayMap<Integer, GroupInfo> mGroupsInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public adapter constructor
|
* Public adapter constructor
|
||||||
*
|
*
|
||||||
@ -47,8 +55,9 @@ public class NotificationsAdapter extends ArrayAdapter<Notif>{
|
|||||||
public NotificationsAdapter(Context context, NotifsList list){
|
public NotificationsAdapter(Context context, NotifsList list){
|
||||||
super(context, 0, list);
|
super(context, 0, list);
|
||||||
|
|
||||||
//Save user information
|
//Save users and groups information
|
||||||
mUsersInfo = list.getUsersInfo();
|
mUsersInfo = list.getUsersInfo();
|
||||||
|
mGroupsInfo = list.getGroupsInfo();
|
||||||
|
|
||||||
mUtils = new Utilities(context);
|
mUtils = new Utilities(context);
|
||||||
}
|
}
|
||||||
@ -75,7 +84,8 @@ public class NotificationsAdapter extends ArrayAdapter<Notif>{
|
|||||||
|
|
||||||
//Update the message of the notification
|
//Update the message of the notification
|
||||||
TextView message = convertView.findViewById(R.id.notification_message);
|
TextView message = convertView.findViewById(R.id.notification_message);
|
||||||
message.setText(NotifsUtils.getNotificationMessage(getContext(), notif, mUsersInfo));
|
message.setText(NotifsUtils.getNotificationMessage(getContext(), notif,
|
||||||
|
mUsersInfo, mGroupsInfo));
|
||||||
|
|
||||||
//Update the date of the notification
|
//Update the date of the notification
|
||||||
TextView date = convertView.findViewById(R.id.notification_date);
|
TextView date = convertView.findViewById(R.id.notification_date);
|
||||||
|
@ -22,6 +22,7 @@ import android.widget.Toast;
|
|||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
import org.communiquons.android.comunic.client.data.enums.NotifElemType;
|
import org.communiquons.android.comunic.client.data.enums.NotifElemType;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.GetUsersHelper;
|
import org.communiquons.android.comunic.client.data.helpers.GetUsersHelper;
|
||||||
|
import org.communiquons.android.comunic.client.data.helpers.GroupsHelper;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.NotificationsHelper;
|
import org.communiquons.android.comunic.client.data.helpers.NotificationsHelper;
|
||||||
import org.communiquons.android.comunic.client.data.arrays.NotifsList;
|
import org.communiquons.android.comunic.client.data.arrays.NotifsList;
|
||||||
import org.communiquons.android.comunic.client.data.models.Notif;
|
import org.communiquons.android.comunic.client.data.models.Notif;
|
||||||
@ -50,6 +51,11 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
|
|||||||
*/
|
*/
|
||||||
private GetUsersHelper mUsersInfoHelper;
|
private GetUsersHelper mUsersInfoHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups heper
|
||||||
|
*/
|
||||||
|
private GroupsHelper mGroupsHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifications list
|
* Notifications list
|
||||||
*/
|
*/
|
||||||
@ -94,11 +100,10 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
|
|||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
//Create notifications helper
|
//Initialize helpers
|
||||||
mNotificationsHelper = new NotificationsHelper(getActivity());
|
mNotificationsHelper = new NotificationsHelper(getActivity());
|
||||||
|
|
||||||
//Create get users helper
|
|
||||||
mUsersInfoHelper = new GetUsersHelper(getActivity());
|
mUsersInfoHelper = new GetUsersHelper(getActivity());
|
||||||
|
mGroupsHelper = new GroupsHelper(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -228,8 +233,10 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
|
|||||||
NotifsList list = mNotificationsHelper.getListUnread();
|
NotifsList list = mNotificationsHelper.getListUnread();
|
||||||
|
|
||||||
//If we got the list of notifications, fetch users information
|
//If we got the list of notifications, fetch users information
|
||||||
if(list != null)
|
if(list != null) {
|
||||||
list.setUsersInfo(mUsersInfoHelper.getMultiple(list.getUsersID()));
|
list.setUsersInfo(mUsersInfoHelper.getMultiple(list.getUsersID()));
|
||||||
|
list.setGroupsInfo(mGroupsHelper.getInfoMultiple(list.getGroupsID()));
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user