1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.ui.social;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.exoplatform.R;
25 import org.exoplatform.model.SocialSpaceInfo;
26 import org.exoplatform.singleton.AccountSetting;
27 import org.exoplatform.singleton.SocialServiceHelper;
28 import org.exoplatform.social.client.api.model.RestSpace;
29
30 import android.app.LoaderManager.LoaderCallbacks;
31 import android.content.AsyncTaskLoader;
32 import android.content.Intent;
33 import android.content.Loader;
34 import android.os.Bundle;
35 import android.support.v4.app.FragmentActivity;
36 import android.util.Log;
37 import android.view.MenuItem;
38 import android.view.View;
39 import android.widget.AdapterView;
40 import android.widget.AdapterView.OnItemClickListener;
41 import android.widget.ListView;
42
43
44
45
46
47
48
49 public class SpaceSelectorActivity extends FragmentActivity implements LoaderCallbacks<List<SocialSpaceInfo>>, OnItemClickListener {
50
51 private static final String LOG_TAG = "____eXo_SpaceSelectorActivity____";
52
53 public static final String SELECTED_SPACE = "SelectedSpace";
54
55 private ListView listViewSpaces;
56
57 private SpaceListAdapter listAdapterSpaces;
58
59 private List<SocialSpaceInfo> listInfoSpaces;
60
61 @Override
62 protected void onCreate(Bundle savedInstanceState) {
63 super.onCreate(savedInstanceState);
64 setContentView(R.layout.compose_message_space_selector_activity);
65 setTitle(R.string.ShareWithWhom);
66
67 listViewSpaces = (ListView) findViewById(R.id.list_spaces);
68 listViewSpaces.setOnItemClickListener(this);
69 listAdapterSpaces = new SpaceListAdapter(this);
70 listViewSpaces.setAdapter(listAdapterSpaces);
71 listViewSpaces.setEmptyView(findViewById(R.id.list_spaces_empty_view));
72 getLoaderManager().initLoader(0, null, this).forceLoad();
73
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 public void selectPublicDestination(View view) {
91 sendResultToComposer(-1);
92 }
93
94 @Override
95 public boolean onOptionsItemSelected(MenuItem item) {
96 switch (item.getItemId()) {
97 case android.R.id.home:
98 finish();
99 break;
100 default:
101 break;
102 }
103
104 return true;
105 }
106
107
108
109
110
111
112
113
114
115
116
117 @Override
118 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
119 SocialSpaceInfo selectedSpace = listInfoSpaces.get(position);
120 if (selectedSpace != null) {
121 sendResultToComposer(position);
122 } else {
123
124 }
125 }
126
127
128
129
130
131
132
133
134
135
136
137 private void sendResultToComposer(int result) {
138 Intent data = new Intent();
139 if (result >= 0 && result < listInfoSpaces.size()) {
140 SocialSpaceInfo space = listInfoSpaces.get(result);
141 data.putExtra(SELECTED_SPACE, space);
142 }
143 setResult(RESULT_OK, data);
144 finish();
145 }
146
147
148
149
150
151 @Override
152 public Loader<List<SocialSpaceInfo>> onCreateLoader(int id, Bundle args) {
153 return new AsyncTaskLoader<List<SocialSpaceInfo>>(this) {
154 @Override
155 public List<SocialSpaceInfo> loadInBackground() {
156 List<SocialSpaceInfo> spacesNames = new ArrayList<SocialSpaceInfo>();
157 if (SocialServiceHelper.getInstance().spaceService == null) {
158 Log.e(LOG_TAG, "Cannot retrieve spaces. Social Space service is null.");
159 return null;
160 }
161 List<RestSpace> spaces = SocialServiceHelper.getInstance().spaceService.getMySocialSpaces();
162 String currentServer = AccountSetting.getInstance().getDomainName();
163 for (RestSpace space : spaces) {
164 SocialSpaceInfo sp = new SocialSpaceInfo();
165 sp.displayName = space.getDisplayName();
166 sp.name = space.getName();
167 sp.avatarUrl = currentServer + space.getAvatarUrl();
168 sp.groupId = space.getGroupId();
169 spacesNames.add(sp);
170 }
171 return spacesNames;
172 }
173 };
174 }
175
176 @Override
177 public void onLoadFinished(Loader<List<SocialSpaceInfo>> loader, List<SocialSpaceInfo> data) {
178 if (data != null) {
179 listInfoSpaces = data;
180 listAdapterSpaces.setSpaceList(data);
181 listAdapterSpaces.notifyDataSetChanged();
182 }
183 }
184
185 @Override
186 public void onLoaderReset(Loader<List<SocialSpaceInfo>> loader) {
187 }
188 }