2020-04-16 15:44:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Proton Technologies AG
|
2021-01-14 16:22:41 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* This file is part of ProtonMail.
|
2021-01-14 16:22:41 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* ProtonMail is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2021-01-14 16:22:41 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* ProtonMail is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2021-01-14 16:22:41 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with ProtonMail. If not, see https://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
package ch.protonmail.android.activities
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.text.TextUtils
|
2021-01-14 16:22:41 +00:00
|
|
|
import ch.protonmail.android.BuildConfig
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.R
|
|
|
|
import ch.protonmail.android.activities.settings.BaseSettingsActivity
|
|
|
|
import ch.protonmail.android.activities.settings.SettingsEnum
|
|
|
|
import ch.protonmail.android.events.FetchLabelsEvent
|
|
|
|
import ch.protonmail.android.utils.PREF_CUSTOM_APP_LANGUAGE
|
|
|
|
import com.squareup.otto.Subscribe
|
2020-10-13 11:52:58 +00:00
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
2021-01-14 16:22:41 +00:00
|
|
|
import me.proton.core.util.kotlin.EMPTY_STRING
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2020-10-13 11:52:58 +00:00
|
|
|
@AndroidEntryPoint
|
2020-04-16 15:44:53 +00:00
|
|
|
class SettingsActivity : BaseSettingsActivity() {
|
|
|
|
|
2020-10-13 09:52:03 +00:00
|
|
|
override fun getLayoutId(): Int = R.layout.activity_settings
|
2020-04-16 15:44:53 +00:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
val actionBar = supportActionBar
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true)
|
|
|
|
actionBar.setTitle(R.string.settings)
|
|
|
|
}
|
|
|
|
|
|
|
|
mSnackLayout = findViewById(R.id.layout_no_connectivity_info)
|
|
|
|
|
|
|
|
setUpSettingsItems(R.raw.settings_structure)
|
|
|
|
renderViews()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
setUpSettingsItems(R.raw.settings_structure)
|
|
|
|
renderViews()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun renderViews() {
|
|
|
|
|
2021-01-14 16:22:41 +00:00
|
|
|
val primaryAddress = checkNotNull(user.addresses.primary)
|
|
|
|
mDisplayName = primaryAddress.displayName?.s
|
|
|
|
?: primaryAddress.email.s
|
2020-04-16 15:44:53 +00:00
|
|
|
setHeader(SettingsEnum.ACCOUNT, mDisplayName)
|
|
|
|
|
2021-01-14 16:22:41 +00:00
|
|
|
if (user.addresses.hasAddresses) {
|
|
|
|
selectedAddress = checkNotNull(user.addresses.primary)
|
|
|
|
mSignature = selectedAddress.signature?.s ?: EMPTY_STRING
|
|
|
|
setValue(SettingsEnum.ACCOUNT, selectedAddress.email.s)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val languageValues = resources.getStringArray(R.array.custom_language_values)
|
|
|
|
val languageLabels = resources.getStringArray(R.array.custom_language_labels)
|
|
|
|
val appLanguage = sharedPreferences!!.getString(PREF_CUSTOM_APP_LANGUAGE, "")
|
|
|
|
if (appLanguage.isNullOrEmpty()) {
|
|
|
|
setValue(SettingsEnum.APP_LANGUAGE, getString(R.string.auto_detect))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (i in languageLabels.indices) {
|
|
|
|
if (languageValues[i] == appLanguage) {
|
|
|
|
setValue(SettingsEnum.APP_LANGUAGE, languageLabels[i])
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 16:22:41 +00:00
|
|
|
mPinValue = legacyUser.isUsePin && !TextUtils.isEmpty(mUserManager.getMailboxPin())
|
2020-04-16 15:44:53 +00:00
|
|
|
val autoLockSettingValue = if (mPinValue) getString(R.string.enabled) else getString(R.string.disabled)
|
|
|
|
setValue(SettingsEnum.AUTO_LOCK, autoLockSettingValue)
|
|
|
|
|
2020-09-23 15:14:11 +00:00
|
|
|
val allowSecureConnectionsViaThirdPartiesSettingValue =
|
2021-01-14 16:22:41 +00:00
|
|
|
if (legacyUser.allowSecureConnectionsViaThirdParties) getString(R.string.allowed) else getString(R.string.denied)
|
2020-05-06 06:25:14 +00:00
|
|
|
setValue(SettingsEnum.CONNECTIONS_VIA_THIRD_PARTIES, allowSecureConnectionsViaThirdPartiesSettingValue)
|
|
|
|
|
2021-01-14 16:22:41 +00:00
|
|
|
setValue(SettingsEnum.COMBINED_CONTACTS, if (legacyUser.combinedContacts) getString(R.string.enabled) else getString(R.string.disabled))
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2020-10-13 09:52:03 +00:00
|
|
|
setValue(
|
|
|
|
SettingsEnum.APP_VERSION,
|
|
|
|
String.format(
|
|
|
|
getString(R.string.app_version_code),
|
2021-01-14 16:22:41 +00:00
|
|
|
BuildConfig.VERSION_NAME,
|
|
|
|
BuildConfig.VERSION_CODE
|
2020-10-13 09:52:03 +00:00
|
|
|
)
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Subscribe
|
|
|
|
override fun onLabelsLoadedEvent(event: FetchLabelsEvent) {
|
|
|
|
super.onLabelsLoadedEvent(event)
|
|
|
|
}
|
|
|
|
}
|