mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
UI code cleanup.
This commit is contained in:
@@ -6,7 +6,6 @@ import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
@@ -44,9 +43,12 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
private AvailableForumsAdapter adapter;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile ForumManager forumManager;
|
||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject protected volatile EventBus eventBus;
|
||||
@Inject
|
||||
protected volatile ForumManager forumManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -75,6 +77,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
|
||||
private void loadForums() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Collection<ForumContacts> available = new ArrayList<>();
|
||||
@@ -102,6 +105,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
|
||||
private void displayForums(final Collection<ForumContacts> available) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (available.isEmpty()) {
|
||||
LOG.info("No forums available, finishing");
|
||||
@@ -124,6 +128,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
LOG.info("Contact removed, reloading");
|
||||
@@ -146,6 +151,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AvailableForumsItem item, boolean accept) {
|
||||
respondToInvitation(item.getForum(), accept);
|
||||
|
||||
@@ -157,6 +163,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
|
||||
private void respondToInvitation(final Forum f, final boolean accept) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
forumSharingManager.respondToInvitation(f, accept);
|
||||
@@ -168,5 +175,4 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ class AvailableForumsAdapter extends
|
||||
new SortedList<>(AvailableForumsItem.class,
|
||||
new SortedListCallBacks());
|
||||
|
||||
AvailableForumsAdapter(Context ctx,
|
||||
AvailableForumClickListener listener) {
|
||||
|
||||
AvailableForumsAdapter(Context ctx, AvailableForumClickListener listener) {
|
||||
this.ctx = ctx;
|
||||
this.listener = listener;
|
||||
}
|
||||
@@ -90,16 +88,14 @@ class AvailableForumsAdapter extends
|
||||
protected static class AvailableForumViewHolder
|
||||
extends RecyclerView.ViewHolder {
|
||||
|
||||
public final ViewGroup layout;
|
||||
public final TextView name;
|
||||
public final TextView sharedBy;
|
||||
public final Button accept;
|
||||
public final Button decline;
|
||||
private final TextView name;
|
||||
private final TextView sharedBy;
|
||||
private final Button accept;
|
||||
private final Button decline;
|
||||
|
||||
public AvailableForumViewHolder(View v) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v;
|
||||
name = (TextView) v.findViewById(R.id.forumNameView);
|
||||
sharedBy = (TextView) v.findViewById(R.id.sharedByView);
|
||||
accept = (Button) v.findViewById(R.id.acceptButton);
|
||||
@@ -156,5 +152,4 @@ class AvailableForumsAdapter extends
|
||||
interface AvailableForumClickListener {
|
||||
void onItemClick(AvailableForumsItem item, boolean accept);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class ContactSelectorAdapter
|
||||
extends
|
||||
BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> {
|
||||
extends BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> {
|
||||
|
||||
public ContactSelectorAdapter(Context context,
|
||||
OnItemClickListener listener) {
|
||||
@@ -32,19 +31,17 @@ public class ContactSelectorAdapter
|
||||
@Override
|
||||
public SelectableContactHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int i) {
|
||||
View v = LayoutInflater.from(ctx)
|
||||
.inflate(R.layout.list_item_selectable_contact, viewGroup,
|
||||
false);
|
||||
View v = LayoutInflater.from(ctx).inflate(
|
||||
R.layout.list_item_selectable_contact, viewGroup, false);
|
||||
|
||||
return new SelectableContactHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final SelectableContactHolder ui,
|
||||
final int position) {
|
||||
public void onBindViewHolder(SelectableContactHolder ui, int position) {
|
||||
super.onBindViewHolder(ui, position);
|
||||
|
||||
final SelectableContactListItem item =
|
||||
SelectableContactListItem item =
|
||||
(SelectableContactListItem) getItem(position);
|
||||
|
||||
if (item.isSelected()) {
|
||||
@@ -90,7 +87,7 @@ public class ContactSelectorAdapter
|
||||
}
|
||||
|
||||
private void grayOutItem(final SelectableContactHolder ui) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
float alpha = 0.25f;
|
||||
ui.avatar.setAlpha(alpha);
|
||||
ui.name.setAlpha(alpha);
|
||||
@@ -103,5 +100,4 @@ public class ContactSelectorAdapter
|
||||
ui.checkBox.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,17 +44,17 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
BaseContactListAdapter.OnItemClickListener {
|
||||
|
||||
public final static String TAG = "ContactSelectorFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactSelectorFragment.class.getName());
|
||||
|
||||
private ShareForumActivity shareForumActivity;
|
||||
private Menu menu;
|
||||
private BriarRecyclerView list;
|
||||
private ContactSelectorAdapter adapter;
|
||||
private Collection<ContactId> selectedContacts;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactSelectorFragment.class.getName());
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
protected volatile GroupId groupId;
|
||||
@Inject
|
||||
protected volatile ContactManager contactManager;
|
||||
@Inject
|
||||
@@ -62,6 +62,8 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
protected volatile GroupId groupId;
|
||||
|
||||
public void initBundle(GroupId groupId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putByteArray(GROUP_ID, groupId.getBytes());
|
||||
@@ -97,11 +99,10 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View contentView =
|
||||
inflater.inflate(R.layout.introduction_contact_chooser,
|
||||
container, false);
|
||||
View contentView = inflater.inflate(
|
||||
R.layout.introduction_contact_chooser, container, false);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
setExitTransition(new Fade());
|
||||
}
|
||||
|
||||
@@ -116,7 +117,8 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
if (savedInstanceState != null) {
|
||||
ArrayList<Integer> intContacts =
|
||||
savedInstanceState.getIntegerArrayList(CONTACTS);
|
||||
selectedContacts = ShareForumActivity.getContactsFromIntegers(intContacts);
|
||||
selectedContacts = ShareForumActivity.getContactsFromIntegers(
|
||||
intContacts);
|
||||
}
|
||||
|
||||
return contentView;
|
||||
@@ -126,11 +128,9 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (selectedContacts != null) {
|
||||
if (selectedContacts != null)
|
||||
loadContacts(Collections.unmodifiableCollection(selectedContacts));
|
||||
} else {
|
||||
loadContacts(null);
|
||||
}
|
||||
else loadContacts(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -182,11 +182,11 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
|
||||
private void loadContacts(final Collection<ContactId> selection) {
|
||||
shareForumActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
List<ContactListItem> contacts =
|
||||
new ArrayList<>();
|
||||
List<ContactListItem> contacts = new ArrayList<>();
|
||||
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
LocalAuthor localAuthor = identityManager
|
||||
@@ -197,9 +197,8 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
// do we have already some sharing with that contact?
|
||||
boolean disabled =
|
||||
!forumSharingManager.canBeShared(groupId, c);
|
||||
contacts.add(
|
||||
new SelectableContactListItem(c, localAuthor,
|
||||
groupId, selected, disabled));
|
||||
contacts.add(new SelectableContactListItem(c,
|
||||
localAuthor, groupId, selected, disabled));
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
@@ -216,12 +215,10 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
|
||||
private void displayContacts(final List<ContactListItem> contacts) {
|
||||
shareForumActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!contacts.isEmpty()) {
|
||||
adapter.addAll(contacts);
|
||||
} else {
|
||||
list.showData();
|
||||
}
|
||||
if (!contacts.isEmpty()) adapter.addAll(contacts);
|
||||
else list.showData();
|
||||
updateMenuItem();
|
||||
}
|
||||
});
|
||||
@@ -239,5 +236,4 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
item.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ public class CreateForumActivity extends BriarActivity
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(CreateForumActivity.class.getName());
|
||||
|
||||
private EditText nameEntry = null;
|
||||
private Button createForumButton = null;
|
||||
private ProgressBar progress = null;
|
||||
private TextView feedback = null;
|
||||
private EditText nameEntry;
|
||||
private Button createForumButton;
|
||||
private ProgressBar progress;
|
||||
private TextView feedback;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@@ -95,6 +95,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
createForumButton.setEnabled(validateName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||
hideSoftKeyboard(textView);
|
||||
return true;
|
||||
@@ -111,6 +112,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
return length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view == createForumButton) {
|
||||
hideSoftKeyboard(view);
|
||||
@@ -123,6 +125,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
|
||||
private void storeForum(final String name) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -143,6 +146,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
|
||||
private void displayForum(final Forum f) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent i = new Intent(CreateForumActivity.this,
|
||||
ForumActivity.class);
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ForumListAdapter extends
|
||||
|
||||
private SortedList<ForumListItem> forums = new SortedList<>(
|
||||
ForumListItem.class, new SortedList.Callback<ForumListItem>() {
|
||||
|
||||
@Override
|
||||
public int compare(ForumListItem a, ForumListItem b) {
|
||||
if (a == b) return 0;
|
||||
@@ -71,6 +72,7 @@ public class ForumListAdapter extends
|
||||
return a.getForum().equals(b.getForum());
|
||||
}
|
||||
});
|
||||
|
||||
private final Context ctx;
|
||||
|
||||
public ForumListAdapter(Context ctx) {
|
||||
@@ -78,11 +80,9 @@ public class ForumListAdapter extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForumViewHolder onCreateViewHolder(ViewGroup parent,
|
||||
int viewType) {
|
||||
|
||||
View v = LayoutInflater.from(ctx)
|
||||
.inflate(R.layout.list_item_forum, parent, false);
|
||||
public ForumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(ctx).inflate(
|
||||
R.layout.list_item_forum, parent, false);
|
||||
return new ForumViewHolder(v);
|
||||
}
|
||||
|
||||
@@ -175,10 +175,10 @@ public class ForumListAdapter extends
|
||||
|
||||
protected static class ForumViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public final ViewGroup layout;
|
||||
public final TextView name;
|
||||
public final TextView unread;
|
||||
public final TextView date;
|
||||
private final ViewGroup layout;
|
||||
private final TextView name;
|
||||
private final TextView unread;
|
||||
private final TextView date;
|
||||
|
||||
public ForumViewHolder(View v) {
|
||||
super(v);
|
||||
@@ -189,5 +189,4 @@ public class ForumListAdapter extends
|
||||
date = (TextView) v.findViewById(R.id.dateView);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void loadForumHeaders() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// load forums
|
||||
@@ -162,6 +163,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void displayForumHeaders(final Collection<ForumListItem> forums) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (forums.size() > 0) adapter.addAll(forums);
|
||||
else list.showData();
|
||||
@@ -171,6 +173,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void loadAvailableForums() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -190,6 +193,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void displayAvailableForums(final int availableCount) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (availableCount == 0) {
|
||||
snackbar.dismiss();
|
||||
@@ -203,6 +207,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
LOG.info("Contact removed, reloading available forums");
|
||||
@@ -235,6 +240,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void loadForumHeaders(final GroupId g) {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -272,9 +278,9 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// snackbar click
|
||||
startActivity(new Intent(getContext(), AvailableForumsActivity.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ public class SelectableContactListItem extends ContactListItem {
|
||||
public SelectableContactListItem(Contact contact, LocalAuthor localAuthor,
|
||||
GroupId groupId, boolean selected, boolean disabled) {
|
||||
|
||||
super(contact, localAuthor, false, groupId, Collections.<ConversationItem>emptyList());
|
||||
super(contact, localAuthor, false, groupId,
|
||||
Collections.<ConversationItem>emptyList());
|
||||
|
||||
this.selected = selected;
|
||||
this.disabled = disabled;
|
||||
@@ -37,5 +38,4 @@ public class SelectableContactListItem extends ContactListItem {
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
@@ -25,6 +24,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.forum.ShareForumActivity.CONTACTS;
|
||||
import static org.briarproject.android.forum.ShareForumActivity.getContactsFromIds;
|
||||
@@ -32,15 +32,17 @@ import static org.briarproject.api.forum.ForumConstants.GROUP_ID;
|
||||
|
||||
public class ShareForumMessageFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = "IntroductionMessageFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ShareForumMessageFragment.class.getName());
|
||||
|
||||
public final static String TAG = "IntroductionMessageFragment";
|
||||
private ShareForumActivity shareForumActivity;
|
||||
private ViewHolder ui;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
private volatile GroupId groupId;
|
||||
private volatile Collection<ContactId> contacts;
|
||||
|
||||
@@ -81,9 +83,8 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// inflate view
|
||||
View v =
|
||||
inflater.inflate(R.layout.share_forum_message, container,
|
||||
false);
|
||||
View v = inflater.inflate(R.layout.share_forum_message, container,
|
||||
false);
|
||||
ui = new ViewHolder(v);
|
||||
ui.button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -131,11 +132,12 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
|
||||
private void shareForum(final String msg) {
|
||||
shareForumActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (ContactId c : contacts) {
|
||||
forumSharingManager
|
||||
.sendForumInvitation(groupId, c, msg);
|
||||
forumSharingManager.sendForumInvitation(groupId, c,
|
||||
msg);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
sharingError();
|
||||
@@ -148,21 +150,20 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
|
||||
private void sharingError() {
|
||||
shareForumActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(shareForumActivity,
|
||||
R.string.introduction_error, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
R.string.introduction_error, LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
final private TextView text;
|
||||
final private EditText message;
|
||||
final private Button button;
|
||||
|
||||
private final EditText message;
|
||||
private final Button button;
|
||||
|
||||
ViewHolder(View v) {
|
||||
text = (TextView) v.findViewById(R.id.introductionText);
|
||||
message = (EditText) v.findViewById(R.id.invitationMessageView);
|
||||
button = (Button) v.findViewById(R.id.shareForumButton);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user