@ -223,74 +223,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
// check for savedInstanceState in order to not handle intent events more than once
if ( intent != null && savedInstanceState == null ) {
val notificationId = intent . getIntExtra ( NOTIFICATION _ID , - 1 )
if ( notificationId != - 1 ) {
// opened from a notification action, cancel the notification
val notificationManager = getSystemService (
NOTIFICATION _SERVICE
) as NotificationManager
notificationManager . cancel ( intent . getStringExtra ( NOTIFICATION _TAG ) , notificationId )
}
/ * * there are two possibilities the accountId can be passed to MainActivity :
* - from our code as Long Intent Extra TUSKY _ACCOUNT _ID
* - from share shortcuts as String ' android . intent . extra . shortcut . ID '
* /
var tuskyAccountId = intent . getLongExtra ( TUSKY _ACCOUNT _ID , - 1 )
if ( tuskyAccountId == - 1L ) {
val accountIdString = intent . getStringExtra ( ShortcutManagerCompat . EXTRA _SHORTCUT _ID )
if ( accountIdString != null ) {
tuskyAccountId = accountIdString . toLong ( )
}
}
val accountRequested = tuskyAccountId != - 1L
if ( accountRequested && tuskyAccountId != activeAccount . id ) {
accountManager . setActiveAccount ( tuskyAccountId )
}
val openDrafts = intent . getBooleanExtra ( OPEN _DRAFTS , false )
if ( canHandleMimeType ( intent . type ) || intent . hasExtra ( COMPOSE _OPTIONS ) ) {
// Sharing to Tusky from an external app
if ( accountRequested ) {
// The correct account is already active
forwardToComposeActivity ( intent )
} else {
// No account was provided, show the chooser
showAccountChooserDialog (
getString ( R . string . action _share _as ) ,
true ,
object : AccountSelectionListener {
override fun onAccountSelected ( account : AccountEntity ) {
val requestedId = account . id
if ( requestedId == activeAccount . id ) {
// The correct account is already active
forwardToComposeActivity ( intent )
} else {
// A different account was requested, restart the activity
intent . putExtra ( TUSKY _ACCOUNT _ID , requestedId )
changeAccount ( requestedId , intent )
}
}
}
)
}
} else if ( openDrafts ) {
val intent = DraftsActivity . newIntent ( this )
startActivity ( intent )
} else if ( accountRequested && intent . hasExtra ( NOTIFICATION _TYPE ) ) {
// user clicked a notification, show follow requests for type FOLLOW_REQUEST,
// otherwise show notification tab
if ( intent . getStringExtra ( NOTIFICATION _TYPE ) == Notification . Type . FOLLOW _REQUEST . name ) {
val intent = AccountListActivity . newIntent (
this ,
AccountListActivity . Type . FOLLOW _REQUESTS
)
startActivityWithSlideInAnimation ( intent )
} else {
showNotificationTab = true
}
}
showNotificationTab = handleIntent ( intent , activeAccount )
}
window . statusBarColor = Color . TRANSPARENT // don't draw a status bar, the DrawerLayout and the MaterialDrawerLayout have their own
setContentView ( binding . root )
@ -417,6 +350,94 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
draftsAlert . observeInContext ( this , true )
}
override fun onNewIntent ( intent : Intent ) {
super . onNewIntent ( intent )
val activeAccount = accountManager . activeAccount ?: return
val showNotificationTab = handleIntent ( intent , activeAccount )
if ( showNotificationTab ) {
val tabs = activeAccount . tabPreferences
val position = tabs . indexOfFirst { it . id == NOTIFICATIONS }
if ( position != - 1 ) {
binding . viewPager . setCurrentItem ( position , false )
}
}
}
/ * * Handle an incoming Intent ,
* @returns true when the intent is coming from an notification and the interface should show the notification tab .
* /
private fun handleIntent ( intent : Intent , activeAccount : AccountEntity ) : Boolean {
val notificationId = intent . getIntExtra ( NOTIFICATION _ID , - 1 )
if ( notificationId != - 1 ) {
// opened from a notification action, cancel the notification
val notificationManager = getSystemService (
NOTIFICATION _SERVICE
) as NotificationManager
notificationManager . cancel ( intent . getStringExtra ( NOTIFICATION _TAG ) , notificationId )
}
/ * * there are two possibilities the accountId can be passed to MainActivity :
* - from our code as Long Intent Extra TUSKY _ACCOUNT _ID
* - from share shortcuts as String ' android . intent . extra . shortcut . ID '
* /
var tuskyAccountId = intent . getLongExtra ( TUSKY _ACCOUNT _ID , - 1 )
if ( tuskyAccountId == - 1L ) {
val accountIdString = intent . getStringExtra ( ShortcutManagerCompat . EXTRA _SHORTCUT _ID )
if ( accountIdString != null ) {
tuskyAccountId = accountIdString . toLong ( )
}
}
val accountRequested = tuskyAccountId != - 1L
if ( accountRequested && tuskyAccountId != activeAccount . id ) {
accountManager . setActiveAccount ( tuskyAccountId )
}
val openDrafts = intent . getBooleanExtra ( OPEN _DRAFTS , false )
if ( canHandleMimeType ( intent . type ) || intent . hasExtra ( COMPOSE _OPTIONS ) ) {
// Sharing to Tusky from an external app
if ( accountRequested ) {
// The correct account is already active
forwardToComposeActivity ( intent )
} else {
// No account was provided, show the chooser
showAccountChooserDialog (
getString ( R . string . action _share _as ) ,
true ,
object : AccountSelectionListener {
override fun onAccountSelected ( account : AccountEntity ) {
val requestedId = account . id
if ( requestedId == activeAccount . id ) {
// The correct account is already active
forwardToComposeActivity ( intent )
} else {
// A different account was requested, restart the activity
intent . putExtra ( TUSKY _ACCOUNT _ID , requestedId )
changeAccount ( requestedId , intent )
}
}
}
)
}
} else if ( openDrafts ) {
val draftsIntent = DraftsActivity . newIntent ( this )
startActivity ( draftsIntent )
} else if ( accountRequested && intent . hasExtra ( NOTIFICATION _TYPE ) ) {
// user clicked a notification, show follow requests for type FOLLOW_REQUEST,
// otherwise show notification tab
if ( intent . getStringExtra ( NOTIFICATION _TYPE ) == Notification . Type . FOLLOW _REQUEST . name ) {
val accountListIntent = AccountListActivity . newIntent (
this ,
AccountListActivity . Type . FOLLOW _REQUESTS
)
startActivityWithSlideInAnimation ( accountListIntent )
} else {
return true
}
}
return false
}
private fun showDirectMessageBadge ( showBadge : Boolean ) {
directMessageTab ?. let { tab ->
tab . badge ?. isVisible = showBadge