Use TextQuoteCreator instances instead of static method
This commit is contained in:
parent
5aba2d0327
commit
63b3379e5d
5 changed files with 30 additions and 31 deletions
|
@ -16,6 +16,7 @@ import com.fsck.k9.mail.ssl.LocalKeyStore
|
|||
import com.fsck.k9.mailstore.mailStoreModule
|
||||
import com.fsck.k9.message.extractors.extractorModule
|
||||
import com.fsck.k9.message.html.htmlModule
|
||||
import com.fsck.k9.message.quote.quoteModule
|
||||
import com.fsck.k9.notification.coreNotificationModule
|
||||
import com.fsck.k9.power.DeviceIdleManager
|
||||
import com.fsck.k9.service.BootReceiver
|
||||
|
@ -40,6 +41,7 @@ object Core : KoinComponent {
|
|||
mailStoreModule,
|
||||
extractorModule,
|
||||
htmlModule,
|
||||
quoteModule,
|
||||
coreNotificationModule,
|
||||
controllerModule
|
||||
)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.fsck.k9.message.quote
|
||||
|
||||
import org.koin.dsl.module.applicationContext
|
||||
|
||||
val quoteModule = applicationContext {
|
||||
factory { QuoteHelper(get()) }
|
||||
factory { TextQuoteCreator(get(), get()) }
|
||||
}
|
|
@ -3,11 +3,8 @@ package com.fsck.k9.message.quote;
|
|||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.fsck.k9.Account.QuoteStyle;
|
||||
import com.fsck.k9.CoreResourceProvider;
|
||||
import com.fsck.k9.DI;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.Message.RecipientType;
|
||||
|
@ -16,6 +13,15 @@ import static com.fsck.k9.message.quote.QuoteHelper.QUOTE_BUFFER_LENGTH;
|
|||
|
||||
|
||||
public class TextQuoteCreator {
|
||||
private final QuoteHelper quoteHelper;
|
||||
private final CoreResourceProvider resourceProvider;
|
||||
|
||||
|
||||
public TextQuoteCreator(QuoteHelper quoteHelper, CoreResourceProvider resourceProvider) {
|
||||
this.quoteHelper = quoteHelper;
|
||||
this.resourceProvider = resourceProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add quoting markup to a text message.
|
||||
* @param originalMessage Metadata for message being quoted.
|
||||
|
@ -23,10 +29,10 @@ public class TextQuoteCreator {
|
|||
* @param quoteStyle Style of quoting.
|
||||
* @return Quoted text.
|
||||
*/
|
||||
public static String quoteOriginalTextMessage(Resources resources, Message originalMessage, String messageBody, QuoteStyle quoteStyle, String prefix) {
|
||||
CoreResourceProvider resourceProvider = DI.get(CoreResourceProvider.class);
|
||||
public String quoteOriginalTextMessage(Message originalMessage, String messageBody, QuoteStyle quoteStyle,
|
||||
String prefix) {
|
||||
String body = messageBody == null ? "" : messageBody;
|
||||
String sentDate = new QuoteHelper(resources).getSentDateText(originalMessage);
|
||||
String sentDate = quoteHelper.getSentDateText(originalMessage);
|
||||
if (quoteStyle == QuoteStyle.PREFIX) {
|
||||
String sender = Address.toString(originalMessage.getFrom());
|
||||
StringBuilder quotedText = new StringBuilder(body.length() + QUOTE_BUFFER_LENGTH);
|
||||
|
|
|
@ -4,7 +4,6 @@ package com.fsck.k9.message.quote
|
|||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import com.fsck.k9.Account.QuoteStyle
|
||||
import com.fsck.k9.CoreResourceProvider
|
||||
import com.fsck.k9.K9
|
||||
import com.fsck.k9.RobolectricTest
|
||||
import com.fsck.k9.TestCoreResourceProvider
|
||||
|
@ -15,11 +14,8 @@ import com.fsck.k9.mail.Message.RecipientType
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import com.nhaarman.mockito_kotlin.doReturn
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.koin.dsl.module.applicationContext
|
||||
import org.koin.standalone.StandAloneContext
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
|
@ -35,21 +31,12 @@ class TextQuoteCreatorTest : RobolectricTest() {
|
|||
on { getRecipients(RecipientType.CC) } doReturn emptyArray<Address>()
|
||||
on { subject } doReturn "Message subject"
|
||||
}
|
||||
val textQuoteCreator = TextQuoteCreator(QuoteHelper(resources), TestCoreResourceProvider())
|
||||
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
K9.setHideTimeZone(true)
|
||||
|
||||
val koinModule = applicationContext {
|
||||
bean { TestCoreResourceProvider() } bind CoreResourceProvider::class
|
||||
}
|
||||
StandAloneContext.startKoin(listOf(koinModule))
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
StandAloneContext.closeKoin()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -123,12 +110,6 @@ class TextQuoteCreatorTest : RobolectricTest() {
|
|||
}
|
||||
|
||||
private fun createQuote(messageBody: String, quoteStyle: QuoteStyle, quotePrefix: String = ""): String {
|
||||
return TextQuoteCreator.quoteOriginalTextMessage(
|
||||
resources,
|
||||
originalMessage,
|
||||
messageBody,
|
||||
quoteStyle,
|
||||
quotePrefix
|
||||
)
|
||||
return textQuoteCreator.quoteOriginalTextMessage(originalMessage, messageBody, quoteStyle, quotePrefix)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.Map;
|
|||
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.fsck.k9.DI;
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
|
@ -39,7 +41,7 @@ public class QuotedMessagePresenter {
|
|||
|
||||
private static final int UNKNOWN_LENGTH = 0;
|
||||
|
||||
|
||||
private final TextQuoteCreator textQuoteCreator = DI.get(TextQuoteCreator.class);
|
||||
private final QuotedMessageMvpView view;
|
||||
private final MessageCompose messageCompose;
|
||||
private final Resources resources;
|
||||
|
@ -119,7 +121,7 @@ public class QuotedMessagePresenter {
|
|||
AttachmentResolver.createFromPart(messageViewInfo.rootPart));
|
||||
|
||||
// TODO: Also strip the signature from the text/plain part
|
||||
view.setQuotedText(TextQuoteCreator.quoteOriginalTextMessage(resources, messageViewInfo.message,
|
||||
view.setQuotedText(textQuoteCreator.quoteOriginalTextMessage(messageViewInfo.message,
|
||||
BodyTextExtractor.getBodyTextFromMessage(messageViewInfo.rootPart, SimpleMessageFormat.TEXT),
|
||||
quoteStyle, account.getQuotePrefix()));
|
||||
|
||||
|
@ -128,8 +130,8 @@ public class QuotedMessagePresenter {
|
|||
content = TextSignatureRemover.stripSignature(content);
|
||||
}
|
||||
|
||||
view.setQuotedText(TextQuoteCreator.quoteOriginalTextMessage(
|
||||
resources, messageViewInfo.message, content, quoteStyle, account.getQuotePrefix()));
|
||||
view.setQuotedText(textQuoteCreator.quoteOriginalTextMessage(
|
||||
messageViewInfo.message, content, quoteStyle, account.getQuotePrefix()));
|
||||
}
|
||||
|
||||
if (showQuotedText) {
|
||||
|
|
Loading…
Reference in a new issue