refactor: Rename variables and functions in MainActivity (#966)
Rename some variables and functions in MainActivity to more accurately or consistently reflect what they do.
This commit is contained in:
parent
33726431e8
commit
4b3b275c97
|
@ -259,18 +259,18 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
|||
pachliAccountId = accountIdString.toLong()
|
||||
}
|
||||
}
|
||||
val accountRequested = pachliAccountId != -1L
|
||||
if (accountRequested && pachliAccountId != activeAccount.id) {
|
||||
val accountSwitchRequested = pachliAccountId != -1L
|
||||
if (accountSwitchRequested && pachliAccountId != activeAccount.id) {
|
||||
accountManager.setActiveAccount(pachliAccountId)
|
||||
}
|
||||
|
||||
val openDrafts = MainActivityIntent.getOpenDrafts(intent)
|
||||
|
||||
// Sharing to Pachli from an external app.
|
||||
if (canHandleMimeType(intent.type) || MainActivityIntent.hasComposeOptions(intent)) {
|
||||
// Sharing to Tusky from an external app
|
||||
if (accountRequested) {
|
||||
if (accountSwitchRequested) {
|
||||
// The correct account is already active
|
||||
forwardToComposeActivity(intent)
|
||||
forwardToComposeActivityAndExit(intent)
|
||||
} else {
|
||||
// No account was provided, show the chooser
|
||||
showAccountChooserDialog(
|
||||
|
@ -281,11 +281,12 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
|||
val requestedId = account.id
|
||||
if (requestedId == activeAccount.id) {
|
||||
// The correct account is already active
|
||||
forwardToComposeActivity(intent)
|
||||
forwardToComposeActivityAndExit(intent)
|
||||
} else {
|
||||
// A different account was requested, restart the activity
|
||||
// A different account was requested, restart the activity,
|
||||
// forwarding this intent to the restarted activity.
|
||||
MainActivityIntent.setPachliAccountId(intent, requestedId)
|
||||
changeAccount(requestedId, intent)
|
||||
changeAccountAndRestart(requestedId, intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -294,7 +295,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
|||
} else if (openDrafts) {
|
||||
val intent = DraftsActivityIntent(this)
|
||||
startActivity(intent)
|
||||
} else if (accountRequested && MainActivityIntent.hasNotificationType(intent)) {
|
||||
} else if (accountSwitchRequested && MainActivityIntent.hasNotificationType(intent)) {
|
||||
// user clicked a notification, show follow requests for type FOLLOW_REQUEST,
|
||||
// otherwise show notification tab
|
||||
if (MainActivityIntent.getNotificationType(intent) == Notification.Type.FOLLOW_REQUEST) {
|
||||
|
@ -512,7 +513,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
|||
}
|
||||
}
|
||||
|
||||
private fun forwardToComposeActivity(intent: Intent) {
|
||||
private fun forwardToComposeActivityAndExit(intent: Intent) {
|
||||
val composeOptions = ComposeActivityIntent.getOptions(intent)
|
||||
|
||||
val composeIntent = if (composeOptions != null) {
|
||||
|
@ -547,7 +548,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
|||
headerBackgroundScaleType = ImageView.ScaleType.CENTER_CROP
|
||||
currentHiddenInList = true
|
||||
onAccountHeaderListener = { _: View?, profile: IProfile, current: Boolean ->
|
||||
handleProfileClick(profile, current)
|
||||
onAccountHeaderClick(profile, current)
|
||||
false
|
||||
}
|
||||
addProfile(
|
||||
|
@ -981,7 +982,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
|||
} ?: binding.composeButton.hide()
|
||||
}
|
||||
|
||||
private fun handleProfileClick(profile: IProfile, current: Boolean) {
|
||||
private fun onAccountHeaderClick(profile: IProfile, current: Boolean) {
|
||||
val activeAccount = accountManager.activeAccount
|
||||
|
||||
// open profile when active image was clicked
|
||||
|
@ -998,13 +999,16 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
|||
return
|
||||
}
|
||||
// change Account
|
||||
changeAccount(profile.identifier, null)
|
||||
changeAccountAndRestart(profile.identifier, null)
|
||||
return
|
||||
}
|
||||
|
||||
private fun changeAccount(newSelectedId: Long, forward: Intent?) {
|
||||
/**
|
||||
* Relaunches MainActivity, switched to the account identified by [accountId].
|
||||
*/
|
||||
private fun changeAccountAndRestart(accountId: Long, forward: Intent?) {
|
||||
cacheUpdater.stop()
|
||||
accountManager.setActiveAccount(newSelectedId)
|
||||
accountManager.setActiveAccount(accountId)
|
||||
val intent = MainActivityIntent(this)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
if (forward != null) {
|
||||
|
|
Loading…
Reference in New Issue