use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.
the class MainActivity method logout.
private void logout() {
AccountEntity activeAccount = accountManager.getActiveAccount();
if (activeAccount != null) {
new AlertDialog.Builder(this).setTitle(R.string.action_logout).setMessage(getString(R.string.action_logout_confirm, activeAccount.getFullName())).setPositiveButton(android.R.string.yes, (dialog, which) -> {
NotificationHelper.deleteNotificationChannelsForAccount(accountManager.getActiveAccount(), MainActivity.this);
AccountEntity newAccount = accountManager.logActiveAccountOut();
if (!NotificationHelper.areNotificationsEnabled(MainActivity.this))
disablePushNotifications();
Intent intent;
if (newAccount == null) {
intent = LoginActivity.getIntent(MainActivity.this, false);
} else {
intent = new Intent(MainActivity.this, MainActivity.class);
}
startActivity(intent);
finish();
}).setNegativeButton(android.R.string.no, null).show();
}
}
use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by Vavassor.
the class SFragment method more.
protected void more(@NonNull final Status status, View view, final int position) {
final String id = status.getActionableId();
final String accountId = status.getActionableStatus().getAccount().getId();
final String accountUsername = status.getActionableStatus().getAccount().getUsername();
final String statusUrl = status.getActionableStatus().getUrl();
List<AccountEntity> accounts = accountManager.getAllAccountsOrderedByActive();
String openAsTitle = null;
String loggedInAccountId = null;
AccountEntity activeAccount = accountManager.getActiveAccount();
if (activeAccount != null) {
loggedInAccountId = activeAccount.getAccountId();
}
PopupMenu popup = new PopupMenu(getContext(), view);
// Give a different menu depending on whether this is the user's own toot or not.
boolean statusIsByCurrentUser = loggedInAccountId != null && loggedInAccountId.equals(accountId);
if (statusIsByCurrentUser) {
popup.inflate(R.menu.status_more_for_user);
Menu menu = popup.getMenu();
switch(status.getVisibility()) {
case PUBLIC:
case UNLISTED:
{
final String textId = getString(status.isPinned() ? R.string.unpin_action : R.string.pin_action);
menu.add(0, R.id.pin, 1, textId);
break;
}
case PRIVATE:
{
boolean reblogged = status.getReblogged();
if (status.getReblog() != null)
reblogged = status.getReblog().getReblogged();
menu.findItem(R.id.status_reblog_private).setVisible(!reblogged);
menu.findItem(R.id.status_unreblog_private).setVisible(reblogged);
break;
}
}
} else {
popup.inflate(R.menu.status_more);
Menu menu = popup.getMenu();
menu.findItem(R.id.status_download_media).setVisible(!status.getAttachments().isEmpty());
}
Menu menu = popup.getMenu();
MenuItem openAsItem = menu.findItem(R.id.status_open_as);
switch(accounts.size()) {
case 0:
case 1:
openAsItem.setVisible(false);
break;
case 2:
for (AccountEntity account : accounts) {
if (account != activeAccount) {
openAsTitle = String.format(getString(R.string.action_open_as), account.getFullName());
break;
}
}
break;
default:
openAsTitle = String.format(getString(R.string.action_open_as), "…");
break;
}
openAsItem.setTitle(openAsTitle);
MenuItem muteConversationItem = menu.findItem(R.id.status_mute_conversation);
boolean mutable = statusIsByCurrentUser || accountIsInMentions(activeAccount, status.getMentions());
muteConversationItem.setVisible(mutable);
if (mutable) {
muteConversationItem.setTitle((status.getMuted() == null || !status.getMuted()) ? R.string.action_mute_conversation : R.string.action_unmute_conversation);
}
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.status_share_content:
{
Status statusToShare = status;
if (statusToShare.getReblog() != null)
statusToShare = statusToShare.getReblog();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
String stringToShare = statusToShare.getAccount().getUsername() + " - " + statusToShare.getContent().toString();
sendIntent.putExtra(Intent.EXTRA_TEXT, stringToShare);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, statusUrl);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_content_to)));
return true;
}
case R.id.status_share_link:
{
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, statusUrl);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to)));
return true;
}
case R.id.status_copy_link:
{
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(null, statusUrl);
clipboard.setPrimaryClip(clip);
return true;
}
case R.id.status_open_as:
{
showOpenAsDialog(statusUrl, item.getTitle());
return true;
}
case R.id.status_download_media:
{
requestDownloadAllMedia(status);
return true;
}
case R.id.status_mute:
{
onMute(accountId, accountUsername);
return true;
}
case R.id.status_block:
{
onBlock(accountId, accountUsername);
return true;
}
case R.id.status_report:
{
openReportPage(accountId, accountUsername, id);
return true;
}
case R.id.status_unreblog_private:
{
onReblog(false, position);
return true;
}
case R.id.status_reblog_private:
{
onReblog(true, position);
return true;
}
case R.id.status_delete:
{
showConfirmDeleteDialog(id, position);
return true;
}
case R.id.status_delete_and_redraft:
{
showConfirmEditDialog(id, position, status);
return true;
}
case R.id.pin:
{
timelineCases.pin(status.getId(), !status.isPinned()).to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))).subscribe();
return true;
}
case R.id.status_mute_conversation:
{
timelineCases.muteConversation(status.getId(), status.getMuted() == null || !status.getMuted()).onErrorReturnItem(status).observeOn(AndroidSchedulers.mainThread()).to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))).subscribe();
return true;
}
}
return false;
});
popup.show();
}
use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by Vavassor.
the class SFragment method reply.
protected void reply(Status status) {
String inReplyToId = status.getActionableId();
Status actionableStatus = status.getActionableStatus();
Status.Visibility replyVisibility = actionableStatus.getVisibility();
String contentWarning = actionableStatus.getSpoilerText();
List<Status.Mention> mentions = actionableStatus.getMentions();
Set<String> mentionedUsernames = new LinkedHashSet<>();
mentionedUsernames.add(actionableStatus.getAccount().getUsername());
String loggedInUsername = null;
AccountEntity activeAccount = accountManager.getActiveAccount();
if (activeAccount != null) {
loggedInUsername = activeAccount.getUsername();
}
for (Status.Mention mention : mentions) {
mentionedUsernames.add(mention.getUsername());
}
mentionedUsernames.remove(loggedInUsername);
ComposeOptions composeOptions = new ComposeOptions();
composeOptions.setInReplyToId(inReplyToId);
composeOptions.setReplyVisibility(replyVisibility);
composeOptions.setContentWarning(contentWarning);
composeOptions.setMentionedUsernames(mentionedUsernames);
composeOptions.setReplyingStatusAuthor(actionableStatus.getAccount().getLocalUsername());
composeOptions.setReplyingStatusContent(actionableStatus.getContent().toString());
Intent intent = ComposeActivity.startIntent(getContext(), composeOptions);
getActivity().startActivity(intent);
}
use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by Vavassor.
the class NotificationsFragment method saveNotificationsFilter.
private void saveNotificationsFilter() {
AccountEntity account = accountManager.getActiveAccount();
if (account != null) {
account.setNotificationsFilter(NotificationTypeConverterKt.serialize(notificationFilter));
accountManager.saveAccount(account);
}
}
use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by Vavassor.
the class NotificationsFragment method loadNotificationsFilter.
private void loadNotificationsFilter() {
AccountEntity account = accountManager.getActiveAccount();
if (account != null) {
notificationFilter.clear();
notificationFilter.addAll(NotificationTypeConverterKt.deserialize(account.getNotificationsFilter()));
}
}
Aggregations