Remove getInstance as instance should be controlled by dependency injection

This commit is contained in:
Wolf Montwé 2023-03-06 16:46:40 +01:00
parent 264deb98f2
commit 979240b6e1
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
3 changed files with 6 additions and 18 deletions

View file

@ -7,7 +7,7 @@ import org.koin.dsl.module
val helperModule = module {
single { ClipboardManager(get()) }
single { MessageHelper.getInstance() }
single { MessageHelper(resourceProvider = get(), contacts = get()) }
factory<KeyStoreDirectoryProvider> { AndroidKeyStoreDirectoryProvider(context = get()) }
factory { get<Context>().getSystemService(Context.ALARM_SERVICE) as AlarmManager }
single { AlarmManagerCompat(alarmManager = get()) }

View file

@ -6,7 +6,6 @@ import android.text.SpannableStringBuilder
import android.text.TextUtils
import android.text.style.ForegroundColorSpan
import com.fsck.k9.CoreResourceProvider
import com.fsck.k9.DI
import com.fsck.k9.K9.contactNameColor
import com.fsck.k9.K9.isChangeContactNameColor
import com.fsck.k9.K9.isShowContactName
@ -14,15 +13,16 @@ import com.fsck.k9.K9.isShowCorrespondentNames
import com.fsck.k9.mail.Address
import java.util.regex.Pattern
class MessageHelper private constructor(
class MessageHelper(
private val resourceProvider: CoreResourceProvider,
private val contacts: Contacts,
) {
fun getSenderDisplayName(address: Address?): CharSequence {
if (address == null) {
return resourceProvider.contactUnknownSender()
}
val contactHelper = if (isShowContactName) DI.get(Contacts::class.java) else null
val contactHelper = if (isShowContactName) contacts else null
return toFriendly(address, contactHelper)
}
@ -30,7 +30,7 @@ class MessageHelper private constructor(
if (addresses == null || addresses.isEmpty()) {
return resourceProvider.contactUnknownRecipient()
}
val contactHelper = if (isShowContactName) DI.get(Contacts::class.java) else null
val contactHelper = if (isShowContactName) contacts else null
val recipients = toFriendly(addresses, contactHelper)
return SpannableStringBuilder(resourceProvider.contactDisplayNamePrefix()).append(recipients)
}
@ -46,17 +46,6 @@ class MessageHelper private constructor(
*/
private const val TOO_MANY_ADDRESSES = 50
private val SPOOF_ADDRESS_PATTERN = Pattern.compile("[^(]@")
private var sInstance: MessageHelper? = null
@JvmStatic
@Synchronized
fun getInstance(): MessageHelper? {
if (sInstance == null) {
val resourceProvider = DI.get(CoreResourceProvider::class.java)
sInstance = MessageHelper(resourceProvider)
}
return sInstance
}
/**
* Returns the name of the contact this email address belongs to if

View file

@ -47,6 +47,7 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
private final MessageViewRecipientFormatter recipientFormatter = DI.get(MessageViewRecipientFormatter.class);
private final ReplyActionStrategy replyActionStrategy = DI.get(ReplyActionStrategy.class);
private final MessageHelper messageHelper = DI.get(MessageHelper.class);
private final FontSizes fontSizes = K9.getFontSizes();
private Chip accountChip;
@ -59,7 +60,6 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
private TextView dateView;
private ImageView menuPrimaryActionView;
private MessageHelper messageHelper;
private RelativeDateTimeFormatter relativeDateTimeFormatter;
private MessageHeaderClickListener messageHeaderClickListener;
@ -70,7 +70,6 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
super(context, attrs);
if (!isInEditMode()) {
messageHelper = MessageHelper.getInstance();
relativeDateTimeFormatter = DI.get(RelativeDateTimeFormatter.class);
}
}