1 /*
2 * Copyright (C) 2003-2015 eXo Platform SAS.
3 *
4 * This is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 3 of
7 * the License, or (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this software; if not, write to the Free
16 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18 */
19 package org.exoplatform.model;
20
21 import android.os.Parcel;
22 import android.os.Parcelable;
23
24 /**
25 * Created by The eXo Platform SAS
26 *
27 * @author Philippe Aristote paristote@exoplatform.com
28 * @since Apr 22, 2015
29 */
30 public class SocialSpaceInfo implements Parcelable {
31
32 public String id;
33
34 public String avatarUrl;
35
36 public String displayName;
37
38 public String name;
39
40 public String groupId;
41
42 public SocialSpaceInfo() {
43 }
44
45 @Override
46 public String toString() {
47 return displayName;
48 }
49
50 /**
51 * If the space has been renamed, it's still possible to retrieve the original
52 * name from the groupId.<br/>
53 * It works by extracting the last part of the groupId, e.g.
54 *
55 * <pre>
56 * name = new_name
57 * groupId = /spaces/old_name
58 * original name = old_name
59 * </pre>
60 *
61 * @return the original name, or the current name if extraction fails.
62 */
63 public String getOriginalName() {
64 String origName = name;
65 if (groupId != null) {
66 int lastPart = groupId.lastIndexOf('/');
67 if (lastPart >= 0 && lastPart < groupId.length()) {
68 origName = groupId.substring(lastPart + 1);
69 }
70 }
71 return origName;
72 }
73
74 /*
75 * PARCEL
76 */
77
78 private SocialSpaceInfo(Parcel in) {
79 readFromParcel(in);
80 }
81
82 public static final Parcelable.Creator<SocialSpaceInfo> CREATOR = new Parcelable.Creator<SocialSpaceInfo>() {
83 public SocialSpaceInfo createFromParcel(Parcel in) {
84 return new SocialSpaceInfo(in);
85 }
86
87 public SocialSpaceInfo[] newArray(int size) {
88 return new SocialSpaceInfo[size];
89 }
90 };
91
92 @Override
93 public int describeContents() {
94 return 0;
95 }
96
97 @Override
98 public void writeToParcel(Parcel dest, int flags) {
99 dest.writeString(id);
100 dest.writeString(name);
101 dest.writeString(displayName);
102 dest.writeString(groupId);
103 dest.writeString(avatarUrl);
104 }
105
106 public void readFromParcel(Parcel in) {
107 id = in.readString();
108 name = in.readString();
109 displayName = in.readString();
110 groupId = in.readString();
111 avatarUrl = in.readString();
112 }
113
114 }