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()
|
pachliAccountId = accountIdString.toLong()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val accountRequested = pachliAccountId != -1L
|
val accountSwitchRequested = pachliAccountId != -1L
|
||||||
if (accountRequested && pachliAccountId != activeAccount.id) {
|
if (accountSwitchRequested && pachliAccountId != activeAccount.id) {
|
||||||
accountManager.setActiveAccount(pachliAccountId)
|
accountManager.setActiveAccount(pachliAccountId)
|
||||||
}
|
}
|
||||||
|
|
||||||
val openDrafts = MainActivityIntent.getOpenDrafts(intent)
|
val openDrafts = MainActivityIntent.getOpenDrafts(intent)
|
||||||
|
|
||||||
|
// Sharing to Pachli from an external app.
|
||||||
if (canHandleMimeType(intent.type) || MainActivityIntent.hasComposeOptions(intent)) {
|
if (canHandleMimeType(intent.type) || MainActivityIntent.hasComposeOptions(intent)) {
|
||||||
// Sharing to Tusky from an external app
|
if (accountSwitchRequested) {
|
||||||
if (accountRequested) {
|
|
||||||
// The correct account is already active
|
// The correct account is already active
|
||||||
forwardToComposeActivity(intent)
|
forwardToComposeActivityAndExit(intent)
|
||||||
} else {
|
} else {
|
||||||
// No account was provided, show the chooser
|
// No account was provided, show the chooser
|
||||||
showAccountChooserDialog(
|
showAccountChooserDialog(
|
||||||
|
@ -281,11 +281,12 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
||||||
val requestedId = account.id
|
val requestedId = account.id
|
||||||
if (requestedId == activeAccount.id) {
|
if (requestedId == activeAccount.id) {
|
||||||
// The correct account is already active
|
// The correct account is already active
|
||||||
forwardToComposeActivity(intent)
|
forwardToComposeActivityAndExit(intent)
|
||||||
} else {
|
} 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)
|
MainActivityIntent.setPachliAccountId(intent, requestedId)
|
||||||
changeAccount(requestedId, intent)
|
changeAccountAndRestart(requestedId, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -294,7 +295,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
||||||
} else if (openDrafts) {
|
} else if (openDrafts) {
|
||||||
val intent = DraftsActivityIntent(this)
|
val intent = DraftsActivityIntent(this)
|
||||||
startActivity(intent)
|
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,
|
// user clicked a notification, show follow requests for type FOLLOW_REQUEST,
|
||||||
// otherwise show notification tab
|
// otherwise show notification tab
|
||||||
if (MainActivityIntent.getNotificationType(intent) == Notification.Type.FOLLOW_REQUEST) {
|
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 composeOptions = ComposeActivityIntent.getOptions(intent)
|
||||||
|
|
||||||
val composeIntent = if (composeOptions != null) {
|
val composeIntent = if (composeOptions != null) {
|
||||||
|
@ -547,7 +548,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
||||||
headerBackgroundScaleType = ImageView.ScaleType.CENTER_CROP
|
headerBackgroundScaleType = ImageView.ScaleType.CENTER_CROP
|
||||||
currentHiddenInList = true
|
currentHiddenInList = true
|
||||||
onAccountHeaderListener = { _: View?, profile: IProfile, current: Boolean ->
|
onAccountHeaderListener = { _: View?, profile: IProfile, current: Boolean ->
|
||||||
handleProfileClick(profile, current)
|
onAccountHeaderClick(profile, current)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
addProfile(
|
addProfile(
|
||||||
|
@ -981,7 +982,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
||||||
} ?: binding.composeButton.hide()
|
} ?: binding.composeButton.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleProfileClick(profile: IProfile, current: Boolean) {
|
private fun onAccountHeaderClick(profile: IProfile, current: Boolean) {
|
||||||
val activeAccount = accountManager.activeAccount
|
val activeAccount = accountManager.activeAccount
|
||||||
|
|
||||||
// open profile when active image was clicked
|
// open profile when active image was clicked
|
||||||
|
@ -998,13 +999,16 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// change Account
|
// change Account
|
||||||
changeAccount(profile.identifier, null)
|
changeAccountAndRestart(profile.identifier, null)
|
||||||
return
|
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()
|
cacheUpdater.stop()
|
||||||
accountManager.setActiveAccount(newSelectedId)
|
accountManager.setActiveAccount(accountId)
|
||||||
val intent = MainActivityIntent(this)
|
val intent = MainActivityIntent(this)
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
if (forward != null) {
|
if (forward != null) {
|
||||||
|
|
Loading…
Reference in New Issue