|
|
|
|
@ -67,8 +67,11 @@ import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
|
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator |
|
|
|
|
import com.keylesspalace.tusky.appstore.AnnouncementReadEvent |
|
|
|
|
import com.keylesspalace.tusky.appstore.CacheUpdater |
|
|
|
|
import com.keylesspalace.tusky.appstore.ConversationsLoadingEvent |
|
|
|
|
import com.keylesspalace.tusky.appstore.EventHub |
|
|
|
|
import com.keylesspalace.tusky.appstore.MainTabsChangedEvent |
|
|
|
|
import com.keylesspalace.tusky.appstore.NewNotificationsEvent |
|
|
|
|
import com.keylesspalace.tusky.appstore.NotificationsLoadingEvent |
|
|
|
|
import com.keylesspalace.tusky.appstore.ProfileEditedEvent |
|
|
|
|
import com.keylesspalace.tusky.components.account.AccountActivity |
|
|
|
|
import com.keylesspalace.tusky.components.accountlist.AccountListActivity |
|
|
|
|
@ -90,6 +93,7 @@ import com.keylesspalace.tusky.db.AccountEntity
|
|
|
|
|
import com.keylesspalace.tusky.db.DraftsAlert |
|
|
|
|
import com.keylesspalace.tusky.entity.Account |
|
|
|
|
import com.keylesspalace.tusky.entity.Notification |
|
|
|
|
import com.keylesspalace.tusky.entity.Status |
|
|
|
|
import com.keylesspalace.tusky.interfaces.AccountSelectionListener |
|
|
|
|
import com.keylesspalace.tusky.interfaces.ActionButtonActivity |
|
|
|
|
import com.keylesspalace.tusky.interfaces.FabFragment |
|
|
|
|
@ -181,6 +185,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
|
|
|
|
/** Adapter for the different timeline tabs */ |
|
|
|
|
private lateinit var tabAdapter: MainPagerAdapter |
|
|
|
|
|
|
|
|
|
private var directMessageTab: TabLayout.Tab? = null |
|
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION") |
|
|
|
|
@SuppressLint("RestrictedApi") |
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
@ -324,11 +330,32 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
|
|
|
|
|
|
|
|
|
setupTabs(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
is AnnouncementReadEvent -> { |
|
|
|
|
unreadAnnouncementsCount-- |
|
|
|
|
updateAnnouncementsBadge() |
|
|
|
|
} |
|
|
|
|
is NewNotificationsEvent -> { |
|
|
|
|
directMessageTab?.let { tab -> |
|
|
|
|
if (event.accountId == activeAccount.accountId) { |
|
|
|
|
val hasDirectMessageNotification = |
|
|
|
|
event.notifications.any { it.type == Notification.Type.MENTION && it.status?.visibility == Status.Visibility.DIRECT } |
|
|
|
|
|
|
|
|
|
if (hasDirectMessageNotification) { |
|
|
|
|
showDirectMessageBadge(true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
is NotificationsLoadingEvent -> { |
|
|
|
|
if (event.accountId == activeAccount.accountId) { |
|
|
|
|
showDirectMessageBadge(false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
is ConversationsLoadingEvent -> { |
|
|
|
|
if (event.accountId == activeAccount.accountId) { |
|
|
|
|
showDirectMessageBadge(false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -374,6 +401,20 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
|
|
|
|
draftsAlert.observeInContext(this, true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun showDirectMessageBadge(showBadge: Boolean) { |
|
|
|
|
directMessageTab?.let { tab -> |
|
|
|
|
tab.badge?.isVisible = showBadge |
|
|
|
|
|
|
|
|
|
// TODO a bit cumbersome (also for resetting) |
|
|
|
|
accountManager.activeAccount?.let { |
|
|
|
|
if (it.hasDirectMessageBadge != showBadge) { |
|
|
|
|
it.hasDirectMessageBadge = showBadge |
|
|
|
|
accountManager.saveAccount(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { |
|
|
|
|
menuInflater.inflate(R.menu.activity_main, menu) |
|
|
|
|
menu.findItem(R.id.action_search)?.apply { |
|
|
|
|
@ -770,6 +811,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
|
|
|
|
// Detach any existing mediator before changing tab contents and attaching a new mediator |
|
|
|
|
tabLayoutMediator?.detach() |
|
|
|
|
|
|
|
|
|
directMessageTab = null |
|
|
|
|
|
|
|
|
|
tabAdapter.tabs = tabs |
|
|
|
|
tabAdapter.notifyItemRangeChanged(0, tabs.size) |
|
|
|
|
|
|
|
|
|
@ -780,6 +823,11 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
|
|
|
|
LIST -> tabs[position].arguments[1] |
|
|
|
|
else -> getString(tabs[position].text) |
|
|
|
|
} |
|
|
|
|
if (tabs[position].id == DIRECT) { |
|
|
|
|
tab.orCreateBadge |
|
|
|
|
tab.badge?.isVisible = accountManager.activeAccount?.hasDirectMessageBadge ?: false |
|
|
|
|
directMessageTab = tab |
|
|
|
|
} |
|
|
|
|
}.also { it.attach() } |
|
|
|
|
|
|
|
|
|
// Selected tab is either |
|
|
|
|
@ -808,6 +856,17 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
|
|
|
|
binding.mainToolbar.title = tab.contentDescription |
|
|
|
|
|
|
|
|
|
refreshComposeButtonState(tabAdapter, tab.position) |
|
|
|
|
|
|
|
|
|
if (tab == directMessageTab) { |
|
|
|
|
tab.badge?.isVisible = false |
|
|
|
|
|
|
|
|
|
accountManager.activeAccount?.let { |
|
|
|
|
if (it.hasDirectMessageBadge) { |
|
|
|
|
it.hasDirectMessageBadge = false |
|
|
|
|
accountManager.saveAccount(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) {} |
|
|
|
|
|