2020-04-16 15:44:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Proton Technologies AG
|
2021-01-26 09:39:03 +00:00
|
|
|
*
|
2020-04-16 15:44:53 +00:00
|
|
|
* This file is part of ProtonMail.
|
2021-01-26 09:39:03 +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-26 09:39:03 +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-26 09:39:03 +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.settings
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.preference.PreferenceManager
|
2020-10-13 09:52:03 +00:00
|
|
|
import android.provider.Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
|
|
|
|
import android.provider.Settings.EXTRA_APP_PACKAGE
|
|
|
|
import android.provider.Settings.EXTRA_CHANNEL_ID
|
2020-04-16 15:44:53 +00:00
|
|
|
import android.view.Gravity
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.View
|
2020-11-13 15:13:23 +00:00
|
|
|
import androidx.activity.viewModels
|
2020-04-16 15:44:53 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import ch.protonmail.android.R
|
2020-10-13 09:52:03 +00:00
|
|
|
import ch.protonmail.android.activities.AccountSettingsActivity
|
|
|
|
import ch.protonmail.android.activities.AccountTypeActivity
|
|
|
|
import ch.protonmail.android.activities.BaseConnectivityActivity
|
|
|
|
import ch.protonmail.android.activities.ChangePasswordActivity
|
|
|
|
import ch.protonmail.android.activities.DefaultAddressActivity
|
|
|
|
import ch.protonmail.android.activities.EXTRA_CURRENT_ACTION
|
|
|
|
import ch.protonmail.android.activities.EXTRA_SETTINGS_ITEM_TYPE
|
|
|
|
import ch.protonmail.android.activities.EXTRA_SETTINGS_ITEM_VALUE
|
|
|
|
import ch.protonmail.android.activities.EXTRA_SWIPE_ID
|
|
|
|
import ch.protonmail.android.activities.EditSettingsItemActivity
|
|
|
|
import ch.protonmail.android.activities.SettingsItem
|
|
|
|
import ch.protonmail.android.activities.SnoozeNotificationsActivity
|
|
|
|
import ch.protonmail.android.activities.SwipeChooserActivity
|
|
|
|
import ch.protonmail.android.activities.SwipeType
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.activities.labelsManager.EXTRA_MANAGE_FOLDERS
|
|
|
|
import ch.protonmail.android.activities.labelsManager.LabelsManagerActivity
|
|
|
|
import ch.protonmail.android.activities.mailbox.MailboxActivity
|
2021-01-26 13:02:26 +00:00
|
|
|
import ch.protonmail.android.activities.settings.SettingsEnum.*
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.adapters.SettingsAdapter
|
|
|
|
import ch.protonmail.android.core.Constants
|
2021-01-26 13:02:26 +00:00
|
|
|
import ch.protonmail.android.core.UserManager
|
2021-02-18 16:10:43 +00:00
|
|
|
import ch.protonmail.android.data.local.AttachmentMetadataDao
|
2021-03-17 14:54:52 +00:00
|
|
|
import ch.protonmail.android.data.local.ContactDao
|
|
|
|
import ch.protonmail.android.data.local.ContactDatabase
|
2021-03-18 09:47:58 +00:00
|
|
|
import ch.protonmail.android.data.local.CounterDao
|
|
|
|
import ch.protonmail.android.data.local.CounterDatabase
|
2021-03-17 14:45:53 +00:00
|
|
|
import ch.protonmail.android.data.local.MessageDao
|
|
|
|
import ch.protonmail.android.data.local.MessageDatabase
|
2021-01-21 16:15:05 +00:00
|
|
|
import ch.protonmail.android.data.local.NotificationDao
|
|
|
|
import ch.protonmail.android.data.local.NotificationDatabase
|
2021-03-17 14:46:14 +00:00
|
|
|
import ch.protonmail.android.data.local.PendingActionDao
|
|
|
|
import ch.protonmail.android.data.local.PendingActionDatabase
|
2021-03-18 09:46:25 +00:00
|
|
|
import ch.protonmail.android.data.local.model.*
|
2021-01-26 13:02:26 +00:00
|
|
|
import ch.protonmail.android.domain.entity.user.Address
|
|
|
|
import ch.protonmail.android.domain.entity.user.User
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.events.FetchLabelsEvent
|
|
|
|
import ch.protonmail.android.jobs.FetchByLocationJob
|
|
|
|
import ch.protonmail.android.servers.notification.CHANNEL_ID_EMAIL
|
|
|
|
import ch.protonmail.android.settings.pin.PinSettingsActivity
|
|
|
|
import ch.protonmail.android.uiModel.SettingsItemUiModel
|
2020-11-05 11:16:54 +00:00
|
|
|
import ch.protonmail.android.usecase.fetch.LaunchInitialDataFetch
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.utils.AppUtil
|
|
|
|
import ch.protonmail.android.utils.CustomLocale
|
|
|
|
import ch.protonmail.android.utils.PREF_CUSTOM_APP_LANGUAGE
|
2021-01-26 13:02:26 +00:00
|
|
|
import ch.protonmail.android.utils.extensions.app
|
2020-04-16 15:44:53 +00:00
|
|
|
import ch.protonmail.android.utils.extensions.showToast
|
2020-10-13 11:52:58 +00:00
|
|
|
import ch.protonmail.android.viewmodel.ConnectivityBaseViewModel
|
2020-04-16 15:44:53 +00:00
|
|
|
import com.google.gson.Gson
|
2020-10-13 11:52:58 +00:00
|
|
|
import timber.log.Timber
|
2020-10-13 09:52:03 +00:00
|
|
|
import java.util.Locale
|
2020-04-16 15:44:53 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean
|
2020-10-13 11:52:58 +00:00
|
|
|
import javax.inject.Inject
|
2021-01-26 13:02:26 +00:00
|
|
|
import ch.protonmail.android.api.models.User as LegacyUser
|
2020-04-16 15:44:53 +00:00
|
|
|
|
|
|
|
// region constants
|
|
|
|
const val EXTRA_CURRENT_MAILBOX_LOCATION = "Extra_Current_Mailbox_Location"
|
|
|
|
const val EXTRA_CURRENT_MAILBOX_LABEL_ID = "Extra_Current_Mailbox_Label_ID"
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
abstract class BaseSettingsActivity : BaseConnectivityActivity() {
|
|
|
|
|
2020-11-13 15:13:23 +00:00
|
|
|
val viewModel: ConnectivityBaseViewModel by viewModels()
|
2020-10-13 11:52:58 +00:00
|
|
|
|
2021-01-26 13:02:26 +00:00
|
|
|
@Inject
|
|
|
|
lateinit var userManager: UserManager
|
|
|
|
|
2020-11-02 13:26:50 +00:00
|
|
|
@Inject
|
2020-11-05 11:16:54 +00:00
|
|
|
lateinit var launchInitialDataFetch: LaunchInitialDataFetch
|
2020-11-02 13:26:50 +00:00
|
|
|
|
2021-03-04 16:04:11 +00:00
|
|
|
@Inject
|
|
|
|
lateinit var attachmentMetadataDao: AttachmentMetadataDao
|
|
|
|
|
2020-04-16 15:44:53 +00:00
|
|
|
// region views
|
|
|
|
private val toolbar by lazy { findViewById<Toolbar>(R.id.toolbar) }
|
|
|
|
private val settingsRecyclerView by lazy { findViewById<RecyclerView>(R.id.settingsRecyclerView) }
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
private val settingsAdapter = SettingsAdapter()
|
|
|
|
|
|
|
|
var settingsUiList: List<SettingsItemUiModel> = ArrayList()
|
|
|
|
|
2021-03-17 14:54:52 +00:00
|
|
|
var contactDao: ContactDao? = null
|
2021-03-17 14:45:53 +00:00
|
|
|
var messageDao: MessageDao? = null
|
|
|
|
private var searchDatabase: MessageDao? = null
|
2021-01-21 16:15:05 +00:00
|
|
|
private var notificationDao: NotificationDao? = null
|
2021-02-11 12:56:45 +00:00
|
|
|
var counterDao: CounterDao? = null
|
2021-03-17 14:46:14 +00:00
|
|
|
var pendingActionDao: PendingActionDao? = null
|
2020-04-16 15:44:53 +00:00
|
|
|
var sharedPreferences: SharedPreferences? = null
|
|
|
|
|
|
|
|
private var mMailboxLocation: Constants.MessageLocationType = Constants.MessageLocationType.INBOX
|
|
|
|
private var mLabelId: String? = null
|
|
|
|
var mBackgroundSyncValue: Boolean = false
|
|
|
|
var mAttachmentStorageValue: Int = 0
|
|
|
|
var mAutoDownloadGcmMessages: Boolean = false
|
|
|
|
var mPinValue: Boolean = false
|
|
|
|
var mRecoveryEmail: String = ""
|
|
|
|
var mNotificationOptionValue: Int = 0
|
2021-01-26 13:02:26 +00:00
|
|
|
lateinit var selectedAddress: Address
|
2020-04-16 15:44:53 +00:00
|
|
|
var mDisplayName: String = ""
|
|
|
|
var mSignature: String = ""
|
2021-01-26 13:02:26 +00:00
|
|
|
@Deprecated("Use new User model", ReplaceWith("user"))
|
|
|
|
lateinit var legacyUser: LegacyUser
|
2020-04-16 15:44:53 +00:00
|
|
|
lateinit var user: User
|
|
|
|
|
|
|
|
private var canClick = AtomicBoolean(true)
|
|
|
|
|
|
|
|
init {
|
|
|
|
settingsAdapter.onItemClick = { settingItem ->
|
|
|
|
|
2021-01-26 13:02:26 +00:00
|
|
|
if (settingItem.isSection.not() &&
|
|
|
|
(settingItem.settingType == SettingsItemUiModel.SettingsItemTypeEnum.DRILL_DOWN ||
|
|
|
|
settingItem.settingType == SettingsItemUiModel.SettingsItemTypeEnum.BUTTON)) {
|
2020-04-16 15:44:53 +00:00
|
|
|
selectItem(settingItem.settingId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 13:02:26 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
2021-03-18 09:47:58 +00:00
|
|
|
legacyUser = userManager.requireCurrentLegacyUserBlocking()
|
|
|
|
user = legacyUser.toNewUser()
|
|
|
|
val userId = user.id
|
|
|
|
|
|
|
|
contactDao = ContactDatabase.getInstance(applicationContext, userId).getDao()
|
|
|
|
messageDao = MessageDatabase.getInstance(applicationContext, userId).getDao()
|
|
|
|
searchDatabase = MessageDatabase.getSearchDatabase(applicationContext, userId).getDao()
|
|
|
|
notificationDao = NotificationDatabase.getInstance(applicationContext, userId).getDao()
|
|
|
|
counterDao = CounterDatabase.getInstance(applicationContext, userId).getDao()
|
|
|
|
pendingActionDao = PendingActionDatabase.getInstance(applicationContext, userId).getDao()
|
2021-01-26 13:02:26 +00:00
|
|
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this@BaseSettingsActivity)
|
|
|
|
|
|
|
|
mMailboxLocation = Constants.MessageLocationType
|
|
|
|
.fromInt(intent.getIntExtra(EXTRA_CURRENT_MAILBOX_LOCATION, 0))
|
|
|
|
mLabelId = intent.getStringExtra(EXTRA_CURRENT_MAILBOX_LABEL_ID)
|
|
|
|
|
|
|
|
fetchOrganizationData()
|
|
|
|
|
|
|
|
|
|
|
|
val primaryAddress = checkNotNull(user.addresses.primary)
|
|
|
|
mDisplayName = primaryAddress.displayName?.s
|
|
|
|
?: primaryAddress.email.s
|
|
|
|
|
|
|
|
viewModel.hasConnectivity.observe(this, ::onConnectivityEvent)
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:44:53 +00:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
2021-01-26 13:02:26 +00:00
|
|
|
app.bus.register(this)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2021-01-26 13:02:26 +00:00
|
|
|
legacyUser = userManager.requireCurrentLegacyUserBlocking()
|
|
|
|
user = legacyUser.toNewUser()
|
|
|
|
settingsAdapter.notifyDataSetChanged()
|
2020-10-13 11:52:58 +00:00
|
|
|
viewModel.checkConnectivity()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
super.onStop()
|
2021-01-26 13:02:26 +00:00
|
|
|
app.bus.unregister(this)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
if (item.itemId == android.R.id.home) {
|
|
|
|
onBackPressed()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
saveLastInteraction()
|
|
|
|
setResult(Activity.RESULT_OK)
|
|
|
|
finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setContentView(layoutResID: Int) {
|
|
|
|
super.setContentView(layoutResID)
|
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract fun renderViews()
|
|
|
|
|
|
|
|
private fun showCustomLocaleDialog() {
|
|
|
|
val selectedLanguage = sharedPreferences!!.getString(PREF_CUSTOM_APP_LANGUAGE, "")
|
|
|
|
val languageValues = resources.getStringArray(R.array.custom_language_values)
|
2021-01-26 13:02:26 +00:00
|
|
|
val selectedLanguageIndex = languageValues.indexOfFirst { it == selectedLanguage }
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-01-26 13:02:26 +00:00
|
|
|
AlertDialog.Builder(this)
|
|
|
|
.setTitle(R.string.custom_language_dialog_title)
|
|
|
|
.setSingleChoiceItems(
|
|
|
|
resources.getStringArray(R.array.custom_language_labels),
|
|
|
|
selectedLanguageIndex
|
|
|
|
) { dialog, which ->
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-01-26 13:02:26 +00:00
|
|
|
val language = resources.getStringArray(R.array.custom_language_values)[which]
|
|
|
|
CustomLocale.setLanguage(this@BaseSettingsActivity, language)
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-01-26 13:02:26 +00:00
|
|
|
val recreatedMailboxIntent = Intent(this@BaseSettingsActivity, MailboxActivity::class.java)
|
|
|
|
recreatedMailboxIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
2020-04-16 15:44:53 +00:00
|
|
|
|
2021-01-26 13:02:26 +00:00
|
|
|
dialog.dismiss()
|
|
|
|
startActivity(recreatedMailboxIntent)
|
|
|
|
}
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
|
|
|
.create()
|
|
|
|
.show()
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun showSortAliasDialog() {
|
|
|
|
val defaultAddressIntent = AppUtil.decorInAppIntent(Intent(this, DefaultAddressActivity::class.java))
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(defaultAddressIntent, DEFAULT_EMAIL.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun selectItem(settingsId: String) {
|
2021-01-26 13:02:26 +00:00
|
|
|
legacyUser = userManager.requireCurrentLegacyUserBlocking()
|
|
|
|
user = legacyUser.toNewUser()
|
|
|
|
when (valueOf(settingsId.toUpperCase(Locale.ENGLISH))) {
|
|
|
|
ACCOUNT -> {
|
|
|
|
val accountSettingsIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, AccountSettingsActivity::class.java))
|
|
|
|
startActivityForResult(accountSettingsIntent, ACCOUNT.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
SUBSCRIPTION -> {
|
|
|
|
val accountTypeIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, AccountTypeActivity::class.java))
|
2020-04-16 15:44:53 +00:00
|
|
|
startActivity(accountTypeIntent)
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
PASSWORD_MANAGEMENT -> {
|
|
|
|
val passwordManagerIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, ChangePasswordActivity::class.java))
|
|
|
|
startActivityForResult(passwordManagerIntent, PASSWORD_MANAGEMENT.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
RECOVERY_EMAIL -> {
|
|
|
|
val recoveryEmailIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, EditSettingsItemActivity::class.java))
|
2020-04-16 15:44:53 +00:00
|
|
|
recoveryEmailIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.RECOVERY_EMAIL)
|
|
|
|
recoveryEmailIntent.putExtra(EXTRA_SETTINGS_ITEM_VALUE, mRecoveryEmail)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(recoveryEmailIntent, RECOVERY_EMAIL.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
DEFAULT_EMAIL -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
showSortAliasDialog()
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
DISPLAY_NAME_N_SIGNATURE -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val editSignatureIntent = Intent(this, EditSettingsItemActivity::class.java)
|
|
|
|
editSignatureIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.DISPLAY_NAME_AND_SIGNATURE)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(editSignatureIntent), DISPLAY_NAME_N_SIGNATURE.ordinal
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
NOTIFICATION_SNOOZE -> {
|
|
|
|
val notificationSnoozeIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, SnoozeNotificationsActivity::class.java))
|
|
|
|
startActivityForResult(notificationSnoozeIntent, NOTIFICATION_SNOOZE.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
PRIVACY -> {
|
|
|
|
val privacyIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, EditSettingsItemActivity::class.java))
|
2020-04-16 15:44:53 +00:00
|
|
|
privacyIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.PRIVACY)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(privacyIntent, PRIVACY.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
AUTO_DOWNLOAD_MESSAGES -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val gcmAutoDownloadIntent = Intent(this, EditSettingsItemActivity::class.java)
|
|
|
|
gcmAutoDownloadIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.AUTO_DOWNLOAD_MESSAGES)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(gcmAutoDownloadIntent), AUTO_DOWNLOAD_MESSAGES.ordinal
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
BACKGROUND_REFRESH -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val backgroundSyncIntent = Intent(this, EditSettingsItemActivity::class.java)
|
|
|
|
backgroundSyncIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.BACKGROUND_SYNC)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(backgroundSyncIntent), BACKGROUND_REFRESH.ordinal
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
LABELS_N_FOLDERS -> {
|
|
|
|
val labelsNFoldersIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, EditSettingsItemActivity::class.java))
|
2020-04-16 15:44:53 +00:00
|
|
|
labelsNFoldersIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.LABELS_AND_FOLDERS)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(labelsNFoldersIntent, LABELS_N_FOLDERS.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
LABELS_MANAGER -> {
|
|
|
|
val labelsManagerIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, LabelsManagerActivity::class.java))
|
2020-04-16 15:44:53 +00:00
|
|
|
startActivity(labelsManagerIntent)
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
FOLDERS_MANAGER -> {
|
2020-10-13 09:52:03 +00:00
|
|
|
val foldersManagerIntent = AppUtil.decorInAppIntent(
|
|
|
|
Intent(
|
|
|
|
this,
|
|
|
|
LabelsManagerActivity::class.java
|
|
|
|
)
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
foldersManagerIntent.putExtra(EXTRA_MANAGE_FOLDERS, true)
|
|
|
|
startActivity(foldersManagerIntent)
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
SWIPING_GESTURE -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val swipeGestureIntent = Intent(this, EditSettingsItemActivity::class.java)
|
|
|
|
swipeGestureIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.SWIPE)
|
2020-10-13 09:52:03 +00:00
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(swipeGestureIntent),
|
2021-01-26 13:02:26 +00:00
|
|
|
SWIPING_GESTURE.ordinal
|
2020-10-13 09:52:03 +00:00
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
SWIPE_LEFT -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val swipeLeftChooserIntent = Intent(this, SwipeChooserActivity::class.java)
|
2021-01-26 13:02:26 +00:00
|
|
|
val mailSettings = checkNotNull(userManager.getCurrentUserMailSettingsBlocking())
|
|
|
|
swipeLeftChooserIntent.putExtra(EXTRA_CURRENT_ACTION, mailSettings.leftSwipeAction)
|
2020-06-26 16:39:30 +00:00
|
|
|
swipeLeftChooserIntent.putExtra(EXTRA_SWIPE_ID, SwipeType.LEFT)
|
2020-10-13 09:52:03 +00:00
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(swipeLeftChooserIntent),
|
2021-01-26 13:02:26 +00:00
|
|
|
SWIPE_LEFT.ordinal
|
2020-10-13 09:52:03 +00:00
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
SWIPE_RIGHT -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val rightLeftChooserIntent = Intent(this, SwipeChooserActivity::class.java)
|
2021-01-26 13:02:26 +00:00
|
|
|
val mailSettings = checkNotNull(userManager.getCurrentUserMailSettingsBlocking())
|
|
|
|
rightLeftChooserIntent.putExtra(EXTRA_CURRENT_ACTION, mailSettings.rightSwipeAction)
|
2020-06-26 16:39:30 +00:00
|
|
|
rightLeftChooserIntent.putExtra(EXTRA_SWIPE_ID, SwipeType.RIGHT)
|
2020-10-13 09:52:03 +00:00
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(rightLeftChooserIntent),
|
2021-01-26 13:02:26 +00:00
|
|
|
SWIPE_RIGHT.ordinal
|
2020-10-13 09:52:03 +00:00
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
LOCAL_STORAGE_LIMIT -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val attachmentStorageIntent = Intent(this, AttachmentStorageActivity::class.java)
|
2021-01-26 13:02:26 +00:00
|
|
|
attachmentStorageIntent.putExtra(
|
|
|
|
AttachmentStorageActivity.EXTRA_SETTINGS_ATTACHMENT_STORAGE_VALUE,
|
|
|
|
mAttachmentStorageValue
|
|
|
|
)
|
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(attachmentStorageIntent), LOCAL_STORAGE_LIMIT.ordinal
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
PUSH_NOTIFICATION -> {
|
|
|
|
val privateNotificationsIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, EditSettingsItemActivity::class.java))
|
2020-04-16 15:44:53 +00:00
|
|
|
privateNotificationsIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.PUSH_NOTIFICATIONS)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(privateNotificationsIntent, PUSH_NOTIFICATION.ordinal)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
NOTIFICATION_SETTINGS -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
val intent = Intent(ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
|
|
|
intent.putExtra(EXTRA_CHANNEL_ID, CHANNEL_ID_EMAIL)
|
|
|
|
intent.putExtra(EXTRA_APP_PACKAGE, packageName)
|
|
|
|
startActivity(intent)
|
|
|
|
} else {
|
2021-01-26 13:02:26 +00:00
|
|
|
mNotificationOptionValue = legacyUser.notificationSetting
|
2020-04-16 15:44:53 +00:00
|
|
|
val notificationSettingsIntent = Intent(this, NotificationSettingsActivity::class.java)
|
|
|
|
notificationSettingsIntent.putExtra(EXTRA_CURRENT_ACTION, mNotificationOptionValue)
|
2021-01-26 13:02:26 +00:00
|
|
|
startActivityForResult(
|
|
|
|
AppUtil.decorInAppIntent(notificationSettingsIntent), NOTIFICATION_SETTINGS.ordinal
|
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
AUTO_LOCK -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val pinManagerIntent = AppUtil.decorInAppIntent(Intent(this, PinSettingsActivity::class.java))
|
|
|
|
startActivity(pinManagerIntent)
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
CONNECTIONS_VIA_THIRD_PARTIES -> {
|
|
|
|
val allowThirdPartiesSecureConnectionsIntent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(this, EditSettingsItemActivity::class.java))
|
|
|
|
allowThirdPartiesSecureConnectionsIntent
|
|
|
|
.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.CONNECTIONS_VIA_THIRD_PARTIES)
|
|
|
|
startActivity(allowThirdPartiesSecureConnectionsIntent)
|
2020-05-06 06:25:14 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
APP_LANGUAGE -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
showCustomLocaleDialog()
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
COMBINED_CONTACTS -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
val combinedContactsIntent = Intent(this, EditSettingsItemActivity::class.java)
|
|
|
|
combinedContactsIntent.putExtra(EXTRA_SETTINGS_ITEM_TYPE, SettingsItem.COMBINED_CONTACTS)
|
|
|
|
startActivity(AppUtil.decorInAppIntent(combinedContactsIntent))
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
APP_LOCAL_CACHE -> {
|
2020-04-16 15:44:53 +00:00
|
|
|
showToast(R.string.processing_request, gravity = Gravity.CENTER)
|
|
|
|
if (canClick.getAndSet(false)) {
|
2021-01-26 13:02:26 +00:00
|
|
|
AppUtil.clearStorage(
|
2021-03-17 14:54:52 +00:00
|
|
|
contactDao,
|
2021-03-17 14:45:53 +00:00
|
|
|
messageDao,
|
2021-01-26 13:02:26 +00:00
|
|
|
searchDatabase,
|
2021-01-21 16:15:05 +00:00
|
|
|
notificationDao,
|
2021-02-11 12:56:45 +00:00
|
|
|
counterDao,
|
2021-02-18 16:10:43 +00:00
|
|
|
attachmentMetadataDao,
|
2021-03-17 14:46:14 +00:00
|
|
|
pendingActionDao,
|
2021-01-26 13:02:26 +00:00
|
|
|
true
|
|
|
|
)
|
|
|
|
launchInitialDataFetch()
|
|
|
|
mJobManager.addJobInBackground(
|
|
|
|
FetchByLocationJob(
|
|
|
|
mMailboxLocation,
|
|
|
|
mLabelId,
|
|
|
|
true,
|
|
|
|
null,
|
|
|
|
false
|
2020-10-13 09:52:03 +00:00
|
|
|
)
|
2021-01-26 13:02:26 +00:00
|
|
|
)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
ACCOUNT_SECTION,
|
|
|
|
ACCOUNT_SETTINGS,
|
|
|
|
ADDRESSES,
|
|
|
|
ALLOW_SECURE_CONNECTIONS_VIA_THIRD_PARTIES,
|
|
|
|
APP_INFORMATION,
|
|
|
|
APP_SETTINGS,
|
|
|
|
APP_VERSION,
|
|
|
|
DISPLAY_NAME,
|
|
|
|
EXTENDED_NOTIFICATION,
|
|
|
|
LINK_CONFIRMATION,
|
|
|
|
MAILBOX,
|
|
|
|
MAILBOX_SIZE,
|
|
|
|
MOBILE_SIGNATURE,
|
|
|
|
PREVENT_SCREENSHOTS,
|
|
|
|
SEARCH,
|
|
|
|
SHOW_EMBEDDED_IMAGES,
|
|
|
|
SHOW_REMOTE_IMAGES,
|
|
|
|
SIGNATURE,
|
|
|
|
SNOOZE -> { /* ignored */ }
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected fun setUpSettingsItems(jsonId: Int) {
|
|
|
|
val jsonSettingsListResponse = resources.openRawResource(jsonId).bufferedReader().use { it.readText() }
|
|
|
|
|
|
|
|
val gson = Gson()
|
|
|
|
settingsUiList = gson.fromJson(jsonSettingsListResponse, Array<SettingsItemUiModel>::class.java).asList()
|
|
|
|
settingsAdapter.items = settingsUiList
|
|
|
|
settingsRecyclerView.layoutManager = LinearLayoutManager(this@BaseSettingsActivity)
|
|
|
|
settingsRecyclerView.adapter = settingsAdapter
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected fun setUpSettingsItems(settingsList: List<SettingsItemUiModel>) {
|
|
|
|
settingsUiList = settingsList
|
|
|
|
settingsAdapter.items = settingsUiList
|
|
|
|
settingsRecyclerView.layoutManager = LinearLayoutManager(this@BaseSettingsActivity)
|
|
|
|
settingsRecyclerView.adapter = settingsAdapter
|
|
|
|
}
|
|
|
|
|
|
|
|
protected fun refreshSettings(settingsList: List<SettingsItemUiModel>) {
|
|
|
|
settingsAdapter.items = settingsList
|
|
|
|
}
|
|
|
|
|
|
|
|
protected fun setToggleListener(settingType: SettingsEnum, listener: ((View, Boolean) -> Unit)?) {
|
2021-01-26 13:02:26 +00:00
|
|
|
settingsAdapter.items
|
|
|
|
.find { it.settingId == settingType.name.toLowerCase(Locale.ENGLISH) }
|
|
|
|
?.apply { toggleListener = listener }
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected fun setEditTextListener(settingType: SettingsEnum, listener: (View) -> Unit) {
|
2021-01-26 13:02:26 +00:00
|
|
|
settingsAdapter.items
|
|
|
|
.find { it.settingId == settingType.name.toLowerCase(Locale.ENGLISH) }
|
|
|
|
?.apply { editTextListener = listener }
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 14:36:39 +00:00
|
|
|
protected fun setEditTextChangeListener(settingType: SettingsEnum, listener: (String) -> Unit) {
|
|
|
|
settingsAdapter.items.find { it.settingId == settingType.name.toLowerCase(Locale.ENGLISH) }
|
|
|
|
?.apply { editTextChangeListener = listener }
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:44:53 +00:00
|
|
|
protected fun setValue(settingType: SettingsEnum, settingValueNew: String) {
|
2021-01-26 13:02:26 +00:00
|
|
|
settingsAdapter.items
|
|
|
|
.find { it.settingId == settingType.name.toLowerCase(Locale.ENGLISH) }
|
|
|
|
?.apply { settingValue = settingValueNew }
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turns the value of setting with [settingType] ON or OFF.
|
|
|
|
*/
|
|
|
|
protected fun setEnabled(settingType: SettingsEnum, settingValueEnabled: Boolean) {
|
2021-01-26 13:02:26 +00:00
|
|
|
settingsAdapter.items
|
|
|
|
.find { it.settingId == settingType.name.toLowerCase(Locale.ENGLISH) }
|
|
|
|
?.apply { enabled = settingValueEnabled }
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the setting with [settingType] to locked, so the user can't change. Usually if the account is on a free plan.
|
|
|
|
*/
|
|
|
|
protected fun setSettingDisabled(settingType: SettingsEnum, settingDisabledNew: Boolean, description: String) {
|
|
|
|
settingsAdapter.items.find { it.settingId == settingType.name.toLowerCase(Locale.ENGLISH) }?.apply {
|
|
|
|
settingDisabled = settingDisabledNew
|
|
|
|
settingsDescription = description
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected fun setHeader(settingType: SettingsEnum, settingHeaderNew: String = "") {
|
|
|
|
settingsAdapter.items.find { it.settingId == settingType.name.toLowerCase(Locale.ENGLISH) }?.apply {
|
|
|
|
settingHeader = if (settingHeaderNew.isNotEmpty()) {
|
|
|
|
settingHeaderNew
|
|
|
|
} else {
|
2021-01-26 13:02:26 +00:00
|
|
|
valueOf(settingType.name).getHeader(this@BaseSettingsActivity)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
2021-01-26 13:02:26 +00:00
|
|
|
settingsHint = valueOf(settingType.name).getHint(this@BaseSettingsActivity)
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-24 16:26:52 +00:00
|
|
|
private fun onConnectivityEvent(connectivity: Constants.ConnectionState) {
|
2021-02-23 17:14:51 +00:00
|
|
|
Timber.v("onConnectivityEvent hasConnection:${connectivity.name}")
|
2021-02-24 16:26:52 +00:00
|
|
|
if (connectivity != Constants.ConnectionState.CONNECTED) {
|
2020-10-13 11:52:58 +00:00
|
|
|
networkSnackBarUtil.getNoConnectionSnackBar(
|
|
|
|
mSnackLayout,
|
|
|
|
mUserManager.user,
|
|
|
|
this,
|
2021-02-23 17:14:51 +00:00
|
|
|
{ onConnectivityCheckRetry() },
|
2021-02-24 16:26:52 +00:00
|
|
|
isOffline = connectivity == Constants.ConnectionState.NO_INTERNET
|
2020-10-13 11:52:58 +00:00
|
|
|
).show()
|
2020-04-16 15:44:53 +00:00
|
|
|
} else {
|
2020-10-13 11:52:58 +00:00
|
|
|
networkSnackBarUtil.hideAllSnackBars()
|
2020-04-16 15:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-13 11:52:58 +00:00
|
|
|
private fun onConnectivityCheckRetry() {
|
|
|
|
networkSnackBarUtil.getCheckingConnectionSnackBar(
|
|
|
|
mSnackLayout
|
|
|
|
).show()
|
|
|
|
|
|
|
|
viewModel.checkConnectivityDelayed()
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:44:53 +00:00
|
|
|
open fun onLabelsLoadedEvent(event: FetchLabelsEvent) {
|
|
|
|
if (!canClick.get()) {
|
|
|
|
showToast(R.string.cache_cleared, gravity = Gravity.CENTER)
|
|
|
|
}
|
|
|
|
canClick.set(true)
|
|
|
|
}
|
|
|
|
}
|