Skip to content

Commit

Permalink
Fixed a bug of updating labels. Refactored code.| #716
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Aug 26, 2020
1 parent 1c3416c commit 31ab716
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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("")
}

Expand Down
3 changes: 1 addition & 2 deletions FlowCrypt/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<resources>
<item name="loader_id_parse_public_keys" type="id" />

<item name="syns_request_code_update_label_passive" type="id" />
<item name="syns_request_code_update_label_active" type="id" />
<item name="syns_request_code_update_labels" type="id" />
<item name="syns_request_code_load_next_messages" type="id" />
<item name="syns_request_code_refresh_msgs" type="id" />
<item name="syns_request_code_load_raw_mime_msg" type="id" />
Expand Down

0 comments on commit 31ab716

Please sign in to comment.