Reformatted BaseConnectivityActivity, moved RESPONSE_CODE_API_OFFLINE to Contstants, also changed log level in onCancel in ProtonMailBaseJob.
MAILAND-999
This commit is contained in:
parent
f1de20e965
commit
28b9dda5ef
|
@ -27,80 +27,89 @@ import butterknife.BindView
|
|||
import ch.protonmail.android.R
|
||||
import ch.protonmail.android.jobs.PingJob
|
||||
import ch.protonmail.android.utils.INetworkConfiguratorCallback
|
||||
import ch.protonmail.android.utils.Logger
|
||||
import ch.protonmail.android.utils.NetworkUtil
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.snackbar.SnackbarContentLayout
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Created by dkadrikj on 11/2/15.
|
||||
*/
|
||||
abstract class BaseConnectivityActivity : BaseActivity() {
|
||||
|
||||
// region constants
|
||||
const val TAG = "BaseConnectivityActivity"
|
||||
// endregion
|
||||
abstract class BaseConnectivityActivity: BaseActivity() {
|
||||
@BindView(R.id.layout_no_connectivity_info)
|
||||
protected lateinit var mSnackLayout: View
|
||||
var mNoConnectivitySnack: Snackbar? = null
|
||||
protected var mCheckForConnectivitySnack: Snackbar? = null
|
||||
|
||||
@BindView(R.id.layout_no_connectivity_info)
|
||||
protected lateinit var mSnackLayout: View
|
||||
var mNoConnectivitySnack: Snackbar? = null
|
||||
protected var mCheckForConnectivitySnack: Snackbar? = null
|
||||
protected var pingHandler = Handler()
|
||||
protected var pingRunnable: Runnable = Runnable { mJobManager.addJobInBackground(PingJob()) }
|
||||
|
||||
protected var pingHandler = Handler()
|
||||
protected var pingRunnable: Runnable = Runnable { mJobManager.addJobInBackground(PingJob()) }
|
||||
private var connectivityRetryListener = RetryListener()
|
||||
|
||||
private var connectivityRetryListener = RetryListener()
|
||||
protected open inner class RetryListener : View.OnClickListener {
|
||||
|
||||
protected open inner class RetryListener : View.OnClickListener {
|
||||
override fun onClick(v: View) {
|
||||
mCheckForConnectivitySnack = NetworkUtil.setCheckingConnectionSnackLayout(
|
||||
mSnackLayout,
|
||||
this@BaseConnectivityActivity
|
||||
)
|
||||
mCheckForConnectivitySnack!!.show()
|
||||
if (mNoConnectivitySnack != null && mNoConnectivitySnack!!.isShownOrQueued) {
|
||||
mNoConnectivitySnack!!.dismiss()
|
||||
}
|
||||
pingHandler.removeCallbacks(pingRunnable)
|
||||
pingHandler.postDelayed(pingRunnable, 3000)
|
||||
|
||||
override fun onClick(v: View) {
|
||||
mCheckForConnectivitySnack = NetworkUtil.setCheckingConnectionSnackLayout(mSnackLayout, this@BaseConnectivityActivity)
|
||||
mCheckForConnectivitySnack!!.show()
|
||||
if (mNoConnectivitySnack != null && mNoConnectivitySnack!!.isShownOrQueued) {
|
||||
mNoConnectivitySnack!!.dismiss()
|
||||
}
|
||||
pingHandler.removeCallbacks(pingRunnable)
|
||||
pingHandler.postDelayed(pingRunnable, 3000)
|
||||
|
||||
retryWithDoh()
|
||||
}
|
||||
}
|
||||
|
||||
protected fun retryWithDoh() {
|
||||
if (mNetworkUtil.isConnected()) {
|
||||
val thirdPartyConnectionsEnabled = mUserManager.user.allowSecureConnectionsViaThirdParties
|
||||
if (thirdPartyConnectionsEnabled) {
|
||||
Timber.d("Third party connections enabled, attempting DoH...")
|
||||
networkConfigurator.refreshDomainsAsync() // refreshDomains(false) // switch to new here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
protected fun showNoConnSnack(listener: RetryListener? = null, @StringRes message: Int = R.string.no_connectivity_detected_troubleshoot,
|
||||
view: View = mSnackLayout, callback: INetworkConfiguratorCallback) {
|
||||
val user = mUserManager.user
|
||||
mNoConnectivitySnack = mNoConnectivitySnack ?: NetworkUtil.setNoConnectionSnackLayout(view,
|
||||
this, listener ?: connectivityRetryListener, false, message, user, callback)
|
||||
mNoConnectivitySnack!!.show()
|
||||
val contentLayout = (mNoConnectivitySnack!!.view as ViewGroup).getChildAt(0) as SnackbarContentLayout
|
||||
val vvv: TextView = contentLayout.actionView
|
||||
mCheckForConnectivitySnack?.saveDismiss()
|
||||
|
||||
if (mUserManager.user.allowSecureConnectionsViaThirdParties && autoRetry && !isDohOngoing && !isFinishing) {
|
||||
window.decorView.postDelayed({ vvv.callOnClick() }, 500)
|
||||
retryWithDoh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected fun hideNoConnSnack() {
|
||||
mNoConnectivitySnack?.saveDismiss()
|
||||
mCheckForConnectivitySnack?.saveDismiss()
|
||||
}
|
||||
protected fun retryWithDoh() {
|
||||
if (mNetworkUtil.isConnected()) {
|
||||
val thirdPartyConnectionsEnabled = mUserManager.user.allowSecureConnectionsViaThirdParties
|
||||
if (thirdPartyConnectionsEnabled) {
|
||||
Timber.d("Third party connections enabled, attempting DoH...")
|
||||
networkConfigurator.refreshDomainsAsync() // refreshDomains(false) // switch to new here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Snackbar.saveDismiss() {
|
||||
@JvmOverloads
|
||||
protected fun showNoConnSnack(
|
||||
listener: RetryListener? = null,
|
||||
@StringRes message: Int = R.string.no_connectivity_detected_troubleshoot,
|
||||
view: View = mSnackLayout,
|
||||
callback: INetworkConfiguratorCallback
|
||||
) {
|
||||
val user = mUserManager.user
|
||||
mNoConnectivitySnack = mNoConnectivitySnack ?: NetworkUtil.setNoConnectionSnackLayout(
|
||||
view,
|
||||
this,
|
||||
listener ?: connectivityRetryListener,
|
||||
false,
|
||||
message,
|
||||
user,
|
||||
callback
|
||||
)
|
||||
mNoConnectivitySnack!!.show()
|
||||
val contentLayout = (mNoConnectivitySnack!!.view as ViewGroup).getChildAt(0) as SnackbarContentLayout
|
||||
val vvv: TextView = contentLayout.actionView
|
||||
mCheckForConnectivitySnack?.saveDismiss()
|
||||
|
||||
if (mUserManager.user.allowSecureConnectionsViaThirdParties && autoRetry && !isDohOngoing && !isFinishing) {
|
||||
window.decorView.postDelayed(
|
||||
{ vvv.callOnClick() },
|
||||
500
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun hideNoConnSnack() {
|
||||
mNoConnectivitySnack?.saveDismiss()
|
||||
mCheckForConnectivitySnack?.saveDismiss()
|
||||
}
|
||||
|
||||
private fun Snackbar.saveDismiss() {
|
||||
if (isShownOrQueued) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,12 +100,12 @@ class NetworkConfigurator @Inject constructor(
|
|||
}
|
||||
|
||||
val proxies =
|
||||
if (alternativeProxyList.isEmpty()) {
|
||||
// if the new list is empty, try with the old list perhaps there will be an api url available there
|
||||
Proxies.getInstance(null, prefs) // or just try the last used proxy
|
||||
} else {
|
||||
Proxies.getInstance(ProxyList(alternativeProxyList), prefs)
|
||||
}
|
||||
if (alternativeProxyList.isEmpty()) {
|
||||
// if the new list is empty, try with the old list perhaps there will be an api url available there
|
||||
Proxies.getInstance(null, prefs) // or just try the last used proxy
|
||||
} else {
|
||||
Proxies.getInstance(ProxyList(alternativeProxyList), prefs)
|
||||
}
|
||||
|
||||
// supplying proxy list means that the savings will be invalidated
|
||||
// val proxies = Proxies.getInstance(ProxyList(alternativeProxyList), prefs)
|
||||
|
|
|
@ -53,7 +53,6 @@ const val RESPONSE_CODE_NEW_PASSWORD_MESSED_UP = 12020
|
|||
const val RESPONSE_CODE_ATTACHMENT_DELETE_ID_INVALID = 11123
|
||||
const val RESPONSE_CODE_INVALID_APP_CODE = 5002
|
||||
const val RESPONSE_CODE_FORCE_UPGRADE = 5003
|
||||
const val RESPONSE_CODE_API_OFFLINE = 7001
|
||||
const val RESPONSE_CODE_RECIPIENT_NOT_FOUND = 33102
|
||||
const val RESPONSE_CODE_INVALID_EMAIL = 12065
|
||||
const val RESPONSE_CODE_INCORRECT_PASSWORD = 12066
|
||||
|
|
|
@ -27,4 +27,4 @@ class ConnectivityApi(val pingService: PingService) : BaseApi(), ConnectivityApi
|
|||
override fun ping(): ResponseBody = ParseUtils.parse(pingService.ping().execute())
|
||||
|
||||
override suspend fun pingAsync(): ResponseBody = pingService.pingAsync().body()!!
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,4 @@ interface ConnectivityApiSpec {
|
|||
fun ping(): ResponseBody
|
||||
|
||||
suspend fun pingAsync(): ResponseBody
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,12 +94,10 @@ object Constants {
|
|||
// Address types
|
||||
const val ADDRESS_TYPE_PRIMARY = 1
|
||||
|
||||
// BCrypt
|
||||
const val BCRYPT_PREFIX = "$2a$10$"
|
||||
|
||||
// Response codes
|
||||
const val RESPONSE_CODE_OK = 1000
|
||||
const val RESPONSE_CODE_MULTIPLE_OK = 1001
|
||||
const val RESPONSE_CODE_API_OFFLINE = 7001
|
||||
|
||||
// JobIntentService IDs
|
||||
const val JOB_INTENT_SERVICE_ID_EVENT_UPDATER = 870
|
||||
|
|
|
@ -28,8 +28,6 @@ import ch.protonmail.android.core.Constants;
|
|||
import ch.protonmail.android.events.ConnectivityEvent;
|
||||
import ch.protonmail.android.utils.AppUtil;
|
||||
|
||||
import static ch.protonmail.android.api.segments.BaseApiKt.RESPONSE_CODE_API_OFFLINE;
|
||||
|
||||
/**
|
||||
* Created by dkadrikj on 10/27/15.
|
||||
*/
|
||||
|
@ -51,7 +49,7 @@ public class PingJob extends ProtonMailBaseJob {
|
|||
ResponseBody ping = getApi().ping();
|
||||
if (ping.getCode() == Constants.RESPONSE_CODE_OK) {
|
||||
return true;
|
||||
} else if (ping.getCode() == RESPONSE_CODE_API_OFFLINE) {
|
||||
} else if (ping.getCode() == Constants.RESPONSE_CODE_API_OFFLINE) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -67,9 +67,9 @@ import ch.protonmail.android.events.ForceUpgradeEvent;
|
|||
import ch.protonmail.android.storage.AttachmentClearingService;
|
||||
import ch.protonmail.android.storage.MessageBodyClearingService;
|
||||
|
||||
import static ch.protonmail.android.api.segments.BaseApiKt.RESPONSE_CODE_API_OFFLINE;
|
||||
import static ch.protonmail.android.api.segments.BaseApiKt.RESPONSE_CODE_FORCE_UPGRADE;
|
||||
import static ch.protonmail.android.api.segments.BaseApiKt.RESPONSE_CODE_INVALID_APP_CODE;
|
||||
import static ch.protonmail.android.core.Constants.RESPONSE_CODE_API_OFFLINE;
|
||||
import static ch.protonmail.android.core.ProtonMailApplication.getApplication;
|
||||
import static ch.protonmail.android.core.UserManagerKt.PREF_PIN;
|
||||
import static ch.protonmail.android.prefs.SecureSharedPreferencesKt.PREF_SYMMETRIC_KEY;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package ch.protonmail.android.worker
|
||||
|
||||
import org.junit.Before
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
class PingWorkerTest {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue