Commit 7d6a052e authored by Ricki Hirner's avatar Ricki Hirner 🐑

Move strings out of global App context

parent a7f59ded
......@@ -226,7 +226,7 @@ class AccountSettings @Throws(InvalidAccountException::class) constructor(
try {
// don't run syncs during the migration
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 0)
ContentResolver.setIsSyncable(account, App.addressBooksAuthority, 0)
ContentResolver.setIsSyncable(account, context.getString(R.string.address_books_authority), 0)
ContentResolver.cancelSync(account, null)
// get previous address book settings (including URL)
......@@ -246,7 +246,7 @@ class AccountSettings @Throws(InvalidAccountException::class) constructor(
info.type = CollectionInfo.Type.ADDRESS_BOOK
info.displayName = account.name
Logger.log.log(Level.INFO, "Creating new address book account", url)
val addressBookAccount = Account(LocalAddressBook.accountName(account, info), App.addressBookAccountType)
val addressBookAccount = Account(LocalAddressBook.accountName(account, info), context.getString(R.string.account_type_address_book))
if (!accountManager.addAccountExplicitly(addressBookAccount, null, LocalAddressBook.initialUserData(account, info.url)))
throw ContactsStorageException("Couldn't create address book account")
......@@ -282,8 +282,8 @@ class AccountSettings @Throws(InvalidAccountException::class) constructor(
accountManager.setUserData(account, KEY_SETTINGS_VERSION, "6")
// request sync of new address book account
ContentResolver.setIsSyncable(account, App.addressBooksAuthority, 1)
setSyncInterval(App.addressBooksAuthority, Constants.DEFAULT_SYNC_INTERVAL)
ContentResolver.setIsSyncable(account, context.getString(R.string.address_books_authority), 1)
setSyncInterval(context.getString(R.string.address_books_authority), Constants.DEFAULT_SYNC_INTERVAL)
}
/* Android 7.1.1 OpenTasks fix */
......
......@@ -27,8 +27,6 @@ class App: Application() {
@JvmField val OVERRIDE_PROXY_HOST_DEFAULT = "localhost"
@JvmField val OVERRIDE_PROXY_PORT_DEFAULT = 8118
lateinit var addressBookAccountType: String
lateinit var addressBooksAuthority: String
@JvmStatic
fun getLauncherBitmap(context: Context): Bitmap? {
......@@ -48,11 +46,7 @@ class App: Application() {
override fun onCreate() {
super.onCreate()
Logger.reinitLogger(this)
addressBookAccountType = getString(R.string.account_type_address_book)
addressBooksAuthority = getString(R.string.address_books_authority)
}
}
......@@ -125,7 +125,7 @@ class DavService: Service() {
}
// delete orphaned address book accounts
accountManager.getAccountsByType(App.addressBookAccountType)
accountManager.getAccountsByType(getString(R.string.account_type_address_book))
.map { LocalAddressBook(this, it, null) }
.forEach {
try {
......
......@@ -18,8 +18,8 @@ import android.provider.ContactsContract.CommonDataKinds.GroupMembership
import android.provider.ContactsContract.Groups
import android.provider.ContactsContract.RawContacts
import android.util.Base64
import at.bitfire.davdroid.App
import at.bitfire.davdroid.DavUtils
import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.model.CollectionInfo
import at.bitfire.vcard4android.*
......@@ -46,7 +46,7 @@ class LocalAddressBook(
fun create(context: Context, provider: ContentProviderClient, mainAccount: Account, info: CollectionInfo): LocalAddressBook {
val accountManager = AccountManager.get(context)
val account = Account(accountName(mainAccount, info), App.addressBookAccountType)
val account = Account(accountName(mainAccount, info), context.getString(R.string.account_type_address_book))
if (!accountManager.addAccountExplicitly(account, null, initialUserData(mainAccount, info.url)))
throw ContactsStorageException("Couldn't create address book account")
......@@ -61,7 +61,7 @@ class LocalAddressBook(
val accountManager = AccountManager.get(context)
val result = LinkedList<LocalAddressBook>()
accountManager.getAccountsByType(App.addressBookAccountType)
accountManager.getAccountsByType(context.getString(R.string.account_type_address_book))
.map { LocalAddressBook(context, it, provider) }
.filter { mainAccount == null || it.getMainAccount() == mainAccount }
.forEach { result += it }
......
......@@ -32,7 +32,6 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.*
import android.widget.*
import at.bitfire.davdroid.App
import at.bitfire.davdroid.DavService
import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
......@@ -54,9 +53,9 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
companion object {
@JvmField val EXTRA_ACCOUNT = "account"
private fun requestSync(account: Account) {
private fun requestSync(context: Context, account: Account) {
val authorities = arrayOf(
App.addressBooksAuthority,
context.getString(R.string.address_books_authority),
CalendarContract.AUTHORITY,
TaskProvider.ProviderName.OpenTasks.authority
)
......@@ -405,10 +404,10 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
carddav.id = id
carddav.refreshing =
davService?.isRefreshing(id) ?: false ||
ContentResolver.isSyncActive(account, App.addressBooksAuthority)
ContentResolver.isSyncActive(account, context.getString(R.string.address_books_authority))
val accountManager = AccountManager.get(context)
for (addrBookAccount in accountManager.getAccountsByType(App.addressBookAccountType)) {
for (addrBookAccount in accountManager.getAccountsByType(context.getString(R.string.account_type_address_book))) {
val addressBook = LocalAddressBook(context, addrBookAccount, null)
try {
if (account == addressBook.getMainAccount())
......@@ -602,7 +601,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
// cancel maybe running synchronization
ContentResolver.cancelSync(oldAccount, null)
for (addrBookAccount in accountManager.getAccountsByType(App.addressBookAccountType))
for (addrBookAccount in accountManager.getAccountsByType(getString(R.string.account_type_address_book)))
ContentResolver.cancelSync(addrBookAccount, null)
// update account name references in database
......@@ -612,7 +611,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
// update main account of address book accounts
try {
for (addrBookAccount in accountManager.getAccountsByType(App.addressBookAccountType)) {
for (addrBookAccount in accountManager.getAccountsByType(getString(R.string.account_type_address_book))) {
val provider = activity.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)
try {
if (provider != null) {
......@@ -643,7 +642,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
}
// synchronize again
requestSync(Account(newName, oldAccount.type))
requestSync(activity, Account(newName, oldAccount.type))
}, null)
activity.finish()
})
......@@ -679,7 +678,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
}
private fun requestSync() {
requestSync(account)
requestSync(this, account)
Snackbar.make(findViewById(R.id.parent), R.string.account_synchronizing_now, Snackbar.LENGTH_LONG).show()
}
......
......@@ -25,7 +25,8 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.preference.*
import android.support.v7.preference.Preference.OnPreferenceChangeListener
import android.view.MenuItem
import at.bitfire.davdroid.*
import at.bitfire.davdroid.AccountSettings
import at.bitfire.davdroid.InvalidAccountException
import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
import at.bitfire.ical4android.TaskProvider
......@@ -107,7 +108,7 @@ class AccountSettingsActivity: AppCompatActivity() {
// category: synchronization
val prefSyncContacts = findPreference("sync_interval_contacts") as ListPreference
val syncIntervalContacts = settings.getSyncInterval(App.addressBooksAuthority)
val syncIntervalContacts = settings.getSyncInterval(getString(R.string.address_books_authority))
if (syncIntervalContacts != null) {
prefSyncContacts.value = syncIntervalContacts.toString()
if (syncIntervalContacts == AccountSettings.SYNC_INTERVAL_MANUALLY)
......@@ -115,7 +116,7 @@ class AccountSettingsActivity: AppCompatActivity() {
else
prefSyncContacts.summary = getString(R.string.settings_sync_summary_periodically, syncIntervalContacts / 60)
prefSyncContacts.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue ->
settings.setSyncInterval(App.addressBooksAuthority, (newValue as String).toLong())
settings.setSyncInterval(getString(R.string.address_books_authority), (newValue as String).toLong())
loaderManager.restartLoader(0, arguments, this)
false
}
......
......@@ -116,9 +116,9 @@ class AccountDetailsFragment: Fragment() {
settings.setGroupMethod(GroupMethod.valueOf(groupMethodName))
// contact sync is automatically enabled by isAlwaysSyncable="true" in res/xml/sync_address_books.xml
settings.setSyncInterval(App.addressBooksAuthority, Constants.DEFAULT_SYNC_INTERVAL)
settings.setSyncInterval(getString(R.string.address_books_authority), Constants.DEFAULT_SYNC_INTERVAL)
} else
ContentResolver.setIsSyncable(account, App.addressBooksAuthority, 0)
ContentResolver.setIsSyncable(account, getString(R.string.address_books_authority), 0)
if (config.calDAV != null) {
// insert CalDAV service
......
Subproject commit 25e369a99bffee01b64dac1ecc7a771f88f1a006
Subproject commit 4af27ab355130facb9b4ba61a3d9455e73acf201
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment