mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-06 17:25:01 -05:00
refactored muc bookmark to extend element. keep all elements the server or other clients added before
This commit is contained in:
parent
6b3097ee27
commit
b788b84c31
@ -7,46 +7,35 @@ import android.graphics.Bitmap;
|
||||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import eu.siacs.conversations.xml.Element;
|
||||
|
||||
public class Bookmark implements ListItem {
|
||||
public class Bookmark extends Element implements ListItem {
|
||||
|
||||
private Account account;
|
||||
private String jid;
|
||||
private String nick;
|
||||
private String name;
|
||||
private String password;
|
||||
private boolean autojoin;
|
||||
private boolean providePassword;
|
||||
private Conversation mJoinedConversation;
|
||||
|
||||
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.jid = jid;
|
||||
}
|
||||
|
||||
public static Bookmark parse(Element element, Account account) {
|
||||
Bookmark bookmark = new Bookmark(account, element.getAttribute("jid"));
|
||||
bookmark.setName(element.getAttribute("name"));
|
||||
String autojoin = element.getAttribute("autojoin");
|
||||
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);
|
||||
}
|
||||
Bookmark bookmark = new Bookmark(account);
|
||||
bookmark.setAttributes(element.getAttributes());
|
||||
bookmark.setChildren(element.getChildren());
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
public void setAutojoin(boolean autojoin) {
|
||||
this.autojoin = autojoin;
|
||||
if (autojoin) {
|
||||
this.setAttribute("autojoin", "true");
|
||||
} else {
|
||||
this.setAttribute("autojoin", "false");
|
||||
}
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
@ -54,15 +43,18 @@ public class Bookmark implements ListItem {
|
||||
}
|
||||
|
||||
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) {
|
||||
this.password = password;
|
||||
Element element = this.findChild("password");
|
||||
if (element != null) {
|
||||
element.setContent(password);
|
||||
}
|
||||
|
||||
private void setProvidePassword(boolean providePassword) {
|
||||
this.providePassword = providePassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,32 +68,45 @@ public class Bookmark implements ListItem {
|
||||
if (this.mJoinedConversation != null
|
||||
&& (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
|
||||
return this.mJoinedConversation.getMucOptions().getSubject();
|
||||
} else if (name != null) {
|
||||
return name;
|
||||
} else if (getName() != null) {
|
||||
return getName();
|
||||
} else {
|
||||
return this.jid.split("@")[0];
|
||||
return this.getJid().split("@")[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
return this.nick;
|
||||
Element nick = this.findChild("nick");
|
||||
if (nick != null) {
|
||||
return nick.getContent();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean autojoin() {
|
||||
return autojoin;
|
||||
String autojoin = this.getAttribute("autojoin");
|
||||
return (autojoin != null && (autojoin.equalsIgnoreCase("true") || autojoin
|
||||
.equalsIgnoreCase("1")));
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
Element password = this.findChild("password");
|
||||
if (password != null) {
|
||||
return password.getContent();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isProvidePassword() {
|
||||
return this.providePassword;
|
||||
}
|
||||
|
||||
public boolean match(String needle) {
|
||||
@ -131,27 +136,7 @@ public class Bookmark implements ListItem {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return 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;
|
||||
return this.getAttribute("name");
|
||||
}
|
||||
|
||||
public void unregisterConversation() {
|
||||
|
@ -165,8 +165,7 @@ public class MucOptions {
|
||||
}
|
||||
aboutToRename = false;
|
||||
}
|
||||
if (conversation.getBookmark() != null
|
||||
&& conversation.getBookmark().isProvidePassword()) {
|
||||
if (conversation.getBookmark() != null) {
|
||||
this.passwordChanged = false;
|
||||
}
|
||||
} else {
|
||||
@ -213,8 +212,7 @@ public class MucOptions {
|
||||
this.error = ERROR_NICK_IN_USE;
|
||||
}
|
||||
} else if (error.hasChild("not-authorized")) {
|
||||
if (conversation.getBookmark() != null
|
||||
&& conversation.getBookmark().isProvidePassword()) {
|
||||
if (conversation.getBookmark() != null) {
|
||||
this.passwordChanged = true;
|
||||
}
|
||||
this.error = ERROR_PASSWORD_REQUIRED;
|
||||
@ -357,8 +355,7 @@ public class MucOptions {
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
if (conversation.getBookmark() != null
|
||||
&& conversation.getBookmark().isProvidePassword()) {
|
||||
if (conversation.getBookmark() != null) {
|
||||
conversation.getBookmark().setPassword(password);
|
||||
} else {
|
||||
this.password = password;
|
||||
@ -367,7 +364,7 @@ public class MucOptions {
|
||||
.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
|
||||
}
|
||||
|
||||
public boolean isPasswordChanged() {
|
||||
public boolean isPasswordChanged2() {
|
||||
return this.passwordChanged;
|
||||
}
|
||||
|
||||
|
@ -748,7 +748,7 @@ public class XmppConnectionService extends Service {
|
||||
Element query = iqPacket.query("jabber:iq:private");
|
||||
Element storage = query.addChild("storage", "storage:bookmarks");
|
||||
for (Bookmark bookmark : account.getBookmarks()) {
|
||||
storage.addChild(bookmark.toElement());
|
||||
storage.addChild(bookmark);
|
||||
}
|
||||
sendIqPacket(account, iqPacket, null);
|
||||
}
|
||||
@ -1120,11 +1120,8 @@ public class XmppConnectionService extends Service {
|
||||
public void providePasswordForMuc(Conversation conversation, String password) {
|
||||
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
conversation.getMucOptions().setPassword(password);
|
||||
if (conversation.getBookmark() != null
|
||||
&& conversation.getMucOptions().isPasswordChanged()) {
|
||||
if (!conversation.getBookmark().autojoin()) {
|
||||
if (conversation.getBookmark() != null) {
|
||||
conversation.getBookmark().setAutojoin(true);
|
||||
}
|
||||
pushBookmarks(conversation.getAccount());
|
||||
}
|
||||
databaseBackend.updateConversation(conversation);
|
||||
|
@ -172,7 +172,8 @@ public class ConversationActivity extends XmppActivity implements
|
||||
if (mContentView instanceof SlidingPaneLayout) {
|
||||
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
|
||||
mSlidingPaneLayout.setParallaxDistance(150);
|
||||
mSlidingPaneLayout.setShadowResource(R.drawable.es_slidingpane_shadow);
|
||||
mSlidingPaneLayout
|
||||
.setShadowResource(R.drawable.es_slidingpane_shadow);
|
||||
mSlidingPaneLayout.setSliderFadeColor(0);
|
||||
mSlidingPaneLayout.setPanelSlideListener(new PanelSlideListener() {
|
||||
|
||||
@ -253,7 +254,8 @@ public class ConversationActivity extends XmppActivity implements
|
||||
.findItem(R.id.action_invite);
|
||||
MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute);
|
||||
|
||||
if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) {
|
||||
if (isConversationsOverviewVisable()
|
||||
&& isConversationsOverviewHideable()) {
|
||||
menuArchive.setVisible(false);
|
||||
menuMucDetails.setVisible(false);
|
||||
menuContactDetails.setVisible(false);
|
||||
@ -669,7 +671,8 @@ public class ConversationActivity extends XmppActivity implements
|
||||
public void onSaveInstanceState(Bundle savedInstanceState) {
|
||||
savedInstanceState.putString(STATE_OPEN_CONVERSATION,
|
||||
getSelectedConversation().getUuid());
|
||||
savedInstanceState.putBoolean(STATE_PANEL_OPEN, isConversationsOverviewVisable());
|
||||
savedInstanceState.putBoolean(STATE_PANEL_OPEN,
|
||||
isConversationsOverviewVisable());
|
||||
super.onSaveInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,8 @@ public abstract class XmppActivity extends Activity {
|
||||
mColorOrange = getResources().getColor(R.color.orange);
|
||||
mColorGreen = getResources().getColor(R.color.green);
|
||||
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)) {
|
||||
setTheme(R.style.ConversationsTheme_LargerText);
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|
||||
ConversationActivity activity = (ConversationActivity) this.activity;
|
||||
if (!activity.isConversationsOverviewHideable()) {
|
||||
if (conv == activity.getSelectedConversation()) {
|
||||
view.setBackgroundColor(activity.getSecondaryBackgroundColor());
|
||||
view.setBackgroundColor(activity
|
||||
.getSecondaryBackgroundColor());
|
||||
} else {
|
||||
view.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
@ -35,7 +35,8 @@ public class DNSHelper {
|
||||
Bundle b = queryDNS(host, ip);
|
||||
if (b.containsKey("name")) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user