Use Koin instead of custom by lazy
code
This commit is contained in:
parent
f91f3e268b
commit
125e1af9d6
7 changed files with 17 additions and 10 deletions
|
@ -1,12 +1,15 @@
|
|||
package com.fsck.k9
|
||||
|
||||
import android.view.ContextThemeWrapper
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.work.WorkerParameters
|
||||
import com.fsck.k9.job.MailSyncWorker
|
||||
import com.fsck.k9.ui.R
|
||||
import com.fsck.k9.ui.changelog.ChangeLogMode
|
||||
import com.fsck.k9.ui.changelog.ChangelogViewModel
|
||||
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferActivity
|
||||
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferPresenter
|
||||
import com.fsck.k9.ui.folders.FolderIconProvider
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatter
|
||||
import com.fsck.k9.ui.helper.SizeFormatter
|
||||
import org.junit.Test
|
||||
|
@ -44,6 +47,9 @@ class DependencyInjectionTest : AutoCloseKoinTest() {
|
|||
withParameter<SizeFormatter> { RuntimeEnvironment.getApplication() }
|
||||
withParameter<ChangelogViewModel> { ChangeLogMode.CHANGE_LOG }
|
||||
withParameter<MailSyncWorker> { mock<WorkerParameters>() }
|
||||
withParameter<FolderIconProvider> {
|
||||
ContextThemeWrapper(RuntimeEnvironment.getApplication(), R.style.Theme_K9_DayNight).theme
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.fsck.k9.ui.helper.HtmlToSpanned
|
|||
import com.fsck.k9.ui.helper.SizeFormatter
|
||||
import com.fsck.k9.ui.messageview.LinkTextHandler
|
||||
import com.fsck.k9.ui.share.ShareIntentBuilder
|
||||
import org.koin.core.qualifier.named
|
||||
import org.koin.dsl.module
|
||||
|
||||
val uiModule = module {
|
||||
|
@ -15,6 +16,7 @@ val uiModule = module {
|
|||
single<ThemeProvider> { K9ThemeProvider() }
|
||||
single { HtmlSettingsProvider(get()) }
|
||||
single { DisplayHtmlUiFactory(get()) }
|
||||
factory(named("MessageView")) { get<DisplayHtmlUiFactory>().createForMessageView() }
|
||||
factory { (context: Context) -> SizeFormatter(context.resources) }
|
||||
factory { ShareIntentBuilder(resourceProvider = get(), textPartFinder = get(), quoteDateFormatter = get()) }
|
||||
factory { LinkTextHandler(context = get(), clipboardManager = get()) }
|
||||
|
|
|
@ -31,7 +31,7 @@ class ChooseFolderActivity : K9Activity() {
|
|||
private val preferences: Preferences by inject()
|
||||
private val messagingController: MessagingController by inject()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject { parametersOf(this) }
|
||||
private val folderIconProvider by lazy { FolderIconProvider(theme) }
|
||||
private val folderIconProvider: FolderIconProvider by inject { parametersOf(theme) }
|
||||
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var itemAdapter: ItemAdapter<FolderListItem>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.fsck.k9.ui.folders
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources.Theme
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.dsl.module
|
||||
|
||||
|
@ -8,4 +9,5 @@ val foldersUiModule = module {
|
|||
single { FolderNameFormatterFactory() }
|
||||
factory { (context: Context) -> FolderNameFormatter(context.resources) }
|
||||
viewModel { FoldersViewModel(folderRepository = get(), messageCountsProvider = get()) }
|
||||
factory { (theme: Theme) -> FolderIconProvider(theme) }
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class ManageFoldersFragment : Fragment() {
|
|||
private val folderNameFormatter: FolderNameFormatter by inject { parametersOf(requireActivity()) }
|
||||
private val messagingController: MessagingController by inject()
|
||||
private val preferences: Preferences by inject()
|
||||
private val folderIconProvider by lazy { FolderIconProvider(requireActivity().theme) }
|
||||
private val folderIconProvider: FolderIconProvider by inject { parametersOf(requireActivity().theme) }
|
||||
|
||||
private lateinit var account: Account
|
||||
private lateinit var itemAdapter: ItemAdapter<FolderListItem>
|
||||
|
|
|
@ -53,7 +53,6 @@ import com.fsck.k9.ui.changelog.RecentChangesViewModel
|
|||
import com.fsck.k9.ui.choosefolder.ChooseFolderActivity
|
||||
import com.fsck.k9.ui.fab.ShrinkFabOnScrollListener
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatter
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatterFactory
|
||||
import com.fsck.k9.ui.helper.RelativeDateTimeFormatter
|
||||
import com.fsck.k9.ui.messagelist.MessageListFragment.MessageListFragmentListener.Companion.MAX_PROGRESS
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
|
@ -63,6 +62,7 @@ import java.util.concurrent.Future
|
|||
import net.jcip.annotations.GuardedBy
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koin.core.parameter.parametersOf
|
||||
import timber.log.Timber
|
||||
|
||||
private const val MAXIMUM_MESSAGE_SORT_OVERRIDES = 3
|
||||
|
@ -77,8 +77,7 @@ class MessageListFragment :
|
|||
private val recentChangesViewModel: RecentChangesViewModel by viewModel()
|
||||
|
||||
private val sortTypeToastProvider: SortTypeToastProvider by inject()
|
||||
private val folderNameFormatterFactory: FolderNameFormatterFactory by inject()
|
||||
private val folderNameFormatter: FolderNameFormatter by lazy { folderNameFormatterFactory.create(requireContext()) }
|
||||
private val folderNameFormatter: FolderNameFormatter by inject { parametersOf(requireContext()) }
|
||||
private val messagingController: MessagingController by inject()
|
||||
private val preferences: Preferences by inject()
|
||||
private val clock: Clock by inject()
|
||||
|
|
|
@ -31,23 +31,21 @@ import com.fsck.k9.mail.Address
|
|||
import com.fsck.k9.mailstore.AttachmentResolver
|
||||
import com.fsck.k9.mailstore.AttachmentViewInfo
|
||||
import com.fsck.k9.mailstore.MessageViewInfo
|
||||
import com.fsck.k9.message.html.DisplayHtml
|
||||
import com.fsck.k9.ui.R
|
||||
import com.fsck.k9.ui.helper.DisplayHtmlUiFactory
|
||||
import com.fsck.k9.view.MessageWebView
|
||||
import com.fsck.k9.view.MessageWebView.OnPageFinishedListener
|
||||
import com.fsck.k9.view.WebViewConfigProvider
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
import org.koin.core.component.inject
|
||||
import org.koin.core.qualifier.named
|
||||
|
||||
class MessageContainerView(context: Context, attrs: AttributeSet?) :
|
||||
LinearLayout(context, attrs),
|
||||
OnCreateContextMenuListener,
|
||||
KoinComponent {
|
||||
|
||||
private val displayHtml by lazy(mode = LazyThreadSafetyMode.NONE) {
|
||||
get<DisplayHtmlUiFactory>().createForMessageView()
|
||||
}
|
||||
private val displayHtml: DisplayHtml by inject(named("MessageView"))
|
||||
private val webViewConfigProvider: WebViewConfigProvider by inject()
|
||||
private val clipboardManager: ClipboardManager by inject()
|
||||
private val linkTextHandler: LinkTextHandler by inject()
|
||||
|
|
Loading…
Reference in a new issue