From 31ab716ab3d31bc4cb23bd81cec24037d7514e6c Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Wed, 26 Aug 2020 13:10:49 +0300 Subject: [PATCH] Fixed a bug of updating labels. Refactored code.| #716 --- .../accounts/FlowcryptAccountAuthenticator.kt | 2 +- .../email/ui/activity/EmailManagerActivity.kt | 6 ++--- .../ui/activity/fragment/EmailListFragment.kt | 23 ++++++++++++++----- FlowCrypt/src/main/res/values/ids.xml | 3 +-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/accounts/FlowcryptAccountAuthenticator.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/accounts/FlowcryptAccountAuthenticator.kt index 9fda7dbe02..6c4b6644fa 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/accounts/FlowcryptAccountAuthenticator.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/accounts/FlowcryptAccountAuthenticator.kt @@ -71,7 +71,7 @@ class FlowcryptAccountAuthenticator(val context: Context) : AbstractAccountAuthe try { val refreshToken = KeyStoreCryptoManager.decrypt(encryptedRefreshToken) val apiService = ApiHelper.getInstance(context).retrofit.create(ApiService::class.java) - val apiResponse = apiService.refreshMicrosoftOAuth2Token(refreshToken + " 12").execute() + val apiResponse = apiService.refreshMicrosoftOAuth2Token(refreshToken).execute() if (apiResponse.isSuccessful) { val tokenResponse = apiResponse.body() authToken = KeyStoreCryptoManager.encrypt(tokenResponse?.accessToken) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt index 1ed0b67801..98a26d033c 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/EmailManagerActivity.kt @@ -344,7 +344,7 @@ class EmailManagerActivity : BaseEmailListActivity(), NavigationView.OnNavigatio onRefreshMsgsCompleted() } - R.id.syns_request_code_update_label_passive, R.id.syns_request_code_update_label_active -> { + R.id.syns_request_code_update_labels -> { onErrorOccurred(requestCode, errorType, e) } @@ -366,7 +366,7 @@ class EmailManagerActivity : BaseEmailListActivity(), NavigationView.OnNavigatio override fun onSyncServiceConnected() { super.onSyncServiceConnected() - updateLabels(R.id.syns_request_code_update_label_passive) + updateLabels(R.id.syns_request_code_update_labels) } override fun onBackPressed() { @@ -768,7 +768,7 @@ class EmailManagerActivity : BaseEmailListActivity(), NavigationView.OnNavigatio super.onDrawerOpened(drawerView) if (GeneralUtil.isConnected(this@EmailManagerActivity)) { - updateLabels(R.id.syns_request_code_update_label_passive) + updateLabels(R.id.syns_request_code_update_labels) } labelsViewModel.updateOutboxMsgsCount() diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/EmailListFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/EmailListFragment.kt index 193bc53669..46f2b89bd4 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/EmailListFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/EmailListFragment.kt @@ -5,6 +5,7 @@ package com.flowcrypt.email.ui.activity.fragment +import android.accounts.AuthenticatorException import android.content.Context import android.content.Intent import android.graphics.Canvas @@ -262,6 +263,7 @@ class EmailListFragment : BaseSyncFragment(), SwipeRefreshLayout.OnRefreshListen if (localFolder == null) { swipeRefreshLayout?.isRefreshing = false + baseSyncActivity.updateLabels(R.id.syns_request_code_update_labels) return } @@ -334,17 +336,26 @@ class EmailListFragment : BaseSyncFragment(), SwipeRefreshLayout.OnRefreshListen } } - R.id.syns_request_code_update_label_passive, R.id.syns_request_code_update_label_active -> + R.id.syns_request_code_update_labels -> if (listener?.currentFolder == null) { var errorMsg = getString(R.string.failed_load_labels_from_email_server) - if (e is AuthenticationFailedException) { - if (getString(R.string.gmail_imap_disabled_error).equals(e.message, ignoreCase = true)) { - errorMsg = getString(R.string.it_seems_imap_access_is_disabled) + when (e) { + is AuthenticationFailedException -> { + if (getString(R.string.gmail_imap_disabled_error).equals(e.message, ignoreCase = true)) { + errorMsg = getString(R.string.it_seems_imap_access_is_disabled) + super.onErrorOccurred(requestCode, errorType, Exception(errorMsg)) + } + } + + is AuthenticatorException -> { + super.onErrorOccurred(requestCode, errorType, e) } - } - super.onErrorOccurred(requestCode, errorType, Exception(errorMsg)) + else -> { + super.onErrorOccurred(requestCode, errorType, Exception(errorMsg)) + } + } setSupportActionBarTitle("") } diff --git a/FlowCrypt/src/main/res/values/ids.xml b/FlowCrypt/src/main/res/values/ids.xml index bb60f3af7a..3430e4e4af 100644 --- a/FlowCrypt/src/main/res/values/ids.xml +++ b/FlowCrypt/src/main/res/values/ids.xml @@ -6,8 +6,7 @@ - - +