mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Navigation drawer (squashed and rebased).
This commit is contained in:
committed by
akwizgran
parent
d33dbca25a
commit
dae29eecce
@@ -18,11 +18,11 @@ 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> {
|
||||
public class ForumListAdapter extends ArrayAdapter<ForumListItem> {
|
||||
|
||||
private final int pad;
|
||||
|
||||
ForumListAdapter(Context ctx) {
|
||||
public ForumListAdapter(Context ctx) {
|
||||
super(ctx, android.R.layout.simple_expandable_list_item_1,
|
||||
new ArrayList<ForumListItem>());
|
||||
pad = LayoutUtils.getPadding(ctx);
|
||||
|
||||
@@ -3,15 +3,15 @@ package org.briarproject.android.forum;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnCreateContextMenuListener;
|
||||
import android.view.ViewGroup;
|
||||
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;
|
||||
@@ -19,15 +19,13 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.fragment.BaseEventFragment;
|
||||
import org.briarproject.android.util.HorizontalBorder;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.NoSuchSubscriptionException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.MessageValidatedEvent;
|
||||
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
|
||||
import org.briarproject.api.event.SubscriptionAddedEvent;
|
||||
@@ -58,13 +56,24 @@ 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,
|
||||
OnCreateContextMenuListener {
|
||||
public class ForumListFragment extends BaseEventFragment implements
|
||||
AdapterView.OnItemClickListener, View.OnClickListener {
|
||||
|
||||
public final static String TAG = "ForumListFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ForumListFragment.class.getName());
|
||||
|
||||
public static ForumListFragment newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
ForumListFragment fragment = new ForumListFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private static final int MENU_ITEM_UNSUBSCRIBE = 1;
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ForumListActivity.class.getName());
|
||||
|
||||
private TextView empty = null;
|
||||
private ForumListAdapter adapter = null;
|
||||
@@ -74,20 +83,21 @@ public class ForumListActivity extends BriarActivity
|
||||
private ImageButton newForumButton = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@Inject private volatile EventBus eventBus;
|
||||
@Inject
|
||||
private volatile ForumManager forumManager;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
LinearLayout layout = new LinearLayout(getContext());
|
||||
layout.setLayoutParams(MATCH_MATCH);
|
||||
layout.setOrientation(VERTICAL);
|
||||
layout.setGravity(CENTER_HORIZONTAL);
|
||||
|
||||
int pad = LayoutUtils.getPadding(this);
|
||||
int pad = LayoutUtils.getPadding(getContext());
|
||||
|
||||
empty = new TextView(this);
|
||||
empty = new TextView(getContext());
|
||||
empty.setLayoutParams(MATCH_WRAP_1);
|
||||
empty.setGravity(CENTER);
|
||||
empty.setTextSize(18);
|
||||
@@ -95,8 +105,8 @@ public class ForumListActivity extends BriarActivity
|
||||
empty.setVisibility(GONE);
|
||||
layout.addView(empty);
|
||||
|
||||
adapter = new ForumListAdapter(this);
|
||||
list = new ListView(this);
|
||||
adapter = new ForumListAdapter(getContext());
|
||||
list = new ListView(getContext());
|
||||
list.setLayoutParams(MATCH_WRAP_1);
|
||||
list.setAdapter(adapter);
|
||||
list.setOnItemClickListener(this);
|
||||
@@ -105,10 +115,10 @@ public class ForumListActivity extends BriarActivity
|
||||
layout.addView(list);
|
||||
|
||||
// Show a progress bar while the list is loading
|
||||
loading = new ListLoadingProgressBar(this);
|
||||
loading = new ListLoadingProgressBar(getContext());
|
||||
layout.addView(loading);
|
||||
|
||||
available = new TextView(this);
|
||||
available = new TextView(getContext());
|
||||
available.setLayoutParams(MATCH_WRAP);
|
||||
available.setGravity(CENTER);
|
||||
available.setTextSize(18);
|
||||
@@ -120,33 +130,37 @@ public class ForumListActivity extends BriarActivity
|
||||
available.setVisibility(GONE);
|
||||
layout.addView(available);
|
||||
|
||||
layout.addView(new HorizontalBorder(this));
|
||||
layout.addView(new HorizontalBorder(getContext()));
|
||||
|
||||
LinearLayout footer = new LinearLayout(this);
|
||||
LinearLayout footer = new LinearLayout(getContext());
|
||||
footer.setLayoutParams(MATCH_WRAP);
|
||||
footer.setOrientation(HORIZONTAL);
|
||||
footer.setGravity(CENTER);
|
||||
footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
|
||||
newForumButton = new ImageButton(this);
|
||||
newForumButton = new ImageButton(getContext());
|
||||
newForumButton.setBackgroundResource(0);
|
||||
newForumButton.setImageResource(R.drawable.social_new_chat);
|
||||
newForumButton.setOnClickListener(this);
|
||||
footer.addView(newForumButton);
|
||||
layout.addView(footer);
|
||||
|
||||
setContentView(layout);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
eventBus.addListener(this);
|
||||
loadHeaders();
|
||||
}
|
||||
|
||||
private void loadHeaders() {
|
||||
clearHeaders();
|
||||
runOnDbThread(new Runnable() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -173,7 +187,7 @@ public class ForumListActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void clearHeaders() {
|
||||
runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
empty.setVisibility(GONE);
|
||||
list.setVisibility(GONE);
|
||||
@@ -186,7 +200,7 @@ public class ForumListActivity extends BriarActivity
|
||||
|
||||
private void displayHeaders(final Forum f,
|
||||
final Collection<ForumPostHeader> headers) {
|
||||
runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
list.setVisibility(VISIBLE);
|
||||
loading.setVisibility(GONE);
|
||||
@@ -202,7 +216,7 @@ public class ForumListActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void displayAvailable(final int availableCount) {
|
||||
runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (adapter.isEmpty()) empty.setVisibility(VISIBLE);
|
||||
loading.setVisibility(GONE);
|
||||
@@ -239,12 +253,6 @@ public class ForumListActivity extends BriarActivity
|
||||
else list.setSelection(firstUnread);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof MessageValidatedEvent) {
|
||||
MessageValidatedEvent m = (MessageValidatedEvent) e;
|
||||
@@ -269,7 +277,7 @@ public class ForumListActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void loadHeaders(final GroupId g) {
|
||||
runOnDbThread(new Runnable() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -291,7 +299,7 @@ public class ForumListActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void removeForum(final GroupId g) {
|
||||
runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ForumListItem item = findForum(g);
|
||||
if (item != null) {
|
||||
@@ -308,7 +316,7 @@ public class ForumListActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void loadAvailable() {
|
||||
runOnDbThread(new Runnable() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -327,15 +335,16 @@ public class ForumListActivity extends BriarActivity
|
||||
|
||||
public void onClick(View view) {
|
||||
if (view == available) {
|
||||
startActivity(new Intent(this, AvailableForumsActivity.class));
|
||||
startActivity(new Intent(getContext(),
|
||||
AvailableForumsActivity.class));
|
||||
} else if (view == newForumButton) {
|
||||
startActivity(new Intent(this, CreateForumActivity.class));
|
||||
startActivity(new Intent(getContext(), CreateForumActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
Intent i = new Intent(this, ForumActivity.class);
|
||||
Intent i = new Intent(getContext(), ForumActivity.class);
|
||||
Forum f = adapter.getItem(position).getForum();
|
||||
i.putExtra("briar.GROUP_ID", f.getId().getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", f.getName());
|
||||
@@ -344,7 +353,7 @@ public class ForumListActivity extends BriarActivity
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view,
|
||||
ContextMenu.ContextMenuInfo info) {
|
||||
ContextMenuInfo info) {
|
||||
String delete = getString(R.string.unsubscribe);
|
||||
menu.add(NONE, MENU_ITEM_UNSUBSCRIBE, NONE, delete);
|
||||
}
|
||||
@@ -357,13 +366,13 @@ public class ForumListActivity extends BriarActivity
|
||||
ForumListItem item = adapter.getItem(position);
|
||||
removeSubscription(item.getForum());
|
||||
String unsubscribed = getString(R.string.unsubscribed_toast);
|
||||
Toast.makeText(this, unsubscribed, LENGTH_SHORT).show();
|
||||
Toast.makeText(getContext(), unsubscribed, LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void removeSubscription(final Forum f) {
|
||||
runOnDbThread(new Runnable() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -378,4 +387,4 @@ public class ForumListActivity extends BriarActivity
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package org.briarproject.android.forum;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
class ForumListItemComparator implements Comparator<ForumListItem> {
|
||||
public class ForumListItemComparator implements Comparator<ForumListItem> {
|
||||
|
||||
static final ForumListItemComparator INSTANCE =
|
||||
public static final ForumListItemComparator INSTANCE =
|
||||
new ForumListItemComparator();
|
||||
|
||||
public int compare(ForumListItem a, ForumListItem b) {
|
||||
|
||||
Reference in New Issue
Block a user