refactored muc bookmark to extend element. keep all elements the server or other clients added before

This commit is contained in:
iNPUTmice 2014-10-06 00:33:52 +02:00
parent 6b3097ee27
commit b788b84c31
9 changed files with 78 additions and 93 deletions

View file

@ -7,46 +7,35 @@ import android.graphics.Bitmap;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
public class Bookmark implements ListItem { public class Bookmark extends Element implements ListItem {
private Account account; private Account account;
private String jid;
private String nick;
private String name;
private String password;
private boolean autojoin;
private boolean providePassword;
private Conversation mJoinedConversation; private Conversation mJoinedConversation;
public Bookmark(Account account, String jid) { public Bookmark(Account account, String jid) {
super("conference");
this.setAttribute("jid", jid);
this.account = account;
}
private Bookmark(Account account) {
super("conference");
this.account = account; this.account = account;
this.jid = jid;
} }
public static Bookmark parse(Element element, Account account) { public static Bookmark parse(Element element, Account account) {
Bookmark bookmark = new Bookmark(account, element.getAttribute("jid")); Bookmark bookmark = new Bookmark(account);
bookmark.setName(element.getAttribute("name")); bookmark.setAttributes(element.getAttributes());
String autojoin = element.getAttribute("autojoin"); bookmark.setChildren(element.getChildren());
if (autojoin != null
&& (autojoin.equals("true") || autojoin.equals("1"))) {
bookmark.setAutojoin(true);
} else {
bookmark.setAutojoin(false);
}
Element nick = element.findChild("nick");
if (nick != null) {
bookmark.setNick(nick.getContent());
}
Element password = element.findChild("password");
if (password != null) {
bookmark.setPassword(password.getContent());
bookmark.setProvidePassword(true);
}
return bookmark; return bookmark;
} }
public void setAutojoin(boolean autojoin) { public void setAutojoin(boolean autojoin) {
this.autojoin = autojoin; if (autojoin) {
this.setAttribute("autojoin", "true");
} else {
this.setAttribute("autojoin", "false");
}
} }
public void setName(String name) { public void setName(String name) {
@ -54,15 +43,18 @@ public class Bookmark implements ListItem {
} }
public void setNick(String nick) { public void setNick(String nick) {
this.nick = nick; Element element = this.findChild("nick");
if (element == null) {
element = this.addChild("nick");
}
element.setContent(nick);
} }
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; Element element = this.findChild("password");
} if (element != null) {
element.setContent(password);
private void setProvidePassword(boolean providePassword) { }
this.providePassword = providePassword;
} }
@Override @Override
@ -76,32 +68,45 @@ public class Bookmark implements ListItem {
if (this.mJoinedConversation != null if (this.mJoinedConversation != null
&& (this.mJoinedConversation.getMucOptions().getSubject() != null)) { && (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
return this.mJoinedConversation.getMucOptions().getSubject(); return this.mJoinedConversation.getMucOptions().getSubject();
} else if (name != null) { } else if (getName() != null) {
return name; return getName();
} else { } else {
return this.jid.split("@")[0]; return this.getJid().split("@")[0];
} }
} }
@Override @Override
public String getJid() { public String getJid() {
return this.jid.toLowerCase(Locale.US); String jid = this.getAttribute("jid");
if (jid != null) {
return jid.toLowerCase(Locale.US);
} else {
return null;
}
} }
public String getNick() { public String getNick() {
return this.nick; Element nick = this.findChild("nick");
if (nick != null) {
return nick.getContent();
} else {
return null;
}
} }
public boolean autojoin() { public boolean autojoin() {
return autojoin; String autojoin = this.getAttribute("autojoin");
return (autojoin != null && (autojoin.equalsIgnoreCase("true") || autojoin
.equalsIgnoreCase("1")));
} }
public String getPassword() { public String getPassword() {
return this.password; Element password = this.findChild("password");
} if (password != null) {
return password.getContent();
public boolean isProvidePassword() { } else {
return this.providePassword; return null;
}
} }
public boolean match(String needle) { public boolean match(String needle) {
@ -131,27 +136,7 @@ public class Bookmark implements ListItem {
} }
public String getName() { public String getName() {
return name; return this.getAttribute("name");
}
public Element toElement() {
Element element = new Element("conference");
element.setAttribute("jid", this.getJid());
if (this.getName() != null) {
element.setAttribute("name", this.getName());
}
if (this.autojoin) {
element.setAttribute("autojoin", "true");
} else {
element.setAttribute("autojoin", "false");
}
if (this.nick != null) {
element.addChild("nick").setContent(this.nick);
}
if (this.password != null && isProvidePassword()) {
element.addChild("password").setContent(this.password);
}
return element;
} }
public void unregisterConversation() { public void unregisterConversation() {

View file

@ -165,8 +165,7 @@ public class MucOptions {
} }
aboutToRename = false; aboutToRename = false;
} }
if (conversation.getBookmark() != null if (conversation.getBookmark() != null) {
&& conversation.getBookmark().isProvidePassword()) {
this.passwordChanged = false; this.passwordChanged = false;
} }
} else { } else {
@ -213,8 +212,7 @@ public class MucOptions {
this.error = ERROR_NICK_IN_USE; this.error = ERROR_NICK_IN_USE;
} }
} else if (error.hasChild("not-authorized")) { } else if (error.hasChild("not-authorized")) {
if (conversation.getBookmark() != null if (conversation.getBookmark() != null) {
&& conversation.getBookmark().isProvidePassword()) {
this.passwordChanged = true; this.passwordChanged = true;
} }
this.error = ERROR_PASSWORD_REQUIRED; this.error = ERROR_PASSWORD_REQUIRED;
@ -357,8 +355,7 @@ public class MucOptions {
} }
public void setPassword(String password) { public void setPassword(String password) {
if (conversation.getBookmark() != null if (conversation.getBookmark() != null) {
&& conversation.getBookmark().isProvidePassword()) {
conversation.getBookmark().setPassword(password); conversation.getBookmark().setPassword(password);
} else { } else {
this.password = password; this.password = password;
@ -367,7 +364,7 @@ public class MucOptions {
.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password); .setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
} }
public boolean isPasswordChanged() { public boolean isPasswordChanged2() {
return this.passwordChanged; return this.passwordChanged;
} }

View file

@ -73,7 +73,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
IqPacket response = mXmppConnectionService.getIqGenerator() IqPacket response = mXmppConnectionService.getIqGenerator()
.discoResponse(packet); .discoResponse(packet);
account.getXmppConnection().sendIqPacket(response, null); account.getXmppConnection().sendIqPacket(response, null);
} else if (packet.hasChild("ping","urn:xmpp:ping")) { } else if (packet.hasChild("ping", "urn:xmpp:ping")) {
IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT); IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT);
mXmppConnectionService.sendIqPacket(account, response, null); mXmppConnectionService.sendIqPacket(account, response, null);
} else { } else {

View file

@ -748,7 +748,7 @@ public class XmppConnectionService extends Service {
Element query = iqPacket.query("jabber:iq:private"); Element query = iqPacket.query("jabber:iq:private");
Element storage = query.addChild("storage", "storage:bookmarks"); Element storage = query.addChild("storage", "storage:bookmarks");
for (Bookmark bookmark : account.getBookmarks()) { for (Bookmark bookmark : account.getBookmarks()) {
storage.addChild(bookmark.toElement()); storage.addChild(bookmark);
} }
sendIqPacket(account, iqPacket, null); sendIqPacket(account, iqPacket, null);
} }
@ -1120,11 +1120,8 @@ public class XmppConnectionService extends Service {
public void providePasswordForMuc(Conversation conversation, String password) { public void providePasswordForMuc(Conversation conversation, String password) {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
conversation.getMucOptions().setPassword(password); conversation.getMucOptions().setPassword(password);
if (conversation.getBookmark() != null if (conversation.getBookmark() != null) {
&& conversation.getMucOptions().isPasswordChanged()) { conversation.getBookmark().setAutojoin(true);
if (!conversation.getBookmark().autojoin()) {
conversation.getBookmark().setAutojoin(true);
}
pushBookmarks(conversation.getAccount()); pushBookmarks(conversation.getAccount());
} }
databaseBackend.updateConversation(conversation); databaseBackend.updateConversation(conversation);

View file

@ -88,7 +88,7 @@ public class ConversationActivity extends XmppActivity implements
} }
public void setSelectedConversation(Conversation conversation) { public void setSelectedConversation(Conversation conversation) {
this.selectedConversation = conversation; this.selectedConversation = conversation;
} }
public ListView getConversationListView() { public ListView getConversationListView() {
@ -98,21 +98,21 @@ public class ConversationActivity extends XmppActivity implements
public boolean shouldPaneBeOpen() { public boolean shouldPaneBeOpen() {
return paneShouldBeOpen; return paneShouldBeOpen;
} }
public void showConversationsOverview() { public void showConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.openPane(); mSlidingPaneLayout.openPane();
} }
} }
public void hideConversationsOverview() { public void hideConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.closePane(); mSlidingPaneLayout.closePane();
} }
} }
public boolean isConversationsOverviewHideable() { public boolean isConversationsOverviewHideable() {
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
@ -121,7 +121,7 @@ public class ConversationActivity extends XmppActivity implements
return false; return false;
} }
} }
public boolean isConversationsOverviewVisable() { public boolean isConversationsOverviewVisable() {
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
@ -166,13 +166,14 @@ public class ConversationActivity extends XmppActivity implements
} }
}); });
mContentView = findViewById(R.id.content_view_spl); mContentView = findViewById(R.id.content_view_spl);
if (mContentView==null) { if (mContentView == null) {
mContentView = findViewById(R.id.content_view_ll); mContentView = findViewById(R.id.content_view_ll);
} }
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.setParallaxDistance(150); mSlidingPaneLayout.setParallaxDistance(150);
mSlidingPaneLayout.setShadowResource(R.drawable.es_slidingpane_shadow); mSlidingPaneLayout
.setShadowResource(R.drawable.es_slidingpane_shadow);
mSlidingPaneLayout.setSliderFadeColor(0); mSlidingPaneLayout.setSliderFadeColor(0);
mSlidingPaneLayout.setPanelSlideListener(new PanelSlideListener() { mSlidingPaneLayout.setPanelSlideListener(new PanelSlideListener() {
@ -253,7 +254,8 @@ public class ConversationActivity extends XmppActivity implements
.findItem(R.id.action_invite); .findItem(R.id.action_invite);
MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute); MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute);
if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) { if (isConversationsOverviewVisable()
&& isConversationsOverviewHideable()) {
menuArchive.setVisible(false); menuArchive.setVisible(false);
menuMucDetails.setVisible(false); menuMucDetails.setVisible(false);
menuContactDetails.setVisible(false); menuContactDetails.setVisible(false);
@ -669,7 +671,8 @@ public class ConversationActivity extends XmppActivity implements
public void onSaveInstanceState(Bundle savedInstanceState) { public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString(STATE_OPEN_CONVERSATION, savedInstanceState.putString(STATE_OPEN_CONVERSATION,
getSelectedConversation().getUuid()); getSelectedConversation().getUuid());
savedInstanceState.putBoolean(STATE_PANEL_OPEN, isConversationsOverviewVisable()); savedInstanceState.putBoolean(STATE_PANEL_OPEN,
isConversationsOverviewVisable());
super.onSaveInstanceState(savedInstanceState); super.onSaveInstanceState(savedInstanceState);
} }

View file

@ -403,7 +403,7 @@ public class StartConversationActivity extends XmppActivity {
String conferenceJid = jid.getText().toString(); String conferenceJid = jid.getText().toString();
Account account = xmppConnectionService Account account = xmppConnectionService
.findAccountByJid(accountJid); .findAccountByJid(accountJid);
if (account==null) { if (account == null) {
dialog.dismiss(); dialog.dismiss();
return; return;
} }

View file

@ -208,7 +208,8 @@ public abstract class XmppActivity extends Activity {
mColorOrange = getResources().getColor(R.color.orange); mColorOrange = getResources().getColor(R.color.orange);
mColorGreen = getResources().getColor(R.color.green); mColorGreen = getResources().getColor(R.color.green);
mPrimaryColor = getResources().getColor(R.color.primary); mPrimaryColor = getResources().getColor(R.color.primary);
mSecondaryBackgroundColor = getResources().getColor(R.color.secondarybackground); mSecondaryBackgroundColor = getResources().getColor(
R.color.secondarybackground);
if (getPreferences().getBoolean("use_larger_font", false)) { if (getPreferences().getBoolean("use_larger_font", false)) {
setTheme(R.style.ConversationsTheme_LargerText); setTheme(R.style.ConversationsTheme_LargerText);
} }
@ -520,7 +521,7 @@ public abstract class XmppActivity extends Activity {
public int getPrimaryColor() { public int getPrimaryColor() {
return this.mPrimaryColor; return this.mPrimaryColor;
} }
public int getSecondaryBackgroundColor() { public int getSecondaryBackgroundColor() {
return this.mSecondaryBackgroundColor; return this.mSecondaryBackgroundColor;
} }

View file

@ -42,7 +42,8 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
ConversationActivity activity = (ConversationActivity) this.activity; ConversationActivity activity = (ConversationActivity) this.activity;
if (!activity.isConversationsOverviewHideable()) { if (!activity.isConversationsOverviewHideable()) {
if (conv == activity.getSelectedConversation()) { if (conv == activity.getSelectedConversation()) {
view.setBackgroundColor(activity.getSecondaryBackgroundColor()); view.setBackgroundColor(activity
.getSecondaryBackgroundColor());
} else { } else {
view.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.TRANSPARENT);
} }

View file

@ -35,7 +35,8 @@ public class DNSHelper {
Bundle b = queryDNS(host, ip); Bundle b = queryDNS(host, ip);
if (b.containsKey("name")) { if (b.containsKey("name")) {
return b; return b;
} else if (b.containsKey("error") && "nosrv".equals(b.getString("error", null))) { } else if (b.containsKey("error")
&& "nosrv".equals(b.getString("error", null))) {
return b; return b;
} }
} }