mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
UI code cleanup.
This commit is contained in:
@@ -55,7 +55,7 @@ public class ContactChooserAdapter extends ContactListAdapter {
|
||||
}
|
||||
|
||||
private void grayOutItem(final ContactHolder ui) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
float alpha = 0.25f;
|
||||
ui.bulb.setAlpha(alpha);
|
||||
ui.avatar.setAlpha(alpha);
|
||||
|
||||
@@ -44,14 +44,15 @@ import static java.util.logging.Level.WARNING;
|
||||
public class ContactChooserFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = "ContactChooserFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactChooserFragment.class.getName());
|
||||
|
||||
private IntroductionActivity introductionActivity;
|
||||
private BriarRecyclerView list;
|
||||
private ContactChooserAdapter adapter;
|
||||
private int contactId;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactChooserFragment.class.getName());
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
protected volatile Contact c1;
|
||||
@Inject
|
||||
@@ -76,7 +77,7 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
try {
|
||||
introductionActivity = (IntroductionActivity) context;
|
||||
} catch (ClassCastException e) {
|
||||
throw new java.lang.InstantiationError(
|
||||
throw new InstantiationError(
|
||||
"This fragment is only meant to be attached to the IntroductionActivity");
|
||||
}
|
||||
}
|
||||
@@ -90,7 +91,7 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
container, false);
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
setExitTransition(new Fade());
|
||||
}
|
||||
|
||||
@@ -99,14 +100,15 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
@Override
|
||||
public void onItemClick(View view, ContactListItem item) {
|
||||
if (c1 == null) {
|
||||
throw new RuntimeException("c1 not initialized");
|
||||
throw new RuntimeException("c1 not accountExists");
|
||||
}
|
||||
Contact c2 = item.getContact();
|
||||
if (!c1.getLocalAuthorId()
|
||||
.equals(c2.getLocalAuthorId())) {
|
||||
warnAboutDifferentIdentities(view, c1, c2);
|
||||
} else {
|
||||
introductionActivity.showMessageScreen(view, c1, c2);
|
||||
introductionActivity.showMessageScreen(view, c1,
|
||||
c2);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -142,11 +144,11 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
|
||||
private void loadContacts() {
|
||||
introductionActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<ContactListItem> contacts =
|
||||
new ArrayList<ContactListItem>();
|
||||
AuthorId localAuthorId= null;
|
||||
List<ContactListItem> contacts = new ArrayList<>();
|
||||
AuthorId localAuthorId = null;
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
if (c.getId().getInt() == contactId) {
|
||||
c1 = c;
|
||||
@@ -177,6 +179,7 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
private void displayContacts(final AuthorId localAuthorId,
|
||||
final List<ContactListItem> contacts) {
|
||||
introductionActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.setLocalAuthor(localAuthorId);
|
||||
if (contacts.size() == 0) list.showData();
|
||||
@@ -206,14 +209,15 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
builder.show();
|
||||
}
|
||||
|
||||
/** This needs to be called from the DbThread */
|
||||
/**
|
||||
* This needs to be called from the DbThread
|
||||
*/
|
||||
private Collection<ConversationItem> getMessages(ContactId id)
|
||||
throws DbException {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Collection<ConversationItem> messages =
|
||||
new ArrayList<ConversationItem>();
|
||||
Collection<ConversationItem> messages = new ArrayList<>();
|
||||
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessageHeaders(id);
|
||||
@@ -237,5 +241,4 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.android.introduction;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.transition.ChangeBounds;
|
||||
import android.transition.Fade;
|
||||
@@ -20,6 +19,7 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
BaseFragment.BaseFragmentListener {
|
||||
|
||||
public static final String CONTACT_ID = "briar.CONTACT_ID";
|
||||
|
||||
private int contactId;
|
||||
|
||||
@Override
|
||||
@@ -34,7 +34,8 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
setContentView(R.layout.activity_introduction);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.introductionContainer,
|
||||
activityComponent.newContactChooserFragment())
|
||||
.commit();
|
||||
@@ -82,21 +83,21 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public void showMessageScreen(final View view, final Contact c1,
|
||||
final Contact c2) {
|
||||
public void showMessageScreen(View view, Contact c1, Contact c2) {
|
||||
|
||||
IntroductionMessageFragment messageFragment =
|
||||
activityComponent.newIntroductionMessageFragment();
|
||||
messageFragment.initBundle(c1.getId().getInt(), c2.getId().getInt());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
messageFragment.setSharedElementEnterTransition(new ChangeBounds());
|
||||
messageFragment.setEnterTransition(new Fade());
|
||||
messageFragment
|
||||
.setSharedElementReturnTransition(new ChangeBounds());
|
||||
messageFragment.setSharedElementReturnTransition(
|
||||
new ChangeBounds());
|
||||
}
|
||||
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.setCustomAnimations(android.R.anim.fade_in,
|
||||
android.R.anim.fade_out,
|
||||
android.R.anim.slide_in_left,
|
||||
@@ -107,5 +108,4 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,19 +28,22 @@ import javax.inject.Inject;
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
import im.delight.android.identicons.IdenticonDrawable;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public class IntroductionMessageFragment extends BaseFragment {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(IntroductionMessageFragment.class.getName());
|
||||
|
||||
public final static String TAG = "IntroductionMessageFragment";
|
||||
private IntroductionActivity introductionActivity;
|
||||
private ViewHolder ui;
|
||||
|
||||
private final static String CONTACT_ID_1 = "contact1";
|
||||
private final static String CONTACT_ID_2 = "contact2";
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(IntroductionMessageFragment.class.getName());
|
||||
|
||||
private IntroductionActivity introductionActivity;
|
||||
private ViewHolder ui;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@@ -83,13 +86,12 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
// inflate view
|
||||
View v =
|
||||
inflater.inflate(R.layout.introduction_message, container,
|
||||
false);
|
||||
View v = inflater.inflate(R.layout.introduction_message, container,
|
||||
false);
|
||||
|
||||
// show progress bar until contacts have been loaded
|
||||
ui = new ViewHolder(v);
|
||||
ui.text.setVisibility(View.GONE);
|
||||
ui.text.setVisibility(GONE);
|
||||
ui.button.setEnabled(false);
|
||||
|
||||
// get contact IDs from fragment arguments
|
||||
@@ -114,12 +116,13 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
private void prepareToSetUpViews(final int contactId1,
|
||||
final int contactId2) {
|
||||
introductionActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Contact c1 = contactManager
|
||||
.getContact(new ContactId(contactId1));
|
||||
Contact c2 = contactManager
|
||||
.getContact(new ContactId(contactId2));
|
||||
Contact c1 = contactManager.getContact(
|
||||
new ContactId(contactId1));
|
||||
Contact c2 = contactManager.getContact(
|
||||
new ContactId(contactId2));
|
||||
setUpViews(c1, c2);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
@@ -131,6 +134,7 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
|
||||
private void setUpViews(final Contact c1, final Contact c2) {
|
||||
introductionActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// set avatars
|
||||
ui.avatar1.setImageDrawable(new IdenticonDrawable(
|
||||
@@ -152,8 +156,8 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
});
|
||||
|
||||
// hide progress bar and show views
|
||||
ui.progressBar.setVisibility(View.GONE);
|
||||
ui.text.setVisibility(View.VISIBLE);
|
||||
ui.progressBar.setVisibility(GONE);
|
||||
ui.text.setVisibility(VISIBLE);
|
||||
ui.button.setEnabled(true);
|
||||
}
|
||||
});
|
||||
@@ -174,17 +178,14 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
private void makeIntroduction(final Contact c1, final Contact c2,
|
||||
final String msg) {
|
||||
introductionActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// actually make the introduction
|
||||
try {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
introductionManager
|
||||
.makeIntroduction(c1, c2, msg, timestamp);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
introductionError();
|
||||
} catch (FormatException e) {
|
||||
introductionManager.makeIntroduction(c1, c2, msg,
|
||||
timestamp);
|
||||
} catch (DbException | FormatException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
introductionError();
|
||||
@@ -195,26 +196,24 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
|
||||
private void introductionError() {
|
||||
introductionActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(introductionActivity,
|
||||
R.string.introduction_error, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
R.string.introduction_error, LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
ProgressBar progressBar;
|
||||
ViewGroup header;
|
||||
CircleImageView avatar1;
|
||||
CircleImageView avatar2;
|
||||
TextView text;
|
||||
EditText message;
|
||||
Button button;
|
||||
|
||||
private final ProgressBar progressBar;
|
||||
private final CircleImageView avatar1, avatar2;
|
||||
private final TextView text;
|
||||
private final EditText message;
|
||||
private final Button button;
|
||||
|
||||
ViewHolder(View v) {
|
||||
progressBar = (ProgressBar) v.findViewById(R.id.progressBar);
|
||||
header = (ViewGroup) v.findViewById(R.id.introductionHeader);
|
||||
avatar1 = (CircleImageView) v.findViewById(R.id.avatarContact1);
|
||||
avatar2 = (CircleImageView) v.findViewById(R.id.avatarContact2);
|
||||
text = (TextView) v.findViewById(R.id.introductionText);
|
||||
|
||||
Reference in New Issue
Block a user