happy hanukkah

This commit is contained in:
iNPUTmice 2014-11-16 17:21:21 +01:00
parent 84b2ce10b7
commit cf00f3fade
13 changed files with 162 additions and 24 deletions

View File

@ -1,5 +1,7 @@
package eu.siacs.conversations.entities; package eu.siacs.conversations.entities;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
@ -88,6 +90,11 @@ public class Bookmark extends Element implements ListItem {
} }
} }
@Override
public List<Tag> getTags() {
return new ArrayList<Tag>();
}
public String getNick() { public String getNick() {
Element nick = this.findChild("nick"); Element nick = this.findChild("nick");
if (nick != null) { if (nick != null) {

View File

@ -9,8 +9,10 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
@ -29,6 +31,7 @@ public class Contact implements ListItem {
public static final String AVATAR = "avatar"; public static final String AVATAR = "avatar";
public static final String LAST_PRESENCE = "last_presence"; public static final String LAST_PRESENCE = "last_presence";
public static final String LAST_TIME = "last_time"; public static final String LAST_TIME = "last_time";
public static final String GROUPS = "groups";
protected String accountUuid; protected String accountUuid;
protected String systemName; protected String systemName;
@ -40,6 +43,7 @@ public class Contact implements ListItem {
protected String photoUri; protected String photoUri;
protected String avatar; protected String avatar;
protected JSONObject keys = new JSONObject(); protected JSONObject keys = new JSONObject();
protected JSONArray groups = new JSONArray();
protected Presences presences = new Presences(); protected Presences presences = new Presences();
protected Account account; protected Account account;
@ -48,16 +52,7 @@ public class Contact implements ListItem {
public Contact(final String account, final String systemName, final String serverName, public Contact(final String account, final String systemName, final String serverName,
final Jid jid, final int subscription, final String photoUri, final Jid jid, final int subscription, final String photoUri,
final String systemAccount, final String keys, final String avatar, final String systemAccount, final String keys, final String avatar, final Lastseen lastseen, final String groups) {
final Lastseen lastseen) {
this(account, systemName, serverName, jid, subscription, photoUri, systemAccount, keys,
avatar);
this.lastseen = lastseen;
}
public Contact(final String account, final String systemName, final String serverName,
final Jid jid, final int subscription, final String photoUri,
final String systemAccount, final String keys, final String avatar) {
this.accountUuid = account; this.accountUuid = account;
this.systemName = systemName; this.systemName = systemName;
this.serverName = serverName; this.serverName = serverName;
@ -71,6 +66,12 @@ public class Contact implements ListItem {
this.keys = new JSONObject(); this.keys = new JSONObject();
} }
this.avatar = avatar; this.avatar = avatar;
try {
this.groups = (groups == null ? new JSONArray() : new JSONArray(groups));
} catch (JSONException e) {
this.groups = new JSONArray();
}
this.lastseen = lastseen;
} }
public Contact(final Jid jid) { public Contact(final Jid jid) {
@ -99,6 +100,31 @@ public class Contact implements ListItem {
return jid; return jid;
} }
@Override
public List<Tag> getTags() {
ArrayList<Tag> tags = new ArrayList<Tag>();
for(String group : getGroups()) {
tags.add(new Tag(group, UIHelper.getColorForName(group)));
}
int status = getMostAvailableStatus();
switch (getMostAvailableStatus()) {
case Presences.CHAT:
case Presences.ONLINE:
tags.add(new Tag("online",0xff259b24));
break;
case Presences.AWAY:
tags.add(new Tag("away",0xffff9800));
break;
case Presences.XA:
tags.add(new Tag("not available",0xffe51c23));
break;
case Presences.DND:
tags.add(new Tag("dnd",0xffe51c23));
break;
}
return tags;
}
public boolean match(String needle) { public boolean match(String needle) {
return needle == null return needle == null
|| jid.toString().contains(needle.toLowerCase()) || jid.toString().contains(needle.toLowerCase())
@ -119,6 +145,7 @@ public class Contact implements ListItem {
values.put(AVATAR, avatar); values.put(AVATAR, avatar);
values.put(LAST_PRESENCE, lastseen.presence); values.put(LAST_PRESENCE, lastseen.presence);
values.put(LAST_TIME, lastseen.time); values.put(LAST_TIME, lastseen.time);
values.put(GROUPS,groups.toString());
return values; return values;
} }
@ -142,7 +169,8 @@ public class Contact implements ListItem {
cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)), cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)),
cursor.getString(cursor.getColumnIndex(KEYS)), cursor.getString(cursor.getColumnIndex(KEYS)),
cursor.getString(cursor.getColumnIndex(AVATAR)), cursor.getString(cursor.getColumnIndex(AVATAR)),
lastseen); lastseen,
cursor.getString(cursor.getColumnIndex(GROUPS)));
} }
public int getSubscription() { public int getSubscription() {
@ -207,6 +235,17 @@ public class Contact implements ListItem {
return systemAccount; return systemAccount;
} }
public List<String> getGroups() {
ArrayList<String> groups = new ArrayList<String>();
for(int i = 0; i < this.groups.length(); ++i) {
try {
groups.add(this.groups.getString(i));
} catch (final JSONException ignored) {
}
}
return groups;
}
public ArrayList<String> getOtrFingerprints() { public ArrayList<String> getOtrFingerprints() {
ArrayList<String> fingerprints = new ArrayList<String>(); ArrayList<String> fingerprints = new ArrayList<String>();
try { try {
@ -318,12 +357,24 @@ public class Contact implements ListItem {
} }
} }
public void parseGroupsFromElement(Element item) {
this.groups = new JSONArray();
for(Element element : item.getChildren()) {
if (element.getName().equals("group") && element.getContent() != null) {
this.groups.put(element.getContent());
}
}
}
public Element asElement() { public Element asElement() {
final Element item = new Element("item"); final Element item = new Element("item");
item.setAttribute("jid", this.jid.toString()); item.setAttribute("jid", this.jid.toString());
if (this.serverName != null) { if (this.serverName != null) {
item.setAttribute("name", this.serverName); item.setAttribute("name", this.serverName);
} }
for(String group : getGroups()) {
item.addChild("group").setContent(group);
}
return item; return item;
} }

View File

@ -1,9 +1,31 @@
package eu.siacs.conversations.entities; package eu.siacs.conversations.entities;
import java.util.List;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
public interface ListItem extends Comparable<ListItem> { public interface ListItem extends Comparable<ListItem> {
public String getDisplayName(); public String getDisplayName();
public Jid getJid(); public Jid getJid();
public List<Tag> getTags();
public final class Tag {
private String name;
private int color;
public Tag(String name, int color) {
this.name = name;
this.color = color;
}
public int getColor() {
return this.color;
}
public String getName() {
return this.name;
}
}
} }

View File

@ -34,6 +34,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
Contact contact = account.getRoster().getContact(jid); Contact contact = account.getRoster().getContact(jid);
if (!contact.getOption(Contact.Options.DIRTY_PUSH)) { if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
contact.setServerName(name); contact.setServerName(name);
contact.parseGroupsFromElement(item);
} }
if (subscription != null) { if (subscription != null) {
if (subscription.equals("remove")) { if (subscription.equals("remove")) {

View File

@ -22,7 +22,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null; private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history"; private static final String DATABASE_NAME = "history";
private static final int DATABASE_VERSION = 10; private static final int DATABASE_VERSION = 11;
private static String CREATE_CONTATCS_STATEMENT = "create table " private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@ -31,7 +31,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ Contact.PHOTOURI + " TEXT," + Contact.OPTIONS + " NUMBER," + Contact.PHOTOURI + " TEXT," + Contact.OPTIONS + " NUMBER,"
+ Contact.SYSTEMACCOUNT + " NUMBER, " + Contact.AVATAR + " TEXT, " + Contact.SYSTEMACCOUNT + " NUMBER, " + Contact.AVATAR + " TEXT, "
+ Contact.LAST_PRESENCE + " TEXT, " + Contact.LAST_TIME + " NUMBER, " + Contact.LAST_PRESENCE + " TEXT, " + Contact.LAST_TIME + " NUMBER, "
+ "FOREIGN KEY(" + Contact.ACCOUNT + ") REFERENCES " + Contact.GROUPS + " TEXT, FOREIGN KEY(" + Contact.ACCOUNT + ") REFERENCES "
+ Account.TABLENAME + "(" + Account.UUID + Account.TABLENAME + "(" + Account.UUID
+ ") ON DELETE CASCADE, UNIQUE(" + Contact.ACCOUNT + ", " + ") ON DELETE CASCADE, UNIQUE(" + Contact.ACCOUNT + ", "
+ Contact.JID + ") ON CONFLICT REPLACE);"; + Contact.JID + ") ON CONFLICT REPLACE);";
@ -115,6 +115,12 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "
+ Message.RELATIVE_FILE_PATH + " TEXT"); + Message.RELATIVE_FILE_PATH + " TEXT");
} }
if (oldVersion < 11 && newVersion >= 11) {
db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN "
+ Contact.GROUPS + " TEXT");
db.execSQL("delete from "+Contact.TABLENAME);
db.execSQL("update "+Account.TABLENAME+" set "+Account.ROSTERVERSION+" = NULL");
}
} }
public static synchronized DatabaseBackend getInstance(Context context) { public static synchronized DatabaseBackend getInstance(Context context) {

View File

@ -17,6 +17,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.utils.UIHelper;
public class AvatarService { public class AvatarService {
@ -119,7 +120,7 @@ public class AvatarService {
if (count == 0) { if (count == 0) {
String name = mucOptions.getConversation().getName(); String name = mucOptions.getConversation().getName();
String letter = name.substring(0, 1); String letter = name.substring(0, 1);
int color = this.getColorForName(name); int color = UIHelper.getColorForName(name);
drawTile(canvas, letter, color, 0, 0, size, size); drawTile(canvas, letter, color, 0, 0, size, size);
} else if (count == 1) { } else if (count == 1) {
drawTile(canvas, users.get(0), 0, 0, size, size); drawTile(canvas, users.get(0), 0, 0, size, size);
@ -209,7 +210,7 @@ public class AvatarService {
int color; int color;
if (name.length() > 0) { if (name.length() > 0) {
letter = name.substring(0, 1); letter = name.substring(0, 1);
color = this.getColorForName(name); color = UIHelper.getColorForName(name);
} else { } else {
letter = "X"; letter = "X";
color = PLACEHOLDER_COLOR; color = PLACEHOLDER_COLOR;
@ -272,7 +273,7 @@ public class AvatarService {
int color; int color;
if (name.length() > 0) { if (name.length() > 0) {
letter = name.substring(0, 1); letter = name.substring(0, 1);
color = this.getColorForName(name); color = UIHelper.getColorForName(name);
} else { } else {
letter = "X"; letter = "X";
color = PLACEHOLDER_COLOR; color = PLACEHOLDER_COLOR;
@ -286,11 +287,4 @@ public class AvatarService {
canvas.drawBitmap(bm, null, dst, null); canvas.drawBitmap(bm, null, dst, null);
} }
private int getColorForName(String name) {
int holoColors[] = {0xFFe91e63, 0xFF9c27b0, 0xFF673ab7, 0xFF3f51b5,
0xFF5677fc, 0xFF03a9f4, 0xFF00bcd4, 0xFF009688, 0xFFff5722,
0xFF795548, 0xFF607d8b};
return holoColors[(int) ((name.hashCode() & 0xffffffffl) % holoColors.length)];
}
} }

View File

@ -6,20 +6,26 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.XmppActivity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
public class ListItemAdapter extends ArrayAdapter<ListItem> { public class ListItemAdapter extends ArrayAdapter<ListItem> {
protected XmppActivity activity; protected XmppActivity activity;
protected boolean showDynamicTags = false;
public ListItemAdapter(XmppActivity activity, List<ListItem> objects) { public ListItemAdapter(XmppActivity activity, List<ListItem> objects) {
super(activity, 0, objects); super(activity, 0, objects);
this.activity = activity; this.activity = activity;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
this.showDynamicTags = preferences.getBoolean("show_dynamic_tags",false);
} }
@Override @Override
@ -33,6 +39,21 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
TextView name = (TextView) view.findViewById(R.id.contact_display_name); TextView name = (TextView) view.findViewById(R.id.contact_display_name);
TextView jid = (TextView) view.findViewById(R.id.contact_jid); TextView jid = (TextView) view.findViewById(R.id.contact_jid);
ImageView picture = (ImageView) view.findViewById(R.id.contact_photo); ImageView picture = (ImageView) view.findViewById(R.id.contact_photo);
LinearLayout tagLayout = (LinearLayout) view.findViewById(R.id.tags);
List<ListItem.Tag> tags = item.getTags();
if (tags.size() == 0 || !this.showDynamicTags) {
tagLayout.setVisibility(View.GONE);
} else {
tagLayout.setVisibility(View.VISIBLE);
tagLayout.removeAllViewsInLayout();
for(ListItem.Tag tag : tags) {
TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag,tagLayout,false);
tv.setText(tag.getName());
tv.setBackgroundColor(tag.getColor());
tagLayout.addView(tv);
}
}
jid.setText(item.getJid().toString()); jid.setText(item.getJid().toString());
name.setText(item.getDisplayName()); name.setText(item.getDisplayName());

View File

@ -188,4 +188,11 @@ public class UIHelper {
} }
return body; return body;
} }
public static int getColorForName(String name) {
int colors[] = {0xFFe91e63, 0xFF9c27b0, 0xFF673ab7, 0xFF3f51b5,
0xFF5677fc, 0xFF03a9f4, 0xFF00bcd4, 0xFF009688, 0xFFff5722,
0xFF795548, 0xFF607d8b};
return colors[(int) ((name.hashCode() & 0xffffffffl) % colors.length)];
}
} }

View File

@ -37,7 +37,13 @@
android:singleLine="true" android:singleLine="true"
android:textColor="@color/primarytext" android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeBody" /> android:textSize="?attr/TextSizeBody" />
<LinearLayout
android:id="@+id/tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
</LinearLayout>
<TextView <TextView
android:id="@+id/key" android:id="@+id/key"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:textSize="?attr/TextSizeInfo"
android:textColor="@color/ondarktext"
android:textAllCaps="true"
android:layout_marginRight="8dp"
/>

View File

@ -349,4 +349,6 @@
<string name="could_not_verify_fingerprint">Could not verify fingerprint</string> <string name="could_not_verify_fingerprint">Could not verify fingerprint</string>
<string name="manually_verify">Manually verify</string> <string name="manually_verify">Manually verify</string>
<string name="are_you_sure_verify_fingerprint">Are you sure that you want to verify your contacts OTR fingerprint?</string> <string name="are_you_sure_verify_fingerprint">Are you sure that you want to verify your contacts OTR fingerprint?</string>
<string name="pref_show_dynamic_tags">Show dynamic tags</string>
<string name="pref_show_dynamic_tags_summary">Display read-only tags underneath contacts</string>
</resources> </resources>

View File

@ -4,5 +4,8 @@
<item name="android:layout_height">1.5dp</item> <item name="android:layout_height">1.5dp</item>
<item name="android:background">@color/divider</item> <item name="android:background">@color/divider</item>
</style> </style>
<style name="Tag">
</style>
</resources> </resources>

View File

@ -73,6 +73,11 @@
android:key="send_button_status" android:key="send_button_status"
android:summary="@string/pref_use_send_button_to_indicate_status_summary" android:summary="@string/pref_use_send_button_to_indicate_status_summary"
android:title="@string/pref_use_send_button_to_indicate_status" /> android:title="@string/pref_use_send_button_to_indicate_status" />
<CheckBoxPreference
android:defaultValue="false"
android:key="show_dynamic_tags"
android:summary="@string/pref_show_dynamic_tags_summary"
android:title="@string/pref_show_dynamic_tags" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_advanced_options" > <PreferenceCategory android:title="@string/pref_advanced_options" >
<PreferenceScreen <PreferenceScreen