mirror of
https://github.com/etesync/android
synced 2024-11-16 04:49:06 +00:00
Journal item: Implement showing contacts.
This shows address book journal items in a nicer way.
This commit is contained in:
parent
b964b8dfe1
commit
c3ee3aac22
@ -33,10 +33,23 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Formatter;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import at.bitfire.ical4android.Event;
|
||||
import at.bitfire.ical4android.InvalidCalendarException;
|
||||
import at.bitfire.vcard4android.Contact;
|
||||
import at.bitfire.vcard4android.LabeledProperty;
|
||||
import ezvcard.parameter.AddressType;
|
||||
import ezvcard.parameter.EmailType;
|
||||
import ezvcard.parameter.RelatedType;
|
||||
import ezvcard.parameter.TelephoneType;
|
||||
import ezvcard.property.Address;
|
||||
import ezvcard.property.Email;
|
||||
import ezvcard.property.Impp;
|
||||
import ezvcard.property.Related;
|
||||
import ezvcard.property.Telephone;
|
||||
import ezvcard.property.Url;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
|
||||
@ -120,7 +133,7 @@ public class JournalItemActivity extends BaseActivity implements Refreshable {
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (position == 0) {
|
||||
return EventFragment.newInstance(info, syncEntry);
|
||||
return PrettyFragment.newInstance(info, syncEntry);
|
||||
} else {
|
||||
return TextFragment.newInstance(syncEntry);
|
||||
}
|
||||
@ -149,12 +162,12 @@ public class JournalItemActivity extends BaseActivity implements Refreshable {
|
||||
}
|
||||
}
|
||||
|
||||
public static class EventFragment extends Fragment {
|
||||
public static class PrettyFragment extends Fragment {
|
||||
CollectionInfo info;
|
||||
SyncEntry syncEntry;
|
||||
|
||||
public static EventFragment newInstance(CollectionInfo info, SyncEntry syncEntry) {
|
||||
EventFragment frag = new EventFragment();
|
||||
public static PrettyFragment newInstance(CollectionInfo info, SyncEntry syncEntry) {
|
||||
PrettyFragment frag = new PrettyFragment();
|
||||
Bundle args = new Bundle(1);
|
||||
args.putSerializable(Constants.KEY_COLLECTION_INFO, info);
|
||||
args.putSerializable(KEY_SYNC_ENTRY, syncEntry);
|
||||
@ -164,12 +177,21 @@ public class JournalItemActivity extends BaseActivity implements Refreshable {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.event_info, container, false);
|
||||
View v = null;
|
||||
|
||||
info = (CollectionInfo) getArguments().getSerializable(Constants.KEY_COLLECTION_INFO);
|
||||
syncEntry = (SyncEntry) getArguments().getSerializable(KEY_SYNC_ENTRY);
|
||||
|
||||
new LoadEventTask(v).execute();
|
||||
switch (info.type) {
|
||||
case ADDRESS_BOOK:
|
||||
v = inflater.inflate(R.layout.contact_info, container, false);
|
||||
new LoadContactTask(v).execute();
|
||||
break;
|
||||
case CALENDAR:
|
||||
v = inflater.inflate(R.layout.event_info, container, false);
|
||||
new LoadEventTask(v).execute();
|
||||
break;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
@ -185,8 +207,7 @@ public class JournalItemActivity extends BaseActivity implements Refreshable {
|
||||
InputStream is = new ByteArrayInputStream(syncEntry.getContent().getBytes(Charsets.UTF_8));
|
||||
|
||||
try {
|
||||
Event event = Event.fromStream(is, Charsets.UTF_8, null)[0];
|
||||
return event;
|
||||
return Event.fromStream(is, Charsets.UTF_8, null)[0];
|
||||
} catch (InvalidCalendarException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
@ -247,6 +268,125 @@ public class JournalItemActivity extends BaseActivity implements Refreshable {
|
||||
}
|
||||
}
|
||||
|
||||
private class LoadContactTask extends AsyncTask<Void, Void, Contact> {
|
||||
View view;
|
||||
|
||||
LoadContactTask(View v) {
|
||||
super();
|
||||
view = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Contact doInBackground(Void... aVoids) {
|
||||
InputStream is = new ByteArrayInputStream(syncEntry.getContent().getBytes(Charsets.UTF_8));
|
||||
|
||||
try {
|
||||
return Contact.fromStream(is, Charsets.UTF_8, null)[0];
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Contact contact) {
|
||||
final View loader = view.findViewById(R.id.loading_msg);
|
||||
loader.setVisibility(View.GONE);
|
||||
final View contentContainer = view.findViewById(R.id.content_container);
|
||||
contentContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
TextView tv = (TextView) view.findViewById(R.id.display_name);
|
||||
tv.setText(contact.displayName);
|
||||
|
||||
final ViewGroup mainCard = (ViewGroup) view.findViewById(R.id.main_card);
|
||||
final ViewGroup aboutCard = (ViewGroup) view.findViewById(R.id.about_card);
|
||||
aboutCard.findViewById(R.id.title_container).setVisibility(View.VISIBLE);
|
||||
|
||||
// TEL
|
||||
for (LabeledProperty<Telephone> labeledPhone : contact.phoneNumbers) {
|
||||
List<TelephoneType> types = labeledPhone.property.getTypes();
|
||||
String type = (types.size() > 0) ? types.get(0).getValue() : null;
|
||||
addInfoItem(view.getContext(), mainCard, "Phone", type, labeledPhone.property.getText());
|
||||
}
|
||||
|
||||
// EMAIL
|
||||
for (LabeledProperty<Email> labeledEmail : contact.emails) {
|
||||
List<EmailType> types = labeledEmail.property.getTypes();
|
||||
String type = (types.size() > 0) ? types.get(0).getValue() : null;
|
||||
addInfoItem(view.getContext(), mainCard, "Email", type, labeledEmail.property.getValue());
|
||||
}
|
||||
|
||||
// ORG, TITLE, ROLE
|
||||
if (contact.organization != null) {
|
||||
addInfoItem(view.getContext(), aboutCard, "Organization", contact.jobTitle, contact.organization.getValues().get(0));
|
||||
}
|
||||
if (contact.jobDescription != null) {
|
||||
addInfoItem(view.getContext(), aboutCard, "Job Description", null, contact.jobTitle);
|
||||
}
|
||||
|
||||
// IMPP
|
||||
for (LabeledProperty<Impp> labeledImpp : contact.impps) {
|
||||
addInfoItem(view.getContext(), mainCard, "Instant Messaging", labeledImpp.property.getProtocol(), labeledImpp.property.getHandle());
|
||||
}
|
||||
|
||||
// NICKNAME
|
||||
if (contact.nickName != null) {
|
||||
addInfoItem(view.getContext(), aboutCard, "Nickname", null, contact.nickName.getValues().get(0));
|
||||
}
|
||||
|
||||
// ADR
|
||||
for (LabeledProperty<Address> labeledAddress : contact.addresses) {
|
||||
List<AddressType> types = labeledAddress.property.getTypes();
|
||||
String type = (types.size() > 0) ? types.get(0).getValue() : null;
|
||||
addInfoItem(view.getContext(), mainCard, "Address", type, labeledAddress.property.getLabel());
|
||||
}
|
||||
|
||||
// NOTE
|
||||
if (contact.note != null) {
|
||||
addInfoItem(view.getContext(), aboutCard, "Note", null, contact.note);
|
||||
}
|
||||
|
||||
// URL
|
||||
for (LabeledProperty<Url> labeledUrl : contact.urls) {
|
||||
addInfoItem(view.getContext(), aboutCard, "Website", null, labeledUrl.property.getValue());
|
||||
}
|
||||
|
||||
// ANNIVERSARY
|
||||
if (contact.anniversary != null) {
|
||||
String date = getDisplayedDatetime(contact.anniversary.getDate().getTime(), contact.anniversary.getDate().getTime(), true, getContext());
|
||||
addInfoItem(view.getContext(), aboutCard, "Anniversary", null, date);
|
||||
}
|
||||
// BDAY
|
||||
if (contact.birthDay != null) {
|
||||
String date = getDisplayedDatetime(contact.birthDay.getDate().getTime(), contact.birthDay.getDate().getTime(), true, getContext());
|
||||
addInfoItem(view.getContext(), aboutCard, "Birthday", null, date);
|
||||
}
|
||||
|
||||
// RELATED
|
||||
for (Related related : contact.relations) {
|
||||
List<RelatedType> types = related.getTypes();
|
||||
String type = (types.size() > 0) ? types.get(0).getValue() : null;
|
||||
addInfoItem(view.getContext(), aboutCard, "Relation", type, related.getText());
|
||||
}
|
||||
|
||||
// PHOTO
|
||||
// if (contact.photo != null)
|
||||
}
|
||||
}
|
||||
|
||||
private static View addInfoItem(Context context, ViewGroup parent, String type, String label, String value) {
|
||||
ViewGroup layout = (ViewGroup) parent.findViewById(R.id.container);
|
||||
View infoItem = LayoutInflater.from(context).inflate(R.layout.contact_info_item, layout, false);
|
||||
layout.addView(infoItem);
|
||||
setTextViewText(infoItem, R.id.type, type);
|
||||
setTextViewText(infoItem, R.id.title, label);
|
||||
setTextViewText(infoItem, R.id.content, value);
|
||||
parent.setVisibility(View.VISIBLE);
|
||||
|
||||
return infoItem;
|
||||
}
|
||||
|
||||
private static void setTextViewText(View parent, int id, String text) {
|
||||
TextView tv = (TextView) parent.findViewById(id);
|
||||
if (text == null) {
|
||||
|
78
app/src/main/res/layout/contact_info.xml
Normal file
78
app/src/main/res/layout/contact_info.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#fafafa"
|
||||
android:padding="0dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/loading_msg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/event_info_progress_bar"
|
||||
android:layout_width="100dip"
|
||||
android:layout_height="100dip"
|
||||
android:layout_centerInParent="true"
|
||||
android:indeterminate="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/event_info_progress_bar"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="16dip"
|
||||
android:text="@string/loading" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/display_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/orange400"
|
||||
android:padding="16dp"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textColor="@color/White"
|
||||
android:textIsSelectable="true"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:fadingEdge="none"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/main_card"
|
||||
layout="@layout/contact_info_item_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="8dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include
|
||||
android:id="@+id/about_card"
|
||||
layout="@layout/contact_info_item_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="8dp"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
38
app/src/main/res/layout/contact_info_item.xml
Normal file
38
app/src/main/res/layout/contact_info_item.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_marginRight="@dimen/activity_margin"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:textIsSelectable="true"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:textIsSelectable="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:textIsSelectable="true" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
</LinearLayout>
|
43
app/src/main/res/layout/contact_info_item_group.xml
Normal file
43
app/src/main/res/layout/contact_info_item_group.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/title_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/activity_margin"
|
||||
android:text="@string/about"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="@color/orange400"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
@ -129,6 +129,7 @@
|
||||
<string name="collection_members_remove">Would you like to revoke %s\'s access?\nPlease be advised that a malicious user would potentially be able to retain access to encryption keys. Please refer to the FAQ for more information.</string>
|
||||
|
||||
<!-- JournalItemActivity -->
|
||||
<string name="about">About</string>
|
||||
|
||||
<!-- PermissionsActivity -->
|
||||
<string name="permissions_title">EteSync permissions</string>
|
||||
|
Loading…
Reference in New Issue
Block a user