refactor: Convert AccountSelectionListener to fun interface (#1118)

`AccountSelectionListener` only has one method; converting to a Kotlin
`fun interface` simplifies the calling code.
This commit is contained in:
Nik Clayton 2024-11-20 19:50:04 +01:00 committed by GitHub
parent 632282d0e2
commit 9f908cfb7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 53 deletions

View File

@ -63,7 +63,6 @@ import app.pachli.components.compose.ComposeActivity.Companion.canHandleMimeType
import app.pachli.components.notifications.createNotificationChannelsForAccount import app.pachli.components.notifications.createNotificationChannelsForAccount
import app.pachli.components.notifications.domain.AndroidNotificationsAreEnabledUseCase import app.pachli.components.notifications.domain.AndroidNotificationsAreEnabledUseCase
import app.pachli.components.notifications.domain.EnableAllNotificationsUseCase import app.pachli.components.notifications.domain.EnableAllNotificationsUseCase
import app.pachli.core.activity.AccountSelectionListener
import app.pachli.core.activity.BottomSheetActivity import app.pachli.core.activity.BottomSheetActivity
import app.pachli.core.activity.PostLookupFallbackBehavior import app.pachli.core.activity.PostLookupFallbackBehavior
import app.pachli.core.activity.ReselectableFragment import app.pachli.core.activity.ReselectableFragment
@ -269,16 +268,10 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
when (val payload = MainActivityIntent.payload(intent)) { when (val payload = MainActivityIntent.payload(intent)) {
is Payload.QuickTile -> { is Payload.QuickTile -> {
showAccountChooserDialog( showAccountChooserDialog(getString(R.string.action_share_as), true) { account ->
getString(R.string.action_share_as),
true,
object : AccountSelectionListener {
override fun onAccountSelected(account: AccountEntity) {
val requestedId = account.id val requestedId = account.id
launchComposeActivityAndExit(requestedId) launchComposeActivityAndExit(requestedId)
} }
},
)
return return
} }
@ -330,16 +323,10 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
// and start the composer. // and start the composer.
if (canHandleMimeType(intent.type)) { if (canHandleMimeType(intent.type)) {
// Determine the account to use. // Determine the account to use.
showAccountChooserDialog( showAccountChooserDialog(getString(R.string.action_share_as), true) { account ->
getString(R.string.action_share_as),
true,
object : AccountSelectionListener {
override fun onAccountSelected(account: AccountEntity) {
val requestedId = account.id val requestedId = account.id
forwardToComposeActivityAndExit(requestedId, intent) forwardToComposeActivityAndExit(requestedId, intent)
} }
},
)
} }
} }
} }

View File

@ -51,7 +51,6 @@ import androidx.core.widget.doAfterTextChanged
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewpager2.widget.MarginPageTransformer import androidx.viewpager2.widget.MarginPageTransformer
import app.pachli.R import app.pachli.R
import app.pachli.core.activity.AccountSelectionListener
import app.pachli.core.activity.BottomSheetActivity import app.pachli.core.activity.BottomSheetActivity
import app.pachli.core.activity.ReselectableFragment import app.pachli.core.activity.ReselectableFragment
import app.pachli.core.activity.emojify import app.pachli.core.activity.emojify
@ -64,7 +63,6 @@ import app.pachli.core.common.extensions.show
import app.pachli.core.common.extensions.viewBinding import app.pachli.core.common.extensions.viewBinding
import app.pachli.core.common.extensions.visible import app.pachli.core.common.extensions.visible
import app.pachli.core.common.util.unsafeLazy import app.pachli.core.common.util.unsafeLazy
import app.pachli.core.database.model.AccountEntity
import app.pachli.core.designsystem.R as DR import app.pachli.core.designsystem.R as DR
import app.pachli.core.navigation.AccountActivityIntent import app.pachli.core.navigation.AccountActivityIntent
import app.pachli.core.navigation.AccountListActivityIntent import app.pachli.core.navigation.AccountListActivityIntent
@ -997,15 +995,9 @@ class AccountActivity :
} }
R.id.action_open_as -> { R.id.action_open_as -> {
loadedAccount?.let { loadedAccount -> loadedAccount?.let { loadedAccount ->
showAccountChooserDialog( showAccountChooserDialog(item.title, false) { account ->
item.title,
false,
object : AccountSelectionListener {
override fun onAccountSelected(account: AccountEntity) {
openAsAccount(loadedAccount.url, account) openAsAccount(loadedAccount.url, account)
} }
},
)
} }
} }
R.id.action_share_account_link -> { R.id.action_share_account_link -> {

View File

@ -33,7 +33,6 @@ import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import app.pachli.R import app.pachli.R
import app.pachli.components.search.adapter.SearchStatusesAdapter import app.pachli.components.search.adapter.SearchStatusesAdapter
import app.pachli.core.activity.AccountSelectionListener
import app.pachli.core.activity.BaseActivity import app.pachli.core.activity.BaseActivity
import app.pachli.core.activity.extensions.TransitionKind import app.pachli.core.activity.extensions.TransitionKind
import app.pachli.core.activity.extensions.startActivityWithDefaultTransition import app.pachli.core.activity.extensions.startActivityWithDefaultTransition
@ -363,15 +362,9 @@ class SearchStatusesFragment : SearchFragment<StatusViewData>(), StatusActionLis
} }
private fun showOpenAsDialog(statusUrl: String, dialogTitle: CharSequence?) { private fun showOpenAsDialog(statusUrl: String, dialogTitle: CharSequence?) {
bottomSheetActivity?.showAccountChooserDialog( bottomSheetActivity?.showAccountChooserDialog(dialogTitle, false) { account ->
dialogTitle,
false,
object : AccountSelectionListener {
override fun onAccountSelected(account: AccountEntity) {
bottomSheetActivity?.openAsAccount(statusUrl, account) bottomSheetActivity?.openAsAccount(statusUrl, account)
} }
},
)
} }
private fun downloadAllMedia(status: Status) { private fun downloadAllMedia(status: Status) {

View File

@ -36,7 +36,6 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import app.pachli.R import app.pachli.R
import app.pachli.core.activity.AccountSelectionListener
import app.pachli.core.activity.BaseActivity import app.pachli.core.activity.BaseActivity
import app.pachli.core.activity.BottomSheetActivity import app.pachli.core.activity.BottomSheetActivity
import app.pachli.core.activity.PostLookupFallbackBehavior import app.pachli.core.activity.PostLookupFallbackBehavior
@ -538,15 +537,9 @@ abstract class SFragment<T : IStatusViewData> : Fragment(), StatusActionListener
} }
(activity as BaseActivity).apply { (activity as BaseActivity).apply {
showAccountChooserDialog( showAccountChooserDialog(dialogTitle, false) { account ->
dialogTitle,
false,
object : AccountSelectionListener {
override fun onAccountSelected(account: AccountEntity) {
openAsAccount(statusUrl, account) openAsAccount(statusUrl, account)
} }
},
)
} }
} }

View File

@ -18,6 +18,6 @@ package app.pachli.core.activity
import app.pachli.core.database.model.AccountEntity import app.pachli.core.database.model.AccountEntity
interface AccountSelectionListener { fun interface AccountSelectionListener {
fun onAccountSelected(account: AccountEntity) fun onAccountSelected(account: AccountEntity)
} }