Search in sources :

Example 16 with AccountEntity

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();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Intent(android.content.Intent) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 17 with AccountEntity

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();
}
Also used : Status(com.keylesspalace.tusky.entity.Status) ClipboardManager(android.content.ClipboardManager) MenuItem(android.view.MenuItem) Intent(android.content.Intent) Menu(android.view.Menu) PopupMenu(androidx.appcompat.widget.PopupMenu) ClipData(android.content.ClipData) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 18 with AccountEntity

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);
}
Also used : Status(com.keylesspalace.tusky.entity.Status) LinkedHashSet(java.util.LinkedHashSet) ComposeOptions(com.keylesspalace.tusky.components.compose.ComposeActivity.ComposeOptions) Intent(android.content.Intent) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 19 with AccountEntity

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);
    }
}
Also used : AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 20 with AccountEntity

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()));
    }
}
Also used : AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Aggregations

AccountEntity (com.keylesspalace.tusky.db.AccountEntity)23 Intent (android.content.Intent)12 AccountManager (com.keylesspalace.tusky.db.AccountManager)9 ArrayList (java.util.ArrayList)4 NotificationManager (android.app.NotificationManager)3 Drawable (android.graphics.drawable.Drawable)3 MenuItem (android.view.MenuItem)3 Status (com.keylesspalace.tusky.entity.Status)3 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Bitmap (android.graphics.Bitmap)2 Bundle (android.os.Bundle)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 TabLayout (android.support.design.widget.TabLayout)2 ActionBar (android.support.v7.app.ActionBar)2 Toolbar (android.support.v7.widget.Toolbar)2 Log (android.util.Log)2 Menu (android.view.Menu)2 View (android.view.View)2 ImageView (android.widget.ImageView)2