2017-05-03 20:29:33 +02:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky;
|
|
|
|
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.lifecycle.Lifecycle;
|
2019-04-08 15:40:16 +02:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
import android.content.Intent;
|
2017-12-08 12:15:46 +01:00
|
|
|
import android.graphics.Color;
|
2017-05-03 20:29:33 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2019-04-08 15:40:16 +02:00
|
|
|
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.annotation.Nullable;
|
2019-04-08 15:40:16 +02:00
|
|
|
|
2019-04-16 21:39:12 +02:00
|
|
|
import com.bumptech.glide.Glide;
|
2018-12-17 15:25:35 +01:00
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
import com.google.android.material.tabs.TabLayout;
|
2019-04-08 15:40:16 +02:00
|
|
|
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.emoji.text.EmojiCompat;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2019-04-08 15:40:16 +02:00
|
|
|
|
2018-12-05 22:37:04 +01:00
|
|
|
import android.os.Handler;
|
2019-05-26 08:46:08 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2017-05-23 21:34:31 +02:00
|
|
|
import android.util.Log;
|
2017-06-25 03:21:57 +02:00
|
|
|
import android.view.KeyEvent;
|
2017-06-20 02:50:40 +02:00
|
|
|
import android.widget.ImageButton;
|
2017-05-03 20:29:33 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import com.keylesspalace.tusky.appstore.CacheUpdater;
|
2018-08-15 20:47:09 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.EventHub;
|
2019-02-12 19:22:37 +01:00
|
|
|
import com.keylesspalace.tusky.appstore.MainTabsChangedEvent;
|
2018-08-15 20:47:09 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.ProfileEditedEvent;
|
2019-02-13 19:21:04 +01:00
|
|
|
import com.keylesspalace.tusky.components.conversation.ConversationsRepository;
|
2019-07-19 20:10:20 +02:00
|
|
|
import com.keylesspalace.tusky.components.search.SearchActivity;
|
2018-02-03 22:45:14 +01:00
|
|
|
import com.keylesspalace.tusky.db.AccountEntity;
|
2017-05-03 20:29:33 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Account;
|
2019-07-08 12:57:53 +02:00
|
|
|
import com.keylesspalace.tusky.fragment.SFragment;
|
2017-08-04 11:44:10 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
2019-04-08 15:40:16 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.ReselectableFragment;
|
2019-02-12 19:22:37 +01:00
|
|
|
import com.keylesspalace.tusky.pager.MainPagerAdapter;
|
2018-07-30 15:43:27 +02:00
|
|
|
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
2018-02-12 22:03:08 +01:00
|
|
|
import com.keylesspalace.tusky.util.NotificationHelper;
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
2017-05-03 20:29:33 +02:00
|
|
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
|
|
|
import com.mikepenz.materialdrawer.AccountHeader;
|
|
|
|
import com.mikepenz.materialdrawer.AccountHeaderBuilder;
|
|
|
|
import com.mikepenz.materialdrawer.Drawer;
|
|
|
|
import com.mikepenz.materialdrawer.DrawerBuilder;
|
|
|
|
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
|
|
|
|
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
|
|
|
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
2018-02-03 22:45:14 +01:00
|
|
|
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem;
|
2017-05-03 20:29:33 +02:00
|
|
|
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
|
|
|
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
|
|
|
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
|
|
|
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
|
|
|
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-03-27 19:47:00 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
import dagger.android.AndroidInjector;
|
|
|
|
import dagger.android.DispatchingAndroidInjector;
|
2019-06-09 19:48:04 +02:00
|
|
|
import dagger.android.HasAndroidInjector;
|
2018-08-15 20:47:09 +02:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
2017-05-03 20:29:33 +02:00
|
|
|
|
2018-10-01 11:50:17 +02:00
|
|
|
import static com.keylesspalace.tusky.util.MediaUtilsKt.deleteStaleCachedMedia;
|
2018-08-15 20:47:09 +02:00
|
|
|
import static com.uber.autodispose.AutoDispose.autoDisposable;
|
|
|
|
import static com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from;
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
public final class MainActivity extends BottomSheetActivity implements ActionButtonActivity,
|
2019-06-09 19:48:04 +02:00
|
|
|
HasAndroidInjector {
|
2018-07-30 15:43:27 +02:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
private static final String TAG = "MainActivity"; // logging tag
|
2018-02-03 22:45:14 +01:00
|
|
|
private static final long DRAWER_ITEM_ADD_ACCOUNT = -13;
|
2017-06-19 21:47:53 +02:00
|
|
|
private static final long DRAWER_ITEM_EDIT_PROFILE = 0;
|
|
|
|
private static final long DRAWER_ITEM_FAVOURITES = 1;
|
2018-11-12 21:09:39 +01:00
|
|
|
private static final long DRAWER_ITEM_LISTS = 2;
|
|
|
|
private static final long DRAWER_ITEM_SEARCH = 3;
|
|
|
|
private static final long DRAWER_ITEM_SAVED_TOOT = 4;
|
|
|
|
private static final long DRAWER_ITEM_ACCOUNT_SETTINGS = 5;
|
|
|
|
private static final long DRAWER_ITEM_SETTINGS = 6;
|
|
|
|
private static final long DRAWER_ITEM_ABOUT = 7;
|
|
|
|
private static final long DRAWER_ITEM_LOG_OUT = 8;
|
|
|
|
private static final long DRAWER_ITEM_FOLLOW_REQUESTS = 9;
|
2019-01-16 20:50:09 +01:00
|
|
|
public static final String STATUS_URL = "statusUrl";
|
2017-05-03 20:29:33 +02:00
|
|
|
|
2018-03-27 19:47:00 +02:00
|
|
|
@Inject
|
2019-06-09 19:48:04 +02:00
|
|
|
public DispatchingAndroidInjector<Object> androidInjector;
|
2018-08-15 20:47:09 +02:00
|
|
|
@Inject
|
|
|
|
public EventHub eventHub;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
@Inject
|
|
|
|
public CacheUpdater cacheUpdater;
|
2019-02-13 19:21:04 +01:00
|
|
|
@Inject
|
|
|
|
ConversationsRepository conversationRepository;
|
2018-03-27 19:47:00 +02:00
|
|
|
|
2017-08-04 11:44:10 +02:00
|
|
|
private FloatingActionButton composeButton;
|
2017-05-03 20:29:33 +02:00
|
|
|
private AccountHeader headerResult;
|
|
|
|
private Drawer drawer;
|
2019-02-12 19:22:37 +01:00
|
|
|
private TabLayout tabLayout;
|
2017-06-22 20:59:12 +02:00
|
|
|
private ViewPager viewPager;
|
2017-05-03 20:29:33 +02:00
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
private int notificationTabPosition;
|
2019-04-08 15:40:16 +02:00
|
|
|
private MainPagerAdapter adapter;
|
2019-02-06 10:23:02 +01:00
|
|
|
|
2019-07-10 21:10:07 +02:00
|
|
|
private final EmojiCompat.InitCallback emojiInitCallback = new EmojiCompat.InitCallback() {
|
|
|
|
@Override
|
|
|
|
public void onInitialized() {
|
2019-07-16 19:27:26 +02:00
|
|
|
if(!isDestroyed()) {
|
|
|
|
updateProfiles();
|
|
|
|
}
|
2019-07-10 21:10:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2018-04-22 20:40:52 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2019-04-08 15:40:16 +02:00
|
|
|
if (accountManager.getActiveAccount() == null) {
|
2019-03-03 21:27:34 +01:00
|
|
|
// will be redirected to LoginActivity by BaseActivity
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-03 22:45:14 +01:00
|
|
|
Intent intent = getIntent();
|
2019-02-12 19:22:37 +01:00
|
|
|
boolean showNotificationTab = false;
|
2018-02-12 22:03:08 +01:00
|
|
|
|
2018-02-03 22:45:14 +01:00
|
|
|
if (intent != null) {
|
2018-02-12 22:03:08 +01:00
|
|
|
long accountId = intent.getLongExtra(NotificationHelper.ACCOUNT_ID, -1);
|
2019-02-06 10:23:02 +01:00
|
|
|
boolean accountRequested = (accountId != -1);
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2019-02-06 10:23:02 +01:00
|
|
|
if (accountRequested) {
|
2018-03-09 22:02:32 +01:00
|
|
|
AccountEntity account = accountManager.getActiveAccount();
|
2018-02-03 22:45:14 +01:00
|
|
|
if (account == null || accountId != account.getId()) {
|
2018-03-09 22:02:32 +01:00
|
|
|
accountManager.setActiveAccount(accountId);
|
2018-02-03 22:45:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-06 10:23:02 +01:00
|
|
|
if (ComposeActivity.canHandleMimeType(intent.getType())) {
|
|
|
|
// Sharing to Tusky from an external app
|
|
|
|
if (accountRequested) {
|
|
|
|
// The correct account is already active
|
|
|
|
forwardShare(intent);
|
|
|
|
} else {
|
|
|
|
// No account was provided, show the chooser
|
|
|
|
showAccountChooserDialog(getString(R.string.action_share_as), true, account -> {
|
|
|
|
long requestedId = account.getId();
|
|
|
|
AccountEntity activeAccount = accountManager.getActiveAccount();
|
|
|
|
if (activeAccount != null && requestedId == activeAccount.getId()) {
|
|
|
|
// The correct account is already active
|
|
|
|
forwardShare(intent);
|
|
|
|
} else {
|
|
|
|
// A different account was requested, restart the activity
|
|
|
|
intent.putExtra(NotificationHelper.ACCOUNT_ID, requestedId);
|
|
|
|
changeAccount(requestedId, intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (accountRequested) {
|
|
|
|
// user clicked a notification, show notification tab and switch user if necessary
|
2019-02-12 19:22:37 +01:00
|
|
|
showNotificationTab = true;
|
2019-02-06 10:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
2017-05-03 20:29:33 +02:00
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
2018-07-31 21:25:25 +02:00
|
|
|
composeButton = findViewById(R.id.floating_btn);
|
2017-10-18 00:20:26 +02:00
|
|
|
ImageButton drawerToggle = findViewById(R.id.drawer_toggle);
|
2019-02-12 19:22:37 +01:00
|
|
|
tabLayout = findViewById(R.id.tab_layout);
|
2017-10-18 00:20:26 +02:00
|
|
|
viewPager = findViewById(R.id.pager);
|
2017-05-03 20:29:33 +02:00
|
|
|
|
2018-07-31 21:25:25 +02:00
|
|
|
composeButton.setOnClickListener(v -> {
|
2018-02-03 22:45:14 +01:00
|
|
|
Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class);
|
2018-07-30 15:43:27 +02:00
|
|
|
startActivity(composeIntent);
|
2017-05-03 20:29:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
setupDrawer();
|
2017-06-20 02:50:40 +02:00
|
|
|
|
|
|
|
// Setup the navigation drawer toggle button.
|
|
|
|
ThemeUtils.setDrawableTint(this, drawerToggle.getDrawable(), R.attr.toolbar_icon_tint);
|
2017-11-15 21:50:15 +01:00
|
|
|
drawerToggle.setOnClickListener(v -> drawer.openDrawer());
|
2017-05-03 20:29:33 +02:00
|
|
|
|
2018-02-03 22:45:14 +01:00
|
|
|
/* Fetch user info while we're doing other things. This has to be done after setting up the
|
2017-05-03 20:29:33 +02:00
|
|
|
* drawer, though, because its callback touches the header in the drawer. */
|
|
|
|
fetchUserInfo();
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
setupTabs(showNotificationTab);
|
2017-05-03 20:29:33 +02:00
|
|
|
|
|
|
|
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);
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
|
viewPager.setCurrentItem(tab.getPosition());
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
if (tab.getPosition() == notificationTabPosition) {
|
2018-07-23 21:59:10 +02:00
|
|
|
NotificationHelper.clearNotificationsForActiveAccount(MainActivity.this, accountManager);
|
2017-11-15 21:18:35 +01:00
|
|
|
}
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-09 22:02:32 +01:00
|
|
|
public void onTabReselected(TabLayout.Tab tab) {
|
2019-04-08 15:40:16 +02:00
|
|
|
if (adapter != null) {
|
|
|
|
Fragment fragment = adapter.getFragment(tab.getPosition());
|
|
|
|
if (fragment instanceof ReselectableFragment) {
|
|
|
|
((ReselectableFragment) fragment).onReselect();
|
|
|
|
}
|
|
|
|
}
|
2018-03-09 22:02:32 +01:00
|
|
|
}
|
2017-05-03 20:29:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Setup push notifications
|
2018-07-23 21:59:10 +02:00
|
|
|
if (NotificationHelper.areNotificationsEnabled(this, accountManager)) {
|
2018-11-12 21:09:39 +01:00
|
|
|
NotificationHelper.enablePullNotifications();
|
2017-05-03 20:29:33 +02:00
|
|
|
} else {
|
2018-11-12 21:09:39 +01:00
|
|
|
NotificationHelper.disablePullNotifications();
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 20:47:09 +02:00
|
|
|
eventHub.getEvents()
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(event -> {
|
|
|
|
if (event instanceof ProfileEditedEvent) {
|
|
|
|
onFetchUserInfoSuccess(((ProfileEditedEvent) event).getNewProfileData());
|
|
|
|
}
|
2019-02-12 19:22:37 +01:00
|
|
|
if (event instanceof MainTabsChangedEvent) {
|
|
|
|
setupTabs(false);
|
|
|
|
}
|
2018-08-15 20:47:09 +02:00
|
|
|
});
|
|
|
|
|
2018-10-01 11:50:17 +02:00
|
|
|
// Flush old media that was cached for sharing
|
|
|
|
deleteStaleCachedMedia(getApplicationContext().getExternalFilesDir("Tusky"));
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2018-07-23 21:59:10 +02:00
|
|
|
NotificationHelper.clearNotificationsForActiveAccount(this, accountManager);
|
2017-05-03 20:29:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-09 02:59:48 +02:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (drawer != null && drawer.isDrawerOpen()) {
|
|
|
|
drawer.closeDrawer();
|
2017-11-13 20:43:16 +01:00
|
|
|
} else if (viewPager.getCurrentItem() != 0) {
|
|
|
|
viewPager.setCurrentItem(0);
|
2017-07-09 02:59:48 +02:00
|
|
|
} else {
|
2017-11-13 20:43:16 +01:00
|
|
|
super.onBackPressed();
|
2017-07-09 02:59:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_MENU: {
|
|
|
|
if (drawer.isDrawerOpen()) {
|
|
|
|
drawer.closeDrawer();
|
|
|
|
} else {
|
|
|
|
drawer.openDrawer();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case KeyEvent.KEYCODE_SEARCH: {
|
2019-07-19 20:10:20 +02:00
|
|
|
startActivityWithSlideInAnimation(SearchActivity.getIntent(this));
|
2017-07-09 02:59:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-05-30 13:32:18 +02:00
|
|
|
|
|
|
|
if (event.isCtrlPressed() || event.isShiftPressed()) {
|
|
|
|
// FIXME: blackberry keyONE raises SHIFT key event even CTRL IS PRESSED
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_N: {
|
|
|
|
// open compose activity by pressing SHIFT + N (or CTRL + N)
|
|
|
|
Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class);
|
|
|
|
startActivity(composeIntent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 10:34:53 +02:00
|
|
|
|
|
|
|
return super.onKeyDown(keyCode, event);
|
2019-05-30 13:32:18 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:50:09 +01:00
|
|
|
@Override
|
|
|
|
public void onPostCreate(Bundle savedInstanceState) {
|
|
|
|
super.onPostCreate(savedInstanceState);
|
|
|
|
Intent intent = getIntent();
|
|
|
|
if (intent != null) {
|
|
|
|
String statusUrl = intent.getStringExtra(STATUS_URL);
|
|
|
|
if (statusUrl != null) {
|
|
|
|
viewUrl(statusUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 21:10:07 +02:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
EmojiCompat.get().unregisterInitCallback(emojiInitCallback);
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
private void forwardShare(Intent intent) {
|
|
|
|
Intent composeIntent = new Intent(this, ComposeActivity.class);
|
|
|
|
composeIntent.setAction(intent.getAction());
|
|
|
|
composeIntent.setType(intent.getType());
|
|
|
|
composeIntent.putExtras(intent);
|
2019-02-19 20:56:13 +01:00
|
|
|
composeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
2019-02-12 19:22:37 +01:00
|
|
|
startActivity(composeIntent);
|
2019-02-19 20:56:13 +01:00
|
|
|
finish();
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setupDrawer() {
|
|
|
|
headerResult = new AccountHeaderBuilder()
|
|
|
|
.withActivity(this)
|
|
|
|
.withDividerBelowHeader(false)
|
2017-07-19 06:15:53 +02:00
|
|
|
.withHeaderBackgroundScaleType(ImageView.ScaleType.CENTER_CROP)
|
2018-02-03 22:45:14 +01:00
|
|
|
.withCurrentProfileHiddenInList(true)
|
|
|
|
.withOnAccountHeaderListener((view, profile, current) -> handleProfileClick(profile, current))
|
|
|
|
.addProfiles(
|
|
|
|
new ProfileSettingDrawerItem()
|
|
|
|
.withIdentifier(DRAWER_ITEM_ADD_ACCOUNT)
|
|
|
|
.withName(R.string.add_account_name)
|
|
|
|
.withDescription(R.string.add_account_description)
|
|
|
|
.withIcon(GoogleMaterial.Icon.gmd_add))
|
2017-05-03 20:29:33 +02:00
|
|
|
.build();
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
headerResult.getView()
|
|
|
|
.findViewById(R.id.material_drawer_account_header_current)
|
|
|
|
.setContentDescription(getString(R.string.action_view_profile));
|
|
|
|
|
2018-02-27 19:37:21 +01:00
|
|
|
ImageView background = headerResult.getHeaderBackgroundView();
|
|
|
|
background.setColorFilter(ContextCompat.getColor(this, R.color.header_background_filter));
|
|
|
|
background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));
|
|
|
|
|
2019-05-26 08:46:08 +02:00
|
|
|
final boolean animateAvatars = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
.getBoolean("animateGifAvatars", false);
|
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
DrawerImageLoader.init(new AbstractDrawerImageLoader() {
|
|
|
|
@Override
|
2017-11-15 21:50:15 +01:00
|
|
|
public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) {
|
2019-05-26 08:46:08 +02:00
|
|
|
if(animateAvatars) {
|
|
|
|
Glide.with(MainActivity.this)
|
|
|
|
.load(uri)
|
|
|
|
.placeholder(placeholder)
|
|
|
|
.into(imageView);
|
|
|
|
} else {
|
|
|
|
Glide.with(MainActivity.this)
|
|
|
|
.asBitmap()
|
|
|
|
.load(uri)
|
|
|
|
.placeholder(placeholder)
|
|
|
|
.into(imageView);
|
|
|
|
}
|
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cancel(ImageView imageView) {
|
2019-04-16 21:39:12 +02:00
|
|
|
Glide.with(MainActivity.this).clear(imageView);
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-12 21:09:39 +01:00
|
|
|
List<IDrawerItem> listItems = new ArrayList<>(10);
|
2018-07-30 15:43:27 +02:00
|
|
|
listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_EDIT_PROFILE).withName(R.string.action_edit_profile).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person));
|
|
|
|
listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_FAVOURITES).withName(R.string.action_view_favourites).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star));
|
|
|
|
listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_LISTS).withName(R.string.action_lists).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_list));
|
|
|
|
listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SEARCH).withName(R.string.action_search).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search));
|
2018-11-12 21:09:39 +01:00
|
|
|
listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SAVED_TOOT).withName(R.string.action_access_saved_toot).withSelectable(false).withIcon(R.drawable.ic_notebook).withIconTintingEnabled(true));
|
2018-07-30 15:43:27 +02:00
|
|
|
listItems.add(new DividerDrawerItem());
|
2018-11-12 21:09:39 +01:00
|
|
|
listItems.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_ACCOUNT_SETTINGS).withName(R.string.action_view_account_preferences).withSelectable(false).withIcon(R.drawable.ic_account_settings).withIconTintingEnabled(true));
|
|
|
|
listItems.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_SETTINGS).withName(R.string.action_view_preferences).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings));
|
2018-07-30 15:43:27 +02:00
|
|
|
listItems.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_ABOUT).withName(R.string.about_title_activity).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info));
|
2018-11-12 21:09:39 +01:00
|
|
|
listItems.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_LOG_OUT).withName(R.string.action_logout).withSelectable(false).withIcon(R.drawable.ic_logout).withIconTintingEnabled(true));
|
2017-06-29 17:56:36 +02:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
drawer = new DrawerBuilder()
|
|
|
|
.withActivity(this)
|
|
|
|
.withAccountHeader(headerResult)
|
|
|
|
.withHasStableIds(true)
|
|
|
|
.withSelectedItem(-1)
|
2018-07-30 15:43:27 +02:00
|
|
|
.withDrawerItems(listItems)
|
2017-11-15 21:50:15 +01:00
|
|
|
.withOnDrawerItemClickListener((view, position, drawerItem) -> {
|
|
|
|
if (drawerItem != null) {
|
|
|
|
long drawerItemIdentifier = drawerItem.getIdentifier();
|
2017-05-03 20:29:33 +02:00
|
|
|
|
2017-11-15 21:50:15 +01:00
|
|
|
if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) {
|
|
|
|
Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent);
|
2017-11-15 21:50:15 +01:00
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) {
|
|
|
|
Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent);
|
2017-11-15 21:50:15 +01:00
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) {
|
2019-07-19 20:10:20 +02:00
|
|
|
startActivityWithSlideInAnimation(SearchActivity.getIntent(this));
|
2018-11-12 21:09:39 +01:00
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_ACCOUNT_SETTINGS) {
|
|
|
|
Intent intent = PreferencesActivity.newIntent(MainActivity.this, PreferencesActivity.ACCOUNT_PREFERENCES);
|
|
|
|
startActivityWithSlideInAnimation(intent);
|
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_SETTINGS) {
|
|
|
|
Intent intent = PreferencesActivity.newIntent(MainActivity.this, PreferencesActivity.GENERAL_PREFERENCES);
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent);
|
2017-11-15 21:50:15 +01:00
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) {
|
|
|
|
Intent intent = new Intent(MainActivity.this, AboutActivity.class);
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent);
|
2017-11-15 21:50:15 +01:00
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) {
|
|
|
|
logout();
|
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) {
|
|
|
|
Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
|
|
|
|
intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent);
|
2017-11-15 21:50:15 +01:00
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_SAVED_TOOT) {
|
|
|
|
Intent intent = new Intent(MainActivity.this, SavedTootActivity.class);
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent);
|
2018-01-06 19:01:37 +01:00
|
|
|
} else if (drawerItemIdentifier == DRAWER_ITEM_LISTS) {
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(ListsActivity.newIntent(this));
|
2017-11-15 21:50:15 +01:00
|
|
|
}
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
2017-11-15 21:50:15 +01:00
|
|
|
|
|
|
|
return false;
|
2017-05-03 20:29:33 +02:00
|
|
|
})
|
|
|
|
.build();
|
2017-12-08 12:15:46 +01:00
|
|
|
|
2018-03-09 22:02:32 +01:00
|
|
|
if (BuildConfig.DEBUG) {
|
2017-12-08 12:15:46 +01:00
|
|
|
IDrawerItem debugItem = new SecondaryDrawerItem()
|
|
|
|
.withIdentifier(1337)
|
|
|
|
.withName("debug")
|
|
|
|
.withDisabledTextColor(Color.GREEN)
|
|
|
|
.withSelectable(false)
|
|
|
|
.withEnabled(false);
|
|
|
|
drawer.addItem(debugItem);
|
|
|
|
}
|
2018-02-27 19:37:21 +01:00
|
|
|
|
2019-07-10 21:10:07 +02:00
|
|
|
EmojiCompat.get().registerInitCallback(emojiInitCallback);
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
private void setupTabs(boolean selectNotificationTab) {
|
|
|
|
List<TabData> tabs = accountManager.getActiveAccount().getTabPreferences();
|
|
|
|
|
2019-04-08 15:40:16 +02:00
|
|
|
adapter = new MainPagerAdapter(tabs, getSupportFragmentManager());
|
2019-02-12 19:22:37 +01:00
|
|
|
viewPager.setAdapter(adapter);
|
|
|
|
|
|
|
|
tabLayout.setupWithViewPager(viewPager);
|
|
|
|
tabLayout.removeAllTabs();
|
|
|
|
for (int i = 0; i < tabs.size(); i++) {
|
|
|
|
TabLayout.Tab tab = tabLayout.newTab()
|
|
|
|
.setIcon(tabs.get(i).getIcon())
|
|
|
|
.setContentDescription(tabs.get(i).getText());
|
|
|
|
tabLayout.addTab(tab);
|
2019-04-08 15:40:16 +02:00
|
|
|
if (tabs.get(i).getId().equals(TabDataKt.NOTIFICATIONS)) {
|
2019-02-12 19:22:37 +01:00
|
|
|
notificationTabPosition = i;
|
2019-04-08 15:40:16 +02:00
|
|
|
if (selectNotificationTab) {
|
2019-02-12 19:22:37 +01:00
|
|
|
tab.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-03 22:45:14 +01:00
|
|
|
private boolean handleProfileClick(IProfile profile, boolean current) {
|
2018-03-09 22:02:32 +01:00
|
|
|
AccountEntity activeAccount = accountManager.getActiveAccount();
|
2018-02-03 22:45:14 +01:00
|
|
|
|
|
|
|
//open profile when active image was clicked
|
|
|
|
if (current && activeAccount != null) {
|
2018-06-18 13:26:18 +02:00
|
|
|
Intent intent = AccountActivity.getIntent(this, activeAccount.getAccountId());
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent);
|
2018-12-05 22:37:04 +01:00
|
|
|
new Handler().postDelayed(() -> drawer.closeDrawer(), 100);
|
2018-02-03 22:45:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//open LoginActivity to add new account
|
2018-03-09 22:02:32 +01:00
|
|
|
if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) {
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(LoginActivity.getIntent(this, true));
|
2018-12-05 22:37:04 +01:00
|
|
|
new Handler().postDelayed(() -> drawer.closeDrawer(), 100);
|
2018-02-03 22:45:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//change Account
|
2019-02-06 10:23:02 +01:00
|
|
|
changeAccount(profile.getIdentifier(), null);
|
2018-02-03 22:45:14 +01:00
|
|
|
return false;
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-06 10:23:02 +01:00
|
|
|
private void changeAccount(long newSelectedId, @Nullable Intent forward) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
cacheUpdater.stop();
|
2019-07-08 12:57:53 +02:00
|
|
|
SFragment.flushFilters();
|
2018-03-09 22:02:32 +01:00
|
|
|
accountManager.setActiveAccount(newSelectedId);
|
2018-02-03 22:45:14 +01:00
|
|
|
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
2019-02-06 10:23:02 +01:00
|
|
|
if (forward != null) {
|
|
|
|
intent.setType(forward.getType());
|
|
|
|
intent.setAction(forward.getAction());
|
|
|
|
intent.putExtras(forward);
|
|
|
|
}
|
2018-09-03 20:16:12 +02:00
|
|
|
startActivity(intent);
|
2018-08-07 23:08:53 +02:00
|
|
|
finishWithoutSlideOutAnimation();
|
2018-02-03 22:45:14 +01:00
|
|
|
|
|
|
|
overridePendingTransition(R.anim.explode, R.anim.explode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void logout() {
|
|
|
|
|
2018-03-09 22:02:32 +01:00
|
|
|
AccountEntity activeAccount = accountManager.getActiveAccount();
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2018-03-09 22:02:32 +01:00
|
|
|
if (activeAccount != null) {
|
2018-02-03 22:45:14 +01:00
|
|
|
|
|
|
|
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) -> {
|
|
|
|
|
2018-02-12 22:03:08 +01:00
|
|
|
NotificationHelper.deleteNotificationChannelsForAccount(accountManager.getActiveAccount(), MainActivity.this);
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
cacheUpdater.clearForUser(activeAccount.getId());
|
2019-02-13 19:21:04 +01:00
|
|
|
conversationRepository.deleteCacheForAccount(activeAccount.getId());
|
2018-02-03 22:45:14 +01:00
|
|
|
|
|
|
|
AccountEntity newAccount = accountManager.logActiveAccountOut();
|
|
|
|
|
2018-11-12 21:09:39 +01:00
|
|
|
if (!NotificationHelper.areNotificationsEnabled(MainActivity.this, accountManager)) {
|
|
|
|
NotificationHelper.disablePullNotifications();
|
|
|
|
}
|
2018-02-03 22:45:14 +01:00
|
|
|
|
|
|
|
Intent intent;
|
|
|
|
if (newAccount == null) {
|
|
|
|
intent = LoginActivity.getIntent(MainActivity.this, false);
|
|
|
|
} else {
|
|
|
|
intent = new Intent(MainActivity.this, MainActivity.class);
|
|
|
|
}
|
2018-08-07 23:08:53 +02:00
|
|
|
startActivity(intent);
|
|
|
|
finishWithoutSlideOutAnimation();
|
2018-02-03 22:45:14 +01:00
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.no, null)
|
|
|
|
.show();
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
2018-02-03 22:45:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchUserInfo() {
|
2019-04-27 18:20:42 +02:00
|
|
|
mastodonApi.accountVerifyCredentials()
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(this::onFetchUserInfoSuccess, MainActivity::onFetchUserInfoFailure);
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 22:45:14 +01:00
|
|
|
private void onFetchUserInfoSuccess(Account me) {
|
2019-04-27 18:20:42 +02:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
// Add the header image and avatar from the account, into the navigation drawer header.
|
2018-02-27 19:37:21 +01:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
ImageView background = headerResult.getHeaderBackgroundView();
|
2018-02-27 19:37:21 +01:00
|
|
|
|
2019-04-16 21:39:12 +02:00
|
|
|
Glide.with(MainActivity.this)
|
2019-05-08 21:42:22 +02:00
|
|
|
.asBitmap()
|
2018-03-03 13:24:03 +01:00
|
|
|
.load(me.getHeader())
|
2017-05-03 20:29:33 +02:00
|
|
|
.into(background);
|
|
|
|
|
2018-03-09 22:02:32 +01:00
|
|
|
accountManager.updateActiveAccount(me);
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2018-03-09 22:02:32 +01:00
|
|
|
NotificationHelper.createNotificationChannelsForAccount(accountManager.getActiveAccount(), this);
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2018-02-27 19:37:21 +01:00
|
|
|
// Show follow requests in the menu, if this is a locked account.
|
2018-03-03 13:24:03 +01:00
|
|
|
if (me.getLocked() && drawer.getDrawerItem(DRAWER_ITEM_FOLLOW_REQUESTS) == null) {
|
2018-02-27 19:37:21 +01:00
|
|
|
PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem()
|
|
|
|
.withIdentifier(DRAWER_ITEM_FOLLOW_REQUESTS)
|
|
|
|
.withName(R.string.action_view_follow_requests)
|
|
|
|
.withSelectable(false)
|
|
|
|
.withIcon(GoogleMaterial.Icon.gmd_person_add);
|
|
|
|
drawer.addItemAtPosition(followRequestsItem, 3);
|
2019-04-08 15:40:16 +02:00
|
|
|
} else if (!me.getLocked()) {
|
2018-03-27 20:46:53 +02:00
|
|
|
drawer.removeItem(DRAWER_ITEM_FOLLOW_REQUESTS);
|
2018-02-27 19:37:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateProfiles();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateProfiles() {
|
|
|
|
|
2018-03-09 22:02:32 +01:00
|
|
|
List<AccountEntity> allAccounts = accountManager.getAllAccountsOrderedByActive();
|
2018-02-03 22:45:14 +01:00
|
|
|
|
2019-04-08 15:40:16 +02:00
|
|
|
List<IProfile> profiles = new ArrayList<>(allAccounts.size() + 1);
|
2018-02-12 22:04:18 +01:00
|
|
|
|
2018-03-09 22:02:32 +01:00
|
|
|
for (AccountEntity acc : allAccounts) {
|
2018-07-30 15:43:27 +02:00
|
|
|
CharSequence emojifiedName = CustomEmojiHelper.emojifyString(acc.getDisplayName(), acc.getEmojis(), headerResult.getView());
|
|
|
|
emojifiedName = EmojiCompat.get().process(emojifiedName);
|
|
|
|
|
2018-09-03 20:16:12 +02:00
|
|
|
profiles.add(
|
2018-02-03 22:45:14 +01:00
|
|
|
new ProfileDrawerItem()
|
2018-09-03 20:16:12 +02:00
|
|
|
.withSetSelected(acc.isActive())
|
2018-07-30 15:43:27 +02:00
|
|
|
.withName(emojifiedName)
|
2018-02-03 22:45:14 +01:00
|
|
|
.withIcon(acc.getProfilePictureUrl())
|
|
|
|
.withNameShown(true)
|
|
|
|
.withIdentifier(acc.getId())
|
|
|
|
.withEmail(acc.getFullName()));
|
2018-03-03 13:24:03 +01:00
|
|
|
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
2018-09-03 20:16:12 +02:00
|
|
|
|
|
|
|
// reuse the already existing "add account" item
|
2019-04-08 15:40:16 +02:00
|
|
|
for (IProfile profile : headerResult.getProfiles()) {
|
2018-09-03 20:16:12 +02:00
|
|
|
if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) {
|
|
|
|
profiles.add(profile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
headerResult.clear();
|
2018-07-30 15:43:27 +02:00
|
|
|
headerResult.setProfiles(profiles);
|
2019-01-18 18:08:11 +01:00
|
|
|
headerResult.setActiveProfile(accountManager.getActiveAccount().getId());
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 18:20:42 +02:00
|
|
|
private static void onFetchUserInfoFailure(Throwable throwable) {
|
|
|
|
Log.e(TAG, "Failed to fetch user info. " + throwable.getMessage());
|
2017-05-03 20:29:33 +02:00
|
|
|
}
|
2017-08-04 11:44:10 +02:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public FloatingActionButton getActionButton() {
|
|
|
|
return composeButton;
|
|
|
|
}
|
2018-03-27 19:47:00 +02:00
|
|
|
|
|
|
|
@Override
|
2019-06-09 19:48:04 +02:00
|
|
|
public AndroidInjector<Object> androidInjector() {
|
|
|
|
return androidInjector;
|
2018-03-27 19:47:00 +02:00
|
|
|
}
|
2017-03-11 02:50:49 +01:00
|
|
|
}
|