Search in sources :

Example 11 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class NotificationHelper method clearNotificationsForActiveAccount.

public static void clearNotificationsForActiveAccount(Context context) {
    AccountManager accountManager = TuskyApplication.getInstance(context).getServiceLocator().get(AccountManager.class);
    AccountEntity account = accountManager.getActiveAccount();
    if (account != null) {
        account.setActiveNotifications("[]");
        accountManager.saveAccount(account);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // noinspection ConstantConditions
        notificationManager.cancel((int) account.getId());
    }
}
Also used : NotificationManager(android.app.NotificationManager) AccountManager(com.keylesspalace.tusky.db.AccountManager) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 12 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class AccountActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    avatar = findViewById(R.id.account_avatar);
    header = findViewById(R.id.account_header);
    floatingBtn = findViewById(R.id.floating_btn);
    followBtn = findViewById(R.id.follow_btn);
    followsYouView = findViewById(R.id.account_follows_you);
    tabLayout = findViewById(R.id.tab_layout);
    accountLockedView = findViewById(R.id.account_locked);
    container = findViewById(R.id.activity_account);
    followersTextView = findViewById(R.id.followers_tv);
    followingTextView = findViewById(R.id.following_tv);
    statusesTextView = findViewById(R.id.statuses_btn);
    if (savedInstanceState != null) {
        accountId = savedInstanceState.getString("accountId");
        followState = (FollowState) savedInstanceState.getSerializable("followState");
        blocking = savedInstanceState.getBoolean("blocking");
        muting = savedInstanceState.getBoolean("muting");
    } else {
        Intent intent = getIntent();
        accountId = intent.getStringExtra("id");
        followState = FollowState.NOT_FOLLOWING;
        blocking = false;
        muting = false;
    }
    loadedAccount = null;
    // Setup the toolbar.
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }
    hideFab = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fabHide", false);
    // Add a listener to change the toolbar icon color when it enters/exits its collapsed state.
    AppBarLayout appBarLayout = findViewById(R.id.account_app_bar_layout);
    final CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @AttrRes
        int priorAttribute = R.attr.account_toolbar_icon_tint_uncollapsed;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            @AttrRes int attribute;
            if (collapsingToolbar.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) {
                toolbar.setTitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorPrimary));
                toolbar.setSubtitleTextColor(ThemeUtils.getColor(AccountActivity.this, android.R.attr.textColorSecondary));
                attribute = R.attr.account_toolbar_icon_tint_collapsed;
            } else {
                toolbar.setTitleTextColor(Color.TRANSPARENT);
                toolbar.setSubtitleTextColor(Color.TRANSPARENT);
                attribute = R.attr.account_toolbar_icon_tint_uncollapsed;
            }
            if (attribute != priorAttribute) {
                priorAttribute = attribute;
                Context context = toolbar.getContext();
                ThemeUtils.setDrawableTint(context, toolbar.getNavigationIcon(), attribute);
                ThemeUtils.setDrawableTint(context, toolbar.getOverflowIcon(), attribute);
            }
            if (floatingBtn != null && hideFab && !isSelf && !blocking) {
                if (verticalOffset > oldOffset) {
                    floatingBtn.show();
                }
                if (verticalOffset < oldOffset) {
                    floatingBtn.hide();
                }
            }
            oldOffset = verticalOffset;
        }
    });
    // Initialise the default UI states.
    floatingBtn.hide();
    followBtn.setVisibility(View.GONE);
    followsYouView.setVisibility(View.GONE);
    // Obtain information to fill out the profile.
    obtainAccount();
    AccountEntity activeAccount = TuskyApplication.getInstance(this).getServiceLocator().get(AccountManager.class).getActiveAccount();
    if (accountId.equals(activeAccount.getAccountId())) {
        isSelf = true;
    } else {
        isSelf = false;
        obtainRelationships();
    }
    // Setup the tabs and timeline pager.
    AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), accountId);
    String[] pageTitles = { getString(R.string.title_statuses), getString(R.string.title_media) };
    adapter.setPageTitles(pageTitles);
    final ViewPager viewPager = findViewById(R.id.pager);
    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(0);
    tabLayout.setupWithViewPager(viewPager);
    View.OnClickListener accountListClickListener = v -> {
        AccountListActivity.Type type;
        switch(v.getId()) {
            case R.id.followers_tv:
                type = AccountListActivity.Type.FOLLOWERS;
                break;
            case R.id.following_tv:
                type = AccountListActivity.Type.FOLLOWING;
                break;
            default:
                throw new AssertionError();
        }
        Intent intent = AccountListActivity.newIntent(AccountActivity.this, type, accountId);
        startActivity(intent);
    };
    followersTextView.setOnClickListener(accountListClickListener);
    followingTextView.setOnClickListener(accountListClickListener);
    statusesTextView.setOnClickListener(v -> {
        // Make nice ripple effect on tab
        // noinspection ConstantConditions
        tabLayout.getTabAt(0).select();
        final View poorTabView = ((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0);
        poorTabView.setPressed(true);
        tabLayout.postDelayed(() -> poorTabView.setPressed(false), 300);
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Drawable(android.graphics.drawable.Drawable) Picasso(com.squareup.picasso.Picasso) Assert(com.keylesspalace.tusky.util.Assert) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) AttrRes(android.support.annotation.AttrRes) ViewCompat(android.support.v4.view.ViewCompat) Account(com.keylesspalace.tusky.entity.Account) PreferenceManager(android.preference.PreferenceManager) DispatchingAndroidInjector(dagger.android.DispatchingAndroidInjector) Log(android.util.Log) FloatingActionButton(android.support.design.widget.FloatingActionButton) AndroidInjector(dagger.android.AndroidInjector) Fragment(android.support.v4.app.Fragment) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) List(java.util.List) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) HasSupportFragmentInjector(dagger.android.support.HasSupportFragmentInjector) Call(retrofit2.Call) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Response(retrofit2.Response) NumberFormat(java.text.NumberFormat) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Menu(android.view.Menu) ActionBar(android.support.v7.app.ActionBar) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) DialogInterface(android.content.DialogInterface) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) TimelineReceiver(com.keylesspalace.tusky.receiver.TimelineReceiver) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) LinkListener(com.keylesspalace.tusky.interfaces.LinkListener) Color(android.graphics.Color) Callback(retrofit2.Callback) Toolbar(android.support.v7.widget.Toolbar) CircularImageView(com.pkmmte.view.CircularImageView) MastodonApi(com.keylesspalace.tusky.network.MastodonApi) AccountManager(com.keylesspalace.tusky.db.AccountManager) Collections(java.util.Collections) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AccountPagerAdapter(com.keylesspalace.tusky.pager.AccountPagerAdapter) ViewPager(android.support.v4.view.ViewPager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CircularImageView(com.pkmmte.view.CircularImageView) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) AttrRes(android.support.annotation.AttrRes) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AccountManager(com.keylesspalace.tusky.db.AccountManager) AppBarLayout(android.support.design.widget.AppBarLayout) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 13 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class BaseActivity method redirectIfNotLoggedIn.

protected boolean redirectIfNotLoggedIn() {
    // This is very ugly but we cannot inject into parent class and injecting into every
    // subclass seems inconvenient as well.
    AccountEntity account = ((TuskyApplication) getApplicationContext()).getServiceLocator().get(AccountManager.class).getActiveAccount();
    if (account == null) {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
        return true;
    }
    return false;
}
Also used : AccountManager(com.keylesspalace.tusky.db.AccountManager) Intent(android.content.Intent) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 14 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class ComposeActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose);
    replyTextView = findViewById(R.id.reply_tv);
    replyContentTextView = findViewById(R.id.reply_content_tv);
    textEditor = findViewById(R.id.compose_edit_field);
    mediaPreviewBar = findViewById(R.id.compose_media_preview_bar);
    contentWarningBar = findViewById(R.id.compose_content_warning_bar);
    contentWarningEditor = findViewById(R.id.field_content_warning);
    charactersLeft = findViewById(R.id.characters_left);
    floatingBtn = findViewById(R.id.floating_btn);
    pickButton = findViewById(R.id.compose_photo_pick);
    visibilityBtn = findViewById(R.id.action_toggle_visibility);
    saveButton = findViewById(R.id.compose_save_draft);
    hideMediaToggle = findViewById(R.id.action_hide_media);
    postProgress = findViewById(R.id.postProgress);
    // Setup the toolbar.
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
        ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
        actionBar.setHomeAsUpIndicator(closeIcon);
    }
    // setup the account image
    final AccountEntity activeAccount = accountManager.getActiveAccount();
    if (activeAccount != null) {
        ImageView composeAvatar = findViewById(R.id.composeAvatar);
        if (TextUtils.isEmpty(activeAccount.getProfilePictureUrl())) {
            composeAvatar.setImageResource(R.drawable.avatar_default);
        } else {
            Picasso.with(this).load(activeAccount.getProfilePictureUrl()).transform(new RoundedTransformation(25)).error(R.drawable.avatar_default).placeholder(R.drawable.avatar_default).into(composeAvatar);
        }
        composeAvatar.setContentDescription(getString(R.string.compose_active_account_description, activeAccount.getFullName()));
    } else {
        // do not do anything when not logged in, activity will be finished in super.onCreate() anyway
        return;
    }
    // Setup the interface buttons.
    floatingBtn.setOnClickListener(v -> onSendClicked());
    floatingBtn.setOnLongClickListener(v -> saveDraft());
    pickButton.setOnClickListener(v -> openPickDialog());
    visibilityBtn.setOnClickListener(v -> showComposeOptions());
    saveButton.setOnClickListener(v -> saveDraft());
    hideMediaToggle.setOnClickListener(v -> toggleHideMedia());
    // fix a bug with autocomplete and some keyboards
    int newInputType = textEditor.getInputType() & (textEditor.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
    textEditor.setInputType(newInputType);
    /* Initialise all the state, or restore it from a previous run, to determine a "starting"
         * state. */
    Status.Visibility startingVisibility = Status.Visibility.UNKNOWN;
    boolean startingHideText;
    String startingContentWarning = null;
    ArrayList<SavedQueuedMedia> savedMediaQueued = null;
    if (savedInstanceState != null) {
        showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive");
        startingVisibility = Status.Visibility.byNum(savedInstanceState.getInt("statusVisibility", Status.Visibility.PUBLIC.getNum()));
        statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
        startingHideText = savedInstanceState.getBoolean("statusHideText");
        // Keep these until everything needed to put them in the queue is finished initializing.
        savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
        // These are for restoring an in-progress commit content operation.
        InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat.wrap(savedInstanceState.getParcelable("commitContentInputContentInfo"));
        int previousFlags = savedInstanceState.getInt("commitContentFlags");
        if (previousInputContentInfo != null) {
            onCommitContentInternal(previousInputContentInfo, previousFlags);
        }
        photoUploadUri = savedInstanceState.getParcelable("photoUploadUri");
    } else {
        showMarkSensitive = false;
        statusMarkSensitive = false;
        startingHideText = false;
        photoUploadUri = null;
    }
    /* If the composer is started up as a reply to another post, override the "starting" state
         * based on what the intent from the reply request passes. */
    Intent intent = getIntent();
    String[] mentionedUsernames = null;
    ArrayList<String> loadedDraftMediaUris = null;
    inReplyToId = null;
    if (intent != null) {
        if (startingVisibility == Status.Visibility.UNKNOWN) {
            Status.Visibility replyVisibility = Status.Visibility.byNum(intent.getIntExtra(REPLY_VISIBILITY_EXTRA, Status.Visibility.UNKNOWN.getNum()));
            if (replyVisibility != Status.Visibility.UNKNOWN) {
                startingVisibility = replyVisibility;
            } else {
                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
                startingVisibility = Status.Visibility.byString(preferences.getString("defaultPostPrivacy", Status.Visibility.PUBLIC.serverString()));
            }
        }
        inReplyToId = intent.getStringExtra(IN_REPLY_TO_ID_EXTRA);
        mentionedUsernames = intent.getStringArrayExtra(MENTIONED_USERNAMES_EXTRA);
        String contentWarning = intent.getStringExtra(CONTENT_WARNING_EXTRA);
        if (contentWarning != null) {
            startingHideText = !contentWarning.isEmpty();
            if (startingHideText) {
                startingContentWarning = contentWarning;
            }
        }
        // If come from SavedTootActivity
        String savedTootText = intent.getStringExtra(SAVED_TOOT_TEXT_EXTRA);
        if (!TextUtils.isEmpty(savedTootText)) {
            textEditor.append(savedTootText);
        }
        String savedJsonUrls = intent.getStringExtra(SAVED_JSON_URLS_EXTRA);
        if (!TextUtils.isEmpty(savedJsonUrls)) {
            // try to redo a list of media
            loadedDraftMediaUris = new Gson().fromJson(savedJsonUrls, new TypeToken<ArrayList<String>>() {
            }.getType());
        }
        int savedTootUid = intent.getIntExtra(SAVED_TOOT_UID_EXTRA, 0);
        if (savedTootUid != 0) {
            this.savedTootUid = savedTootUid;
        }
        if (intent.hasExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA)) {
            replyTextView.setVisibility(View.VISIBLE);
            String username = intent.getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA);
            replyTextView.setText(getString(R.string.replying_to, username));
            replyTextView.setOnClickListener(v -> {
                if (replyContentTextView.getVisibility() != View.VISIBLE) {
                    replyContentTextView.setVisibility(View.VISIBLE);
                } else {
                    replyContentTextView.setVisibility(View.GONE);
                }
            });
        }
        if (intent.hasExtra(REPLYING_STATUS_CONTENT_EXTRA)) {
            replyContentTextView.setText(intent.getStringExtra(REPLYING_STATUS_CONTENT_EXTRA));
        }
    }
    // After the starting state is finalised, the interface can be set to reflect this state.
    setStatusVisibility(startingVisibility);
    postProgress.setVisibility(View.INVISIBLE);
    updateHideMediaToggleColor();
    updateVisibleCharactersLeft();
    // Setup the main text field.
    // new String[] { "image/gif", "image/webp" }
    setEditTextMimeTypes();
    final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
    SpanUtils.highlightSpans(textEditor.getText(), mentionColour);
    textEditor.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            SpanUtils.highlightSpans(editable, mentionColour);
        }
    });
    textEditor.setAdapter(new MentionAutoCompleteAdapter(this, R.layout.item_autocomplete, this));
    textEditor.setTokenizer(new MentionTokenizer());
    // Add any mentions to the text field when a reply is first composed.
    if (mentionedUsernames != null) {
        StringBuilder builder = new StringBuilder();
        for (String name : mentionedUsernames) {
            builder.append('@');
            builder.append(name);
            builder.append(' ');
        }
        textEditor.setText(builder);
        textEditor.setSelection(textEditor.length());
    }
    // Initialise the content warning editor.
    contentWarningEditor.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    showContentWarning(startingHideText);
    if (startingContentWarning != null) {
        contentWarningEditor.setText(startingContentWarning);
    }
    // Initialise the empty media queue state.
    waitForMediaLatch = new CountUpDownLatch();
    statusAlreadyInFlight = false;
    // These can only be added after everything affected by the media queue is initialized.
    if (!ListUtils.isEmpty(loadedDraftMediaUris)) {
        for (String uriString : loadedDraftMediaUris) {
            Uri uri = Uri.parse(uriString);
            long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri);
            pickMedia(uri, mediaSize);
        }
    } else if (savedMediaQueued != null) {
        for (SavedQueuedMedia item : savedMediaQueued) {
            Bitmap preview = MediaUtils.getImageThumbnail(getContentResolver(), item.uri, THUMBNAIL_SIZE);
            addMediaToQueue(item.type, preview, item.uri, item.mediaSize, item.readyStage, item.description);
        }
    } else if (intent != null && savedInstanceState == null) {
        /* Get incoming images being sent through a share action from another app. Only do this
             * when savedInstanceState is null, otherwise both the images from the intent and the
             * instance state will be re-queued. */
        String type = intent.getType();
        if (type != null) {
            if (type.startsWith("image/")) {
                List<Uri> uriList = new ArrayList<>();
                if (intent.getAction() != null) {
                    switch(intent.getAction()) {
                        case Intent.ACTION_SEND:
                            {
                                Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                                if (uri != null) {
                                    uriList.add(uri);
                                }
                                break;
                            }
                        case Intent.ACTION_SEND_MULTIPLE:
                            {
                                ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                                if (list != null) {
                                    for (Uri uri : list) {
                                        if (uri != null) {
                                            uriList.add(uri);
                                        }
                                    }
                                }
                                break;
                            }
                    }
                }
                for (Uri uri : uriList) {
                    long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri);
                    pickMedia(uri, mediaSize);
                }
            } else if (type.equals("text/plain")) {
                String action = intent.getAction();
                if (action != null && action.equals(Intent.ACTION_SEND)) {
                    String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                    if (text != null) {
                        int start = Math.max(textEditor.getSelectionStart(), 0);
                        int end = Math.max(textEditor.getSelectionEnd(), 0);
                        int left = Math.min(start, end);
                        int right = Math.max(start, end);
                        textEditor.getText().replace(left, right, text, 0, text.length());
                    }
                }
            }
        }
    }
    textEditor.requestFocus();
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) MentionAutoCompleteAdapter(com.keylesspalace.tusky.adapter.MentionAutoCompleteAdapter) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) CountUpDownLatch(com.keylesspalace.tusky.util.CountUpDownLatch) Uri(android.net.Uri) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) Bitmap(android.graphics.Bitmap) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ImageView(android.widget.ImageView) ProgressImageView(com.keylesspalace.tusky.view.ProgressImageView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) Status(com.keylesspalace.tusky.entity.Status) SharedPreferences(android.content.SharedPreferences) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) MentionTokenizer(com.keylesspalace.tusky.util.MentionTokenizer) RoundedTransformation(com.keylesspalace.tusky.view.RoundedTransformation)

Example 15 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class MainActivity method updateProfiles.

private void updateProfiles() {
    List<AccountEntity> allAccounts = accountManager.getAllAccountsOrderedByActive();
    // remove profiles before adding them again to avoid duplicates
    List<IProfile> profiles = new ArrayList<>(headerResult.getProfiles());
    for (IProfile profile : profiles) {
        if (profile.getIdentifier() != DRAWER_ITEM_ADD_ACCOUNT) {
            headerResult.removeProfile(profile);
        }
    }
    for (AccountEntity acc : allAccounts) {
        headerResult.addProfiles(new ProfileDrawerItem().withName(acc.getDisplayName()).withIcon(acc.getProfilePictureUrl()).withNameShown(true).withIdentifier(acc.getId()).withEmail(acc.getFullName()));
    }
}
Also used : ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) ArrayList(java.util.ArrayList) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) 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