diff --git a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt index 4d7462e54db..4a5cffd0d12 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt @@ -49,8 +49,8 @@ import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.callnotification.CallNotificationActivity import com.nextcloud.talk.chat.ChatActivity -import com.nextcloud.talk.controllers.ServerSelectionController -import com.nextcloud.talk.controllers.WebViewLoginController +import com.nextcloud.talk.controllers.ServerSelectionActivity +import com.nextcloud.talk.controllers.WebViewLoginActivity import com.nextcloud.talk.controllers.base.providers.ActionBarProvider import com.nextcloud.talk.conversationlist.ConversationsListActivity import com.nextcloud.talk.data.user.model.User @@ -132,14 +132,14 @@ class MainActivity : BaseActivity(), ActionBarProvider { if (!TextUtils.isEmpty(resources.getString(R.string.weblogin_url))) { router!!.pushController( RouterTransaction.with( - WebViewLoginController(resources.getString(R.string.weblogin_url), false) + WebViewLoginActivity(resources.getString(R.string.weblogin_url), false) ) .pushChangeHandler(HorizontalChangeHandler()) .popChangeHandler(HorizontalChangeHandler()) ) } else { router!!.setRoot( - RouterTransaction.with(ServerSelectionController()) + RouterTransaction.with(ServerSelectionActivity()) .pushChangeHandler(HorizontalChangeHandler()) .popChangeHandler(HorizontalChangeHandler()) ) @@ -180,7 +180,7 @@ class MainActivity : BaseActivity(), ActionBarProvider { fun addAccount() { router!!.pushController( - RouterTransaction.with(ServerSelectionController()) + RouterTransaction.with(ServerSelectionActivity()) .pushChangeHandler(VerticalChangeHandler()) .popChangeHandler(VerticalChangeHandler()) ) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationActivity.kt similarity index 72% rename from app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt rename to app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationActivity.kt index d6ecd5a812a..1a5a7a356fc 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationActivity.kt @@ -28,24 +28,19 @@ import android.os.Bundle import android.os.Handler import android.text.TextUtils import android.util.Log -import android.view.View import androidx.work.Data import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager import autodagger.AutoInjector -import com.bluelinelabs.conductor.RouterTransaction -import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler import com.bluelinelabs.logansquare.LoganSquare import com.google.android.material.snackbar.Snackbar import com.nextcloud.talk.R +import com.nextcloud.talk.activities.BaseActivity import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication -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.conversationlist.ConversationsListActivity import com.nextcloud.talk.data.user.model.User -import com.nextcloud.talk.databinding.ControllerAccountVerificationBinding +import com.nextcloud.talk.databinding.ActivityAccountVerificationBinding import com.nextcloud.talk.events.EventStatus import com.nextcloud.talk.jobs.CapabilitiesWorker import com.nextcloud.talk.jobs.PushRegistrationWorker @@ -71,20 +66,15 @@ import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers -import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import java.net.CookieManager import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class AccountVerificationController(args: Bundle? = null) : BaseController( - R.layout.controller_account_verification, - args -) { - private val binding: ControllerAccountVerificationBinding? by viewBinding( - ControllerAccountVerificationBinding::bind - ) +class AccountVerificationActivity : BaseActivity() { + + private lateinit var binding: ActivityAccountVerificationBinding @Inject lateinit var ncApi: NcApi @@ -95,8 +85,6 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( @Inject lateinit var cookieManager: CookieManager - @Inject - lateinit var eventBus: EventBus private var internalAccountId: Long = -1 private val disposables: MutableList = ArrayList() @@ -106,21 +94,39 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( private var isAccountImport = false private var originalProtocol: String? = null - override fun onAttach(view: View) { - super.onAttach(view) - eventBus.register(this) - } - override fun onDetach(view: View) { - super.onDetach(view) - eventBus.unregister(this) - } - override fun onViewBound(view: View) { - super.onViewBound(view) - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) + + binding = ActivityAccountVerificationBinding.inflate(layoutInflater) actionBar?.hide() + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + setContentView(binding.root) + setupSystemColors() + // viewThemeUtils.material.themeCardView(binding.searchToolbar) + // viewThemeUtils.material.themeSearchBarText(binding.searchText) + + // onBackPressedDispatcher.addCallback(this, onBackPressedCallback) + + + + val extras = intent.extras!! + baseUrl = extras.getString(KEY_BASE_URL) + username = extras.getString(KEY_USERNAME) + token = extras.getString(KEY_TOKEN) + if (extras.containsKey(KEY_IS_ACCOUNT_IMPORT)) { + isAccountImport = true + } + if (extras.containsKey(KEY_ORIGINAL_PROTOCOL)) { + originalProtocol = extras.getString(KEY_ORIGINAL_PROTOCOL) + } + } + + override fun onResume() { + super.onResume() if ( isAccountImport && @@ -133,6 +139,12 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( } } + + + + + + private fun isSameProtocol(baseUrl: String, originalProtocol: String): Boolean { return !TextUtils.isEmpty(originalProtocol) && !baseUrl.startsWith(originalProtocol) } @@ -166,18 +178,19 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( "http://$baseUrl" } if (isAccountImport) { - router.replaceTopController( - RouterTransaction.with( - WebViewLoginController( - baseUrl, - false, - username, - "" - ) - ) - .pushChangeHandler(HorizontalChangeHandler()) - .popChangeHandler(HorizontalChangeHandler()) - ) + // TODO: start WebViewLoginActivity? + // router.replaceTopController( + // RouterTransaction.with( + // WebViewLoginController( + // baseUrl, + // false, + // username, + // "" + // ) + // ) + // .pushChangeHandler(HorizontalChangeHandler()) + // .popChangeHandler(HorizontalChangeHandler()) + // ) } else { checkEverything() } @@ -214,13 +227,11 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( if (hasTalk) { fetchProfile(credentials, capabilitiesOverall) } else { - if (activity != null && resources != null) { - activity!!.runOnUiThread { - binding?.progressText?.setText( - String.format( - resources!!.getString(R.string.nc_nextcloud_talk_app_not_installed), - resources!!.getString(R.string.nc_app_product_name) - ) + if (resources != null) { + runOnUiThread { + binding.progressText.text = String.format( + resources!!.getString(R.string.nc_nextcloud_talk_app_not_installed), + resources!!.getString(R.string.nc_app_product_name) ) } } @@ -232,9 +243,9 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( } override fun onError(e: Throwable) { - if (activity != null && resources != null) { - activity!!.runOnUiThread { - binding?.progressText?.text = String.format( + if (resources != null) { + runOnUiThread { + binding.progressText.text = String.format( resources!!.getString(R.string.nc_nextcloud_talk_app_not_installed), resources!!.getString(R.string.nc_app_product_name) ) @@ -263,7 +274,7 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( displayName = displayName, pushConfigurationState = null, capabilities = LoganSquare.serialize(capabilities), - certificateAlias = appPreferences!!.temporaryClientCertAlias, + certificateAlias = appPreferences.temporaryClientCertAlias, externalSignalingServer = null ) ) @@ -279,9 +290,9 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( if (ClosedInterfaceImpl().isGooglePlayServicesAvailable) { registerForPush() } else { - activity!!.runOnUiThread { - binding?.progressText?.text = - """ ${binding?.progressText?.text} + runOnUiThread { + binding.progressText.text = + """ ${binding.progressText.text} ${resources!!.getString(R.string.nc_push_disabled)} """.trimIndent() } @@ -291,7 +302,7 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( @SuppressLint("SetTextI18n") override fun onError(e: Throwable) { - binding?.progressText?.text = """ ${binding?.progressText?.text}""".trimIndent() + + binding.progressText.text = """ ${binding.progressText.text}""".trimIndent() + resources!!.getString(R.string.nc_display_name_not_stored) abortVerification() } @@ -328,14 +339,12 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( capabilities.ocs!!.data!!.capabilities!! ) } else { - if (activity != null) { - activity!!.runOnUiThread { - binding?.progressText?.text = - """ - ${binding?.progressText?.text} - ${resources!!.getString(R.string.nc_display_name_not_fetched)} - """.trimIndent() - } + runOnUiThread { + binding.progressText.text = + """ + ${binding.progressText.text} + ${resources!!.getString(R.string.nc_display_name_not_fetched)} + """.trimIndent() } abortVerification() } @@ -343,14 +352,12 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( @SuppressLint("SetTextI18n") override fun onError(e: Throwable) { - if (activity != null) { - activity!!.runOnUiThread { - binding?.progressText?.text = - """ - ${binding?.progressText?.text} - ${resources!!.getString(R.string.nc_display_name_not_fetched)} - """.trimIndent() - } + runOnUiThread { + binding.progressText.text = + """ + ${binding.progressText.text} + ${resources!!.getString(R.string.nc_display_name_not_fetched)} + """.trimIndent() } abortVerification() } @@ -377,11 +384,11 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( @Subscribe(threadMode = ThreadMode.BACKGROUND) fun onMessageEvent(eventStatus: EventStatus) { if (eventStatus.eventType == EventStatus.EventType.PUSH_REGISTRATION) { - if (internalAccountId == eventStatus.userId && !eventStatus.isAllGood && activity != null) { - activity!!.runOnUiThread { - binding?.progressText?.text = + if (internalAccountId == eventStatus.userId && !eventStatus.isAllGood) { + runOnUiThread { + binding.progressText.text = """ - ${binding?.progressText?.text} + ${binding.progressText.text} ${resources!!.getString(R.string.nc_push_disabled)} """.trimIndent() } @@ -389,14 +396,12 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( fetchAndStoreCapabilities() } else if (eventStatus.eventType == EventStatus.EventType.CAPABILITIES_FETCH) { if (internalAccountId == eventStatus.userId && !eventStatus.isAllGood) { - if (activity != null) { - activity!!.runOnUiThread { - binding?.progressText?.text = - """ - ${binding?.progressText?.text} - ${resources!!.getString(R.string.nc_capabilities_failed)} - """.trimIndent() - } + runOnUiThread { + binding.progressText.text = + """ + ${binding.progressText.text} + ${resources!!.getString(R.string.nc_capabilities_failed)} + """.trimIndent() } abortVerification() } else if (internalAccountId == eventStatus.userId && eventStatus.isAllGood) { @@ -404,14 +409,12 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( } } else if (eventStatus.eventType == EventStatus.EventType.SIGNALING_SETTINGS) { if (internalAccountId == eventStatus.userId && !eventStatus.isAllGood) { - if (activity != null) { - activity!!.runOnUiThread { - binding?.progressText?.text = - """ - ${binding?.progressText?.text} - ${resources!!.getString(R.string.nc_external_server_failed)} - """.trimIndent() - } + runOnUiThread { + binding.progressText.text = + """ + ${binding.progressText.text} + ${resources!!.getString(R.string.nc_external_server_failed)} + """.trimIndent() } } proceedWithLogin() @@ -457,8 +460,7 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( Log.d(TAG, "userToSetAsActive: " + userToSetAsActive.username) if (userManager.setUserAsActive(userToSetAsActive).blockingGet()) { - if (activity != null) { - activity!!.runOnUiThread { + runOnUiThread { if (userManager.users.blockingGet().size == 1) { val intent = Intent(context, ConversationsListActivity::class.java) startActivity(intent) @@ -471,10 +473,9 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( startActivity(intent) } } - } } else { Log.e(TAG, "failed to set active user") - Snackbar.make(binding!!.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show() + Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show() } } } @@ -487,11 +488,6 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( } } - override fun onDestroyView(view: View) { - super.onDestroyView(view) - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR - } - public override fun onDestroy() { dispose() super.onDestroy() @@ -502,32 +498,31 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( if (internalAccountId != -1L) { val count = userManager.deleteUser(internalAccountId) if (count > 0) { - activity?.runOnUiThread { Handler().postDelayed({ router.popToRoot() }, DELAY_IN_MILLIS) } + runOnUiThread { Handler().postDelayed({ + // TODO: start ServerSelectionActivity? + // router.popToRoot() + }, DELAY_IN_MILLIS) } } } else { - activity?.runOnUiThread { Handler().postDelayed({ router.popToRoot() }, DELAY_IN_MILLIS) } + runOnUiThread { Handler().postDelayed({ + // TODO: start ServerSelectionActivity? + // router.popToRoot() + }, DELAY_IN_MILLIS) } } } else { - ApplicationWideMessageHolder.getInstance().setMessageType( - ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT - ) - activity?.runOnUiThread { + ApplicationWideMessageHolder.getInstance().messageType = ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT + runOnUiThread { Handler().postDelayed({ - if (router.hasRootController()) { - if (activity != null) { - router.popToRoot() - } + if (userManager.users.blockingGet().isNotEmpty()) { + val intent = Intent(context, ConversationsListActivity::class.java) + startActivity(intent) } else { - if (userManager.users.blockingGet().isNotEmpty()) { - val intent = Intent(context, ConversationsListActivity::class.java) - startActivity(intent) - } else { - router.setRoot( - RouterTransaction.with(ServerSelectionController()) - .pushChangeHandler(HorizontalChangeHandler()) - .popChangeHandler(HorizontalChangeHandler()) - ) - } + // TODO: start ServerSelectionActivity? + // router.setRoot( + // RouterTransaction.with(ServerSelectionController()) + // .pushChangeHandler(HorizontalChangeHandler()) + // .popChangeHandler(HorizontalChangeHandler()) + // ) } }, DELAY_IN_MILLIS) } @@ -538,19 +533,4 @@ class AccountVerificationController(args: Bundle? = null) : BaseController( const val TAG = "AccountVerification" const val DELAY_IN_MILLIS: Long = 7500 } - - init { - sharedApplication!!.componentApplication.inject(this) - if (args != null) { - baseUrl = args.getString(KEY_BASE_URL) - username = args.getString(KEY_USERNAME) - token = args.getString(KEY_TOKEN) - if (args.containsKey(KEY_IS_ACCOUNT_IMPORT)) { - isAccountImport = true - } - if (args.containsKey(KEY_ORIGINAL_PROTOCOL)) { - originalProtocol = args.getString(KEY_ORIGINAL_PROTOCOL) - } - } - } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionActivity.kt similarity index 69% rename from app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.kt rename to app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionActivity.kt index a05899b52a7..9f1f0954200 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionActivity.kt @@ -36,15 +36,11 @@ import android.view.inputmethod.EditorInfo import android.widget.TextView import androidx.core.content.res.ResourcesCompat import autodagger.AutoInjector -import com.bluelinelabs.conductor.RouterTransaction -import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler import com.nextcloud.talk.R +import com.nextcloud.talk.activities.BaseActivity import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication -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.databinding.ControllerServerSelectionBinding +import com.nextcloud.talk.databinding.ActivityServerSelectionBinding import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall import com.nextcloud.talk.models.json.generic.Status import com.nextcloud.talk.users.UserManager @@ -52,6 +48,7 @@ import com.nextcloud.talk.utils.AccountUtils import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.UriUtils +import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_ACCOUNT_IMPORT import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder @@ -63,10 +60,9 @@ import java.security.cert.CertificateException import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class ServerSelectionController : - BaseController(R.layout.controller_server_selection) { +class ServerSelectionActivity : BaseActivity(){ - private val binding: ControllerServerSelectionBinding? by viewBinding(ControllerServerSelectionBinding::bind) + private lateinit var binding: ActivityServerSelectionBinding @Inject lateinit var ncApi: NcApi @@ -76,44 +72,47 @@ class ServerSelectionController : private var statusQueryDisposable: Disposable? = null - fun onCertClick() { - if (activity != null) { - KeyChain.choosePrivateKeyAlias( - activity!!, - { alias: String? -> - if (alias != null) { - appPreferences!!.temporaryClientCertAlias = alias - } else { - appPreferences!!.removeTemporaryClientCertAlias() - } - setCertTextView() - }, - arrayOf("RSA", "EC"), - null, - null, - -1, - null - ) - } - } - - override fun onViewBound(view: View) { - super.onViewBound(view) - sharedApplication!!.componentApplication.inject(this) - if (activity != null) { - activity!!.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) + binding = ActivityServerSelectionBinding.inflate(layoutInflater) actionBar?.hide() + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + setContentView(binding.root) + setupSystemColors() + // // viewThemeUtils.material.themeCardView(binding.searchToolbar) + // // viewThemeUtils.material.themeSearchBarText(binding.searchText) + // + // // onBackPressedDispatcher.addCallback(this, onBackPressedCallback) + // + // + // + // val extras = intent.extras!! + // baseUrl = extras.getString(BundleKeys.KEY_BASE_URL) + // username = extras.getString(BundleKeys.KEY_USERNAME) + // + // + // if (extras.containsKey(BundleKeys.KEY_IS_PASSWORD_UPDATE)) { + // isPasswordUpdate = extras.getBoolean(BundleKeys.KEY_IS_PASSWORD_UPDATE) + // } + // + // if (extras.containsKey(BundleKeys.KEY_PASSWORD)) { + // password = extras.getString(BundleKeys.KEY_PASSWORD) + // } + } - binding?.hostUrlInputHelperText?.text = String.format( + override fun onResume() { + super.onResume() + + binding.hostUrlInputHelperText.text = String.format( resources!!.getString(R.string.nc_server_helper_text), resources!!.getString(R.string.nc_server_product_name) ) - binding?.serverEntryTextInputLayout?.setEndIconOnClickListener { checkServerAndProceed() } + binding.serverEntryTextInputLayout.setEndIconOnClickListener { checkServerAndProceed() } if (resources!!.getBoolean(R.bool.hide_auth_cert)) { - binding?.certTextView?.visibility = View.GONE + binding.certTextView.visibility = View.GONE } val loggedInUsers = userManager.users.blockingGet() @@ -124,21 +123,77 @@ class ServerSelectionController : } else if (isAbleToShowProviderLink() && loggedInUsers.isEmpty()) { showVisitProvidersInfo() } else { - binding?.importOrChooseProviderText?.visibility = View.INVISIBLE + binding.importOrChooseProviderText.visibility = View.INVISIBLE } - binding?.serverEntryTextInputEditText?.requestFocus() + binding.serverEntryTextInputEditText.requestFocus() if (!TextUtils.isEmpty(resources!!.getString(R.string.weblogin_url))) { - binding?.serverEntryTextInputEditText?.setText(resources!!.getString(R.string.weblogin_url)) + binding.serverEntryTextInputEditText.setText(resources!!.getString(R.string.weblogin_url)) checkServerAndProceed() } - binding?.serverEntryTextInputEditText?.setOnEditorActionListener { _: TextView?, i: Int, _: KeyEvent? -> + binding.serverEntryTextInputEditText.setOnEditorActionListener { _: TextView?, i: Int, _: KeyEvent? -> if (i == EditorInfo.IME_ACTION_DONE) { checkServerAndProceed() } false } - binding?.certTextView?.setOnClickListener { onCertClick() } + binding.certTextView.setOnClickListener { onCertClick() } + + + + + + + + + + if (ApplicationWideMessageHolder.getInstance().messageType != null) { + if (ApplicationWideMessageHolder.getInstance().messageType + == ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION + ) { + setErrorText(resources!!.getString(R.string.nc_account_scheduled_for_deletion)) + ApplicationWideMessageHolder.getInstance().messageType = null + } else if (ApplicationWideMessageHolder.getInstance().messageType + == ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK + ) { + setErrorText(resources!!.getString(R.string.nc_settings_no_talk_installed)) + } else if (ApplicationWideMessageHolder.getInstance().messageType + == ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT + ) { + setErrorText(resources!!.getString(R.string.nc_server_failed_to_import_account)) + } + ApplicationWideMessageHolder.getInstance().messageType = null + } + if (resources != null) { + DisplayUtils.applyColorToStatusBar( + this, + ResourcesCompat.getColor(resources!!, R.color.colorPrimary, null) + ) + DisplayUtils.applyColorToNavigationBar( + window, + ResourcesCompat.getColor(resources!!, R.color.colorPrimary, null) + ) + } + setCertTextView() + } + + fun onCertClick() { + KeyChain.choosePrivateKeyAlias( + this, + { alias: String? -> + if (alias != null) { + appPreferences!!.temporaryClientCertAlias = alias + } else { + appPreferences!!.removeTemporaryClientCertAlias() + } + setCertTextView() + }, + arrayOf("RSA", "EC"), + null, + null, + -1, + null + ) } private fun isAbleToShowProviderLink(): Boolean { @@ -152,41 +207,42 @@ class ServerSelectionController : ) ) { if (availableAccounts.size > 1) { - binding?.importOrChooseProviderText?.text = String.format( + binding.importOrChooseProviderText.text = String.format( resources!!.getString(R.string.nc_server_import_accounts), AccountUtils.getAppNameBasedOnPackage(resources!!.getString(R.string.nc_import_accounts_from)) ) } else { - binding?.importOrChooseProviderText?.text = String.format( + binding.importOrChooseProviderText.text = String.format( resources!!.getString(R.string.nc_server_import_account), AccountUtils.getAppNameBasedOnPackage(resources!!.getString(R.string.nc_import_accounts_from)) ) } } else { if (availableAccounts.size > 1) { - binding?.importOrChooseProviderText?.text = + binding.importOrChooseProviderText.text = resources!!.getString(R.string.nc_server_import_accounts_plain) } else { - binding?.importOrChooseProviderText?.text = + binding.importOrChooseProviderText.text = resources!!.getString(R.string.nc_server_import_account_plain) } } - binding?.importOrChooseProviderText?.setOnClickListener { + binding.importOrChooseProviderText.setOnClickListener { val bundle = Bundle() bundle.putBoolean(KEY_IS_ACCOUNT_IMPORT, true) - router.pushController( - RouterTransaction.with( - SwitchAccountController(bundle) - ) - .pushChangeHandler(HorizontalChangeHandler()) - .popChangeHandler(HorizontalChangeHandler()) - ) + // TODO start SwitchAccountActivity? + // router.pushController( + // RouterTransaction.with( + // SwitchAccountController(bundle) + // ) + // .pushChangeHandler(HorizontalChangeHandler()) + // .popChangeHandler(HorizontalChangeHandler()) + // ) } } private fun showVisitProvidersInfo() { - binding?.importOrChooseProviderText?.setText(R.string.nc_get_from_provider) - binding?.importOrChooseProviderText?.setOnClickListener { + binding.importOrChooseProviderText.setText(R.string.nc_get_from_provider) + binding.importOrChooseProviderText.setOnClickListener { val browserIntent = Intent( Intent.ACTION_VIEW, Uri.parse( @@ -206,11 +262,11 @@ class ServerSelectionController : @Suppress("Detekt.TooGenericExceptionCaught") private fun checkServerAndProceed() { dispose() - var url: String = binding?.serverEntryTextInputEditText?.text.toString().trim { it <= ' ' } + var url: String = binding.serverEntryTextInputEditText.text.toString().trim { it <= ' ' } showserverEntryProgressBar() - if (binding?.importOrChooseProviderText?.visibility != View.INVISIBLE) { - binding?.importOrChooseProviderText?.visibility = View.INVISIBLE - binding?.certTextView?.visibility = View.INVISIBLE + if (binding.importOrChooseProviderText.visibility != View.INVISIBLE) { + binding.importOrChooseProviderText.visibility = View.INVISIBLE + binding.certTextView.visibility = View.INVISIBLE } if (url.endsWith("/")) { url = url.substring(0, url.length - 1) @@ -278,17 +334,17 @@ class ServerSelectionController : hideserverEntryProgressBar() } - if (binding?.importOrChooseProviderText?.visibility != View.INVISIBLE) { - binding?.importOrChooseProviderText?.visibility = View.VISIBLE - binding?.certTextView?.visibility = View.VISIBLE + if (binding.importOrChooseProviderText.visibility != View.INVISIBLE) { + binding.importOrChooseProviderText.visibility = View.VISIBLE + binding.certTextView.visibility = View.VISIBLE } dispose() } }) { hideserverEntryProgressBar() - if (binding?.importOrChooseProviderText?.visibility != View.INVISIBLE) { - binding?.importOrChooseProviderText?.visibility = View.VISIBLE - binding?.certTextView?.visibility = View.VISIBLE + if (binding.importOrChooseProviderText.visibility != View.INVISIBLE) { + binding.importOrChooseProviderText.visibility = View.VISIBLE + binding.certTextView.visibility = View.VISIBLE } dispose() } @@ -311,29 +367,37 @@ class ServerSelectionController : capabilities.spreedCapability?.features?.isNotEmpty() == true if (hasTalk) { - activity?.runOnUiThread { + runOnUiThread { if (CapabilitiesUtilNew.isServerEOL(capabilities)) { if (resources != null) { - activity!!.runOnUiThread { + runOnUiThread { setErrorText(resources!!.getString(R.string.nc_settings_server_eol)) } } } else { - router.pushController( - RouterTransaction.with( - WebViewLoginController( - queryUrl.replace("/status.php", ""), - false - ) - ) - .pushChangeHandler(HorizontalChangeHandler()) - .popChangeHandler(HorizontalChangeHandler()) - ) + val bundle = Bundle() + bundle.putString(BundleKeys.KEY_BASE_URL, queryUrl.replace("/status.php", "")) + bundle.putBoolean(BundleKeys.KEY_IS_PASSWORD_UPDATE, false) + + val intent = Intent(context, WebViewLoginActivity::class.java) + intent.putExtras(bundle) + startActivity(intent) + + // router.pushController( + // RouterTransaction.with( + // WebViewLoginActivity( + // queryUrl.replace("/status.php", ""), + // false + // ) + // ) + // .pushChangeHandler(HorizontalChangeHandler()) + // .popChangeHandler(HorizontalChangeHandler()) + // ) } } } else { - if (activity != null && resources != null) { - activity!!.runOnUiThread { + if (resources != null) { + runOnUiThread { setErrorText(resources!!.getString(R.string.nc_server_unsupported)) } } @@ -342,8 +406,8 @@ class ServerSelectionController : override fun onError(e: Throwable) { Log.e(TAG, "Error while checking capabilities", e) - if (activity != null && resources != null) { - activity!!.runOnUiThread { + if (resources != null) { + runOnUiThread { setErrorText(resources!!.getString(R.string.nc_common_error_sorry)) } } @@ -360,70 +424,29 @@ class ServerSelectionController : } private fun setErrorText(text: String) { - binding?.errorWrapper?.visibility = View.VISIBLE - binding?.errorText?.text = text + binding.errorWrapper.visibility = View.VISIBLE + binding.errorText.text = text hideserverEntryProgressBar() } private fun showserverEntryProgressBar() { - binding?.errorWrapper?.visibility = View.INVISIBLE - binding?.serverEntryProgressBar?.visibility = View.VISIBLE + binding.errorWrapper.visibility = View.INVISIBLE + binding.serverEntryProgressBar.visibility = View.VISIBLE } private fun hideserverEntryProgressBar() { - binding?.serverEntryProgressBar?.visibility = View.INVISIBLE - } - - override fun onAttach(view: View) { - super.onAttach(view) - if (ApplicationWideMessageHolder.getInstance().messageType != null) { - if (ApplicationWideMessageHolder.getInstance().messageType - == ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION - ) { - setErrorText(resources!!.getString(R.string.nc_account_scheduled_for_deletion)) - ApplicationWideMessageHolder.getInstance().messageType = null - } else if (ApplicationWideMessageHolder.getInstance().messageType - == ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK - ) { - setErrorText(resources!!.getString(R.string.nc_settings_no_talk_installed)) - } else if (ApplicationWideMessageHolder.getInstance().messageType - == ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT - ) { - setErrorText(resources!!.getString(R.string.nc_server_failed_to_import_account)) - } - ApplicationWideMessageHolder.getInstance().messageType = null - } - if (activity != null && resources != null) { - DisplayUtils.applyColorToStatusBar( - activity, - ResourcesCompat.getColor(resources!!, R.color.colorPrimary, null) - ) - DisplayUtils.applyColorToNavigationBar( - activity!!.window, - ResourcesCompat.getColor(resources!!, R.color.colorPrimary, null) - ) - } - setCertTextView() + binding.serverEntryProgressBar.visibility = View.INVISIBLE } @SuppressLint("LongLogTag") private fun setCertTextView() { - if (activity != null) { - activity!!.runOnUiThread { - if (!TextUtils.isEmpty(appPreferences!!.temporaryClientCertAlias)) { - binding?.certTextView?.setText(R.string.nc_change_cert_auth) - } else { - binding?.certTextView?.setText(R.string.nc_configure_cert_auth) - } - hideserverEntryProgressBar() + runOnUiThread { + if (!TextUtils.isEmpty(appPreferences.temporaryClientCertAlias)) { + binding.certTextView.setText(R.string.nc_change_cert_auth) + } else { + binding.certTextView.setText(R.string.nc_configure_cert_auth) } - } - } - - override fun onDestroyView(view: View) { - super.onDestroyView(view) - if (activity != null) { - activity!!.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR + hideserverEntryProgressBar() } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.kt b/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.kt index 36bf20a0673..296f40fa81b 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.kt @@ -25,27 +25,31 @@ package com.nextcloud.talk.controllers import android.accounts.Account +import android.content.Intent +import android.content.pm.ActivityInfo import android.os.Bundle import android.view.MenuItem import android.view.View import androidx.preference.PreferenceManager import androidx.recyclerview.widget.LinearLayoutManager import autodagger.AutoInjector -import com.bluelinelabs.conductor.RouterTransaction -import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler import com.nextcloud.talk.R +import com.nextcloud.talk.activities.BaseActivity import com.nextcloud.talk.adapters.items.AdvancedUserItem import com.nextcloud.talk.application.NextcloudTalkApplication 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.conversationlist.ConversationsListActivity import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.databinding.ActivityWebViewLoginBinding import com.nextcloud.talk.databinding.ControllerGenericRvBinding import com.nextcloud.talk.models.ImportAccount import com.nextcloud.talk.models.json.participants.Participant import com.nextcloud.talk.users.UserManager import com.nextcloud.talk.utils.AccountUtils.findAvailableAccountsOnDevice import com.nextcloud.talk.utils.AccountUtils.getInformationFromAccount +import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_BASE_URL import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_ACCOUNT_IMPORT import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_TOKEN @@ -58,12 +62,8 @@ import java.net.CookieManager import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class SwitchAccountController(args: Bundle? = null) : - BaseController( - R.layout.controller_generic_rv, - args - ) { - private val binding: ControllerGenericRvBinding? by viewBinding(ControllerGenericRvBinding::bind) +class SwitchAccountController : BaseActivity() { + private lateinit var binding: ControllerGenericRvBinding @Inject lateinit var userManager: UserManager @@ -89,19 +89,32 @@ class SwitchAccountController(args: Bundle? = null) : if (userManager.setUserAsActive(user).blockingGet()) { cookieManager.cookieStore.removeAll() - if (activity != null) { - activity!!.runOnUiThread { router.popCurrentController() } - } + // TODO ??? + // runOnUiThread { router.popCurrentController() } } } true } - init { - setHasOptionsMenu(true) - sharedApplication!!.componentApplication.inject(this) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) + + binding = ControllerGenericRvBinding.inflate(layoutInflater) + actionBar?.hide() + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + setContentView(binding.root) + setupSystemColors() + Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context)) - if (args?.containsKey(KEY_IS_ACCOUNT_IMPORT) == true) { + + + // setHasOptionsMenu(true) + + + val extras = intent.extras!! + if (extras.containsKey(KEY_IS_ACCOUNT_IMPORT)) { isAccountImport = true } } @@ -166,11 +179,11 @@ class SwitchAccountController(args: Bundle? = null) : } private fun prepareViews() { - val layoutManager: LinearLayoutManager = SmoothScrollLinearLayoutManager(activity) - binding?.recyclerView?.layoutManager = layoutManager - binding?.recyclerView?.setHasFixedSize(true) - binding?.recyclerView?.adapter = adapter - binding?.swipeRefreshLayout?.isEnabled = false + val layoutManager: LinearLayoutManager = SmoothScrollLinearLayoutManager(this) + binding.recyclerView.layoutManager = layoutManager + binding.recyclerView.setHasFixedSize(true) + binding.recyclerView.adapter = adapter + binding.swipeRefreshLayout.isEnabled = false } private fun reauthorizeFromImport(account: Account?) { @@ -180,11 +193,15 @@ class SwitchAccountController(args: Bundle? = null) : bundle.putString(KEY_USERNAME, importAccount.getUsername()) bundle.putString(KEY_TOKEN, importAccount.getToken()) bundle.putBoolean(KEY_IS_ACCOUNT_IMPORT, true) - router.pushController( - RouterTransaction.with(AccountVerificationController(bundle)) - .pushChangeHandler(HorizontalChangeHandler()) - .popChangeHandler(HorizontalChangeHandler()) - ) + // router.pushController( + // RouterTransaction.with(AccountVerificationController(bundle)) + // .pushChangeHandler(HorizontalChangeHandler()) + // .popChangeHandler(HorizontalChangeHandler()) + // ) + + val intent = Intent(context, AccountVerificationActivity::class.java) + intent.putExtras(bundle) + startActivity(intent) } override val title: String diff --git a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.kt b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginActivity.kt similarity index 78% rename from app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.kt rename to app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginActivity.kt index 7bddc38c351..f510a17b069 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginActivity.kt @@ -22,6 +22,7 @@ package com.nextcloud.talk.controllers import android.annotation.SuppressLint +import android.content.Intent import android.content.pm.ActivityInfo import android.graphics.Bitmap import android.net.http.SslError @@ -40,25 +41,20 @@ import android.webkit.WebResourceResponse import android.webkit.WebSettings import android.webkit.WebView import android.webkit.WebViewClient -import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.res.ResourcesCompat import androidx.work.Data import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager import autodagger.AutoInjector -import com.bluelinelabs.conductor.RouterTransaction -import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler import com.nextcloud.talk.R +import com.nextcloud.talk.activities.BaseActivity import com.nextcloud.talk.application.NextcloudTalkApplication 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.databinding.ControllerWebViewLoginBinding +import com.nextcloud.talk.databinding.ActivityWebViewLoginBinding import com.nextcloud.talk.events.CertificateEvent import com.nextcloud.talk.jobs.PushRegistrationWorker import com.nextcloud.talk.models.LoginData import com.nextcloud.talk.users.UserManager -import com.nextcloud.talk.utils.DisplayUtils +import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_BASE_URL import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ORIGINAL_PROTOCOL import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_TOKEN @@ -67,7 +63,6 @@ import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder import com.nextcloud.talk.utils.ssl.TrustManager import de.cotech.hw.fido.WebViewFidoBridge import io.reactivex.disposables.Disposable -import org.greenrobot.eventbus.EventBus import java.lang.reflect.Field import java.net.CookieManager import java.net.URLDecoder @@ -78,11 +73,9 @@ import java.util.Locale import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class WebViewLoginController(args: Bundle? = null) : BaseController( - R.layout.controller_web_view_login, - args -) { - private val binding: ControllerWebViewLoginBinding? by viewBinding(ControllerWebViewLoginBinding::bind) +class WebViewLoginActivity : BaseActivity() { + + private lateinit var binding: ActivityWebViewLoginBinding @Inject lateinit var userManager: UserManager @@ -90,9 +83,6 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( @Inject lateinit var trustManager: TrustManager - @Inject - lateinit var eventBus: EventBus - @Inject lateinit var cookieManager: CookieManager @@ -106,17 +96,17 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( private var automatedLoginAttempted = false private var webViewFidoBridge: WebViewFidoBridge? = null - constructor(baseUrl: String?, isPasswordUpdate: Boolean) : this() { - this.baseUrl = baseUrl - this.isPasswordUpdate = isPasswordUpdate - } - - constructor(baseUrl: String?, isPasswordUpdate: Boolean, username: String?, password: String?) : this() { - this.baseUrl = baseUrl - this.isPasswordUpdate = isPasswordUpdate - this.username = username - this.password = password - } + // constructor(baseUrl: String?, isPasswordUpdate: Boolean) : this() { + // this.baseUrl = baseUrl + // this.isPasswordUpdate = isPasswordUpdate + // } + // + // constructor(baseUrl: String?, isPasswordUpdate: Boolean, username: String?, password: String?) : this() { + // this.baseUrl = baseUrl + // this.isPasswordUpdate = isPasswordUpdate + // this.username = username + // this.password = password + // } private val webLoginUserAgent: String get() = ( @@ -129,33 +119,66 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( ")" ) + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) + + binding = ActivityWebViewLoginBinding.inflate(layoutInflater) + actionBar?.hide() + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + setContentView(binding.root) + setupSystemColors() + // viewThemeUtils.material.themeCardView(binding.searchToolbar) + // viewThemeUtils.material.themeSearchBarText(binding.searchText) + + // onBackPressedDispatcher.addCallback(this, onBackPressedCallback) + + + + val extras = intent.extras!! + baseUrl = extras.getString(KEY_BASE_URL) + username = extras.getString(KEY_USERNAME) + + + if (extras.containsKey(BundleKeys.KEY_IS_PASSWORD_UPDATE)) { + isPasswordUpdate = extras.getBoolean(BundleKeys.KEY_IS_PASSWORD_UPDATE) + } + + if (extras.containsKey(BundleKeys.KEY_PASSWORD)) { + password = extras.getString(BundleKeys.KEY_PASSWORD) + } + } + @SuppressLint("SetJavaScriptEnabled") - override fun onViewBound(view: View) { - super.onViewBound(view) - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + override fun onResume() { + super.onResume() + + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT actionBar?.hide() assembledPrefix = resources!!.getString(R.string.nc_talk_login_scheme) + PROTOCOL_SUFFIX + "login/" - binding?.webview?.settings?.allowFileAccess = false - binding?.webview?.settings?.allowFileAccessFromFileURLs = false - binding?.webview?.settings?.javaScriptEnabled = true - binding?.webview?.settings?.javaScriptCanOpenWindowsAutomatically = false - binding?.webview?.settings?.domStorageEnabled = true - binding?.webview?.settings?.setUserAgentString(webLoginUserAgent) - binding?.webview?.settings?.saveFormData = false - binding?.webview?.settings?.savePassword = false - binding?.webview?.settings?.setRenderPriority(WebSettings.RenderPriority.HIGH) - binding?.webview?.clearCache(true) - binding?.webview?.clearFormData() - binding?.webview?.clearHistory() + binding.webview.settings.allowFileAccess = false + binding.webview.settings.allowFileAccessFromFileURLs = false + binding.webview.settings.javaScriptEnabled = true + binding.webview.settings.javaScriptCanOpenWindowsAutomatically = false + binding.webview.settings.domStorageEnabled = true + binding.webview.settings.setUserAgentString(webLoginUserAgent) + binding.webview.settings.saveFormData = false + binding.webview.settings.savePassword = false + binding.webview.settings.setRenderPriority(WebSettings.RenderPriority.HIGH) + binding.webview.clearCache(true) + binding.webview.clearFormData() + binding.webview.clearHistory() WebView.clearClientCertPreferences(null) - webViewFidoBridge = WebViewFidoBridge.createInstanceForWebView(activity as AppCompatActivity?, binding?.webview) - CookieSyncManager.createInstance(activity) + webViewFidoBridge = WebViewFidoBridge.createInstanceForWebView(this, binding.webview) + CookieSyncManager.createInstance(this) android.webkit.CookieManager.getInstance().removeAllCookies(null) val headers: MutableMap = HashMap() - headers.put("OCS-APIRequest", "true") - binding?.webview?.webViewClient = object : WebViewClient() { + headers["OCS-APIRequest"] = "true" + binding.webview.webViewClient = object : WebViewClient() { private var basePageLoaded = false override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? { webViewFidoBridge?.delegateShouldInterceptRequest(view, request) @@ -180,24 +203,24 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( override fun onPageFinished(view: WebView, url: String) { loginStep++ if (!basePageLoaded) { - binding?.progressBar?.visibility = View.GONE - binding?.webview?.visibility = View.VISIBLE + binding.progressBar.visibility = View.GONE + binding.webview.visibility = View.VISIBLE basePageLoaded = true } if (!TextUtils.isEmpty(username)) { if (loginStep == 1) { - binding?.webview?.loadUrl( + binding.webview.loadUrl( "javascript: {document.getElementsByClassName('login')[0].click(); };" ) } else if (!automatedLoginAttempted) { automatedLoginAttempted = true if (TextUtils.isEmpty(password)) { - binding?.webview?.loadUrl( + binding.webview.loadUrl( "javascript:var justStore = document.getElementById('user').value = '$username';" ) } else { - binding?.webview?.loadUrl( + binding.webview.loadUrl( "javascript: {" + "document.getElementById('user').value = '" + username + "';" + "document.getElementById('password').value = '" + password + "';" + @@ -214,7 +237,7 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( val user = userManager.currentUser.blockingGet() var alias: String? = null if (!isPasswordUpdate) { - alias = appPreferences!!.temporaryClientCertAlias + alias = appPreferences.temporaryClientCertAlias } if (TextUtils.isEmpty(alias) && user != null) { alias = user.clientCertificate @@ -223,9 +246,9 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( val finalAlias = alias Thread { try { - val privateKey = KeyChain.getPrivateKey(activity!!, finalAlias!!) + val privateKey = KeyChain.getPrivateKey(applicationContext, finalAlias!!) val certificates = KeyChain.getCertificateChain( - activity!!, + applicationContext, finalAlias ) if (privateKey != null && certificates != null) { @@ -241,16 +264,16 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( }.start() } else { KeyChain.choosePrivateKeyAlias( - activity!!, + this@WebViewLoginActivity, { chosenAlias: String? -> if (chosenAlias != null) { appPreferences!!.temporaryClientCertAlias = chosenAlias Thread { var privateKey: PrivateKey? = null try { - privateKey = KeyChain.getPrivateKey(activity!!, chosenAlias) + privateKey = KeyChain.getPrivateKey(applicationContext, chosenAlias) val certificates = KeyChain.getCertificateChain( - activity!!, + applicationContext, chosenAlias ) if (privateKey != null && certificates != null) { @@ -304,9 +327,14 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( super.onReceivedError(view, errorCode, description, failingUrl) } } - binding?.webview?.loadUrl("$baseUrl/index.php/login/flow", headers) + binding.webview.loadUrl("$baseUrl/index.php/login/flow", headers) } + + + + + private fun dispose() { if (userQueryDisposable != null && !userQueryDisposable!!.isDisposed) { userQueryDisposable!!.dispose() @@ -328,11 +356,13 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( if (userManager.checkIfUserIsScheduledForDeletion(loginData.username!!, baseUrl!!).blockingGet()) { ApplicationWideMessageHolder.getInstance().messageType = ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION - if (!isPasswordUpdate) { - router.popToRoot() - } else { - router.popCurrentController() - } + + // TODO .... + // if (!isPasswordUpdate) { + // router.popToRoot() + // } else { + // router.popCurrentController() + // } } val finalMessageType = messageType cookieManager.cookieStore.removeAll() @@ -350,11 +380,14 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( if (!TextUtils.isEmpty(protocol)) { bundle.putString(KEY_ORIGINAL_PROTOCOL, protocol) } - router.pushController( - RouterTransaction.with(AccountVerificationController(bundle)) - .pushChangeHandler(HorizontalChangeHandler()) - .popChangeHandler(HorizontalChangeHandler()) - ) + // router.pushController( + // RouterTransaction.with(AccountVerificationActivity(bundle)) + // .pushChangeHandler(HorizontalChangeHandler()) + // .popChangeHandler(HorizontalChangeHandler()) + // ) + val intent = Intent(context, AccountVerificationActivity::class.java) + intent.putExtras(bundle) + startActivity(intent) } else { if (isPasswordUpdate) { if (currentUser != null) { @@ -379,7 +412,8 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( .build() WorkManager.getInstance().enqueue(pushRegistrationWork) - router.popCurrentController() + // TODO: start ServerSelectionActivity? + // router.popCurrentController() } } else { if (finalMessageType != null) { @@ -388,7 +422,8 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( // The token is not updated in the database and therefore the account not visible/usable ApplicationWideMessageHolder.getInstance().messageType = finalMessageType } - router.popToRoot() + // TODO: start ServerSelectionActivity? + // router.popToRoot() } } } @@ -432,30 +467,11 @@ class WebViewLoginController(args: Bundle? = null) : BaseController( } } - override fun onAttach(view: View) { - super.onAttach(view) - if (activity != null && resources != null) { - DisplayUtils.applyColorToStatusBar( - activity, - ResourcesCompat.getColor(resources!!, R.color.colorPrimary, null) - ) - DisplayUtils.applyColorToNavigationBar( - activity!!.window, - ResourcesCompat.getColor(resources!!, R.color.colorPrimary, null) - ) - } - } - public override fun onDestroy() { super.onDestroy() dispose() } - override fun onDestroyView(view: View) { - super.onDestroyView(view) - activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR - } - init { sharedApplication!!.componentApplication.inject(this) } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt index 18737bc5ab8..d1d3d9b5868 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.kt @@ -44,10 +44,10 @@ import com.nextcloud.talk.R import com.nextcloud.talk.activities.MainActivity import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication -import com.nextcloud.talk.controllers.AccountVerificationController -import com.nextcloud.talk.controllers.ServerSelectionController +import com.nextcloud.talk.controllers.AccountVerificationActivity +import com.nextcloud.talk.controllers.ServerSelectionActivity import com.nextcloud.talk.controllers.SwitchAccountController -import com.nextcloud.talk.controllers.WebViewLoginController +import com.nextcloud.talk.controllers.WebViewLoginActivity import com.nextcloud.talk.controllers.base.providers.ActionBarProvider import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.preferences.AppPreferences @@ -274,9 +274,9 @@ abstract class BaseController(@LayoutRes var layoutRes: Int, args: Bundle? = nul // TODO: check if this must be migrated when using activities instead of conductor private fun cleanTempCertPreference() { val temporaryClassNames: MutableList = ArrayList() - temporaryClassNames.add(ServerSelectionController::class.java.name) - temporaryClassNames.add(AccountVerificationController::class.java.name) - temporaryClassNames.add(WebViewLoginController::class.java.name) + temporaryClassNames.add(ServerSelectionActivity::class.java.name) + temporaryClassNames.add(AccountVerificationActivity::class.java.name) + temporaryClassNames.add(WebViewLoginActivity::class.java.name) temporaryClassNames.add(SwitchAccountController::class.java.name) if (!temporaryClassNames.contains(javaClass.name)) { appPreferences.removeTemporaryClientCertAlias() diff --git a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt index d5b9cae6e5a..35be056fdfe 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt @@ -86,4 +86,6 @@ object BundleKeys { const val KEY_GEOCODING_RESULT = "KEY_GEOCODING_RESULT" const val ADD_ACCOUNT = "ADD_ACCOUNT" // temp workaround until conductor is removed const val SAVED_TRANSLATED_MESSAGE = "SAVED_TRANSLATED_MESSAGE" + const val KEY_IS_PASSWORD_UPDATE = "KEY_IS_PASSWORD_UPDATE" + const val KEY_PASSWORD = "KEY_PASSWORD" } diff --git a/app/src/main/res/layout/controller_account_verification.xml b/app/src/main/res/layout/activity_account_verification.xml similarity index 100% rename from app/src/main/res/layout/controller_account_verification.xml rename to app/src/main/res/layout/activity_account_verification.xml diff --git a/app/src/main/res/layout/controller_server_selection.xml b/app/src/main/res/layout/activity_server_selection.xml similarity index 100% rename from app/src/main/res/layout/controller_server_selection.xml rename to app/src/main/res/layout/activity_server_selection.xml diff --git a/app/src/main/res/layout/controller_web_view_login.xml b/app/src/main/res/layout/activity_web_view_login.xml similarity index 100% rename from app/src/main/res/layout/controller_web_view_login.xml rename to app/src/main/res/layout/activity_web_view_login.xml