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();
}
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();
}
}
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);
}
}
}
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);
}
}
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();
}
}
Aggregations