MUC: option to set/delete bookmark in conference details.

This commit is contained in:
Michael 2014-11-23 21:36:44 +01:00
parent 49403fda84
commit 31b539daf7
2 changed files with 49 additions and 0 deletions

View file

@ -27,6 +27,8 @@ import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.entities.MucOptions.User;
@ -149,6 +151,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}); });
} }
break; break;
case R.id.action_save_as_bookmark:
saveAsBookmark();
break;
case R.id.action_delete_bookmark:
deleteBookmark();
break;
} }
return super.onOptionsItemSelected(menuItem); return super.onOptionsItemSelected(menuItem);
} }
@ -175,6 +183,21 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} }
} }
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
Account account = mConversation.getAccount();
if (account.hasBookmarkFor(mConversation.getContactJid().toBareJid())) {
menuItemSaveBookmark.setVisible(false);
menuItemDeleteBookmark.setVisible(true);
} else {
menuItemDeleteBookmark.setVisible(false);
menuItemSaveBookmark.setVisible(true);
}
return true;
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.muc_details, menu); getMenuInflater().inflate(R.menu.muc_details, menu);
@ -224,6 +247,22 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} }
} }
protected void saveAsBookmark() {
Account account = mConversation.getAccount();
Bookmark bookmark = new Bookmark(account, mConversation.getContactJid().toBareJid());
account.getBookmarks().add(bookmark);
xmppConnectionService.pushBookmarks(account);
mConversation.setBookmark(bookmark);
}
protected void deleteBookmark() {
Account account = mConversation.getAccount();
Bookmark bookmark = mConversation.getBookmark();
bookmark.unregisterConversation();
account.getBookmarks().remove(bookmark);
xmppConnectionService.pushBookmarks(account);
}
@Override @Override
void onBackendConnected() { void onBackendConnected() {
if (getIntent().getAction().equals(ACTION_VIEW_MUC)) { if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {

View file

@ -11,6 +11,16 @@
android:id="@+id/action_show_qr_code" android:id="@+id/action_show_qr_code"
android:title="@string/show_qr_code" android:title="@string/show_qr_code"
android:showAsAction="never" /> android:showAsAction="never" />
<item
android:id="@+id/action_save_as_bookmark"
android:title="@string/save_as_bookmark"
android:orderInCategory="80"
android:showAsAction="never" />
<item
android:id="@+id/action_delete_bookmark"
android:title="@string/delete_bookmark"
android:orderInCategory="80"
android:showAsAction="never" />
<item <item
android:id="@+id/action_accounts" android:id="@+id/action_accounts"
android:orderInCategory="90" android:orderInCategory="90"