From 40bf3a15cde72ab134477e0eb8f835bcd96231e3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2019 12:35:52 +0200 Subject: [PATCH] Move signout action to the settings General --- .../riotredesign/core/extensions/Session.kt | 4 ++++ .../features/home/HomeActivity.kt | 13 ++++++------ .../settings/VectorSettingsGeneralFragment.kt | 20 +++++++++++++++++++ .../workers/signout/SignOutUiWorker.kt | 4 ++-- .../main/res/xml/vector_settings_general.xml | 9 +++++++++ 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/core/extensions/Session.kt b/vector/src/main/java/im/vector/riotredesign/core/extensions/Session.kt index cc7ca459..a3c90e3b 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/extensions/Session.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/extensions/Session.kt @@ -29,4 +29,8 @@ fun Session.configureAndStart(pushRuleTriggerListener: PushRuleTriggerListener) refreshPushers() pushRuleTriggerListener.startWithSession(this) fetchPushRules() + + // TODO P1 From HomeActivity + // @Inject lateinit var incomingVerificationRequestHandler: IncomingVerificationRequestHandler + // @Inject lateinit var keyRequestHandler: KeyRequestHandler } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index b1d10221..1d04e376 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -29,7 +29,6 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import com.airbnb.mvrx.viewModel -import im.vector.matrix.android.api.Matrix import im.vector.riotredesign.R import im.vector.riotredesign.core.di.ActiveSessionHolder import im.vector.riotredesign.core.di.ScreenComponent @@ -44,9 +43,7 @@ import im.vector.riotredesign.features.crypto.keysrequest.KeyRequestHandler import im.vector.riotredesign.features.crypto.verification.IncomingVerificationRequestHandler import im.vector.riotredesign.features.disclaimer.showDisclaimerDialog import im.vector.riotredesign.features.notifications.NotificationDrawerManager -import im.vector.riotredesign.features.rageshake.BugReporter import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler -import im.vector.riotredesign.features.workers.signout.SignOutUiWorker import im.vector.riotredesign.features.workers.signout.SignOutViewModel import im.vector.riotredesign.push.fcm.FcmHelper import kotlinx.android.synthetic.main.activity_home.* @@ -168,10 +165,12 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.sliding_menu_sign_out -> { - SignOutUiWorker(this, notificationDrawerManager).perform(activeSessionHolder.getActiveSession()) - return true - } +// TODO Remove +// R.id.sliding_menu_sign_out -> { +// SignOutUiWorker(this, notificationDrawerManager) +// .perform(Matrix.getInstance().currentSession!!) +// return true +// } } return true diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsGeneralFragment.kt index 8b52cebc..23c0ee7b 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsGeneralFragment.kt @@ -34,7 +34,9 @@ import androidx.preference.Preference import androidx.preference.PreferenceCategory import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputLayout +import im.vector.matrix.android.api.Matrix import im.vector.riotredesign.R +import im.vector.riotredesign.core.di.ActiveSessionHolder import im.vector.riotredesign.core.extensions.showPassword import im.vector.riotredesign.core.platform.SimpleTextWatcher import im.vector.riotredesign.core.preference.UserAvatarPreference @@ -44,15 +46,21 @@ import im.vector.riotredesign.core.utils.allGranted import im.vector.riotredesign.core.utils.copyToClipboard import im.vector.riotredesign.core.utils.toast import im.vector.riotredesign.features.MainActivity +import im.vector.riotredesign.features.notifications.NotificationDrawerManager import im.vector.riotredesign.features.themes.ThemeUtils +import im.vector.riotredesign.features.workers.signout.SignOutUiWorker import java.lang.ref.WeakReference import java.util.* +import javax.inject.Inject class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { override var titleRes = R.string.settings_general_title override val preferenceXmlRes = R.xml.vector_settings_general + @Inject lateinit var activeSessionHolder: ActiveSessionHolder + @Inject lateinit var notificationDrawerManager: NotificationDrawerManager + private var mDisplayedEmails = ArrayList() private var mDisplayedPhoneNumber = ArrayList() @@ -227,6 +235,18 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { } } + // Sign out + findPreference("SETTINGS_SIGN_OUT_KEY") + .onPreferenceClickListener = Preference.OnPreferenceClickListener { + activity?.let { + SignOutUiWorker(requireActivity(), notificationDrawerManager) + .perform(activeSessionHolder.getActiveSession()) + } + + false + } + + // Deactivate account section // deactivate account diff --git a/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutUiWorker.kt b/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutUiWorker.kt index 32576851..6767dfec 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutUiWorker.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutUiWorker.kt @@ -17,13 +17,13 @@ package im.vector.riotredesign.features.workers.signout import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.FragmentActivity import im.vector.matrix.android.api.session.Session import im.vector.riotredesign.R -import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.features.MainActivity import im.vector.riotredesign.features.notifications.NotificationDrawerManager -class SignOutUiWorker(private val activity: VectorBaseActivity, +class SignOutUiWorker(private val activity: FragmentActivity, private val notificationDrawerManager: NotificationDrawerManager) { fun perform(session: Session) { diff --git a/vector/src/main/res/xml/vector_settings_general.xml b/vector/src/main/res/xml/vector_settings_general.xml index 152bc64d..8bc15fef 100644 --- a/vector/src/main/res/xml/vector_settings_general.xml +++ b/vector/src/main/res/xml/vector_settings_general.xml @@ -93,6 +93,15 @@ + + + + + +