Use 'forum' instead of 'group'. #174

This commit is contained in:
akwizgran
2015-12-15 11:21:41 +00:00
parent 2621ab011c
commit e7e7bf35ea
27 changed files with 602 additions and 622 deletions

View File

@@ -125,35 +125,35 @@
/> />
</activity> </activity>
<activity <activity
android:name=".android.groups.AvailableGroupsActivity" android:name=".android.forum.AvailableForumsActivity"
android:label="@string/available_forums_title" android:label="@string/available_forums_title"
android:parentActivityName=".android.groups.GroupListActivity" > android:parentActivityName=".android.forum.ForumListActivity" >
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".android.groups.GroupListActivity" android:value=".android.forum.ForumListActivity"
/> />
</activity> </activity>
<activity <activity
android:name=".android.groups.CreateGroupActivity" android:name=".android.forum.CreateForumActivity"
android:label="@string/create_forum_title" android:label="@string/create_forum_title"
android:windowSoftInputMode="stateVisible" android:windowSoftInputMode="stateVisible"
android:parentActivityName=".android.groups.GroupListActivity" > android:parentActivityName=".android.forum.ForumListActivity" >
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".android.groups.GroupListActivity" android:value=".android.forum.ForumListActivity"
/> />
</activity> </activity>
<activity <activity
android:name=".android.groups.GroupActivity" android:name=".android.forum.ForumActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:parentActivityName=".android.groups.GroupListActivity" > android:parentActivityName=".android.forum.ForumListActivity" >
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".android.groups.GroupListActivity" android:value=".android.forum.ForumListActivity"
/> />
</activity> </activity>
<activity <activity
android:name=".android.groups.GroupListActivity" android:name=".android.forum.ForumListActivity"
android:label="@string/forums_title" android:label="@string/forums_title"
android:parentActivityName=".android.DashboardActivity" > android:parentActivityName=".android.DashboardActivity" >
<meta-data <meta-data
@@ -162,31 +162,31 @@
/> />
</activity> </activity>
<activity <activity
android:name=".android.groups.ReadGroupPostActivity" android:name=".android.forum.ReadForumPostActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:parentActivityName=".android.groups.GroupListActivity" > android:parentActivityName=".android.forum.ForumListActivity" >
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".android.groups.GroupListActivity" android:value=".android.forum.ForumListActivity"
/> />
</activity> </activity>
<activity <activity
android:name=".android.groups.ShareGroupActivity" android:name=".android.forum.ShareForumActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:parentActivityName=".android.groups.GroupListActivity" > android:parentActivityName=".android.forum.ForumListActivity" >
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".android.groups.GroupListActivity" android:value=".android.forum.ForumListActivity"
/> />
</activity> </activity>
<activity <activity
android:name=".android.groups.WriteGroupPostActivity" android:name=".android.forum.WriteForumPostActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:windowSoftInputMode="stateVisible" android:windowSoftInputMode="stateVisible"
android:parentActivityName=".android.groups.GroupListActivity" > android:parentActivityName=".android.forum.ForumListActivity" >
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".android.groups.GroupListActivity" android:value=".android.forum.ForumListActivity"
/> />
</activity> </activity>
<activity <activity

View File

@@ -104,7 +104,7 @@
<string name="bluetooth_setting_disabled">Only when adding contacts</string> <string name="bluetooth_setting_disabled">Only when adding contacts</string>
<string name="notification_settings_title">NOTIFICATIONS</string> <string name="notification_settings_title">NOTIFICATIONS</string>
<string name="notify_private_messages_setting">Show alerts for private messages</string> <string name="notify_private_messages_setting">Show alerts for private messages</string>
<string name="notify_group_posts_setting">Show alerts for forum posts</string> <string name="notify_forum_posts_setting">Show alerts for forum posts</string>
<string name="notify_vibration_setting">Vibrate</string> <string name="notify_vibration_setting">Vibrate</string>
<string name="notify_sound_setting">Sound</string> <string name="notify_sound_setting">Sound</string>
<string name="notify_sound_setting_default">Default ringtone</string> <string name="notify_sound_setting_default">Default ringtone</string>

View File

@@ -1,27 +1,18 @@
package org.briarproject.android; package org.briarproject.android;
import static android.app.Notification.DEFAULT_LIGHTS; import android.app.Application;
import static android.app.Notification.DEFAULT_SOUND; import android.app.NotificationManager;
import static android.app.Notification.DEFAULT_VIBRATE; import android.content.Context;
import static android.content.Context.NOTIFICATION_SERVICE; import android.content.Intent;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import android.net.Uri;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; import android.support.v4.app.NotificationCompat;
import static java.util.logging.Level.WARNING; import android.support.v4.app.TaskStackBuilder;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.contact.ContactListActivity; import org.briarproject.android.contact.ContactListActivity;
import org.briarproject.android.contact.ConversationActivity; import org.briarproject.android.contact.ConversationActivity;
import org.briarproject.android.groups.GroupActivity; import org.briarproject.android.forum.ForumActivity;
import org.briarproject.android.groups.GroupListActivity; import org.briarproject.android.forum.ForumListActivity;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.Settings; import org.briarproject.api.Settings;
import org.briarproject.api.android.AndroidNotificationManager; import org.briarproject.api.android.AndroidNotificationManager;
@@ -35,23 +26,32 @@ import org.briarproject.api.event.SettingsUpdatedEvent;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.GroupId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import android.app.Application; import java.util.HashMap;
import android.app.NotificationManager; import java.util.Map;
import android.content.Context; import java.util.concurrent.Executor;
import android.content.Intent; import java.util.concurrent.locks.Lock;
import android.net.Uri; import java.util.concurrent.locks.ReentrantLock;
import android.support.v4.app.NotificationCompat; import java.util.logging.Logger;
import android.support.v4.app.TaskStackBuilder;
import javax.inject.Inject;
import static android.app.Notification.DEFAULT_LIGHTS;
import static android.app.Notification.DEFAULT_SOUND;
import static android.app.Notification.DEFAULT_VIBRATE;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static java.util.logging.Level.WARNING;
class AndroidNotificationManagerImpl implements AndroidNotificationManager, class AndroidNotificationManagerImpl implements AndroidNotificationManager,
EventListener { EventListener {
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3; private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
private static final int GROUP_POST_NOTIFICATION_ID = 4; private static final int FORUM_POST_NOTIFICATION_ID = 4;
private static final String CONTACT_URI = private static final String CONTACT_URI =
"content://org.briarproject/contact"; "content://org.briarproject/contact";
private static final String GROUP_URI = private static final String FORUM_URI =
"content://org.briarproject/group"; "content://org.briarproject/forum";
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(AndroidNotificationManagerImpl.class.getName()); Logger.getLogger(AndroidNotificationManagerImpl.class.getName());
@@ -65,9 +65,9 @@ EventListener {
// The following are locking: lock // The following are locking: lock
private final Map<ContactId, Integer> contactCounts = private final Map<ContactId, Integer> contactCounts =
new HashMap<ContactId, Integer>(); new HashMap<ContactId, Integer>();
private final Map<GroupId, Integer> groupCounts = private final Map<GroupId, Integer> forumCounts =
new HashMap<GroupId, Integer>(); new HashMap<GroupId, Integer>();
private int privateTotal = 0, groupTotal = 0; private int contactTotal = 0, forumTotal = 0;
private int nextRequestId = 0; private int nextRequestId = 0;
private volatile Settings settings = new Settings(); private volatile Settings settings = new Settings();
@@ -116,7 +116,7 @@ EventListener {
Integer count = contactCounts.get(c); Integer count = contactCounts.get(c);
if (count == null) contactCounts.put(c, 1); if (count == null) contactCounts.put(c, 1);
else contactCounts.put(c, count + 1); else contactCounts.put(c, count + 1);
privateTotal++; contactTotal++;
updatePrivateMessageNotification(); updatePrivateMessageNotification();
} finally { } finally {
lock.unlock(); lock.unlock();
@@ -128,7 +128,7 @@ EventListener {
try { try {
Integer count = contactCounts.remove(c); Integer count = contactCounts.remove(c);
if (count == null) return; // Already cleared if (count == null) return; // Already cleared
privateTotal -= count; contactTotal -= count;
updatePrivateMessageNotification(); updatePrivateMessageNotification();
} finally { } finally {
lock.unlock(); lock.unlock();
@@ -137,18 +137,16 @@ EventListener {
// Locking: lock // Locking: lock
private void updatePrivateMessageNotification() { private void updatePrivateMessageNotification() {
if (privateTotal == 0) { if (contactTotal == 0) {
clearPrivateMessageNotification(); clearPrivateMessageNotification();
} else if (!settings.getBoolean("notifyPrivateMessages", true)) { } else if (settings.getBoolean("notifyPrivateMessages", true)) {
return;
} else {
NotificationCompat.Builder b = NotificationCompat.Builder b =
new NotificationCompat.Builder(appContext); new NotificationCompat.Builder(appContext);
b.setSmallIcon(R.drawable.message_notification_icon); b.setSmallIcon(R.drawable.message_notification_icon);
b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentTitle(appContext.getText(R.string.app_name));
b.setContentText(appContext.getResources().getQuantityString( b.setContentText(appContext.getResources().getQuantityString(
R.plurals.private_message_notification_text, privateTotal, R.plurals.private_message_notification_text, contactTotal,
privateTotal)); contactTotal));
boolean sound = settings.getBoolean("notifySound", true); boolean sound = settings.getBoolean("notifySound", true);
String ringtoneUri = settings.get("notifyRingtoneUri"); String ringtoneUri = settings.get("notifyRingtoneUri");
if (sound && !StringUtils.isNullOrEmpty(ringtoneUri)) if (sound && !StringUtils.isNullOrEmpty(ringtoneUri))
@@ -198,91 +196,89 @@ EventListener {
return defaults; return defaults;
} }
public void showGroupPostNotification(GroupId g) { public void showForumPostNotification(GroupId g) {
lock.lock(); lock.lock();
try { try {
Integer count = groupCounts.get(g); Integer count = forumCounts.get(g);
if (count == null) groupCounts.put(g, 1); if (count == null) forumCounts.put(g, 1);
else groupCounts.put(g, count + 1); else forumCounts.put(g, count + 1);
groupTotal++; forumTotal++;
updateGroupPostNotification(); updateForumPostNotification();
} finally { } finally {
lock.unlock(); lock.unlock();
} }
} }
public void clearGroupPostNotification(GroupId g) { public void clearForumPostNotification(GroupId g) {
lock.lock(); lock.lock();
try { try {
Integer count = groupCounts.remove(g); Integer count = forumCounts.remove(g);
if (count == null) return; // Already cleared if (count == null) return; // Already cleared
groupTotal -= count; forumTotal -= count;
updateGroupPostNotification(); updateForumPostNotification();
} finally { } finally {
lock.unlock(); lock.unlock();
} }
} }
// Locking: lock // Locking: lock
private void updateGroupPostNotification() { private void updateForumPostNotification() {
if (groupTotal == 0) { if (forumTotal == 0) {
clearGroupPostNotification(); clearForumPostNotification();
} else if (!settings.getBoolean("notifyGroupPosts", true)) { } else if (settings.getBoolean("notifyForumPosts", true)) {
return;
} else {
NotificationCompat.Builder b = NotificationCompat.Builder b =
new NotificationCompat.Builder(appContext); new NotificationCompat.Builder(appContext);
b.setSmallIcon(R.drawable.message_notification_icon); b.setSmallIcon(R.drawable.message_notification_icon);
b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentTitle(appContext.getText(R.string.app_name));
b.setContentText(appContext.getResources().getQuantityString( b.setContentText(appContext.getResources().getQuantityString(
R.plurals.forum_post_notification_text, groupTotal, R.plurals.forum_post_notification_text, forumTotal,
groupTotal)); forumTotal));
String ringtoneUri = settings.get("notifyRingtoneUri"); String ringtoneUri = settings.get("notifyRingtoneUri");
if (!StringUtils.isNullOrEmpty(ringtoneUri)) if (!StringUtils.isNullOrEmpty(ringtoneUri))
b.setSound(Uri.parse(ringtoneUri)); b.setSound(Uri.parse(ringtoneUri));
b.setDefaults(getDefaults()); b.setDefaults(getDefaults());
b.setOnlyAlertOnce(true); b.setOnlyAlertOnce(true);
b.setAutoCancel(true); b.setAutoCancel(true);
if (groupCounts.size() == 1) { if (forumCounts.size() == 1) {
Intent i = new Intent(appContext, GroupActivity.class); Intent i = new Intent(appContext, ForumActivity.class);
GroupId g = groupCounts.keySet().iterator().next(); GroupId g = forumCounts.keySet().iterator().next();
i.putExtra("briar.GROUP_ID", g.getBytes()); i.putExtra("briar.GROUP_ID", g.getBytes());
String idHex = StringUtils.toHexString(g.getBytes()); String idHex = StringUtils.toHexString(g.getBytes());
i.setData(Uri.parse(GROUP_URI + "/" + idHex)); i.setData(Uri.parse(FORUM_URI + "/" + idHex));
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP); i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder t = TaskStackBuilder.create(appContext); TaskStackBuilder t = TaskStackBuilder.create(appContext);
t.addParentStack(GroupActivity.class); t.addParentStack(ForumActivity.class);
t.addNextIntent(i); t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
} else { } else {
Intent i = new Intent(appContext, GroupListActivity.class); Intent i = new Intent(appContext, ForumListActivity.class);
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP); i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder t = TaskStackBuilder.create(appContext); TaskStackBuilder t = TaskStackBuilder.create(appContext);
t.addParentStack(GroupListActivity.class); t.addParentStack(ForumListActivity.class);
t.addNextIntent(i); t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
nm.notify(GROUP_POST_NOTIFICATION_ID, b.build()); nm.notify(FORUM_POST_NOTIFICATION_ID, b.build());
} }
} }
// Locking: lock // Locking: lock
private void clearGroupPostNotification() { private void clearForumPostNotification() {
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
nm.cancel(GROUP_POST_NOTIFICATION_ID); nm.cancel(FORUM_POST_NOTIFICATION_ID);
} }
public void clearNotifications() { public void clearNotifications() {
lock.lock(); lock.lock();
try { try {
contactCounts.clear(); contactCounts.clear();
groupCounts.clear(); forumCounts.clear();
privateTotal = groupTotal = 0; contactTotal = forumTotal = 0;
clearPrivateMessageNotification(); clearPrivateMessageNotification();
clearGroupPostNotification(); clearForumPostNotification();
} finally { } finally {
lock.unlock(); lock.unlock();
} }

View File

@@ -1,18 +1,13 @@
package org.briarproject.android; package org.briarproject.android;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import android.app.NotificationManager;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import android.app.PendingIntent;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; import android.content.ComponentName;
import static java.util.logging.Level.WARNING; import android.content.Intent;
import static org.briarproject.api.lifecycle.LifecycleManager.StartResult.ALREADY_RUNNING; import android.content.ServiceConnection;
import static org.briarproject.api.lifecycle.LifecycleManager.StartResult.SUCCESS; import android.os.Binder;
import android.os.IBinder;
import java.util.concurrent.CountDownLatch; import android.support.v4.app.NotificationCompat;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
@@ -30,15 +25,21 @@ import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.lifecycle.LifecycleManager.StartResult; import org.briarproject.api.lifecycle.LifecycleManager.StartResult;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.GroupId;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.inject.Inject;
import roboguice.service.RoboService; import roboguice.service.RoboService;
import android.app.NotificationManager;
import android.app.PendingIntent; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import android.content.ComponentName; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import android.content.Intent; import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import android.content.ServiceConnection; import static java.util.logging.Level.WARNING;
import android.os.Binder; import static org.briarproject.api.lifecycle.LifecycleManager.StartResult.ALREADY_RUNNING;
import android.os.IBinder; import static org.briarproject.api.lifecycle.LifecycleManager.StartResult.SUCCESS;
import android.support.v4.app.NotificationCompat;
public class BriarService extends RoboService implements EventListener { public class BriarService extends RoboService implements EventListener {
@@ -182,7 +183,7 @@ public class BriarService extends RoboService implements EventListener {
lifecycleManager.waitForDatabase(); lifecycleManager.waitForDatabase();
if (g.equals(db.getInboxGroupId(c))) if (g.equals(db.getInboxGroupId(c)))
notificationManager.showPrivateMessageNotification(c); notificationManager.showPrivateMessageNotification(c);
else notificationManager.showGroupPostNotification(g); else notificationManager.showForumPostNotification(g);
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);

View File

@@ -1,26 +1,5 @@
package org.briarproject.android; package org.briarproject.android;
import static android.view.Gravity.CENTER;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R;
import org.briarproject.android.contact.ContactListActivity;
import org.briarproject.android.groups.GroupListActivity;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.LocalAuthor;
import org.briarproject.api.android.ReferenceManager;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
@@ -34,6 +13,27 @@ import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import org.briarproject.R;
import org.briarproject.android.contact.ContactListActivity;
import org.briarproject.android.forum.ForumListActivity;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.LocalAuthor;
import org.briarproject.api.android.ReferenceManager;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
import static android.view.Gravity.CENTER;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
public class DashboardActivity extends BriarActivity { public class DashboardActivity extends BriarActivity {
private static final Logger LOG = private static final Logger LOG =
@@ -109,7 +109,7 @@ public class DashboardActivity extends BriarActivity {
forumsButton.setOnClickListener(new OnClickListener() { forumsButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) { public void onClick(View view) {
startActivity(new Intent(DashboardActivity.this, startActivity(new Intent(DashboardActivity.this,
GroupListActivity.class)); ForumListActivity.class));
} }
}); });
buttons.add(forumsButton); buttons.add(forumsButton);

View File

@@ -1,5 +1,40 @@
package org.briarproject.android; package org.briarproject.android;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.content.res.Resources;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.util.FixedVerticalSpace;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.Settings;
import org.briarproject.api.TransportConfig;
import org.briarproject.api.TransportId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.SettingsUpdatedEvent;
import org.briarproject.util.StringUtils;
import java.util.logging.Logger;
import javax.inject.Inject;
import static android.graphics.Typeface.DEFAULT_BOLD; import static android.graphics.Typeface.DEFAULT_BOLD;
import static android.media.RingtoneManager.ACTION_RINGTONE_PICKER; import static android.media.RingtoneManager.ACTION_RINGTONE_PICKER;
import static android.media.RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI; import static android.media.RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI;
@@ -20,41 +55,6 @@ import static org.briarproject.android.TestingConstants.SHOW_TESTING_ACTIVITY;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R;
import org.briarproject.android.util.FixedVerticalSpace;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.Settings;
import org.briarproject.api.TransportConfig;
import org.briarproject.api.TransportId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.SettingsUpdatedEvent;
import org.briarproject.util.StringUtils;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.content.res.Resources;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class SettingsActivity extends BriarActivity implements EventListener, public class SettingsActivity extends BriarActivity implements EventListener,
OnClickListener { OnClickListener {
@@ -65,7 +65,7 @@ OnClickListener {
private ScrollView scroll = null; private ScrollView scroll = null;
private TextView enableBluetooth = null, enableBluetoothHint = null; private TextView enableBluetooth = null, enableBluetoothHint = null;
private CheckBox notifyPrivateMessages = null, notifyGroupPosts = null; private CheckBox notifyPrivateMessages = null, notifyForumPosts = null;
private CheckBox notifyVibration = null; private CheckBox notifyVibration = null;
private TextView notifySound = null, notifySoundHint = null; private TextView notifySound = null, notifySoundHint = null;
private ListLoadingProgressBar progress = null; private ListLoadingProgressBar progress = null;
@@ -140,11 +140,11 @@ OnClickListener {
settings.addView(new HorizontalBorder(this)); settings.addView(new HorizontalBorder(this));
settings.addView(new FixedVerticalSpace(this)); settings.addView(new FixedVerticalSpace(this));
notifyGroupPosts = new CheckBox(this); notifyForumPosts = new CheckBox(this);
notifyGroupPosts.setTextSize(18); notifyForumPosts.setTextSize(18);
notifyGroupPosts.setText(R.string.notify_group_posts_setting); notifyForumPosts.setText(R.string.notify_forum_posts_setting);
notifyGroupPosts.setOnClickListener(this); notifyForumPosts.setOnClickListener(this);
settings.addView(notifyGroupPosts); settings.addView(notifyForumPosts);
settings.addView(new FixedVerticalSpace(this)); settings.addView(new FixedVerticalSpace(this));
settings.addView(new HorizontalBorder(this)); settings.addView(new HorizontalBorder(this));
@@ -241,8 +241,8 @@ OnClickListener {
notifyPrivateMessages.setChecked(settings.getBoolean( notifyPrivateMessages.setChecked(settings.getBoolean(
"notifyPrivateMessages", true)); "notifyPrivateMessages", true));
notifyGroupPosts.setChecked(settings.getBoolean( notifyForumPosts.setChecked(settings.getBoolean(
"notifyGroupPosts", true)); "notifyForumPosts", true));
notifyVibration.setChecked(settings.getBoolean( notifyVibration.setChecked(settings.getBoolean(
"notifyVibration", true)); "notifyVibration", true));
@@ -285,9 +285,9 @@ OnClickListener {
s.putBoolean("notifyPrivateMessages", s.putBoolean("notifyPrivateMessages",
notifyPrivateMessages.isChecked()); notifyPrivateMessages.isChecked());
storeSettings(s); storeSettings(s);
} else if (view == notifyGroupPosts) { } else if (view == notifyForumPosts) {
Settings s = new Settings(); Settings s = new Settings();
s.putBoolean("notifyGroupPosts", notifyGroupPosts.isChecked()); s.putBoolean("notifyForumPosts", notifyForumPosts.isChecked());
storeSettings(s); storeSettings(s);
} else if (view == notifyVibration) { } else if (view == notifyVibration) {
Settings s = new Settings(); Settings s = new Settings();

View File

@@ -1,15 +1,11 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.widget.Toast.LENGTH_SHORT; import android.os.Bundle;
import static java.util.logging.Level.INFO; import android.view.View;
import static java.util.logging.Level.WARNING; import android.widget.AdapterView;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import java.util.ArrayList; import android.widget.Toast;
import java.util.Collection;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
@@ -28,20 +24,24 @@ import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.messaging.Group; import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.GroupId;
import android.os.Bundle; import java.util.ArrayList;
import android.view.View; import java.util.Collection;
import android.widget.AdapterView; import java.util.logging.Logger;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;
public class AvailableGroupsActivity extends BriarActivity import javax.inject.Inject;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
public class AvailableForumsActivity extends BriarActivity
implements EventListener, OnItemClickListener { implements EventListener, OnItemClickListener {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(AvailableGroupsActivity.class.getName()); Logger.getLogger(AvailableForumsActivity.class.getName());
private AvailableGroupsAdapter adapter = null; private AvailableForumsAdapter adapter = null;
private ListView list = null; private ListView list = null;
private ListLoadingProgressBar loading = null; private ListLoadingProgressBar loading = null;
@@ -53,7 +53,7 @@ implements EventListener, OnItemClickListener {
public void onCreate(Bundle state) { public void onCreate(Bundle state) {
super.onCreate(state); super.onCreate(state);
adapter = new AvailableGroupsAdapter(this); adapter = new AvailableForumsAdapter(this);
list = new ListView(this); list = new ListView(this);
list.setLayoutParams(MATCH_MATCH); list.setLayoutParams(MATCH_MATCH);
list.setAdapter(adapter); list.setAdapter(adapter);
@@ -68,29 +68,29 @@ implements EventListener, OnItemClickListener {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
eventBus.addListener(this); eventBus.addListener(this);
loadGroups(); loadForums();
} }
private void loadGroups() { private void loadForums() {
runOnDbThread(new Runnable() { runOnDbThread(new Runnable() {
public void run() { public void run() {
try { try {
Collection<GroupContacts> available = Collection<ForumContacts> available =
new ArrayList<GroupContacts>(); new ArrayList<ForumContacts>();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
for (Group g : db.getAvailableGroups()) { for (Group g : db.getAvailableGroups()) {
try { try {
GroupId id = g.getId(); GroupId id = g.getId();
Collection<Contact> c = db.getSubscribers(id); Collection<Contact> c = db.getSubscribers(id);
available.add(new GroupContacts(g, c)); available.add(new ForumContacts(g, c));
} catch (NoSuchSubscriptionException e) { } catch (NoSuchSubscriptionException e) {
continue; // Continue
} }
} }
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms"); LOG.info("Load took " + duration + " ms");
displayGroups(available); displayForums(available);
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);
@@ -99,18 +99,18 @@ implements EventListener, OnItemClickListener {
}); });
} }
private void displayGroups(final Collection<GroupContacts> available) { private void displayForums(final Collection<ForumContacts> available) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
if (available.isEmpty()) { if (available.isEmpty()) {
LOG.info("No groups available, finishing"); LOG.info("No forums available, finishing");
finish(); finish();
} else { } else {
setContentView(list); setContentView(list);
adapter.clear(); adapter.clear();
for (GroupContacts g : available) for (ForumContacts f : available)
adapter.add(new AvailableGroupsItem(g)); adapter.add(new AvailableForumsItem(f));
adapter.sort(AvailableGroupsItemComparator.INSTANCE); adapter.sort(AvailableForumsItemComparator.INSTANCE);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
} }
@@ -126,19 +126,19 @@ implements EventListener, OnItemClickListener {
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof RemoteSubscriptionsUpdatedEvent) { if (e instanceof RemoteSubscriptionsUpdatedEvent) {
LOG.info("Remote subscriptions changed, reloading"); LOG.info("Remote subscriptions changed, reloading");
loadGroups(); loadForums();
} else if (e instanceof SubscriptionAddedEvent) { } else if (e instanceof SubscriptionAddedEvent) {
LOG.info("Subscription added, reloading"); LOG.info("Subscription added, reloading");
loadGroups(); loadForums();
} else if (e instanceof SubscriptionRemovedEvent) { } else if (e instanceof SubscriptionRemovedEvent) {
LOG.info("Subscription removed, reloading"); LOG.info("Subscription removed, reloading");
loadGroups(); loadForums();
} }
} }
public void onItemClick(AdapterView<?> parent, View view, int position, public void onItemClick(AdapterView<?> parent, View view, int position,
long id) { long id) {
AvailableGroupsItem item = adapter.getItem(position); AvailableForumsItem item = adapter.getItem(position);
Collection<ContactId> visible = new ArrayList<ContactId>(); Collection<ContactId> visible = new ArrayList<ContactId>();
for (Contact c : item.getContacts()) visible.add(c.getId()); for (Contact c : item.getContacts()) visible.add(c.getId());
addSubscription(item.getGroup(), visible); addSubscription(item.getGroup(), visible);

View File

@@ -1,15 +1,4 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.text.TextUtils.TruncateAt.END;
import static android.widget.LinearLayout.VERTICAL;
import java.util.ArrayList;
import java.util.Collection;
import org.briarproject.R;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.Contact;
import org.briarproject.util.StringUtils;
import android.content.Context; import android.content.Context;
import android.view.View; import android.view.View;
@@ -18,19 +7,30 @@ import android.widget.ArrayAdapter;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
class AvailableGroupsAdapter extends ArrayAdapter<AvailableGroupsItem> { import org.briarproject.R;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.Contact;
import org.briarproject.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import static android.text.TextUtils.TruncateAt.END;
import static android.widget.LinearLayout.VERTICAL;
class AvailableForumsAdapter extends ArrayAdapter<AvailableForumsItem> {
private final int pad; private final int pad;
AvailableGroupsAdapter(Context ctx) { AvailableForumsAdapter(Context ctx) {
super(ctx, android.R.layout.simple_expandable_list_item_1, super(ctx, android.R.layout.simple_expandable_list_item_1,
new ArrayList<AvailableGroupsItem>()); new ArrayList<AvailableForumsItem>());
pad = LayoutUtils.getPadding(ctx); pad = LayoutUtils.getPadding(ctx);
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
AvailableGroupsItem item = getItem(position); AvailableForumsItem item = getItem(position);
Context ctx = getContext(); Context ctx = getContext();
LinearLayout layout = new LinearLayout(ctx); LinearLayout layout = new LinearLayout(ctx);

View File

@@ -0,0 +1,23 @@
package org.briarproject.android.forum;
import org.briarproject.api.Contact;
import org.briarproject.api.messaging.Group;
import java.util.Collection;
class AvailableForumsItem {
private final ForumContacts forumContacts;
AvailableForumsItem(ForumContacts forumContacts) {
this.forumContacts = forumContacts;
}
Group getGroup() {
return forumContacts.getGroup();
}
Collection<Contact> getContacts() {
return forumContacts.getContacts();
}
}

View File

@@ -0,0 +1,16 @@
package org.briarproject.android.forum;
import java.util.Comparator;
class AvailableForumsItemComparator implements Comparator<AvailableForumsItem> {
static final AvailableForumsItemComparator INSTANCE =
new AvailableForumsItemComparator();
public int compare(AvailableForumsItem a, AvailableForumsItem b) {
if (a == b) return 0;
String aName = a.getGroup().getName();
String bName = b.getGroup().getName();
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
}
}

View File

@@ -1,4 +1,30 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.util.StringUtils;
import java.util.logging.Logger;
import javax.inject.Inject;
import static android.text.InputType.TYPE_CLASS_TEXT; import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
@@ -14,37 +40,11 @@ import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP; import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH; import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
import java.util.logging.Logger; public class CreateForumActivity extends BriarActivity
import javax.inject.Inject;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.util.StringUtils;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
public class CreateGroupActivity extends BriarActivity
implements OnEditorActionListener, OnClickListener { implements OnEditorActionListener, OnClickListener {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(CreateGroupActivity.class.getName()); Logger.getLogger(CreateForumActivity.class.getName());
private EditText nameEntry = null; private EditText nameEntry = null;
private Button createForumButton = null; private Button createForumButton = null;
@@ -130,11 +130,11 @@ implements OnEditorActionListener, OnClickListener {
if (!validateName()) return; if (!validateName()) return;
createForumButton.setVisibility(GONE); createForumButton.setVisibility(GONE);
progress.setVisibility(VISIBLE); progress.setVisibility(VISIBLE);
storeGroup(nameEntry.getText().toString()); storeForum(nameEntry.getText().toString());
} }
} }
private void storeGroup(final String name) { private void storeForum(final String name) {
runOnDbThread(new Runnable() { runOnDbThread(new Runnable() {
public void run() { public void run() {
try { try {
@@ -143,8 +143,8 @@ implements OnEditorActionListener, OnClickListener {
db.addGroup(g); db.addGroup(g);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Storing group took " + duration + " ms"); LOG.info("Storing forum took " + duration + " ms");
displayGroup(g); displayForum(g);
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);
@@ -154,15 +154,15 @@ implements OnEditorActionListener, OnClickListener {
}); });
} }
private void displayGroup(final Group g) { private void displayForum(final Group g) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
Intent i = new Intent(CreateGroupActivity.this, Intent i = new Intent(CreateForumActivity.this,
GroupActivity.class); ForumActivity.class);
i.putExtra("briar.GROUP_ID", g.getId().getBytes()); i.putExtra("briar.GROUP_ID", g.getId().getBytes());
i.putExtra("briar.GROUP_NAME", g.getName()); i.putExtra("briar.FORUM_NAME", g.getName());
startActivity(i); startActivity(i);
Toast.makeText(CreateGroupActivity.this, Toast.makeText(CreateForumActivity.this,
R.string.forum_created_toast, LENGTH_LONG).show(); R.string.forum_created_toast, LENGTH_LONG).show();
finish(); finish();
} }

View File

@@ -1,26 +1,16 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.view.Gravity.CENTER; import android.content.Intent;
import static android.view.Gravity.CENTER_HORIZONTAL; import android.content.res.Resources;
import static android.view.View.GONE; import android.os.Bundle;
import static android.view.View.VISIBLE; import android.view.View;
import static android.widget.LinearLayout.VERTICAL; import android.view.View.OnClickListener;
import static java.util.logging.Level.INFO; import android.widget.AdapterView;
import static java.util.logging.Level.WARNING; import android.widget.AdapterView.OnItemClickListener;
import static org.briarproject.android.groups.ReadGroupPostActivity.RESULT_PREV_NEXT; import android.widget.ImageButton;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; import android.widget.LinearLayout;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import android.widget.ListView;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1; import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
@@ -44,29 +34,39 @@ import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.messaging.MessageId;
import android.content.Intent; import java.util.ArrayList;
import android.content.res.Resources; import java.util.Collection;
import android.os.Bundle; import java.util.Collections;
import android.view.View; import java.util.HashMap;
import android.view.View.OnClickListener; import java.util.List;
import android.widget.AdapterView; import java.util.Map;
import android.widget.AdapterView.OnItemClickListener; import java.util.logging.Logger;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class GroupActivity extends BriarActivity implements EventListener, import javax.inject.Inject;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.forum.ReadForumPostActivity.RESULT_PREV_NEXT;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
public class ForumActivity extends BriarActivity implements EventListener,
OnClickListener, OnItemClickListener { OnClickListener, OnItemClickListener {
private static final int REQUEST_READ = 2; private static final int REQUEST_READ = 2;
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(GroupActivity.class.getName()); Logger.getLogger(ForumActivity.class.getName());
@Inject private AndroidNotificationManager notificationManager; @Inject private AndroidNotificationManager notificationManager;
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>(); private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
private TextView empty = null; private TextView empty = null;
private GroupAdapter adapter = null; private ForumAdapter adapter = null;
private ListView list = null; private ListView list = null;
private ListLoadingProgressBar loading = null; private ListLoadingProgressBar loading = null;
private ImageButton composeButton = null, shareButton = null; private ImageButton composeButton = null, shareButton = null;
@@ -85,8 +85,8 @@ OnClickListener, OnItemClickListener {
byte[] b = i.getByteArrayExtra("briar.GROUP_ID"); byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
if (b == null) throw new IllegalStateException(); if (b == null) throw new IllegalStateException();
groupId = new GroupId(b); groupId = new GroupId(b);
String name = i.getStringExtra("briar.GROUP_NAME"); String forumName = i.getStringExtra("briar.FORUM_NAME");
if (name != null) setTitle(name); if (forumName != null) setTitle(forumName);
LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(MATCH_MATCH); layout.setLayoutParams(MATCH_MATCH);
@@ -101,7 +101,7 @@ OnClickListener, OnItemClickListener {
empty.setVisibility(GONE); empty.setVisibility(GONE);
layout.addView(empty); layout.addView(empty);
adapter = new GroupAdapter(this); adapter = new ForumAdapter(this);
list = new ListView(this); list = new ListView(this);
list.setLayoutParams(MATCH_WRAP_1); list.setLayoutParams(MATCH_WRAP_1);
list.setAdapter(adapter); list.setAdapter(adapter);
@@ -144,11 +144,11 @@ OnClickListener, OnItemClickListener {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
eventBus.addListener(this); eventBus.addListener(this);
loadGroup(); loadForum();
loadHeaders(); loadHeaders();
} }
private void loadGroup() { private void loadForum() {
runOnDbThread(new Runnable() { runOnDbThread(new Runnable() {
public void run() { public void run() {
try { try {
@@ -157,7 +157,7 @@ OnClickListener, OnItemClickListener {
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Loading group " + duration + " ms"); LOG.info("Loading group " + duration + " ms");
displayGroupName(); displayForumName();
} catch (NoSuchSubscriptionException e) { } catch (NoSuchSubscriptionException e) {
finishOnUiThread(); finishOnUiThread();
} catch (DbException e) { } catch (DbException e) {
@@ -168,7 +168,7 @@ OnClickListener, OnItemClickListener {
}); });
} }
private void displayGroupName() { private void displayForumName() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
setTitle(group.getName()); setTitle(group.getName());
@@ -209,13 +209,13 @@ OnClickListener, OnItemClickListener {
empty.setVisibility(GONE); empty.setVisibility(GONE);
list.setVisibility(VISIBLE); list.setVisibility(VISIBLE);
for (MessageHeader h : headers) { for (MessageHeader h : headers) {
GroupItem item = new GroupItem(h); ForumItem item = new ForumItem(h);
byte[] body = bodyCache.get(h.getId()); byte[] body = bodyCache.get(h.getId());
if (body == null) loadMessageBody(h); if (body == null) loadMessageBody(h);
else item.setBody(body); else item.setBody(body);
adapter.add(item); adapter.add(item);
} }
adapter.sort(GroupItemComparator.INSTANCE); adapter.sort(ForumItemComparator.INSTANCE);
// Scroll to the bottom // Scroll to the bottom
list.setSelection(adapter.getCount() - 1); list.setSelection(adapter.getCount() - 1);
} }
@@ -250,7 +250,7 @@ OnClickListener, OnItemClickListener {
bodyCache.put(m, body); bodyCache.put(m, body);
int count = adapter.getCount(); int count = adapter.getCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
GroupItem item = adapter.getItem(i); ForumItem item = adapter.getItem(i);
if (item.getHeader().getId().equals(m)) { if (item.getHeader().getId().equals(m)) {
item.setBody(body); item.setBody(body);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
@@ -281,7 +281,7 @@ OnClickListener, OnItemClickListener {
} }
private void markMessagesRead() { private void markMessagesRead() {
notificationManager.clearGroupPostNotification(groupId); notificationManager.clearForumPostNotification(groupId);
List<MessageId> unread = new ArrayList<MessageId>(); List<MessageId> unread = new ArrayList<MessageId>();
int count = adapter.getCount(); int count = adapter.getCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@@ -331,15 +331,15 @@ OnClickListener, OnItemClickListener {
public void onClick(View view) { public void onClick(View view) {
if (view == composeButton) { if (view == composeButton) {
Intent i = new Intent(this, WriteGroupPostActivity.class); Intent i = new Intent(this, WriteForumPostActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes()); i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.GROUP_NAME", group.getName()); i.putExtra("briar.FORUM_NAME", group.getName());
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewMessage()); i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewMessage());
startActivity(i); startActivity(i);
} else if (view == shareButton) { } else if (view == shareButton) {
Intent i = new Intent(this, ShareGroupActivity.class); Intent i = new Intent(this, ShareForumActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes()); i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.GROUP_NAME", group.getName()); i.putExtra("briar.FORUM_NAME", group.getName());
startActivity(i); startActivity(i);
} }
} }
@@ -362,9 +362,9 @@ OnClickListener, OnItemClickListener {
private void displayMessage(int position) { private void displayMessage(int position) {
MessageHeader item = adapter.getItem(position).getHeader(); MessageHeader item = adapter.getItem(position).getHeader();
Intent i = new Intent(this, ReadGroupPostActivity.class); Intent i = new Intent(this, ReadForumPostActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes()); i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.GROUP_NAME", group.getName()); i.putExtra("briar.FORUM_NAME", group.getName());
i.putExtra("briar.MESSAGE_ID", item.getId().getBytes()); i.putExtra("briar.MESSAGE_ID", item.getId().getBytes());
Author author = item.getAuthor(); Author author = item.getAuthor();
if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName()); if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());

View File

@@ -1,19 +1,4 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
import java.util.ArrayList;
import org.briarproject.R;
import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.Author;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.util.StringUtils;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
@@ -25,19 +10,34 @@ import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
class GroupAdapter extends ArrayAdapter<GroupItem> { import org.briarproject.R;
import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.Author;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.util.StringUtils;
import java.util.ArrayList;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
class ForumAdapter extends ArrayAdapter<ForumItem> {
private final int pad; private final int pad;
GroupAdapter(Context ctx) { ForumAdapter(Context ctx) {
super(ctx, android.R.layout.simple_expandable_list_item_1, super(ctx, android.R.layout.simple_expandable_list_item_1,
new ArrayList<GroupItem>()); new ArrayList<ForumItem>());
pad = LayoutUtils.getPadding(ctx); pad = LayoutUtils.getPadding(ctx);
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
GroupItem item = getItem(position); ForumItem item = getItem(position);
MessageHeader header = item.getHeader(); MessageHeader header = item.getHeader();
Context ctx = getContext(); Context ctx = getContext();
Resources res = ctx.getResources(); Resources res = ctx.getResources();

View File

@@ -1,16 +1,16 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import java.util.Collection;
import org.briarproject.api.Contact; import org.briarproject.api.Contact;
import org.briarproject.api.messaging.Group; import org.briarproject.api.messaging.Group;
class GroupContacts { import java.util.Collection;
class ForumContacts {
private final Group group; private final Group group;
private final Collection<Contact> contacts; private final Collection<Contact> contacts;
GroupContacts(Group group, Collection<Contact> contacts) { ForumContacts(Group group, Collection<Contact> contacts) {
this.group = group; this.group = group;
this.contacts = contacts; this.contacts = contacts;
} }

View File

@@ -1,14 +1,14 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.db.MessageHeader;
// This class is not thread-safe // This class is not thread-safe
class GroupItem { class ForumItem {
private final MessageHeader header; private final MessageHeader header;
private byte[] body; private byte[] body;
GroupItem(MessageHeader header) { ForumItem(MessageHeader header) {
this.header = header; this.header = header;
body = null; body = null;
} }

View File

@@ -1,12 +1,12 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import java.util.Comparator; import java.util.Comparator;
class GroupItemComparator implements Comparator<GroupItem> { class ForumItemComparator implements Comparator<ForumItem> {
static final GroupItemComparator INSTANCE = new GroupItemComparator(); static final ForumItemComparator INSTANCE = new ForumItemComparator();
public int compare(GroupItem a, GroupItem b) { public int compare(ForumItem a, ForumItem b) {
// The oldest message comes first // The oldest message comes first
long aTime = a.getHeader().getTimestamp(); long aTime = a.getHeader().getTimestamp();
long bTime = b.getHeader().getTimestamp(); long bTime = b.getHeader().getTimestamp();

View File

@@ -1,25 +1,22 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.view.Gravity.CENTER; import android.content.Intent;
import static android.view.Gravity.CENTER_HORIZONTAL; import android.content.res.Resources;
import static android.view.Menu.NONE; import android.os.Bundle;
import static android.view.View.GONE; import android.view.ContextMenu;
import static android.view.View.VISIBLE; import android.view.ContextMenu.ContextMenuInfo;
import static android.widget.LinearLayout.HORIZONTAL; import android.view.MenuItem;
import static android.widget.LinearLayout.VERTICAL; import android.view.View;
import static android.widget.Toast.LENGTH_SHORT; import android.view.View.OnClickListener;
import static java.util.logging.Level.INFO; import android.view.View.OnCreateContextMenuListener;
import static java.util.logging.Level.WARNING; import android.widget.AdapterView;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; import android.widget.AdapterView.AdapterContextMenuInfo;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import android.widget.AdapterView.OnItemClickListener;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1; import android.widget.ImageButton;
import android.widget.LinearLayout;
import java.util.Collection; import android.widget.ListView;
import java.util.Map; import android.widget.TextView;
import java.util.concurrent.ConcurrentHashMap; import android.widget.Toast;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
@@ -41,41 +38,44 @@ import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.messaging.Group; import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.GroupId;
import android.content.Intent; import java.util.Collection;
import android.content.res.Resources; import java.util.Map;
import android.os.Bundle; import java.util.concurrent.ConcurrentHashMap;
import android.view.ContextMenu; import java.util.logging.Logger;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class GroupListActivity extends BriarActivity import javax.inject.Inject;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Menu.NONE;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
public class ForumListActivity extends BriarActivity
implements EventListener, OnClickListener, OnItemClickListener, implements EventListener, OnClickListener, OnItemClickListener,
OnCreateContextMenuListener { OnCreateContextMenuListener {
private static final int MENU_ITEM_UNSUBSCRIBE = 1; private static final int MENU_ITEM_UNSUBSCRIBE = 1;
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(GroupListActivity.class.getName()); Logger.getLogger(ForumListActivity.class.getName());
private final Map<GroupId,GroupId> groups = private final Map<GroupId, GroupId> groupIds =
new ConcurrentHashMap<GroupId,GroupId>(); new ConcurrentHashMap<GroupId, GroupId>();
private TextView empty = null; private TextView empty = null;
private GroupListAdapter adapter = null; private ForumListAdapter adapter = null;
private ListView list = null; private ListView list = null;
private ListLoadingProgressBar loading = null; private ListLoadingProgressBar loading = null;
private TextView available = null; private TextView available = null;
private ImageButton newGroupButton = null; private ImageButton newForumButton = null;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db; @Inject private volatile DatabaseComponent db;
@@ -99,7 +99,7 @@ OnCreateContextMenuListener {
empty.setVisibility(GONE); empty.setVisibility(GONE);
layout.addView(empty); layout.addView(empty);
adapter = new GroupListAdapter(this); adapter = new ForumListAdapter(this);
list = new ListView(this); list = new ListView(this);
list.setLayoutParams(MATCH_WRAP_1); list.setLayoutParams(MATCH_WRAP_1);
list.setAdapter(adapter); list.setAdapter(adapter);
@@ -131,11 +131,11 @@ OnCreateContextMenuListener {
footer.setOrientation(HORIZONTAL); footer.setOrientation(HORIZONTAL);
footer.setGravity(CENTER); footer.setGravity(CENTER);
footer.setBackgroundColor(res.getColor(R.color.button_bar_background)); footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
newGroupButton = new ImageButton(this); newForumButton = new ImageButton(this);
newGroupButton.setBackgroundResource(0); newForumButton.setBackgroundResource(0);
newGroupButton.setImageResource(R.drawable.social_new_chat); newForumButton.setImageResource(R.drawable.social_new_chat);
newGroupButton.setOnClickListener(this); newForumButton.setOnClickListener(this);
footer.addView(newGroupButton); footer.addView(newForumButton);
layout.addView(footer); layout.addView(footer);
setContentView(layout); setContentView(layout);
@@ -177,7 +177,7 @@ OnCreateContextMenuListener {
private void clearHeaders() { private void clearHeaders() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
groups.clear(); groupIds.clear();
empty.setVisibility(GONE); empty.setVisibility(GONE);
list.setVisibility(GONE); list.setVisibility(GONE);
available.setVisibility(GONE); available.setVisibility(GONE);
@@ -193,15 +193,15 @@ OnCreateContextMenuListener {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
GroupId id = g.getId(); GroupId id = g.getId();
groups.put(id, id); groupIds.put(id, id);
list.setVisibility(VISIBLE); list.setVisibility(VISIBLE);
loading.setVisibility(GONE); loading.setVisibility(GONE);
// Remove the old item, if any // Remove the old item, if any
GroupListItem item = findGroup(id); ForumListItem item = findForum(id);
if (item != null) adapter.remove(item); if (item != null) adapter.remove(item);
// Add a new item // Add a new item
adapter.add(new GroupListItem(g, headers)); adapter.add(new ForumListItem(g, headers));
adapter.sort(GroupListItemComparator.INSTANCE); adapter.sort(ForumListItemComparator.INSTANCE);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
selectFirstUnread(); selectFirstUnread();
} }
@@ -225,10 +225,10 @@ OnCreateContextMenuListener {
}); });
} }
private GroupListItem findGroup(GroupId g) { private ForumListItem findForum(GroupId g) {
int count = adapter.getCount(); int count = adapter.getCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
GroupListItem item = adapter.getItem(i); ForumListItem item = adapter.getItem(i);
if (item.getGroup().getId().equals(g)) return item; if (item.getGroup().getId().equals(g)) return item;
} }
return null; // Not found return null; // Not found
@@ -255,7 +255,7 @@ OnCreateContextMenuListener {
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof MessageAddedEvent) { if (e instanceof MessageAddedEvent) {
Group g = ((MessageAddedEvent) e).getGroup(); Group g = ((MessageAddedEvent) e).getGroup();
if (groups.containsKey(g.getId())) { if (groupIds.containsKey(g.getId())) {
LOG.info("Message added, reloading"); LOG.info("Message added, reloading");
loadHeaders(g); loadHeaders(g);
} }
@@ -270,7 +270,7 @@ OnCreateContextMenuListener {
loadHeaders(); loadHeaders();
} else if (e instanceof SubscriptionRemovedEvent) { } else if (e instanceof SubscriptionRemovedEvent) {
Group g = ((SubscriptionRemovedEvent) e).getGroup(); Group g = ((SubscriptionRemovedEvent) e).getGroup();
if (groups.containsKey(g.getId())) { if (groupIds.containsKey(g.getId())) {
LOG.info("Group removed, reloading"); LOG.info("Group removed, reloading");
loadHeaders(); loadHeaders();
} }
@@ -289,7 +289,7 @@ OnCreateContextMenuListener {
LOG.info("Partial load took " + duration + " ms"); LOG.info("Partial load took " + duration + " ms");
displayHeaders(g, headers); displayHeaders(g, headers);
} catch (NoSuchSubscriptionException e) { } catch (NoSuchSubscriptionException e) {
removeGroup(g.getId()); removeForum(g.getId());
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);
@@ -298,12 +298,12 @@ OnCreateContextMenuListener {
}); });
} }
private void removeGroup(final GroupId g) { private void removeForum(final GroupId g) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
GroupListItem item = findGroup(g); ForumListItem item = findForum(g);
if (item != null) { if (item != null) {
groups.remove(g); groupIds.remove(g);
adapter.remove(item); adapter.remove(item);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
if (adapter.isEmpty()) { if (adapter.isEmpty()) {
@@ -337,18 +337,18 @@ OnCreateContextMenuListener {
public void onClick(View view) { public void onClick(View view) {
if (view == available) { if (view == available) {
startActivity(new Intent(this, AvailableGroupsActivity.class)); startActivity(new Intent(this, AvailableForumsActivity.class));
} else if (view == newGroupButton) { } else if (view == newForumButton) {
startActivity(new Intent(this, CreateGroupActivity.class)); startActivity(new Intent(this, CreateForumActivity.class));
} }
} }
public void onItemClick(AdapterView<?> parent, View view, int position, public void onItemClick(AdapterView<?> parent, View view, int position,
long id) { long id) {
Intent i = new Intent(this, GroupActivity.class); Intent i = new Intent(this, ForumActivity.class);
Group g = adapter.getItem(position).getGroup(); Group g = adapter.getItem(position).getGroup();
i.putExtra("briar.GROUP_ID", g.getId().getBytes()); i.putExtra("briar.GROUP_ID", g.getId().getBytes());
i.putExtra("briar.GROUP_NAME", g.getName()); i.putExtra("briar.FORUM_NAME", g.getName());
startActivity(i); startActivity(i);
} }
@@ -364,7 +364,7 @@ OnCreateContextMenuListener {
if (menuItem.getItemId() == MENU_ITEM_UNSUBSCRIBE) { if (menuItem.getItemId() == MENU_ITEM_UNSUBSCRIBE) {
ContextMenuInfo info = menuItem.getMenuInfo(); ContextMenuInfo info = menuItem.getMenuInfo();
int position = ((AdapterContextMenuInfo) info).position; int position = ((AdapterContextMenuInfo) info).position;
GroupListItem item = adapter.getItem(position); ForumListItem item = adapter.getItem(position);
removeSubscription(item.getGroup()); removeSubscription(item.getGroup());
String unsubscribed = getString(R.string.unsubscribed_toast); String unsubscribed = getString(R.string.unsubscribed_toast);
Toast.makeText(this, unsubscribed, LENGTH_SHORT).show(); Toast.makeText(this, unsubscribed, LENGTH_SHORT).show();

View File

@@ -1,13 +1,4 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.text.TextUtils.TruncateAt.END;
import static android.widget.LinearLayout.HORIZONTAL;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
import java.util.ArrayList;
import org.briarproject.R;
import org.briarproject.android.util.LayoutUtils;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
@@ -18,19 +9,28 @@ import android.widget.ArrayAdapter;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
class GroupListAdapter extends ArrayAdapter<GroupListItem> { import org.briarproject.R;
import org.briarproject.android.util.LayoutUtils;
import java.util.ArrayList;
import static android.text.TextUtils.TruncateAt.END;
import static android.widget.LinearLayout.HORIZONTAL;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
class ForumListAdapter extends ArrayAdapter<ForumListItem> {
private final int pad; private final int pad;
GroupListAdapter(Context ctx) { ForumListAdapter(Context ctx) {
super(ctx, android.R.layout.simple_expandable_list_item_1, super(ctx, android.R.layout.simple_expandable_list_item_1,
new ArrayList<GroupListItem>()); new ArrayList<ForumListItem>());
pad = LayoutUtils.getPadding(ctx); pad = LayoutUtils.getPadding(ctx);
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
GroupListItem item = getItem(position); ForumListItem item = getItem(position);
Context ctx = getContext(); Context ctx = getContext();
Resources res = ctx.getResources(); Resources res = ctx.getResources();
@@ -46,9 +46,9 @@ class GroupListAdapter extends ArrayAdapter<GroupListItem> {
name.setSingleLine(); name.setSingleLine();
name.setEllipsize(END); name.setEllipsize(END);
name.setPadding(pad, pad, pad, pad); name.setPadding(pad, pad, pad, pad);
String groupName = item.getGroup().getName(); String forumName = item.getGroup().getName();
if (unread > 0) name.setText(groupName + " (" + unread + ")"); if (unread > 0) name.setText(forumName + " (" + unread + ")");
else name.setText(groupName); else name.setText(forumName);
layout.addView(name); layout.addView(name);
if (item.isEmpty()) { if (item.isEmpty()) {

View File

@@ -1,30 +1,26 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import java.util.Collection;
import org.briarproject.api.Author;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.messaging.Group; import org.briarproject.api.messaging.Group;
class GroupListItem { import java.util.Collection;
class ForumListItem {
private final Group group; private final Group group;
private final boolean empty; private final boolean empty;
private final String authorName, contentType;
private final long timestamp; private final long timestamp;
private final int unread; private final int unread;
GroupListItem(Group group, Collection<MessageHeader> headers) { ForumListItem(Group group, Collection<MessageHeader> headers) {
this.group = group; this.group = group;
empty = headers.isEmpty(); empty = headers.isEmpty();
if (empty) { if (empty) {
authorName = null;
contentType = null;
timestamp = 0; timestamp = 0;
unread = 0; unread = 0;
} else { } else {
MessageHeader newest = null; MessageHeader newest = null;
long timestamp = 0; long timestamp = -1;
int unread = 0; int unread = 0;
for (MessageHeader h : headers) { for (MessageHeader h : headers) {
if (h.getTimestamp() > timestamp) { if (h.getTimestamp() > timestamp) {
@@ -33,10 +29,6 @@ class GroupListItem {
} }
if (!h.isRead()) unread++; if (!h.isRead()) unread++;
} }
Author a = newest.getAuthor();
if (a == null) authorName = null;
else authorName = a.getName();
contentType = newest.getContentType();
this.timestamp = newest.getTimestamp(); this.timestamp = newest.getTimestamp();
this.unread = unread; this.unread = unread;
} }
@@ -50,14 +42,6 @@ class GroupListItem {
return empty; return empty;
} }
String getAuthorName() {
return authorName;
}
String getContentType() {
return contentType;
}
long getTimestamp() { long getTimestamp() {
return timestamp; return timestamp;
} }

View File

@@ -1,13 +1,13 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import java.util.Comparator; import java.util.Comparator;
class GroupListItemComparator implements Comparator<GroupListItem> { class ForumListItemComparator implements Comparator<ForumListItem> {
static final GroupListItemComparator INSTANCE = static final ForumListItemComparator INSTANCE =
new GroupListItemComparator(); new ForumListItemComparator();
public int compare(GroupListItem a, GroupListItem b) { public int compare(ForumListItem a, ForumListItem b) {
if (a == b) return 0; if (a == b) return 0;
// The item with the newest message comes first // The item with the newest message comes first
long aTime = a.getTimestamp(), bTime = b.getTimestamp(); long aTime = a.getTimestamp(), bTime = b.getTimestamp();

View File

@@ -1,12 +1,12 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import org.briarproject.R;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import org.briarproject.R;
public class NoContactsDialog { public class NoContactsDialog {
private Listener listener = null; private Listener listener = null;

View File

@@ -1,18 +1,15 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.view.Gravity.CENTER; import android.content.Intent;
import static android.view.Gravity.CENTER_VERTICAL; import android.content.res.Resources;
import static android.widget.LinearLayout.HORIZONTAL; import android.os.Bundle;
import static android.widget.LinearLayout.VERTICAL; import android.text.format.DateUtils;
import static java.util.logging.Level.INFO; import android.view.View;
import static java.util.logging.Level.WARNING; import android.view.View.OnClickListener;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import android.widget.ImageButton;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1; import android.widget.LinearLayout;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1; import android.widget.ScrollView;
import android.widget.TextView;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
@@ -28,29 +25,32 @@ import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.messaging.MessageId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import android.content.Intent; import java.util.logging.Logger;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class ReadGroupPostActivity extends BriarActivity import javax.inject.Inject;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
public class ReadForumPostActivity extends BriarActivity
implements OnClickListener { implements OnClickListener {
static final int RESULT_REPLY = RESULT_FIRST_USER; static final int RESULT_REPLY = RESULT_FIRST_USER;
static final int RESULT_PREV_NEXT = RESULT_FIRST_USER + 1; static final int RESULT_PREV_NEXT = RESULT_FIRST_USER + 1;
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(ReadGroupPostActivity.class.getName()); Logger.getLogger(ReadForumPostActivity.class.getName());
private GroupId groupId = null; private GroupId groupId = null;
private String groupName = null; private String forumName = null;
private long timestamp = -1, minTimestamp = -1; private long minTimestamp = -1;
private ImageButton prevButton = null, nextButton = null; private ImageButton prevButton = null, nextButton = null;
private ImageButton replyButton = null; private ImageButton replyButton = null;
private TextView content = null; private TextView content = null;
@@ -68,15 +68,15 @@ implements OnClickListener {
byte[] b = i.getByteArrayExtra("briar.GROUP_ID"); byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
if (b == null) throw new IllegalStateException(); if (b == null) throw new IllegalStateException();
groupId = new GroupId(b); groupId = new GroupId(b);
groupName = i.getStringExtra("briar.GROUP_NAME"); forumName = i.getStringExtra("briar.FORUM_NAME");
if (groupName == null) throw new IllegalStateException(); if (forumName == null) throw new IllegalStateException();
setTitle(groupName); setTitle(forumName);
b = i.getByteArrayExtra("briar.MESSAGE_ID"); b = i.getByteArrayExtra("briar.MESSAGE_ID");
if (b == null) throw new IllegalStateException(); if (b == null) throw new IllegalStateException();
messageId = new MessageId(b); messageId = new MessageId(b);
String contentType = i.getStringExtra("briar.CONTENT_TYPE"); String contentType = i.getStringExtra("briar.CONTENT_TYPE");
if (contentType == null) throw new IllegalStateException(); if (contentType == null) throw new IllegalStateException();
timestamp = i.getLongExtra("briar.TIMESTAMP", -1); long timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
if (timestamp == -1) throw new IllegalStateException(); if (timestamp == -1) throw new IllegalStateException();
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1); minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
if (minTimestamp == -1) throw new IllegalStateException(); if (minTimestamp == -1) throw new IllegalStateException();
@@ -221,9 +221,9 @@ implements OnClickListener {
setResult(RESULT_PREV_NEXT, i); setResult(RESULT_PREV_NEXT, i);
finish(); finish();
} else if (view == replyButton) { } else if (view == replyButton) {
Intent i = new Intent(this, WriteGroupPostActivity.class); Intent i = new Intent(this, WriteForumPostActivity.class);
i.putExtra("briar.GROUP_ID", groupId.getBytes()); i.putExtra("briar.GROUP_ID", groupId.getBytes());
i.putExtra("briar.GROUP_NAME", groupName); i.putExtra("briar.FORUM_NAME", forumName);
i.putExtra("briar.PARENT_ID", messageId.getBytes()); i.putExtra("briar.PARENT_ID", messageId.getBytes());
i.putExtra("briar.MIN_TIMESTAMP", minTimestamp); i.putExtra("briar.MIN_TIMESTAMP", minTimestamp);
startActivity(i); startActivity(i);

View File

@@ -1,19 +1,14 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.view.Gravity.CENTER_HORIZONTAL; import android.content.Intent;
import static android.view.View.GONE; import android.os.Bundle;
import static android.view.View.VISIBLE; import android.view.View;
import static android.widget.LinearLayout.VERTICAL; import android.view.View.OnClickListener;
import static java.util.logging.Level.INFO; import android.widget.Button;
import static java.util.logging.Level.WARNING; import android.widget.LinearLayout;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; import android.widget.ProgressBar;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP; import android.widget.RadioButton;
import android.widget.RadioGroup;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
@@ -26,24 +21,28 @@ import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.GroupId;
import android.content.Intent; import java.util.Collection;
import android.os.Bundle; import java.util.Collections;
import android.view.View; import java.util.logging.Logger;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class ShareGroupActivity extends BriarActivity import javax.inject.Inject;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
public class ShareForumActivity extends BriarActivity
implements OnClickListener, NoContactsDialog.Listener, implements OnClickListener, NoContactsDialog.Listener,
SelectContactsDialog.Listener { SelectContactsDialog.Listener {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(ShareGroupActivity.class.getName()); Logger.getLogger(ShareForumActivity.class.getName());
private String groupName = null;
private RadioGroup radioGroup = null; private RadioGroup radioGroup = null;
private RadioButton shareWithAll = null, shareWithSome = null; private RadioButton shareWithAll = null, shareWithSome = null;
private Button shareButton = null; private Button shareButton = null;
@@ -64,9 +63,9 @@ SelectContactsDialog.Listener {
byte[] b = i.getByteArrayExtra("briar.GROUP_ID"); byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
if (b == null) throw new IllegalStateException(); if (b == null) throw new IllegalStateException();
groupId = new GroupId(b); groupId = new GroupId(b);
groupName = i.getStringExtra("briar.GROUP_NAME"); String forumName = i.getStringExtra("briar.FORUM_NAME");
if (groupName == null) throw new IllegalStateException(); if (forumName == null) throw new IllegalStateException();
setTitle(groupName); setTitle(forumName);
LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(MATCH_MATCH); layout.setLayoutParams(MATCH_MATCH);
@@ -156,14 +155,14 @@ SelectContactsDialog.Listener {
public void run() { public void run() {
if (contacts.isEmpty()) { if (contacts.isEmpty()) {
NoContactsDialog builder = new NoContactsDialog(); NoContactsDialog builder = new NoContactsDialog();
builder.setListener(ShareGroupActivity.this); builder.setListener(ShareForumActivity.this);
builder.build(ShareGroupActivity.this).show(); builder.build(ShareForumActivity.this).show();
} else { } else {
SelectContactsDialog builder = new SelectContactsDialog(); SelectContactsDialog builder = new SelectContactsDialog();
builder.setListener(ShareGroupActivity.this); builder.setListener(ShareForumActivity.this);
builder.setContacts(contacts); builder.setContacts(contacts);
builder.setSelected(selected); builder.setSelected(selected);
builder.build(ShareGroupActivity.this).show(); builder.build(ShareForumActivity.this).show();
} }
} }
}); });

View File

@@ -1,25 +1,19 @@
package org.briarproject.android.groups; package org.briarproject.android.forum;
import static android.text.InputType.TYPE_CLASS_TEXT; import android.content.Intent;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; import android.os.Bundle;
import static android.widget.LinearLayout.VERTICAL; import android.text.InputType;
import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT; import android.view.View;
import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT; import android.view.View.OnClickListener;
import static android.widget.RelativeLayout.CENTER_VERTICAL; import android.widget.AdapterView;
import static android.widget.RelativeLayout.LEFT_OF; import android.widget.AdapterView.OnItemSelectedListener;
import static android.widget.RelativeLayout.RIGHT_OF; import android.widget.EditText;
import static android.widget.Toast.LENGTH_LONG; import android.widget.ImageButton;
import static java.util.logging.Level.INFO; import android.widget.LinearLayout;
import static java.util.logging.Level.WARNING; import android.widget.RelativeLayout;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import android.widget.Spinner;
import android.widget.TextView;
import java.io.IOException; import android.widget.Toast;
import java.security.GeneralSecurityException;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
@@ -44,27 +38,33 @@ import org.briarproject.api.messaging.MessageFactory;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.messaging.MessageId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import android.content.Intent; import java.io.IOException;
import android.os.Bundle; import java.security.GeneralSecurityException;
import android.text.InputType; import java.util.Collection;
import android.view.View; import java.util.concurrent.Executor;
import android.view.View.OnClickListener; import java.util.logging.Logger;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class WriteGroupPostActivity extends BriarActivity import javax.inject.Inject;
import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT;
import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT;
import static android.widget.RelativeLayout.CENTER_VERTICAL;
import static android.widget.RelativeLayout.LEFT_OF;
import static android.widget.RelativeLayout.RIGHT_OF;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
public class WriteForumPostActivity extends BriarActivity
implements OnItemSelectedListener, OnClickListener { implements OnItemSelectedListener, OnClickListener {
private static final int REQUEST_CREATE_IDENTITY = 2; private static final int REQUEST_CREATE_IDENTITY = 2;
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(WriteGroupPostActivity.class.getName()); Logger.getLogger(WriteForumPostActivity.class.getName());
@Inject @CryptoExecutor private Executor cryptoExecutor; @Inject @CryptoExecutor private Executor cryptoExecutor;
private LocalAuthorSpinnerAdapter adapter = null; private LocalAuthorSpinnerAdapter adapter = null;
@@ -91,9 +91,9 @@ implements OnItemSelectedListener, OnClickListener {
byte[] b = i.getByteArrayExtra("briar.GROUP_ID"); byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
if (b == null) throw new IllegalStateException(); if (b == null) throw new IllegalStateException();
groupId = new GroupId(b); groupId = new GroupId(b);
String groupName = i.getStringExtra("briar.GROUP_NAME"); String forumName = i.getStringExtra("briar.FORUM_NAME");
if (groupName == null) throw new IllegalStateException(); if (forumName == null) throw new IllegalStateException();
setTitle(groupName); setTitle(forumName);
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1); minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
if (minTimestamp == -1) throw new IllegalStateException(); if (minTimestamp == -1) throw new IllegalStateException();
b = i.getByteArrayExtra("briar.PARENT_ID"); b = i.getByteArrayExtra("briar.PARENT_ID");

View File

@@ -1,23 +0,0 @@
package org.briarproject.android.groups;
import java.util.Collection;
import org.briarproject.api.Contact;
import org.briarproject.api.messaging.Group;
class AvailableGroupsItem {
private final GroupContacts groupContacts;
AvailableGroupsItem(GroupContacts groupContacts) {
this.groupContacts = groupContacts;
}
Group getGroup() {
return groupContacts.getGroup();
}
Collection<Contact> getContacts() {
return groupContacts.getContacts();
}
}

View File

@@ -1,16 +0,0 @@
package org.briarproject.android.groups;
import java.util.Comparator;
class AvailableGroupsItemComparator implements Comparator<AvailableGroupsItem> {
static final AvailableGroupsItemComparator INSTANCE =
new AvailableGroupsItemComparator();
public int compare(AvailableGroupsItem a, AvailableGroupsItem b) {
if (a == b) return 0;
String aName = a.getGroup().getName();
String bName = b.getGroup().getName();
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
}
}

View File

@@ -10,13 +10,13 @@ import org.briarproject.api.messaging.GroupId;
*/ */
public interface AndroidNotificationManager extends Service { public interface AndroidNotificationManager extends Service {
public void showPrivateMessageNotification(ContactId c); void showPrivateMessageNotification(ContactId c);
public void clearPrivateMessageNotification(ContactId c); void clearPrivateMessageNotification(ContactId c);
public void showGroupPostNotification(GroupId g); void showForumPostNotification(GroupId g);
public void clearGroupPostNotification(GroupId g); void clearForumPostNotification(GroupId g);
public void clearNotifications(); void clearNotifications();
} }