Search in sources :

Example 6 with AccountEntity

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

the class SplashActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /* Determine whether the user is currently logged in, and if so go ahead and load the
         * timeline. Otherwise, start the activity_login screen. */
    NotificationHelper.deleteLegacyNotificationChannels(this);
    AccountEntity activeAccount = TuskyApplication.getInstance(this).getServiceLocator().get(AccountManager.class).getActiveAccount();
    Intent intent;
    if (activeAccount != null) {
        intent = new Intent(this, MainActivity.class);
    } else {
        intent = LoginActivity.getIntent(this, false);
    }
    startActivity(intent);
    finish();
}
Also used : AccountManager(com.keylesspalace.tusky.db.AccountManager) Intent(android.content.Intent) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 7 with AccountEntity

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

the class NotificationHelper method clearNotificationsForActiveAccount.

public static void clearNotificationsForActiveAccount(@NonNull Context context, @NonNull AccountManager accountManager) {
    AccountEntity account = accountManager.getActiveAccount();
    if (account != null && !account.getActiveNotifications().equals("[]")) {
        Single.fromCallable(() -> {
            account.setActiveNotifications("[]");
            accountManager.saveAccount(account);
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            // noinspection ConstantConditions
            notificationManager.cancel((int) account.getId());
            return true;
        }).subscribeOn(Schedulers.io()).subscribe();
    }
}
Also used : NotificationManager(android.app.NotificationManager) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 8 with AccountEntity

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

the class NotificationsFragment method saveNewestNotificationId.

private void saveNewestNotificationId(List<Notification> notifications) {
    AccountEntity account = accountManager.getActiveAccount();
    if (account != null) {
        String lastNotificationId = account.getLastNotificationId();
        for (Notification noti : notifications) {
            if (isLessThan(lastNotificationId, noti.getId())) {
                lastNotificationId = noti.getId();
            }
        }
        if (!account.getLastNotificationId().equals(lastNotificationId)) {
            Log.d(TAG, "saving newest noti id: " + lastNotificationId);
            account.setLastNotificationId(lastNotificationId);
            accountManager.saveAccount(account);
        }
    }
}
Also used : AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Notification(com.keylesspalace.tusky.entity.Notification)

Example 9 with AccountEntity

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

the class InstanceSwitchAuthInterceptor method intercept.

@Override
public Response intercept(@NonNull Chain chain) throws IOException {
    Request originalRequest = chain.request();
    // only switch domains if the request comes from retrofit
    if (originalRequest.url().host().equals(MastodonApi.PLACEHOLDER_DOMAIN)) {
        AccountEntity currentAccount = accountManager.getActiveAccount();
        Request.Builder builder = originalRequest.newBuilder();
        String instanceHeader = originalRequest.header(MastodonApi.DOMAIN_HEADER);
        if (instanceHeader != null) {
            // use domain explicitly specified in custom header
            builder.url(swapHost(originalRequest.url(), instanceHeader));
            builder.removeHeader(MastodonApi.DOMAIN_HEADER);
        } else if (currentAccount != null) {
            // use domain of current account
            builder.url(swapHost(originalRequest.url(), currentAccount.getDomain())).header("Authorization", String.format("Bearer %s", currentAccount.getAccessToken()));
        }
        Request newRequest = builder.build();
        return chain.proceed(newRequest);
    } else {
        return chain.proceed(originalRequest);
    }
}
Also used : Request(okhttp3.Request) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 10 with AccountEntity

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

the class SFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    AccountEntity activeAccount = TuskyApplication.getInstance(getContext()).getServiceLocator().get(AccountManager.class).getActiveAccount();
    if (activeAccount != null) {
        loggedInAccountId = activeAccount.getAccountId();
        loggedInUsername = activeAccount.getUsername();
    }
}
Also used : AccountManager(com.keylesspalace.tusky.db.AccountManager) 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