Make sure FolderNameFormatter uses the correct Resources instance
This is necessary so special folder names are displayed in the language configured by the user under general settings.
This commit is contained in:
parent
c726a2d902
commit
aa08570a45
11 changed files with 41 additions and 10 deletions
|
@ -4,6 +4,7 @@ import androidx.lifecycle.Lifecycle
|
|||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferActivity
|
||||
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferPresenter
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatter
|
||||
import com.nhaarman.mockitokotlin2.doReturn
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import org.junit.Test
|
||||
|
@ -15,6 +16,7 @@ import org.koin.test.AutoCloseKoinTest
|
|||
import org.koin.test.check.checkModules
|
||||
import org.openintents.openpgp.OpenPgpApiManager
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
|
@ -32,6 +34,7 @@ class DependencyInjectionTest : AutoCloseKoinTest() {
|
|||
getKoin().checkModules {
|
||||
create<OpenPgpApiManager> { parametersOf(lifecycleOwner) }
|
||||
create<AutocryptKeyTransferPresenter> { parametersOf(lifecycleOwner, autocryptTransferView) }
|
||||
create<FolderNameFormatter> { parametersOf(RuntimeEnvironment.application) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import androidx.lifecycle.Lifecycle
|
|||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferActivity
|
||||
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferPresenter
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatter
|
||||
import com.nhaarman.mockitokotlin2.doReturn
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import org.junit.Test
|
||||
|
@ -15,6 +16,7 @@ import org.koin.test.AutoCloseKoinTest
|
|||
import org.koin.test.check.checkModules
|
||||
import org.openintents.openpgp.OpenPgpApiManager
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
|
@ -32,6 +34,7 @@ class DependencyInjectionTest : AutoCloseKoinTest() {
|
|||
getKoin().checkModules {
|
||||
create<OpenPgpApiManager> { parametersOf(lifecycleOwner) }
|
||||
create<AutocryptKeyTransferPresenter> { parametersOf(lifecycleOwner, autocryptTransferView) }
|
||||
create<FolderNameFormatter> { parametersOf(RuntimeEnvironment.application) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.fsck.k9.activity;
|
|||
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.DI;
|
||||
import com.fsck.k9.mailstore.Folder;
|
||||
import com.fsck.k9.mailstore.FolderType;
|
||||
import com.fsck.k9.mailstore.LocalFolder;
|
||||
|
@ -10,7 +9,7 @@ import com.fsck.k9.ui.folders.FolderNameFormatter;
|
|||
|
||||
|
||||
public class FolderInfoHolder {
|
||||
private final FolderNameFormatter folderNameFormatter = DI.get(FolderNameFormatter.class);
|
||||
private final FolderNameFormatter folderNameFormatter;
|
||||
|
||||
public final String serverId;
|
||||
public final String displayName;
|
||||
|
@ -19,7 +18,8 @@ public class FolderInfoHolder {
|
|||
public boolean moreMessages;
|
||||
|
||||
|
||||
public FolderInfoHolder(LocalFolder localFolder, Account account) {
|
||||
public FolderInfoHolder(FolderNameFormatter folderNameFormatter, LocalFolder localFolder, Account account) {
|
||||
this.folderNameFormatter = folderNameFormatter;
|
||||
this.serverId = localFolder.getServerId();
|
||||
this.lastChecked = localFolder.getLastUpdate();
|
||||
this.displayName = getDisplayName(account, localFolder);
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.fsck.k9.mail.MessagingException;
|
|||
import com.fsck.k9.mailstore.LocalFolder;
|
||||
import com.fsck.k9.mailstore.LocalStore;
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatter;
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatterFactory;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
|
@ -43,7 +44,9 @@ public class FolderSettings extends K9PreferenceActivity {
|
|||
|
||||
private final MessagingController messagingController = DI.get(MessagingController.class);
|
||||
private final K9JobManager jobManager = DI.get(K9JobManager.class);
|
||||
private final FolderNameFormatter folderNameFormatter = DI.get(FolderNameFormatter.class);
|
||||
private final FolderNameFormatterFactory folderNameFormatterFactory = DI.get(FolderNameFormatterFactory.class);
|
||||
|
||||
private FolderNameFormatter folderNameFormatter;
|
||||
|
||||
private LocalFolder mFolder;
|
||||
|
||||
|
@ -65,6 +68,8 @@ public class FolderSettings extends K9PreferenceActivity {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
folderNameFormatter = folderNameFormatterFactory.create(this);
|
||||
|
||||
String folderServerId = (String)getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
|
||||
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
||||
Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
||||
|
|
|
@ -62,6 +62,8 @@ import com.fsck.k9.mailstore.LocalFolder;
|
|||
import com.fsck.k9.preferences.StorageEditor;
|
||||
import com.fsck.k9.search.LocalSearch;
|
||||
import com.fsck.k9.ui.R;
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatter;
|
||||
import com.fsck.k9.ui.folders.FolderNameFormatterFactory;
|
||||
import com.fsck.k9.ui.messagelist.MessageListAppearance;
|
||||
import com.fsck.k9.ui.messagelist.MessageListConfig;
|
||||
import com.fsck.k9.ui.messagelist.MessageListFragmentDiContainer;
|
||||
|
@ -105,6 +107,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
|
||||
private final SortTypeToastProvider sortTypeToastProvider = DI.get(SortTypeToastProvider.class);
|
||||
private final MessageListFragmentDiContainer diContainer = new MessageListFragmentDiContainer(this);
|
||||
private final FolderNameFormatterFactory folderNameFormatterFactory = DI.get(FolderNameFormatterFactory.class);
|
||||
private FolderNameFormatter folderNameFormatter;
|
||||
|
||||
ListView listView;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
@ -309,6 +313,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
folderNameFormatter = folderNameFormatterFactory.create(requireActivity());
|
||||
Context appContext = getActivity().getApplicationContext();
|
||||
|
||||
preferences = Preferences.getPreferences(appContext);
|
||||
|
@ -523,7 +528,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
private FolderInfoHolder getFolderInfoHolder(String folderServerId, Account account) {
|
||||
try {
|
||||
LocalFolder localFolder = MlfUtils.getOpenFolder(folderServerId, account);
|
||||
return new FolderInfoHolder(localFolder, account);
|
||||
return new FolderInfoHolder(folderNameFormatter, localFolder, account);
|
||||
} catch (MessagingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -38,10 +38,11 @@ import java.util.HashSet
|
|||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import org.koin.core.parameter.parametersOf
|
||||
|
||||
class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : KoinComponent {
|
||||
private val viewModel: FoldersViewModel by parent.viewModel()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject { parametersOf(parent) }
|
||||
private val preferences: Preferences by inject()
|
||||
private val themeManager: ThemeManager by inject()
|
||||
private val resources: Resources by inject()
|
||||
|
|
|
@ -25,12 +25,13 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter
|
|||
import java.util.Locale
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koin.core.parameter.parametersOf
|
||||
|
||||
class ChooseFolderActivity : K9Activity() {
|
||||
private val viewModel: ChooseFolderViewModel by viewModel()
|
||||
private val preferences: Preferences by inject()
|
||||
private val messagingController: MessagingController by inject()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject { parametersOf(this) }
|
||||
private val folderIconProvider by lazy { FolderIconProvider(theme) }
|
||||
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.fsck.k9.ui.folders
|
||||
|
||||
import android.content.Context
|
||||
|
||||
class FolderNameFormatterFactory {
|
||||
fun create(context: Context): FolderNameFormatter {
|
||||
return FolderNameFormatter(context.resources)
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package com.fsck.k9.ui.folders
|
||||
|
||||
import android.content.Context
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.dsl.module
|
||||
|
||||
val foldersUiModule = module {
|
||||
single { FolderNameFormatter(get()) }
|
||||
single { FolderNameFormatterFactory() }
|
||||
factory { (context: Context) -> FolderNameFormatter(context.resources) }
|
||||
single { FoldersLiveDataFactory(get(), get(), get()) }
|
||||
viewModel { FoldersViewModel(get()) }
|
||||
}
|
||||
|
|
|
@ -29,10 +29,11 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter
|
|||
import java.util.Locale
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koin.core.parameter.parametersOf
|
||||
|
||||
class ManageFoldersActivity : K9Activity() {
|
||||
private val viewModel: ManageFoldersViewModel by viewModel()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject { parametersOf(this) }
|
||||
private val messagingController: MessagingController by inject()
|
||||
private val preferences: Preferences by inject()
|
||||
private val folderIconProvider by lazy { FolderIconProvider(theme) }
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.fsck.k9.ui.R
|
|||
import com.fsck.k9.ui.folders.FolderNameFormatter
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import org.koin.core.parameter.parametersOf
|
||||
|
||||
/**
|
||||
* A [ListPreference] that allows selecting one of an account's folders.
|
||||
|
@ -27,7 +28,7 @@ constructor(
|
|||
android.R.attr.dialogPreferenceStyle),
|
||||
defStyleRes: Int = 0
|
||||
) : ListPreference(context, attrs, defStyleAttr, defStyleRes), KoinComponent {
|
||||
private val folderNameFormatter: FolderNameFormatter by inject()
|
||||
private val folderNameFormatter: FolderNameFormatter by inject { parametersOf(context) }
|
||||
private val noFolderSelectedName = context.getString(R.string.account_settings_no_folder_selected).italicize()
|
||||
private lateinit var automaticFolderOption: CharSequence
|
||||
|
||||
|
|
Loading…
Reference in a new issue