Replace Controller with Activity for settings

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-29 18:18:08 +02:00
parent 20d1824254
commit b5febb7e3d
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
7 changed files with 288 additions and 264 deletions

View File

@ -206,6 +206,10 @@
android:name=".profile.ProfileActivity" android:name=".profile.ProfileActivity"
android:theme="@style/AppTheme" /> android:theme="@style/AppTheme" />
<activity
android:name=".settings.SettingsActivity"
android:theme="@style/AppTheme" />
<receiver android:name=".receivers.PackageReplacedReceiver" <receiver android:name=".receivers.PackageReplacedReceiver"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>

View File

@ -42,12 +42,12 @@ import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.controllers.ConversationsListController import com.nextcloud.talk.controllers.ConversationsListController
import com.nextcloud.talk.controllers.LockedController import com.nextcloud.talk.controllers.LockedController
import com.nextcloud.talk.controllers.ServerSelectionController import com.nextcloud.talk.controllers.ServerSelectionController
import com.nextcloud.talk.controllers.SettingsController
import com.nextcloud.talk.controllers.WebViewLoginController import com.nextcloud.talk.controllers.WebViewLoginController
import com.nextcloud.talk.controllers.base.providers.ActionBarProvider import com.nextcloud.talk.controllers.base.providers.ActionBarProvider
import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ActivityMainBinding import com.nextcloud.talk.databinding.ActivityMainBinding
import com.nextcloud.talk.models.json.conversations.RoomOverall import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.settings.SettingsActivity
import com.nextcloud.talk.users.UserManager import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.SecurityUtils import com.nextcloud.talk.utils.SecurityUtils
@ -193,11 +193,8 @@ class MainActivity : BaseActivity(), ActionBarProvider {
} }
fun openSettings() { fun openSettings() {
router!!.pushController( val intent = Intent(this, SettingsActivity::class.java)
RouterTransaction.with(SettingsController()) startActivity(intent)
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
} }
fun addAccount() { fun addAccount() {

View File

@ -93,6 +93,7 @@ import com.nextcloud.talk.messagesearch.MessageSearchHelper.MessageSearchResults
import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.conversations.RoomsOverall import com.nextcloud.talk.models.json.conversations.RoomsOverall
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
import com.nextcloud.talk.settings.SettingsActivity
import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment
import com.nextcloud.talk.ui.dialog.ChooseAccountShareToDialogFragment import com.nextcloud.talk.ui.dialog.ChooseAccountShareToDialogFragment
import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog
@ -719,11 +720,8 @@ class ConversationsListController(bundle: Bundle) :
ChooseAccountDialogFragment.TAG ChooseAccountDialogFragment.TAG
) )
} else { } else {
router.pushController( val intent = Intent(context, SettingsActivity::class.java)
RouterTransaction.with(SettingsController()) startActivity(intent)
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
} }
} }
} }

View File

@ -23,7 +23,10 @@
package com.nextcloud.talk.jobs; package com.nextcloud.talk.jobs;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
@ -208,5 +211,17 @@ public class AccountRemovalWorker extends Worker {
Log.e(TAG, "error while trying to delete user", e); Log.e(TAG, "error while trying to delete user", e);
} }
} }
if (userManager.getUsers().blockingGet().isEmpty()) {
restartApp(getApplicationContext());
}
}
public static void restartApp(Context context) {
PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(context.getPackageName());
ComponentName componentName = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
context.startActivity(mainIntent);
Runtime.getRuntime().exit(0);
} }
} }

View File

@ -23,6 +23,7 @@ package com.nextcloud.talk.jobs
import android.Manifest import android.Manifest
import android.accounts.Account import android.accounts.Account
import android.accounts.AccountManager import android.accounts.AccountManager
import android.app.Activity
import android.content.ContentProviderOperation import android.content.ContentProviderOperation
import android.content.Context import android.content.Context
import android.content.OperationApplicationException import android.content.OperationApplicationException
@ -39,7 +40,6 @@ import androidx.work.WorkManager
import androidx.work.Worker import androidx.work.Worker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import autodagger.AutoInjector import autodagger.AutoInjector
import com.bluelinelabs.conductor.Controller
import com.google.gson.Gson import com.google.gson.Gson
import com.nextcloud.talk.BuildConfig import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R import com.nextcloud.talk.R
@ -470,7 +470,7 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
} }
} }
fun checkPermission(controller: Controller, context: Context): Boolean { fun checkPermission(activity: Activity, context: Context): Boolean {
if (ContextCompat.checkSelfPermission( if (ContextCompat.checkSelfPermission(
context, context,
Manifest.permission.WRITE_CONTACTS Manifest.permission.WRITE_CONTACTS
@ -480,7 +480,7 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
Manifest.permission.READ_CONTACTS Manifest.permission.READ_CONTACTS
) != PackageManager.PERMISSION_GRANTED ) != PackageManager.PERMISSION_GRANTED
) { ) {
controller.requestPermissions( activity.requestPermissions(
arrayOf( arrayOf(
Manifest.permission.WRITE_CONTACTS, Manifest.permission.WRITE_CONTACTS,
Manifest.permission.READ_CONTACTS Manifest.permission.READ_CONTACTS

View File

@ -21,10 +21,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.nextcloud.talk.controllers package com.nextcloud.talk.settings
import android.animation.Animator import android.animation.Animator
import android.animation.AnimatorListenerAdapter import android.animation.AnimatorListenerAdapter
import android.app.Activity
import android.app.KeyguardManager import android.app.KeyguardManager
import android.content.Context import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
@ -33,6 +34,7 @@ import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.graphics.drawable.ColorDrawable
import android.media.RingtoneManager import android.media.RingtoneManager
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
@ -52,26 +54,21 @@ import android.widget.LinearLayout
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.work.OneTimeWorkRequest import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager import androidx.work.WorkManager
import autodagger.AutoInjector import autodagger.AutoInjector
import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import com.nextcloud.talk.BuildConfig import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.activities.BaseActivity
import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.setAppTheme import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.setAppTheme
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.controllers.base.BaseController
import com.nextcloud.talk.controllers.util.viewBinding
import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ControllerSettingsBinding import com.nextcloud.talk.databinding.ActivitySettingsBinding
import com.nextcloud.talk.jobs.AccountRemovalWorker import com.nextcloud.talk.jobs.AccountRemovalWorker
import com.nextcloud.talk.jobs.ContactAddressBookWorker import com.nextcloud.talk.jobs.ContactAddressBookWorker
import com.nextcloud.talk.jobs.ContactAddressBookWorker.Companion.checkPermission import com.nextcloud.talk.jobs.ContactAddressBookWorker.Companion.checkPermission
@ -87,7 +84,6 @@ import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.NotificationUtils.getCallRingtoneUri import com.nextcloud.talk.utils.NotificationUtils.getCallRingtoneUri
import com.nextcloud.talk.utils.NotificationUtils.getMessageRingtoneUri import com.nextcloud.talk.utils.NotificationUtils.getMessageRingtoneUri
import com.nextcloud.talk.utils.SecurityUtils import com.nextcloud.talk.utils.SecurityUtils
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ARE_CALL_SOUNDS
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
import com.nextcloud.talk.utils.preferences.MagicUserInputModule import com.nextcloud.talk.utils.preferences.MagicUserInputModule
@ -106,8 +102,8 @@ import java.util.Locale
import javax.inject.Inject import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
class SettingsController : BaseController(R.layout.controller_settings) { class SettingsActivity : BaseActivity() {
private val binding: ControllerSettingsBinding? by viewBinding(ControllerSettingsBinding::bind) private lateinit var binding: ActivitySettingsBinding
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -131,21 +127,16 @@ class SettingsController : BaseController(R.layout.controller_settings) {
private var profileQueryDisposable: Disposable? = null private var profileQueryDisposable: Disposable? = null
private var dbQueryDisposable: Disposable? = null private var dbQueryDisposable: Disposable? = null
override val title: String override fun onCreate(savedInstanceState: Bundle?) {
get() = super.onCreate(savedInstanceState)
resources!!.getString(R.string.nc_settings) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
private fun getCurrentUser() { binding = ActivitySettingsBinding.inflate(layoutInflater)
currentUser = currentUserProvider.currentUser.blockingGet() setupActionBar()
credentials = ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token) setupSystemColors()
} setContentView(binding.root)
override fun onViewBound(view: View) { binding.avatarImage.let { ViewCompat.setTransitionName(it, "userAvatar.transitionTag") }
super.onViewBound(view)
setHasOptionsMenu(true)
sharedApplication!!.componentApplication.inject(this)
binding?.avatarImage?.let { ViewCompat.setTransitionName(it, "userAvatar.transitionTag") }
getCurrentUser() getCurrentUser()
@ -155,10 +146,10 @@ class SettingsController : BaseController(R.layout.controller_settings) {
setupLicenceSetting() setupLicenceSetting()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
binding?.settingsIncognitoKeyboard?.visibility = View.GONE binding.settingsIncognitoKeyboard.visibility = View.GONE
} }
binding?.settingsScreenLock?.setSummary( binding.settingsScreenLock.setSummary(
String.format( String.format(
Locale.getDefault(), Locale.getDefault(),
resources!!.getString(R.string.nc_settings_screen_lock_desc), resources!!.getString(R.string.nc_settings_screen_lock_desc),
@ -168,7 +159,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
setupPrivacyUrl() setupPrivacyUrl()
setupSourceCodeUrl() setupSourceCodeUrl()
binding?.settingsVersion?.setSummary("v" + BuildConfig.VERSION_NAME) binding.settingsVersion.setSummary("v" + BuildConfig.VERSION_NAME)
setupSoundSettings() setupSoundSettings()
@ -177,17 +168,115 @@ class SettingsController : BaseController(R.layout.controller_settings) {
setupClientCertView() setupClientCertView()
} }
override fun onResume() {
super.onResume()
supportActionBar?.show()
dispose(null)
binding.settingsVersion.setOnClickListener {
sendLogs()
}
if (!TextUtils.isEmpty(currentUser!!.clientCertificate)) {
binding.settingsClientCert.setTitle(R.string.nc_client_cert_change)
} else {
binding.settingsClientCert.setTitle(R.string.nc_client_cert_setup)
}
setupCheckables()
setupScreenLockSetting()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.settingsNotificationsCategory.setTitle(
resources!!.getString(R.string.nc_settings_notification_sounds_post_oreo)
)
}
val callRingtoneUri = getCallRingtoneUri(context, (appPreferences))
binding.settingsCallSound.setSummary(getRingtoneName(context, callRingtoneUri))
val messageRingtoneUri = getMessageRingtoneUri(context, (appPreferences))
binding.settingsMessageSound.setSummary(getRingtoneName(context, messageRingtoneUri))
setupProxyTypeSettings()
setupProxyCredentialSettings()
if (currentUser != null) {
binding.baseUrlText.text = Uri.parse(currentUser!!.baseUrl).host
setupServerAgeWarning()
// TODO: fix reauthorize
// binding.settingsReauthorize?.addPreferenceClickListener {
// router.pushController(
// RouterTransaction.with(WebViewLoginController(currentUser!!.baseUrl, true))
// .pushChangeHandler(VerticalChangeHandler())
// .popChangeHandler(VerticalChangeHandler())
// )
// }
if (currentUser!!.displayName != null) {
binding.displayNameText.text = currentUser!!.displayName
}
DisplayUtils.loadAvatarImage(currentUser, binding.avatarImage, false)
setupProfileQueryDisposable()
binding.settingsRemoveAccount.addPreferenceClickListener {
showRemoveAccountWarning()
}
}
setupMessageView()
binding.avatarContainer.setOnClickListener {
val intent = Intent(activity, ProfileActivity::class.java)
activity!!.startActivity(intent)
}
themeCategories()
themeSwitchPreferences()
}
private fun setupActionBar() {
setSupportActionBar(binding.settingsToolbar)
binding.settingsToolbar.setNavigationOnClickListener {
onBackPressed()
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setIcon(ColorDrawable(resources!!.getColor(android.R.color.transparent)))
supportActionBar?.title = context.getString(R.string.nc_settings)
}
private fun setupSystemColors() {
DisplayUtils.applyColorToStatusBar(
this,
ResourcesCompat.getColor(
resources,
R.color.appbar,
null
)
)
DisplayUtils.applyColorToNavigationBar(
this.window,
ResourcesCompat.getColor(resources, R.color.bg_default, null)
)
}
private fun getCurrentUser() {
currentUser = currentUserProvider.currentUser.blockingGet()
credentials = ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token)
}
private fun setupPhoneBookIntegration() { private fun setupPhoneBookIntegration() {
if (CapabilitiesUtilNew.isPhoneBookIntegrationAvailable(currentUser!!)) { if (CapabilitiesUtilNew.isPhoneBookIntegrationAvailable(currentUser!!)) {
binding?.settingsPhoneBookIntegration?.visibility = View.VISIBLE binding.settingsPhoneBookIntegration?.visibility = View.VISIBLE
} else { } else {
binding?.settingsPhoneBookIntegration?.visibility = View.GONE binding.settingsPhoneBookIntegration?.visibility = View.GONE
} }
} }
private fun setupSoundSettings() { private fun setupSoundSettings() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding?.settingsCallSound?.setOnClickListener { binding.settingsCallSound.setOnClickListener {
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID)
intent.putExtra( intent.putExtra(
@ -197,7 +286,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
startActivity(intent) startActivity(intent)
} }
binding?.settingsMessageSound?.setOnClickListener { binding.settingsMessageSound.setOnClickListener {
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID)
intent.putExtra( intent.putExtra(
@ -207,32 +296,13 @@ class SettingsController : BaseController(R.layout.controller_settings) {
startActivity(intent) startActivity(intent)
} }
} else { } else {
binding?.settingsCallSound?.setOnClickListener { Log.e(TAG, "setupSoundSettings currently not supported for versions < Build.VERSION_CODES.O")
val bundle = Bundle()
bundle.putBoolean(KEY_ARE_CALL_SOUNDS, true)
router.pushController(
RouterTransaction.with(RingtoneSelectionController(bundle))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
}
binding?.settingsMessageSound?.setOnClickListener {
val bundle = Bundle()
bundle.putBoolean(KEY_ARE_CALL_SOUNDS, false)
router.pushController(
RouterTransaction.with(RingtoneSelectionController(bundle))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
}
} }
} }
private fun setupSourceCodeUrl() { private fun setupSourceCodeUrl() {
if (!TextUtils.isEmpty(resources!!.getString(R.string.nc_source_code_url))) { if (!TextUtils.isEmpty(resources!!.getString(R.string.nc_source_code_url))) {
binding?.settingsSourceCode?.addPreferenceClickListener { binding.settingsSourceCode.addPreferenceClickListener {
startActivity( startActivity(
Intent( Intent(
Intent.ACTION_VIEW, Intent.ACTION_VIEW,
@ -241,13 +311,13 @@ class SettingsController : BaseController(R.layout.controller_settings) {
) )
} }
} else { } else {
binding?.settingsSourceCode?.visibility = View.GONE binding.settingsSourceCode.visibility = View.GONE
} }
} }
private fun setupPrivacyUrl() { private fun setupPrivacyUrl() {
if (!TextUtils.isEmpty(resources!!.getString(R.string.nc_privacy_url))) { if (!TextUtils.isEmpty(resources!!.getString(R.string.nc_privacy_url))) {
binding?.settingsPrivacy?.addPreferenceClickListener { binding.settingsPrivacy.addPreferenceClickListener {
startActivity( startActivity(
Intent( Intent(
Intent.ACTION_VIEW, Intent.ACTION_VIEW,
@ -256,13 +326,13 @@ class SettingsController : BaseController(R.layout.controller_settings) {
) )
} }
} else { } else {
binding?.settingsPrivacy?.visibility = View.GONE binding.settingsPrivacy.visibility = View.GONE
} }
} }
private fun setupLicenceSetting() { private fun setupLicenceSetting() {
if (!TextUtils.isEmpty(resources!!.getString(R.string.nc_gpl3_url))) { if (!TextUtils.isEmpty(resources!!.getString(R.string.nc_gpl3_url))) {
binding?.settingsLicence?.addPreferenceClickListener { binding.settingsLicence.addPreferenceClickListener {
startActivity( startActivity(
Intent( Intent(
Intent.ACTION_VIEW, Intent.ACTION_VIEW,
@ -271,15 +341,15 @@ class SettingsController : BaseController(R.layout.controller_settings) {
) )
} }
} else { } else {
binding?.settingsLicence?.visibility = View.GONE binding.settingsLicence.visibility = View.GONE
} }
} }
private fun setupSettingsScreen() { private fun setupSettingsScreen() {
val listWithIntFields: MutableList<String> = ArrayList() val listWithIntFields: MutableList<String> = ArrayList()
listWithIntFields.add("proxy_port") listWithIntFields.add("proxy_port")
binding?.settingsScreen?.setUserInputModule(MagicUserInputModule(activity, listWithIntFields)) binding.settingsScreen.setUserInputModule(MagicUserInputModule(this, listWithIntFields))
binding?.settingsScreen?.setVisibilityController( binding.settingsScreen.setVisibilityController(
R.id.settings_proxy_use_credentials, R.id.settings_proxy_use_credentials,
Arrays.asList(R.id.settings_proxy_username_edit, R.id.settings_proxy_password_edit), Arrays.asList(R.id.settings_proxy_username_edit, R.id.settings_proxy_password_edit),
true true
@ -298,17 +368,17 @@ class SettingsController : BaseController(R.layout.controller_settings) {
Log.e(TAG, "Failed to create uri") Log.e(TAG, "Failed to create uri")
} }
binding?.settingsClientCert?.addPreferenceClickListener { binding.settingsClientCert.addPreferenceClickListener {
KeyChain.choosePrivateKeyAlias( KeyChain.choosePrivateKeyAlias(
activity!!, this,
{ alias: String? -> { alias: String? ->
var finalAlias: String? = alias var finalAlias: String? = alias
activity!!.runOnUiThread { runOnUiThread {
if (finalAlias != null) { if (finalAlias != null) {
binding?.settingsClientCert?.setTitle(R.string.nc_client_cert_change) binding.settingsClientCert.setTitle(R.string.nc_client_cert_change)
} else { } else {
binding?.settingsClientCert?.setTitle(R.string.nc_client_cert_setup) binding.settingsClientCert.setTitle(R.string.nc_client_cert_setup)
} }
} }
@ -361,39 +431,33 @@ class SettingsController : BaseController(R.layout.controller_settings) {
fun sendLogs() { fun sendLogs() {
if (resources!!.getBoolean(R.bool.nc_is_debug)) { if (resources!!.getBoolean(R.bool.nc_is_debug)) {
sendMailWithAttachment((context)!!) sendMailWithAttachment((context))
} }
} }
override fun onRestoreViewState(view: View, savedViewState: Bundle) {
super.onRestoreViewState(view, savedViewState)
}
private fun showRemoveAccountWarning() { private fun showRemoveAccountWarning() {
if (activity != null) { binding.messageText.context?.let {
binding?.messageText?.context?.let { val materialAlertDialogBuilder = MaterialAlertDialogBuilder(it)
val materialAlertDialogBuilder = MaterialAlertDialogBuilder(it) .setTitle(R.string.nc_settings_remove_account)
.setTitle(R.string.nc_settings_remove_account) .setMessage(R.string.nc_settings_remove_confirmation)
.setMessage(R.string.nc_settings_remove_confirmation) .setPositiveButton(R.string.nc_settings_remove) { _, _ ->
.setPositiveButton(R.string.nc_settings_remove) { _, _ -> removeCurrentAccount()
removeCurrentAccount() }
} .setNegativeButton(R.string.nc_cancel) { _, _ ->
.setNegativeButton(R.string.nc_cancel) { _, _ -> // unused atm
// unused atm }
}
viewThemeUtils.dialog.colorMaterialAlertDialogBackground( viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
it, it,
materialAlertDialogBuilder materialAlertDialogBuilder
) )
val dialog = materialAlertDialogBuilder.show() val dialog = materialAlertDialogBuilder.show()
viewThemeUtils.platform.colorTextButtons( viewThemeUtils.platform.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE), dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE) dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
) )
}
} }
} }
@ -401,15 +465,12 @@ class SettingsController : BaseController(R.layout.controller_settings) {
val otherUserExists = userManager.scheduleUserForDeletionWithId(currentUser!!.id!!).blockingGet() val otherUserExists = userManager.scheduleUserForDeletionWithId(currentUser!!.id!!).blockingGet()
val accountRemovalWork = OneTimeWorkRequest.Builder(AccountRemovalWorker::class.java).build() val accountRemovalWork = OneTimeWorkRequest.Builder(AccountRemovalWorker::class.java).build()
WorkManager.getInstance().enqueue(accountRemovalWork) WorkManager.getInstance().enqueue(accountRemovalWork)
if (otherUserExists && view != null) { if (otherUserExists) {
onViewBound((view)!!) // TODO: find better solution once Conductor is removed
onAttach((view)!!) finish()
startActivity(intent)
} else if (!otherUserExists) { } else if (!otherUserExists) {
router.setRoot( Log.d(TAG, "No other users found. AccountRemovalWorker will restart the app.")
RouterTransaction.with(ServerSelectionController())
.pushChangeHandler(VerticalChangeHandler())
.popChangeHandler(VerticalChangeHandler())
)
} }
} }
@ -426,74 +487,8 @@ class SettingsController : BaseController(R.layout.controller_settings) {
} }
} }
override fun onAttach(view: View) {
super.onAttach(view)
actionBar?.show()
dispose(null)
binding?.settingsVersion?.setOnClickListener {
sendLogs()
}
if (!TextUtils.isEmpty(currentUser!!.clientCertificate)) {
binding?.settingsClientCert?.setTitle(R.string.nc_client_cert_change)
} else {
binding?.settingsClientCert?.setTitle(R.string.nc_client_cert_setup)
}
setupCheckables()
setupScreenLockSetting()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding?.settingsNotificationsCategory?.setTitle(
resources!!.getString(R.string.nc_settings_notification_sounds_post_oreo)
)
}
val callRingtoneUri = getCallRingtoneUri(view.context, (appPreferences)!!)
binding?.settingsCallSound?.setSummary(getRingtoneName(view.context, callRingtoneUri))
val messageRingtoneUri = getMessageRingtoneUri(view.context, (appPreferences)!!)
binding?.settingsMessageSound?.setSummary(getRingtoneName(view.context, messageRingtoneUri))
setupProxyTypeSettings()
setupProxyCredentialSettings()
if (currentUser != null) {
binding?.baseUrlText?.text = Uri.parse(currentUser!!.baseUrl).host
setupServerAgeWarning()
binding?.settingsReauthorize?.addPreferenceClickListener {
router.pushController(
RouterTransaction.with(WebViewLoginController(currentUser!!.baseUrl, true))
.pushChangeHandler(VerticalChangeHandler())
.popChangeHandler(VerticalChangeHandler())
)
}
if (currentUser!!.displayName != null) {
binding?.displayNameText?.text = currentUser!!.displayName
}
DisplayUtils.loadAvatarImage(currentUser, binding?.avatarImage, false)
setupProfileQueryDisposable()
binding?.settingsRemoveAccount?.addPreferenceClickListener {
showRemoveAccountWarning()
}
}
setupMessageView()
binding?.avatarContainer?.setOnClickListener {
val intent = Intent(activity, ProfileActivity::class.java)
activity!!.startActivity(intent)
}
themeCategories()
themeSwitchPreferences()
}
private fun themeSwitchPreferences() { private fun themeSwitchPreferences() {
binding?.run { binding.run {
listOf( listOf(
settingsScreenLock, settingsScreenLock,
settingsScreenSecurity, settingsScreenSecurity,
@ -506,7 +501,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
} }
private fun themeCategories() { private fun themeCategories() {
binding?.run { binding.run {
listOf( listOf(
settingsNotificationsCategory, settingsNotificationsCategory,
settingsAboutCategory, settingsAboutCategory,
@ -537,50 +532,50 @@ class SettingsController : BaseController(R.layout.controller_settings) {
if (ApplicationWideMessageHolder.getInstance().messageType != null) { if (ApplicationWideMessageHolder.getInstance().messageType != null) {
when (ApplicationWideMessageHolder.getInstance().messageType) { when (ApplicationWideMessageHolder.getInstance().messageType) {
ApplicationWideMessageHolder.MessageType.ACCOUNT_UPDATED_NOT_ADDED -> { ApplicationWideMessageHolder.MessageType.ACCOUNT_UPDATED_NOT_ADDED -> {
binding?.messageText?.let { binding.messageText.let {
it.setTextColor( it.setTextColor(
viewThemeUtils.getScheme(it.context).primary viewThemeUtils.getScheme(it.context).primary
) )
it.text = resources!!.getString(R.string.nc_settings_account_updated) it.text = resources!!.getString(R.string.nc_settings_account_updated)
binding?.messageView?.visibility = View.VISIBLE binding.messageView.visibility = View.VISIBLE
} }
} }
ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK -> { ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK -> {
binding?.messageText?.let { binding.messageText.let {
it.setTextColor(resources!!.getColor(R.color.nc_darkRed)) it.setTextColor(resources!!.getColor(R.color.nc_darkRed))
it.text = resources!!.getString(R.string.nc_settings_wrong_account) it.text = resources!!.getString(R.string.nc_settings_wrong_account)
binding?.messageView?.visibility = View.VISIBLE binding.messageView.visibility = View.VISIBLE
it.setTextColor( it.setTextColor(
viewThemeUtils.getScheme(it.context).primary viewThemeUtils.getScheme(it.context).primary
) )
it.text = resources!!.getString(R.string.nc_Server_account_imported) it.text = resources!!.getString(R.string.nc_Server_account_imported)
binding?.messageView?.visibility = View.VISIBLE binding.messageView.visibility = View.VISIBLE
} }
} }
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED -> { ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED -> {
binding?.messageText?.let { binding.messageText.let {
it.setTextColor( it.setTextColor(
viewThemeUtils.getScheme(it.context).primary viewThemeUtils.getScheme(it.context).primary
) )
it.text = resources!!.getString(R.string.nc_Server_account_imported) it.text = resources!!.getString(R.string.nc_Server_account_imported)
binding?.messageView?.visibility = View.VISIBLE binding.messageView.visibility = View.VISIBLE
} }
} }
ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT -> { ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT -> {
binding?.messageText?.let { binding.messageText.let {
it.setTextColor(resources!!.getColor(R.color.nc_darkRed)) it.setTextColor(resources!!.getColor(R.color.nc_darkRed))
it.text = resources!!.getString(R.string.nc_server_failed_to_import_account) it.text = resources!!.getString(R.string.nc_server_failed_to_import_account)
binding?.messageView?.visibility = View.VISIBLE binding.messageView.visibility = View.VISIBLE
} }
} }
else -> binding?.messageView?.visibility = View.GONE else -> binding.messageView.visibility = View.GONE
} }
ApplicationWideMessageHolder.getInstance().messageType = null ApplicationWideMessageHolder.getInstance().messageType = null
binding?.messageView?.animate() binding.messageView.animate()
?.translationY(0f) ?.translationY(0f)
?.alpha(0.0f) ?.alpha(0.0f)
?.setDuration(DURATION) ?.setDuration(DURATION)
@ -588,11 +583,11 @@ class SettingsController : BaseController(R.layout.controller_settings) {
?.setListener(object : AnimatorListenerAdapter() { ?.setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation) super.onAnimationEnd(animation)
binding?.messageView?.visibility = View.GONE binding.messageView.visibility = View.GONE
} }
}) })
} else { } else {
binding?.messageView?.visibility = View.GONE binding.messageView.visibility = View.GONE
} }
} }
@ -620,7 +615,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
if ((!TextUtils.isEmpty(displayName) && !(displayName == currentUser!!.displayName))) { if ((!TextUtils.isEmpty(displayName) && !(displayName == currentUser!!.displayName))) {
currentUser!!.displayName = displayName currentUser!!.displayName = displayName
userManager.updateOrCreateUser(currentUser!!) userManager.updateOrCreateUser(currentUser!!)
binding?.displayNameText?.text = currentUser!!.displayName binding.displayNameText.text = currentUser!!.displayName
} }
}, },
{ dispose(profileQueryDisposable) }, { dispose(profileQueryDisposable) },
@ -631,86 +626,86 @@ class SettingsController : BaseController(R.layout.controller_settings) {
private fun setupServerAgeWarning() { private fun setupServerAgeWarning() {
when { when {
CapabilitiesUtilNew.isServerEOL(currentUser!!) -> { CapabilitiesUtilNew.isServerEOL(currentUser!!) -> {
binding?.serverAgeWarningText?.setTextColor(ContextCompat.getColor((context)!!, R.color.nc_darkRed)) binding.serverAgeWarningText.setTextColor(ContextCompat.getColor((context), R.color.nc_darkRed))
binding?.serverAgeWarningText?.setText(R.string.nc_settings_server_eol) binding.serverAgeWarningText.setText(R.string.nc_settings_server_eol)
binding?.serverAgeWarningIcon?.setColorFilter( binding.serverAgeWarningIcon.setColorFilter(
ContextCompat.getColor((context), R.color.nc_darkRed), ContextCompat.getColor((context), R.color.nc_darkRed),
PorterDuff.Mode.SRC_IN PorterDuff.Mode.SRC_IN
) )
} }
CapabilitiesUtilNew.isServerAlmostEOL(currentUser!!) -> { CapabilitiesUtilNew.isServerAlmostEOL(currentUser!!) -> {
binding?.serverAgeWarningText?.setTextColor( binding.serverAgeWarningText.setTextColor(
ContextCompat.getColor((context), R.color.nc_darkYellow) ContextCompat.getColor((context), R.color.nc_darkYellow)
) )
binding?.serverAgeWarningText?.setText(R.string.nc_settings_server_almost_eol) binding.serverAgeWarningText.setText(R.string.nc_settings_server_almost_eol)
binding?.serverAgeWarningIcon?.setColorFilter( binding.serverAgeWarningIcon.setColorFilter(
ContextCompat.getColor((context), R.color.nc_darkYellow), ContextCompat.getColor((context), R.color.nc_darkYellow),
PorterDuff.Mode.SRC_IN PorterDuff.Mode.SRC_IN
) )
} }
else -> { else -> {
binding?.serverAgeWarningTextCard?.visibility = View.GONE binding.serverAgeWarningTextCard.visibility = View.GONE
} }
} }
} }
private fun setupCheckables() { private fun setupCheckables() {
(binding?.settingsScreenSecurity?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsScreenSecurity.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
appPreferences.isScreenSecured appPreferences.isScreenSecured
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
(binding?.settingsIncognitoKeyboard?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsIncognitoKeyboard.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
appPreferences.isKeyboardIncognito appPreferences.isKeyboardIncognito
} }
(binding?.settingsIncognitoKeyboard?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsIncognitoKeyboard.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
appPreferences.isKeyboardIncognito appPreferences.isKeyboardIncognito
if (CapabilitiesUtilNew.isReadStatusAvailable(userManager.currentUser.blockingGet())) { if (CapabilitiesUtilNew.isReadStatusAvailable(userManager.currentUser.blockingGet())) {
(binding?.settingsReadPrivacy?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsReadPrivacy.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
!CapabilitiesUtilNew.isReadStatusPrivate(currentUser!!) !CapabilitiesUtilNew.isReadStatusPrivate(currentUser!!)
} else { } else {
binding?.settingsReadPrivacy?.visibility = View.GONE binding.settingsReadPrivacy.visibility = View.GONE
} }
(binding?.settingsPhoneBookIntegration?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsPhoneBookIntegration.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
appPreferences.isPhoneBookIntegrationEnabled appPreferences.isPhoneBookIntegrationEnabled
} }
private fun setupScreenLockSetting() { private fun setupScreenLockSetting() {
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (keyguardManager.isKeyguardSecure) { if (keyguardManager.isKeyguardSecure) {
binding?.settingsScreenLock?.isEnabled = true binding.settingsScreenLock.isEnabled = true
binding?.settingsScreenLockTimeout?.isEnabled = true binding.settingsScreenLockTimeout.isEnabled = true
(binding?.settingsScreenLock?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsScreenLock.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
appPreferences.isScreenLocked appPreferences.isScreenLocked
binding?.settingsScreenLockTimeout?.isEnabled = appPreferences.isScreenLocked binding.settingsScreenLockTimeout.isEnabled = appPreferences.isScreenLocked
if (appPreferences.isScreenLocked) { if (appPreferences.isScreenLocked) {
binding?.settingsScreenLockTimeout?.alpha = ENABLED_ALPHA binding.settingsScreenLockTimeout.alpha = ENABLED_ALPHA
} else { } else {
binding?.settingsScreenLockTimeout?.alpha = DISABLED_ALPHA binding.settingsScreenLockTimeout.alpha = DISABLED_ALPHA
} }
binding?.settingsScreenLock?.alpha = ENABLED_ALPHA binding.settingsScreenLock.alpha = ENABLED_ALPHA
} else { } else {
binding?.settingsScreenLock?.isEnabled = false binding.settingsScreenLock.isEnabled = false
binding?.settingsScreenLockTimeout?.isEnabled = false binding.settingsScreenLockTimeout.isEnabled = false
appPreferences.removeScreenLock() appPreferences.removeScreenLock()
appPreferences.removeScreenLockTimeout() appPreferences.removeScreenLockTimeout()
(binding?.settingsScreenLock?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = false (binding.settingsScreenLock.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = false
binding?.settingsScreenLock?.alpha = DISABLED_ALPHA binding.settingsScreenLock.alpha = DISABLED_ALPHA
binding?.settingsScreenLockTimeout?.alpha = DISABLED_ALPHA binding.settingsScreenLockTimeout.alpha = DISABLED_ALPHA
} }
} }
public override fun onDestroy() { public override fun onDestroy() {
appPreferences?.unregisterProxyTypeListener(proxyTypeChangeListener) appPreferences.unregisterProxyTypeListener(proxyTypeChangeListener)
appPreferences?.unregisterProxyCredentialsListener(proxyCredentialsChangeListener) appPreferences.unregisterProxyCredentialsListener(proxyCredentialsChangeListener)
appPreferences?.unregisterScreenSecurityListener(screenSecurityChangeListener) appPreferences.unregisterScreenSecurityListener(screenSecurityChangeListener)
appPreferences?.unregisterScreenLockListener(screenLockChangeListener) appPreferences.unregisterScreenLockListener(screenLockChangeListener)
appPreferences?.unregisterScreenLockTimeoutListener(screenLockTimeoutChangeListener) appPreferences.unregisterScreenLockTimeoutListener(screenLockTimeoutChangeListener)
appPreferences?.unregisterThemeChangeListener(themeChangeListener) appPreferences.unregisterThemeChangeListener(themeChangeListener)
appPreferences?.unregisterReadPrivacyChangeListener(readPrivacyChangeListener) appPreferences.unregisterReadPrivacyChangeListener(readPrivacyChangeListener)
appPreferences?.unregisterPhoneBookIntegrationChangeListener(phoneBookIntegrationChangeListener) appPreferences.unregisterPhoneBookIntegrationChangeListener(phoneBookIntegrationChangeListener)
super.onDestroy() super.onDestroy()
} }
@ -721,35 +716,35 @@ class SettingsController : BaseController(R.layout.controller_settings) {
appPreferences.removeProxyCredentials() appPreferences.removeProxyCredentials()
appPreferences.removeProxyUsername() appPreferences.removeProxyUsername()
appPreferences.removeProxyPassword() appPreferences.removeProxyPassword()
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_host_edit)?.visibility = View.GONE binding.settingsScreen.findViewById<View>(R.id.settings_proxy_host_edit)?.visibility = View.GONE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_port_edit)?.visibility = View.GONE binding.settingsScreen.findViewById<View>(R.id.settings_proxy_port_edit)?.visibility = View.GONE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_use_credentials)?.visibility = binding.settingsScreen.findViewById<View>(R.id.settings_proxy_use_credentials)?.visibility =
View.GONE View.GONE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_username_edit)?.visibility = View.GONE binding.settingsScreen.findViewById<View>(R.id.settings_proxy_username_edit)?.visibility = View.GONE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_password_edit)?.visibility = View.GONE binding.settingsScreen.findViewById<View>(R.id.settings_proxy_password_edit)?.visibility = View.GONE
} }
private fun showProxySettings() { private fun showProxySettings() {
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_host_edit)?.visibility = binding.settingsScreen.findViewById<View>(R.id.settings_proxy_host_edit)?.visibility =
View.VISIBLE View.VISIBLE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_port_edit)?.visibility = binding.settingsScreen.findViewById<View>(R.id.settings_proxy_port_edit)?.visibility =
View.VISIBLE View.VISIBLE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_use_credentials)?.visibility = binding.settingsScreen.findViewById<View>(R.id.settings_proxy_use_credentials)?.visibility =
View.VISIBLE View.VISIBLE
} }
private fun showProxyCredentials() { private fun showProxyCredentials() {
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_username_edit)?.visibility = binding.settingsScreen.findViewById<View>(R.id.settings_proxy_username_edit)?.visibility =
View.VISIBLE View.VISIBLE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_password_edit)?.visibility = binding.settingsScreen.findViewById<View>(R.id.settings_proxy_password_edit)?.visibility =
View.VISIBLE View.VISIBLE
} }
private fun hideProxyCredentials() { private fun hideProxyCredentials() {
appPreferences.removeProxyUsername() appPreferences.removeProxyUsername()
appPreferences.removeProxyPassword() appPreferences.removeProxyPassword()
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_username_edit)?.visibility = View.GONE binding.settingsScreen.findViewById<View>(R.id.settings_proxy_username_edit)?.visibility = View.GONE
binding?.settingsScreen?.findViewById<View>(R.id.settings_proxy_password_edit)?.visibility = View.GONE binding.settingsScreen.findViewById<View>(R.id.settings_proxy_password_edit)?.visibility = View.GONE
} }
private fun dispose(disposable: Disposable?) { private fun dispose(disposable: Disposable?) {
@ -780,6 +775,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
} }
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == ContactAddressBookWorker.REQUEST_PERMISSION && if (requestCode == ContactAddressBookWorker.REQUEST_PERMISSION &&
grantResults.isNotEmpty() && grantResults.isNotEmpty() &&
grantResults[0] == PackageManager.PERMISSION_GRANTED grantResults[0] == PackageManager.PERMISSION_GRANTED
@ -790,7 +786,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
checkForPhoneNumber() checkForPhoneNumber()
} else { } else {
appPreferences.setPhoneBookIntegration(false) appPreferences.setPhoneBookIntegration(false)
(binding?.settingsPhoneBookIntegration?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsPhoneBookIntegration.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
appPreferences.isPhoneBookIntegrationEnabled appPreferences.isPhoneBookIntegrationEnabled
Toast.makeText( Toast.makeText(
context, context,
@ -808,11 +804,11 @@ class SettingsController : BaseController(R.layout.controller_settings) {
private inner class ScreenLockListener : OnPreferenceValueChangedListener<Boolean> { private inner class ScreenLockListener : OnPreferenceValueChangedListener<Boolean> {
override fun onChanged(newValue: Boolean) { override fun onChanged(newValue: Boolean) {
binding?.settingsScreenLockTimeout?.isEnabled = newValue binding.settingsScreenLockTimeout.isEnabled = newValue
if (newValue) { if (newValue) {
binding?.settingsScreenLockTimeout?.alpha = ENABLED_ALPHA binding.settingsScreenLockTimeout.alpha = ENABLED_ALPHA
} else { } else {
binding?.settingsScreenLockTimeout?.alpha = DISABLED_ALPHA binding.settingsScreenLockTimeout.alpha = DISABLED_ALPHA
} }
} }
} }
@ -820,13 +816,9 @@ class SettingsController : BaseController(R.layout.controller_settings) {
private inner class ScreenSecurityChangeListener : OnPreferenceValueChangedListener<Boolean> { private inner class ScreenSecurityChangeListener : OnPreferenceValueChangedListener<Boolean> {
override fun onChanged(newValue: Boolean) { override fun onChanged(newValue: Boolean) {
if (newValue) { if (newValue) {
if (activity != null) { window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
} else { } else {
if (activity != null) { window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
activity!!.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
} }
} }
} }
@ -849,11 +841,11 @@ class SettingsController : BaseController(R.layout.controller_settings) {
} else { } else {
when (newValue) { when (newValue) {
"HTTP" -> "HTTP" ->
binding?.settingsProxyPortEdit?.value = "3128" binding.settingsProxyPortEdit.value = "3128"
"DIRECT" -> "DIRECT" ->
binding?.settingsProxyPortEdit?.value = "8080" binding.settingsProxyPortEdit.value = "8080"
"SOCKS" -> "SOCKS" ->
binding?.settingsProxyPortEdit?.value = "1080" binding.settingsProxyPortEdit.value = "1080"
else -> { else -> {
} }
} }
@ -868,11 +860,11 @@ class SettingsController : BaseController(R.layout.controller_settings) {
} }
} }
private inner class PhoneBookIntegrationChangeListener(private val controller: Controller) : private inner class PhoneBookIntegrationChangeListener(private val activity: Activity) :
OnPreferenceValueChangedListener<Boolean> { OnPreferenceValueChangedListener<Boolean> {
override fun onChanged(isEnabled: Boolean) { override fun onChanged(isEnabled: Boolean) {
if (isEnabled) { if (isEnabled) {
if (checkPermission(controller, (context)!!)) { if (checkPermission(activity, (context))) {
checkForPhoneNumber() checkForPhoneNumber()
} }
} else { } else {
@ -911,11 +903,11 @@ class SettingsController : BaseController(R.layout.controller_settings) {
} }
private fun askForPhoneNumber() { private fun askForPhoneNumber() {
val phoneNumberLayoutWrapper = LinearLayout(activity) val phoneNumberLayoutWrapper = LinearLayout(context)
phoneNumberLayoutWrapper.orientation = LinearLayout.VERTICAL phoneNumberLayoutWrapper.orientation = LinearLayout.VERTICAL
phoneNumberLayoutWrapper.setPadding(PHONE_NUMBER_SIDE_PADDING, 0, PHONE_NUMBER_SIDE_PADDING, 0) phoneNumberLayoutWrapper.setPadding(PHONE_NUMBER_SIDE_PADDING, 0, PHONE_NUMBER_SIDE_PADDING, 0)
val phoneNumberInputLayout = TextInputLayout((activity)!!) val phoneNumberInputLayout = TextInputLayout(context)
val phoneNumberField = EditText(activity) val phoneNumberField = EditText(context)
phoneNumberInputLayout.setHelperTextColor(ColorStateList.valueOf(resources!!.getColor(R.color.nc_darkRed))) phoneNumberInputLayout.setHelperTextColor(ColorStateList.valueOf(resources!!.getColor(R.color.nc_darkRed)))
phoneNumberField.inputType = InputType.TYPE_CLASS_PHONE phoneNumberField.inputType = InputType.TYPE_CLASS_PHONE
phoneNumberField.setText("+") phoneNumberField.setText("+")
@ -1031,7 +1023,7 @@ class SettingsController : BaseController(R.layout.controller_settings) {
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
appPreferences.setReadPrivacy(!newValue) appPreferences.setReadPrivacy(!newValue)
(binding?.settingsReadPrivacy?.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked = (binding.settingsReadPrivacy.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
!newValue !newValue
} }

View File

@ -31,6 +31,23 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/settings_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/settings_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/appbar"
android:theme="?attr/actionBarPopupTheme"
app:layout_scrollFlags="scroll|enterAlways"
app:navigationIconTint="@color/fontAppbar"
app:popupTheme="@style/appActionBarPopupMenu"
app:titleTextColor="@color/fontAppbar"
tools:title="@string/nc_app_product_name" />
</com.google.android.material.appbar.AppBarLayout>
<com.yarolegovich.mp.MaterialPreferenceCategory <com.yarolegovich.mp.MaterialPreferenceCategory
android:id="@+id/message_view" android:id="@+id/message_view"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -258,11 +275,12 @@
apc:cardElevation="0dp" apc:cardElevation="0dp"
apc:mpc_title="@string/nc_settings_advanced_title"> apc:mpc_title="@string/nc_settings_advanced_title">
<com.yarolegovich.mp.MaterialStandardPreference <!-- TODO: fix reauthorize -->
android:id="@+id/settings_reauthorize" <!-- <com.yarolegovich.mp.MaterialStandardPreference-->
android:layout_width="match_parent" <!-- android:id="@+id/settings_reauthorize"-->
android:layout_height="wrap_content" <!-- android:layout_width="match_parent"-->
apc:mp_title="@string/nc_settings_reauthorize" /> <!-- android:layout_height="wrap_content"-->
<!-- apc:mp_title="@string/nc_settings_reauthorize" />-->
<com.yarolegovich.mp.MaterialStandardPreference <com.yarolegovich.mp.MaterialStandardPreference
android:id="@+id/settings_client_cert" android:id="@+id/settings_client_cert"